geas icon indicating copy to clipboard operation
geas copied to clipboard

Targeting specific EVM instruction sets

Open fjl opened this issue 2 years ago • 0 comments

Would be nice if there was a way of setting the target instruction set (Ethereum fork version). It could look like this in the code:

#pragma target "cancun"

The pragma needs to apply to the whole program, so it should be an error if multiple targets are declared in a single program.

To implement this, opcode metadata in package internal/evm needs to be extended to track named instruction sets. I anticipate there will be a couple of these, and there could be support for more EVM versions than the Ethereum mainnet forks. So the best way of tracking these is probably as a tree, i.e.

type InstructionSet struct{
    Name string
    Parent string
    NewOpcodes []string
    RemovedOpcodes []string
}

var allInstructionSets map[string]*InstructionSet

When the user requests a named instruction set, the set of valid opcodes can be created by following the Parent references until the base Frontier instruction set is reached.

fjl avatar Sep 13 '23 17:09 fjl