-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(evm): issue with infinite recursion in erc20 funtoken contracts (#…
…2129) * fix(evm): issue with infinite recursion in erc20 funtoken contracts * fix(evm): issue with infinite recursion in erc20 funtoken contracts * chore: changelog update * fix: flooring 1/64 of the gas limit
- Loading branch information
1 parent
3954394
commit 1a256f2
Showing
7 changed files
with
450 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
316 changes: 316 additions & 0 deletions
316
...embeds/artifacts/contracts/TestInfiniteRecursionERC20.sol/TestInfiniteRecursionERC20.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./IFunToken.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract TestInfiniteRecursionERC20 is ERC20 { | ||
constructor(string memory name, string memory symbol, uint8 decimals_) | ||
ERC20(name, symbol) { | ||
_mint(msg.sender, 1000000 * 10**18); | ||
} | ||
|
||
function balanceOf(address who) public view virtual override returns (uint256) { | ||
// recurse through funtoken.balance(who, address(this)) | ||
address(FUNTOKEN_PRECOMPILE_ADDRESS).staticcall( | ||
abi.encodeWithSignature( | ||
"balance(address,address)", | ||
who, | ||
address(this)) | ||
); | ||
return 0; | ||
} | ||
|
||
function transfer(address to, uint256 amount) public override returns (bool) { | ||
// recurse through funtoken sendToBank | ||
FUNTOKEN_PRECOMPILE.sendToBank( | ||
address(this), | ||
amount, | ||
"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl" // does not matter, it's not reached | ||
); | ||
return true; | ||
} | ||
|
||
function attackBalance() public { | ||
balanceOf(address(0)); | ||
} | ||
|
||
function attackTransfer() public { | ||
transfer(address(0), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters