Decoding hash with solidity

we know how to generate a hash with keccak256 and abi.encodePacked, but is it possible to do the reverse?

That is to say how to decode a hash in solidity?

No, that is sort of the whole point of hashing

So, how do you retrieve the information in the hashed blocks? If you store data structures in a merckle tree, they are hashes of hashes. , you must be able to reverse the process?

I understand that contracts are also hashed. How would they process the information in the nodes if they are irreversibly encapsulated?
Are you sure that a hash cannot be reversed?

Fundamentally hashing can’t be reversed. The idea is that the original data can’t be determined from the hash outside of trying every possible input to find it. They can be verified by using the original data or data acting as proof which is hashed the same way to compare hashes e.g. like an account’s password.

I’m not sure what you mean by hashed blocks. Contracts aren’t hashed.

What are you looking to do?

Yes, it is apparent that I am not clear on the cryptographic principles of blockchain and must be mixing topics.

I think it’s going to be easier to comment on what I want to do.

I’m already sending signed messages to a contract. A hash of data signed by an account.
The contract checks to see if it has been signed by the validating account, and then as you commented, checks that the hash is the correct message with the original data, which is the idGame of the game and the address of the contract on the blockchain.

   function whoSign(uint _idGame, bytes memory signature) internal view returns(bool) {

                // this recreates the message that was signed on the client
        bytes32 message = prefixed(keccak256(abi.encodePacked(_idGame, this)));

              require(recoverSigner(message, signature) == serverAddress, "Security failure");

        return true;
    }

What I am looking for is to send an encrypted and signed message. I don’t care if later this message can be seen on the blockchain. What I want is that the client does not know what is signed.

Example:
The game server sends me back a signed message with my position. I would like that message could not be decrypted until it reaches the blockchain.

What I am looking for is that the client does not know in which position he has been until the contract indicates it. And if I have to send the information that reviews the signed hash, he knows in which position he is.

I hope I have been understood.
Sorry for my English.

If you could outline your program flow step by step and what you want achieved, that would make things clearer, since you’re also using a server. I’m confused by a few things.

Ok, let’s do some sheudocode.

1º A player finishes a game in a game on another server.
2º This server signs a message, has inside a wallet for it, with the position that has been in a game, “Idgame”.
3º Receives the message, and sends it to the blockchain to collect his prize, if he has been in positions with benefits. (This is what I don’t want the player to know, because the signed message has to be sent also to check the hash in the blockchain).
4º The blockchain receives the signed message: It checks that it has been signed by the server account. It reads the message and pays if it is the right thing to do.

If I manage to send the encrypted message the player will not know in which position he has been. So far I send the position and the IdGame of the game together with the signed message to be checked in the blockchain.

I want to avoid capturing a signed message with a position that does not correspond to the player. That’s why it should not know that it is sent until the blockchain responds.

Who or what receives the message in step 3? The user? Does the contract determine the correct positions entirely or is this determined by the server?

Can the server not send the message directly to your contract from step 1 with the user’s position?

I have succeeded. Now the server sends the winning positions in a custom signed hash with each player’s account. The server that signs these hashes is the one of the game that has a wallet for it.

1 Like