Skip to content

Instantly share code, notes, and snippets.

@Saw-mon-and-Natalie
Created June 8, 2022 00:52
Show Gist options
  • Save Saw-mon-and-Natalie/d4933b33237a8529f761aa7aa558595f to your computer and use it in GitHub Desktop.
Save Saw-mon-and-Natalie/d4933b33237a8529f761aa7aa558595f to your computer and use it in GitHub Desktop.
MiddlePerson Contract that accepts tips to transfer calls
%push(end_runtime - start_runtime)
dup1
%push(start_runtime)
returndatasize
codecopy
returndatasize
return
start_runtime:
%include("MiddlePerson.etk")
end_runtime:
# calldata structure:
# [0x00, 0x14) TARGET_ADDRESS: 20 bytes
# [0x14, 0x16) FEE: 2 bytes
# [0x16, end) REST - to be passed to TARGET
returndatasize
returndatasize
returndatasize
returndatasize
# is caller the owner?
caller
push20 0xb055
eq
%push(call_by_owner)
# calculate input size
push1 0x16
calldatasize
sub
returndatasize
# calculate value to pass on
push2 0x2710 # 10_000
callvalue
push1 0x14 # 20
calldataload
push1 0xf0
shr
mul
div
callvalue
sub
# calculate target address
returndatasize
calldataload
push1 0x60 # 96 = 8 * 12 = 16 * 6
shr
call_by_owner:
jumpdest
returndatasize
returndatasize
balance
caller
gas
call
# ----- stack -----
# s = success
# s, 0, 0
returndatasize # rds, s, 0, 0
returndatasize # rds, rds, s, 0, 0
swap4 # 0, rds, s, 0, rds
returndatacopy # s, 0, rds
%push(end)
jumpi
revert
end:
jumpdest
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment