0

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();
        }
    }
}

1 Answer 1

1

keccak256 is a one-way cryptographic hash function, which cannot be decoded in reverse. It is a trick! Anyhow, solution below:

const EXPECTED_BYTES = keccak256('password')`

You can use this tool as a reference:

https://emn178.github.io/online-tools/keccak_256.html

Enter 'password' and generate the keccak256 online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.