1

Need some help modifying the proxy assembly code to work with multiple (n) implementation contracts.

I need the function to revert if the implementation contract reverted, but keep on going if the implementation contract doesn't have the requested function

for (uint256 i = 0; i < implementations.length; ++i) {
    address implementation = implementations[i];
    assembly {
        // Copy msg.data. We take full control of memory in this inline assembly
        // block because it will not return to Solidity code. We overwrite the
        // Solidity scratch pad at memory position 0.
        calldatacopy(0, 0, calldatasize())

        // Call the implementation.
        // out and outsize are 0 because we don't know the size yet.
        let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

        // Copy the returned data.
        returndatacopy(0, 0, returndatasize())

        switch result
        // delegatecall returns 0 on error.
        case 0 {
            // revert(0, returndatasize())
            //TODO: Revert only if the function was indeed found on the Target Contract            
        }
        default {
            return(0, returndatasize())
        }
    }
}
//If Nothing Found
revert("NO_SUCH_FUNCTION");
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Roy Toledo
  • 643
  • 4
  • 20

0 Answers0