Last active
August 17, 2021 22:02
-
-
Save mudgen/d2cd08bbf2a43b894e470624aa6fc31b 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// 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