Created
February 9, 2023 20:25
-
-
Save jtriley-eth/1dc2bcbb9ddf18ff64b53c95d155cdc6 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.18; | |
// returns 42 | |
function freePure() pure returns (uint8) { | |
return 42; | |
} | |
// takes a function and returns that same function | |
function freeHigherOrder( | |
function() pure returns (uint8) func | |
) pure returns ( | |
function() pure returns (uint8) | |
) { | |
return func; | |
} | |
// calls higher order which takes a function then returns it | |
// then that function returns 42 | |
function freePureCaller() pure returns (uint8) { | |
return freeHigherOrder(freePure)(); | |
} | |
contract Funcs { | |
// calls the function that calls higher order which takes | |
// a function then returns it then that function returns 42 | |
function callInternal() external pure returns (uint8) { | |
return freePureCaller(); | |
} | |
// takes an external function and returns it | |
function externalPure( | |
function() external returns (uint8) func | |
) public pure returns ( | |
function() external returns (uint8) | |
) { | |
return func; | |
} | |
// takes an external function, passes it to an external | |
// function which returns the original external function | |
// then calls it | |
function callExternalPure( | |
function() external pure returns (uint8) func | |
) external returns (uint8) { | |
return externalPure(func)(); | |
} | |
} | |
contract A { | |
// returns 69 | |
function a() external pure returns (uint8) { | |
return 69; | |
} | |
} | |
contract B { | |
// takes an external function and returns it | |
function b( | |
function() external pure returns (uint8) a | |
) public pure returns ( | |
function() external pure returns (uint8) | |
) { | |
return a; | |
} | |
} | |
contract C { | |
// takes an external function and an external function | |
// that takes an external function and returns it | |
function c( | |
function() external pure returns (uint8) a, | |
function( | |
function() external pure returns (uint8) | |
) external pure returns ( | |
function() external pure returns (uint8) | |
) b | |
) external pure returns ( | |
function() external pure returns (uint8) | |
) { | |
return b(a); | |
} | |
} | |
contract D { | |
// takes an external function, an external function that | |
// takes an external function and returns it, and an | |
// external function that takes an external function and | |
// an external function that takes an external function | |
// and returns it | |
// then calls the original external function, returning 69 | |
function d( | |
function() external pure returns (uint8) a, | |
function( | |
function() external pure returns (uint8) | |
) external pure returns ( | |
function() external pure returns (uint8) | |
) b, | |
function( | |
function() external pure returns (uint8), | |
function( | |
function() external pure returns (uint8) | |
) external pure returns ( | |
function() external pure returns (uint8) | |
) | |
) external pure returns ( | |
function() external pure returns (uint8) | |
) c | |
) external pure returns (uint8) { | |
return c(a, b)(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment