You see the "Guess the secret number" page, as shown below.
Read the Solidity code. Notice these things:
In this case, the input is only 8 bits long, so there are only 256 possible values. from 0 to 255.
Right-click the contracts folder and click "New File".
Name the new file crack.sol
Paste in the code below.
pragma solidity ^0.4.21;
contract crack{
bytes32 answerHash = 0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365;
function check() public view returns(uint8) {
for (uint8 i=0; i<256; i++) {
if (keccak256(i) == answerHash) {
return i;
}
}
}
}
On the left side of the Remix page, click the Compile icon, outlined in red in the image above.
Click the "Compile crack.sol" button.
Then click the Deploy icon, outlined in light blue in the image above.
In the "DEPLOY & RUN TRANSACTIONS" pane, at the top, change the ENVIRONMENT to "JavaScript VM (London)", outlined in green in the image below.
Click the orange Deploy button.
At the bottom of the "DEPLOY & RUN TRANSACTIONS" pane, expand the "CRACK AT ..." container.
Click the blue-gray check button.
The answer appears, covered by a red rectangle in the image below. Make a note of it.
A MetaMask box pops up.
Click Confirm.
After a few seconds, the left side of the page shows your contract's address, as shown below.
Right-click the contracts folder and click "New File".
Name the new file secret.sol
Paste in the code from the "Guess the secret number" page, as shown below.
On the left side of the Remix page, click the Compile icon, outlined in red in the image above.
Click the "Compile secret.sol" button.
Then click the Deploy icon, outlined in light blue in the image above.
On the "Guess the secret number" page, copy the address of your deployed contract.
In the Remix page, in the lower portion of the "DEPLOY & RUN TRANSACTIONS" pane, paste that address into the box next to the "At Address" button, outlined in red in the image below.
Click the "At Address" button.
In the field next to the red guess button, enter the answer you found from your crack contract, covered by a green rectangle in the image above.
Enter a VALUE of 1 Ether, outlined in light blue in the image above.
Click the red guess button.
If a box pops up saying "Gas estimation failed", click "Send Transaction".
A MetaMask box pops up. Notice that the amount sent is less than 1 ETH, outlined in blue in the image above.
Click Confirm.
At the lower right, a green check mark appears, showing that the transaction succeeded.
Flag C 604.1 Number (15 pts)
The flag is the number you sent, covered by a green rectangle in the image above.
A MetaMask box pops up. Click Confirm. You win, and a little dancing figure appears on the lower left, as shown below.
Posted 5-20-22 by Sam Bowne