-
-
Save midori-fuse/087aa3248da114a0712757348fcce814 to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.8.20; | |
contract Token { | |
mapping(address => mapping(address => uint256)) public allowance; | |
function increaseAllowance(address to, uint256 amount) public { | |
allowance[msg.sender][to] += amount; | |
} | |
} | |
contract InstantApprove { | |
function setApprove(Token ts, uint256 amount) public { | |
ts.increaseAllowance(msg.sender, amount); | |
} | |
function destroy() public { | |
selfdestruct(payable(tx.origin)); | |
} | |
} | |
contract Test { | |
Token public ts; | |
uint256 public constant APPROVE_AMOUNT = 2e18; | |
constructor() { | |
ts = new Token(); | |
} | |
function test(uint _salt) public returns (address) { | |
InstantApprove ia = new InstantApprove{salt: keccak256(abi.encodePacked(_salt))}(); | |
address ia_addr = address(ia); | |
ia.setApprove(ts, APPROVE_AMOUNT); | |
ia.destroy(); | |
return ia_addr; | |
} | |
function getCodeSize(address addr) public view returns (uint) { | |
uint size; | |
assembly { | |
size := extcodesize(addr) | |
} | |
return size; | |
} | |
function getAllowance(address from) public view returns (uint) { | |
return ts.allowance(from, address(this)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment