Solidity.

Post

Share your knowledge.

0x0375...f041.
Jul 10, 2023
Expert Q&A

How to reverse keccak256 in solidity

I need help with the following code where I'm given the keccak256 of a parameter and need to reverse it to find the parameter to solve the challenge

contract LessonFive is AFoundryCourseChallenge {
    error LessonFive__WrongPassword();

    bytes32 public constant EXPECTED_BYTES = 0xb68fe43f0d1a0d7aef123722670be50268e15365401c442f8806ef83b612976b;


    /*
     * CALL THIS FUNCTION!
     * 
     * Use all the help you can on this one! Google, AI, friends, peeranha, ethereum stack exchange, etc. 
     * 
     * Hint: It's a very common...
     * 
     * @param password - A string that when you keccak256 it will return the `EXPECTED_BYTES`!
     * @param yourTwitterHandle - Your twitter handle. Can be a blank string.
     */
    function solveChallenge(string memory password, string memory yourTwitterHandle) external {
        if (keccak256(abi.encodePacked(password)) == EXPECTED_BYTES) {
            _updateAndRewardSolver(yourTwitterHandle);
        } else {
            revert LessonFive__WrongPassword();
        }
    }
}
  • Smart Contract
  • Solidity
2
2
Share
Comments
.

Answers

2
0x7a36...df11.
Jul 15 2023, 13:06

you can't reverse a keccak256 hash output to find its input. This property is fundamental to how blockchain networks achieve data integrity and security. keccak256 is designed to be a one-way function: it's computationally easy to generate a hash from input data, but it's computationally infeasible to generate the original input given only the hash output. here you can only brute force out as in a hint. Tipo "querty" to try to enter. I can't reproduce myself. you see your contract is inherited from the AFoundryCourseChallenge contract. Can you attach the code of this contract, MB there is something interesting)

1
Comments
.
foufrix.
Jul 21 2023, 10:14

As the previous message said, it's impossible to reverse keccak256 as it will break the security hash.

I've also participated in the lesson you are talking about, and there are two hints there :

0
Comments
.

Do you know the answer?

Please log in and share it.

We use cookies to ensure you get the best experience on our website.
More info