Skip to content

Commit d0071ef

Browse files
committed
Add study notes for 2025-08-19
1 parent a0fa6f4 commit d0071ef

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

adureychloe.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,150 @@ timezone: UTC+8
1515
## Notes
1616

1717
<!-- Content_START -->
18+
# 2025-08-19
19+
20+
智能合约实战:OpenZeppelin的Ethernaut挑战
21+
22+
## 第一关:Hello Ethernaut
23+
24+
### 配置钱包
25+
26+
连接钱包,切换到Sepolia测试网。
27+
28+
### 打开浏览器控制台
29+
30+
F12打开浏览器开发者模式,在控制台下输入命令:
31+
32+
```js
33+
player
34+
```
35+
36+
得到玩家地址
37+
38+
![9cb99466b4ef33e557b564b9956bd07e](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019697.PNG)
39+
40+
通过以下命令得到账户余额:
41+
42+
```js
43+
getBalance(player)
44+
```
45+
46+
![dbce830c35d05a6a586ec252042f343a](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019534.PNG)
47+
48+
### ethernaut 合约
49+
50+
```js
51+
ethernaut
52+
```
53+
54+
得到游戏的主要合约,展开来可以和ABI互动:
55+
56+
![39f551a5d75cb149eded5d922674d773](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019643.PNG)
57+
58+
`ethernaut` 是一个 `TruffleContract` 对象, 它包装了部署在区块链上的 `Ethernaut.sol` 合约.
59+
60+
除此之外,合约的 ABI 还提供了所有的 `Ethernaut.sol` 公开方法, 比如 `owner`. 比如输入以下命令:
61+
62+
```js
63+
ethernaut.owner()
64+
```
65+
66+
![3e3fc37045bea203a28cee62bcb1d15a](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019655.PNG)
67+
68+
可以看到合约的拥有者是谁
69+
70+
### 获得关卡实例
71+
72+
请求生成一个level instance,点击页面下方的按钮,钱包会发送请求,部署一个新的合约。
73+
74+
![ea0bcb4f29a5a1927e4e9dc62de988e1](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019181.PNG)
75+
76+
![1ff65b79379e306da6aeb943c940a392](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019187.PNG)
77+
78+
输入 contract 变量来观察这个合约的ABI:
79+
80+
![d1ed8f404e3a01c0edcca44fa2b9f5b5](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224016426.PNG)
81+
82+
### 合约互动
83+
84+
查看info方法,开始得到通关信息:
85+
86+
![60e78d1f167d12dc20dab3b4f980c560](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019197.PNG)
87+
88+
根据提示,调用info1方法后调用info2并传入参数“hello”:
89+
90+
![19ab34df259610b4ca0836aaa5dc1bec](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224016415.PNG)
91+
92+
然后又要调用属性infoNum:
93+
94+
![d7dd13ac0120da749cec163271baf6ba](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019585.PNG)
95+
96+
得到数字42,调用info42方法,又要调用另一个方法:
97+
98+
![1d1710cbacb20549ce214a8c7037cfed](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224016423.PNG)
99+
100+
一直套娃,最后输入认证方法和密码:
101+
102+
![1d712c00a7dd2d3b9678641ad0daee32](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019175.PNG)
103+
104+
![b676f469aed1f6ade11da76e43592b61](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224031694.PNG)
105+
106+
认证成功,通关!!!
107+
108+
![8db4142706a813fbf878f169fb9a3b98](https://adurey-picture.oss-cn-chengdu.aliyuncs.com/img/20250819224019191.PNG)
109+
110+
### 整体代码
111+
112+
```solidity
113+
// SPDX-License-Identifier: MIT
114+
pragma solidity ^0.8.0;
115+
116+
contract Instance {
117+
string public password;
118+
uint8 public infoNum = 42;
119+
string public theMethodName = "The method name is method7123949.";
120+
bool private cleared = false;
121+
122+
// constructor
123+
constructor(string memory _password) {
124+
password = _password;
125+
}
126+
127+
function info() public pure returns (string memory) {
128+
return "You will find what you need in info1().";
129+
}
130+
131+
function info1() public pure returns (string memory) {
132+
return 'Try info2(), but with "hello" as a parameter.';
133+
}
134+
135+
function info2(string memory param) public pure returns (string memory) {
136+
if (keccak256(abi.encodePacked(param)) == keccak256(abi.encodePacked("hello"))) {
137+
return "The property infoNum holds the number of the next info method to call.";
138+
}
139+
return "Wrong parameter.";
140+
}
141+
142+
function info42() public pure returns (string memory) {
143+
return "theMethodName is the name of the next method.";
144+
}
145+
146+
function method7123949() public pure returns (string memory) {
147+
return "If you know the password, submit it to authenticate().";
148+
}
149+
150+
function authenticate(string memory passkey) public {
151+
if (keccak256(abi.encodePacked(passkey)) == keccak256(abi.encodePacked(password))) {
152+
cleared = true;
153+
}
154+
}
155+
156+
function getCleared() public view returns (bool) {
157+
return cleared;
158+
}
159+
}
160+
```
161+
18162
# 2025-08-18
19163

20164
今天了解了一下SocialFi协议Farcaster。

0 commit comments

Comments
 (0)