I am trying to call a library function using assembly and the delegatecall opcode. The library function accepts two parameters, the state object storage pointer and an address, it returns a single uint.
I can tell if the op fails because the data at in_pos is untouched, however when it does work it always returns zero even if the function being called simply returns a 0x01 value.
state
is a struct that is shared by the calling contract and the library, its position is 0
address t = 0xTargetLibraryAddress; address a = 0xAccount; bytes32 result; assembly { let in_pos := mload(0x40) mstore(in_pos, 0x12345678) //a valid func sig within the library mstore(add(in_pos, 0x04), state) mstore(add(in_pos, 0x24), a) let success := delegatecall(sub(gas, 10000), t, in_pos, 0x44, in_pos, 0x20) result := mload(in_pos) mstore(0x40, add(in_pos, 0x44)) }
Any suggestions?
success
?success
is always zero. No matter what combination I try.