-
-
Save ashwinYardi/f7836b05cd30b8025114bb5760e7790c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find facet for function that is called and execute the | |
// function if a facet is found and return any value. | |
fallback() external payable { | |
// get facet from function selector | |
address facet = selectorTofacet[msg.sig]; | |
require(facet != address(0)); | |
// 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