Guess the secret number
1. 题目
1.1 Putting the answer in the code makes things a little too easy.
This time I’ve only stored the hash of the number. Good luck reversing a cryptographic hash!
1.2 题目代码:
1 | // SPDX-License-Identifier: MIT |
2. 分析
- 2.1 这是我第一次感觉自己能想出来的题目了。。。。
- 2.2 反正 uint8 的范围是 0-256 嘛,直接 循环一个一个蛮力法,一个一个试出来
- 2.3 写一个Hack 合约来计算,哈希值为 :
0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365
的数字 - Hack 合约代码:
1 | contract Hack { |
- 运行求出来的结果是 :170
3. 解题
- 3.1 部署合约
- 3.2 将
170
作为参数,调用guss() 函数 - 3.3 同时前两步操作都需要将 msg.value 设置为 1 ether
- 