How to reverse keccak256 in solidity
- Smart Contract
- Solidity 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();
}
}
}
Answers 2
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 :
Hint: It's a very common...
=> Take a look at what are the most used passwords- https://arbiscan.io/address/0xf988Ebf9D801F4D3595592490D7fF029E438deCa is the contract in question. Because we are on the blockchain, you can see everything! Take a look at other people's transactions ;)
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)