Skip to content

Commit

Permalink
move dei into erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Jul 22, 2023
1 parent 2cae86a commit 8c35fed
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 110 deletions.
File renamed without changes.
22 changes: 9 additions & 13 deletions examples/tokens/ERC20/test/ERC20Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,25 @@ abstract contract ERC20Test is SymTest, Test {

function setUp() public virtual;

function checkNoBackdoor(bytes4 selector) public virtual {
function _checkNoBackdoor(bytes4 selector, bytes memory args, address caller, address other) public virtual {
// consider two arbitrary distinct accounts
address caller = svm.createAddress('caller');
address other = svm.createAddress('other');
vm.assume(other != caller);

// assume the caller hasn't been granted any approvals
for (uint i = 0; i < holders.length; i++) {
vm.assume(IERC20(token).allowance(holders[i], caller) == 0);
}

// record their current balances
uint256 oldBalanceCaller = IERC20(token).balanceOf(caller);
uint256 oldBalanceOther = IERC20(token).balanceOf(other);

uint256 oldAllowance = IERC20(token).allowance(other, caller);

// consider an arbitrary function call to the token from the caller
vm.prank(caller);
bytes memory args = svm.createBytes(1024, 'args');
address(token).call(abi.encodePacked(selector, args));

// ensure that the caller cannot spend other' tokens
assert(IERC20(token).balanceOf(caller) <= oldBalanceCaller);
assert(IERC20(token).balanceOf(other) >= oldBalanceOther);
uint256 newBalanceOther = IERC20(token).balanceOf(other);

// ensure that the caller cannot spend other' tokens without approvals
if (newBalanceOther < oldBalanceOther) {
assert(oldAllowance >= oldBalanceOther - newBalanceOther);
}
}

function checkTransfer(address sender, address receiver, address other, uint256 amount) public virtual {
Expand Down
5 changes: 5 additions & 0 deletions examples/tokens/ERC20/test/OpenZeppelinERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ contract OpenZeppelinERC20Test is ERC20Test {
}
}
}

function checkNoBackdoor(bytes4 selector, address caller, address other) public {
bytes memory args = svm.createBytes(1024, 'data');
_checkNoBackdoor(selector, args, caller, other);
}
}
5 changes: 5 additions & 0 deletions examples/tokens/ERC20/test/SolmateERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ contract SolmateERC20Test is ERC20Test {
}
}
}

function checkNoBackdoor(bytes4 selector, address caller, address other) public {
bytes memory args = svm.createBytes(1024, 'data');
_checkNoBackdoor(selector, args, caller, other);
}
}
4 changes: 0 additions & 4 deletions examples/tokens/dei/foundry.toml

This file was deleted.

93 changes: 0 additions & 93 deletions examples/tokens/dei/test/ERC20Test.sol

This file was deleted.

0 comments on commit 8c35fed

Please sign in to comment.