Created
March 19, 2025 16:44
-
-
Save tienshaoku/c2efec65326f7e42d3a26c50a4ce1626 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#define constant OWNER_SLOT = 0x00 | |
#define constant WITHDRAWER_SLOT = 0x01 | |
#define constant LAST_DEPOSITOR_SLOT = 0x02 | |
#define macro DEPOSIT() = takes(0) returns(0) { | |
callvalue iszero error jumpi // revert if msg.value == 0 | |
caller [LAST_DEPOSITOR_SLOT] sstore // store last depositor | |
stop | |
error: | |
0x00 0x00 revert | |
} | |
#define macro WITHDRAW() = takes(0) returns(0) { | |
[WITHDRAWER_SLOT] sload // get withdrawer | |
caller eq iszero error jumpi // revert if caller != withdrawer | |
0x00 0x00 0x00 0x00 // fill stack with 0 | |
selfbalance caller gas // call params | |
call | |
stop | |
error: | |
0x00 0x00 revert | |
} | |
#define macro SET_WITHDRAWER() = takes(0) returns(0) { | |
caller callvalue sload eq iszero error jumpi // require(msg.sender == owner) | |
0x04 calldataload [WITHDRAWER_SLOT] sstore // set new withdrawer | |
stop | |
error: | |
0x00 0x00 revert | |
} | |
#define macro CONSTRUCTOR() = takes(0) returns(0) { | |
caller [OWNER_SLOT] sstore // set deployer as owner | |
} | |
#define macro MAIN() = takes(0) returns(0) { | |
0x00 calldataload 0xE0 shr | |
dup1 0xd0e30db0 eq deposit jumpi | |
dup1 0x3ccfd60b eq withdraw jumpi | |
dup1 0x0d174c24 eq set_withdrawer jumpi | |
deposit: | |
DEPOSIT() | |
withdraw: | |
WITHDRAW() | |
set_withdrawer: | |
SET_WITHDRAWER() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment