I'm writing raw EVM op-codes, and want to return result data
contract Test {
address public addr;
bytes public sourceCode;
function deploy() private returns (address pointer) {
bytes memory code = abi.encodePacked(
hex"60003560805260206080f3"
);
sourceCode = code;
assembly {
pointer := create(0, add(code, 32), mload(code))
}
addr = pointer;
return pointer;
}
function win() public returns (bool, bytes memory, uint) {
address a = deploy();
(bool sent, bytes memory data) = address(this).call(abi.encodeWithSignature("func()"));
uint returnValue = abi.decode(data, (uint));
return (sent, data, returnValue);
}
This bytecode corresponds next opcodes:
PUSH1 0x00
CALLDATALOAD
PUSH1 0x80
MSTORE
PUSH1 0x20
PUSH1 0x80
RETURN
I validate this opcodes on this site
This opcodes take first byte from calldata, placed it into memory and returns this memory as result.
In remix if I call function win it returns true
and 0x0
, but in EVM Playground it returns expected result (first byte from calldata)
My question is: what I'm doing wrong? How can I fix my opcode to return result correctly? No, I can't just write normal solidity code, because I have strong limitation on code size