jiang

jiang

Man who has not escaped from low-class level taste.

DamnVulnerableDeFi-Unstoppable题解

概述#

Damn Vulnerable DeFi 是学习以太坊 DeFi 智能合约攻击性安全的 CTF 游戏。

该游戏涵盖了闪电贷、价格预言机、治理、非同质化代币(NFT)、去中心化交易所(DEX)、借贷池、智能合约钱包、时间锁等多种 DeFi 场景。

这种类似 CTF 的题目的游戏非常适合初学者去学习 solidity/ethers.js 的开发。

挑战描述网站:https://www.damnvulnerabledefi.xyz/
挑战源码地址:https://github.com/tinchoabbate/damn-vulnerable-defi

Unstoppable#

题目描述:
There’s a tokenized vault with a million DVT tokens deposited. It’s offering flash loans for free, until the grace period ends.

To pass the challenge, make the vault stop offering flash loans.

You start with 10 DVT tokens in balance.

解析#

由题意得知我们的目标是为了破环合约让合约的闪电贷服务终止。
带着这样的目标我们去看看合约是怎么实现闪电贷的。

image

可以观察到的一点比较奇怪的判断是这一句:

if (convertToShares(totalSupply) != balanceBefore) revert InvalidBalance(); // enforce ERC4626 requirement

观察到变量 balanceBefore 是该地址的 ERC20 Token 余额

image

并不是 ERC20 标准中由 mint burn 控制的 TotalSupply。

所以攻击该合约只需要补充一行 transfer token 代码就可以让该 totalSupply != balanceBefore 从而让该闪电贷停止工作。

题解#

it('Execution', async function () {
        await token.connect(player).transfer(vault.address, 1);
});

完整题解地址:https://github.com/fenghaojiang/damn-vulnerable-defi/tree/master/test/unstoppable

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。