I want to create a modifier to dynamically forward parameters to a validator lets say I have a contract
contract Foo {
address validatorAddress;
modifier validate() {
assembly {
// Forward the call to the target contract and get the return data
let result := delegatecall(gas(), validatorAddress, add(calldatasize(), 0x20), calldatasize(), 0, 0)
// Check if the call was successful
if iszero(result) {
// Revert execution if the call failed
revert(0, 0)
}
}
_;
}
function bar(uint256 dependent) external validate {
// Function body
}
}
Now I would like to implement a validator like so:
function Validator {
function bar(uint256 dependent, address originalSender) external validate {
}
}
I know the encoding in solidity is not optimal, but is there any simple trick I can use to forward the original sender. I would think I can just overwrite the calldata buffer to append the msg sender, i just dont know if i need to modify padding or something or how gas efficient it would be:
let sender := caller()
let senderSize := 32
EDIT attempt:
let result := delegatecall(gas(), validatorAddress, add(calldatasize() + senderSize, 0x20), calldatasize() + sender, 0, 0)
How can I forward the original msg sender to the validator?
Not really sure how the delegatecall operates, does it just take in a memoryPointer, and the memory size for the calldata? If i append the sender to the call data, it wont be continuous memory if another variable was stored inbetween the calls would I need to deep copy and abi encode?
tx.origin
. Can you please add the minimum reproducible code where you’re trying to pass the original sender in the function call ?