I'm using a low level delegatecall to forward my calls to a library.
I need to (in this order) :
load bytes4 sig into _message from memory
load bounty (STRUCT) into _message from storage
load bytes _data into _message
Delegatecall with the new message
Get return valuesThe contract works (eg the getBounty function will work) but I'm having trouble with the assembly in my forwarder() function. https://ethfiddle.com/po3wHGQraJ
I'm having trouble making my forwarder (in assembly) work properly however.
function forward(bytes32 _sig, bytes memory _data) public payable {
bytes memory data = _data;
bytes4 sig = bytes4(_sig);
address _impl = impl;
require(_impl != address(0));
assembly {
let _message := mload(0x40) //find empty memory location
mstore(_message, sig) //place sig at beginning of empty storage
//add _bounty
mstore(add(_message, 4), sload(bounty_slot))
//add _data
calldatacopy(add(_message, 36), 100, sub(calldatasize,100))
//mstore(add(_message, 36), data)
let size := returndatasize
let result := delegatecall(gas, _impl, _message, msize, 0, 0)
//return data ??????
returndatacopy(_message, 0, size)
switch result
case 0 {revert(_message, size) }
default { return(_message, size) }
}
}
This is what the storage looks like:
0x00
0x687474703a2f2f6170692e6269746275636b65742e636f6d2f33303433303430
0xe1bb4acb579f780cbaf21cef9ac3641b8e3fcd69
0x5b7eaef7
0x3334303330340000000000000000000000000000000000000000000000000000
0x012a05f200
0x00
0x00
0x059ce9161d4fb0
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00