Skip to content

Commit

Permalink
Merge pull request #561 from epitaphial/main
Browse files Browse the repository at this point in the history
Correct the doc about behavior after selfdestruct
  • Loading branch information
AmazingAng authored Nov 6, 2023
2 parents 4a8def7 + 2a06c45 commit b3e1088
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Binary file modified 26_DeleteContract/img/26-1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 26_DeleteContract/img/26-2.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions 26_DeleteContract/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ contract DeleteContract {

部署好合约后,我们向`DeleteContract`合约转入1 `ETH`。这时,`getBalance()`会返回1 `ETH``value`变量是10。

当我们调用`deleteContract()`函数,合约将自毁,所有变量都清空,此时`value`变为默认值`0``getBalance()`也返回空值
当我们调用`deleteContract()`函数,合约将自毁,此时再次调用合约函数交互会失败

### 注意事项
1. 对外提供合约销毁接口时,最好设置为只有合约所有者可以调用,可以使用函数修饰符`onlyOwner`进行函数声明。

2. 当合约被销毁后与智能合约的交互也能成功,并且返回0
2. 当合约被销毁后再次与合约函数交互会报error

3. 当合约中有`selfdestruct`功能时常常会带来安全问题和信任问题,合约中的Selfdestruct功能会为攻击者打开攻击向量(例如使用`selfdestruct`向一个合约频繁转入token进行攻击,这将大大节省了GAS的费用,虽然很少人这么做),此外,此功能还会降低用户对合约的信心。

### 在remix上验证
1. 部署合约并且转入1ETH,查看合约状态

![deployContract.png](./img/26-2.png)
![deployContract.png](./img/26-1.png)

2. 销毁合约,查看合约状态

![deleteContract.png](./img/26-1.png)
![deleteContract.png](./img/26-2.png)

从测试中观察合约状态可以发现合约销毁后的ETH返回给了指定的地址,并且在合约销毁后依然可以请求交互,所以我们不能根据这个来判断合约是否已经销毁
从测试中观察合约状态可以发现合约销毁后的ETH返回给了指定的地址,在合约销毁后再次调用合约函数进行交互则会失败


## 总结
Expand Down

0 comments on commit b3e1088

Please sign in to comment.