Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to allow for arbitrary execution #9

Open
cleanunicorn opened this issue Apr 27, 2022 · 1 comment
Open

Add method to allow for arbitrary execution #9

cleanunicorn opened this issue Apr 27, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@cleanunicorn
Copy link
Owner

cleanunicorn commented Apr 27, 2022

Context

Provide a way to allow for arbitrary execution. The execution can be delegated to an external contract with a predefined interface.

Details

The methods can be defined as:

function givenQueryExecute((bytes memory query_, IMockProviderExec exec_) public
function givenSignatureExecute((bytes4 signature_, IMockProviderExec exec_) public

IMockProviderExec can be defined as:

interface IMockProviderExec {
    function execute(bytes args_) external return (bytes return);
}

Alternatives

A contract could inherit the MockProvider and add the methods is requires with the code it could specify as the implementation for IMockProviderExec.

Has the feature been requested before?

No and not sure if it's useful.

@cleanunicorn cleanunicorn added enhancement New feature or request help wanted Extra attention is needed labels Apr 27, 2022
@cleanunicorn
Copy link
Owner Author

cleanunicorn commented Aug 16, 2022

A proxy forwarder inspired by EIP-2535

contract ProxyForward {

    mapping (bytes4 => address) facets; 

    function setFacet(bytes4 signature_, address facet_) public {
        facets[signature_] = facet_;
    }

    fallback() external {

        address facet = facets[msg.sig];

        // Execute external function from facet using delegatecall and return any value.
        assembly {
            // copy function selector and any arguments
            calldatacopy(0, 0, calldatasize())
            // execute function call using the facet
            let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            // get any return value
            returndatacopy(0, 0, returndatasize())
            // return any return value or error back to the caller
            switch result
            case 0 {revert(0, returndatasize())}
            default {return (0, returndatasize())}
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant