Created
February 28, 2024 08:09
-
-
Save drgorillamd/242ddfdbe499ac391b1ccbdc98610443 to your computer and use it in GitHub Desktop.
internal function pointer
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: 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"); | |
} | |
} |
Author
drgorillamd
commented
Feb 28, 2024
![image](https://private-user-images.githubusercontent.com/83670532/308470103-3306013a-6adb-4687-b0aa-adb396d3f76c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4NDk0MzIsIm5iZiI6MTcyMTg0OTEzMiwicGF0aCI6Ii84MzY3MDUzMi8zMDg0NzAxMDMtMzMwNjAxM2EtNmFkYi00Njg3LWIwYWEtYWRiMzk2ZDNmNzZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI0VDE5MjUzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY4Njg2YTg5M2ZiZmUyMjFjNjk0NWZkNjdjZjEzMWNlNjk1NGY4M2FjNWJmNWM3MThjYjY0MjI0ZmJiZTk1OGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.-rdeL3VCEqFspHFQxexOTiEZ4c905y_70GIL7G52eHA)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment