Skip to content

Instantly share code, notes, and snippets.

@drgorillamd
Created February 28, 2024 08:09
Show Gist options
  • Save drgorillamd/242ddfdbe499ac391b1ccbdc98610443 to your computer and use it in GitHub Desktop.
Save drgorillamd/242ddfdbe499ac391b1ccbdc98610443 to your computer and use it in GitHub Desktop.
internal function pointer
// SPDX-License-Identifier: GPL-3.0
// no optimization
pragma solidity 0.8.19;
contract A {
event Log(string bleh);
// Pass an arbitrary bytecode offset, then make it a fn pointer and call it
function callme(bytes32 _offset) external {
function () internal toCall;
assembly {
toCall := _offset
}
toCall();
}
// Avoid having solc removing _irreachable as it is unused
// + easy way to find the offset
function dontMindMe() external {
_irreachable();
}
// offset of this: 0x0000000000000000000000000000000000000000000000000000000000000081
function _irreachable() internal {
emit Log("pwned pwned pwned");
}
}
@drgorillamd
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment