Skip to content

Instantly share code, notes, and snippets.

@devtooligan
devtooligan / 0ERC20Main.huff
Created July 24, 2022 00:45
Huff -- Inheritance pattern for CONSTRUCTOR() / MAIN()
// This is the main file that will be compiled
/* Imports */
#include "./ERC20.huff"
#include "./utils/Ownable.huff"
#define macro CONSTRUCTOR() = takes (0) returns (0) {
OWNABLE_CONSTRUCTOR()
ERC20_CONSTRUCTOR()
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
/*
Pasting this code into evm.codes playground and stepping through will show that starting on instruction 1d, the
JUMPDEST of the target function (which is 36) is pushed onto the stack. Then there is a SHL(20) performed on it.
Then it's ORed with 00b4 so 36 becomes 36000000b4.
Then later in step 47, when myFunc() calls targetFunc(), it does a SHR(20) to convert 36000000b4 back to 36 which
it then uses for the JUMPDEST to targetFunc(). Nothing is ever done with the 000000b4 part. A copy of the full