zink icon indicating copy to clipboard operation
zink copied to clipboard

Support `msg.data` in host calls

Open clearloop opened this issue 7 months ago • 0 comments

in the implementation of #297, we found that reading the complete call data could be complex: CALLDATA -> memory -> stack, for templates of implementing this (with return but not writing it on stack):

// load the complete call data to memory
PUSH0                   // from 0
PUSH0                   // from 0
CALLDATASIZE     // to size
CALDATALOAD     // calldataload(dest_mem_offset: 0, offest: 0, size: size)

// return the selected memory
PUSH0
CALLDATASIZE
RETURN

considering about the memory pointer:

MSIZE // first we get the memory size as the start pointer for the memory allocation
PUSH0 // to get the complete calldata, we start form offset 0
CALLDATASIZE // complete calldata
CALLDATALOAD // load the calldata to memory

// now we return the calldata
MSIZE
CALLDATASIZE
SUB
CALLDATASIZE
RETURN

for the real implementation, we might need to write the calldata on stack, need to do sort of research on it, mb learn from solidity or huff!

clearloop avatar Mar 26 '25 08:03 clearloop