github.com/ethereum/go-ethereum@v1.16.1/core/vm/jump_table_export.go (about) 1 // Copyright 2023 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 import ( 20 "errors" 21 22 "github.com/ethereum/go-ethereum/params" 23 ) 24 25 // LookupInstructionSet returns the instruction set for the fork configured by 26 // the rules. 27 func LookupInstructionSet(rules params.Rules) (JumpTable, error) { 28 switch { 29 case rules.IsVerkle: 30 return newCancunInstructionSet(), errors.New("verkle-fork not defined yet") 31 case rules.IsOsaka: 32 return newPragueInstructionSet(), errors.New("osaka-fork not defined yet") 33 case rules.IsPrague: 34 return newPragueInstructionSet(), nil 35 case rules.IsCancun: 36 return newCancunInstructionSet(), nil 37 case rules.IsShanghai: 38 return newShanghaiInstructionSet(), nil 39 case rules.IsMerge: 40 return newMergeInstructionSet(), nil 41 case rules.IsLondon: 42 return newLondonInstructionSet(), nil 43 case rules.IsBerlin: 44 return newBerlinInstructionSet(), nil 45 case rules.IsIstanbul: 46 return newIstanbulInstructionSet(), nil 47 case rules.IsConstantinople: 48 return newConstantinopleInstructionSet(), nil 49 case rules.IsByzantium: 50 return newByzantiumInstructionSet(), nil 51 case rules.IsEIP158: 52 return newSpuriousDragonInstructionSet(), nil 53 case rules.IsEIP150: 54 return newTangerineWhistleInstructionSet(), nil 55 case rules.IsHomestead: 56 return newHomesteadInstructionSet(), nil 57 } 58 return newFrontierInstructionSet(), nil 59 } 60 61 // Stack returns the minimum and maximum stack requirements. 62 func (op *operation) Stack() (int, int) { 63 return op.minStack, op.maxStack 64 } 65 66 // HasCost returns true if the opcode has a cost. Opcodes which do _not_ have 67 // a cost assigned are one of two things: 68 // - undefined, a.k.a invalid opcodes, 69 // - the STOP opcode. 70 // This method can thus be used to check if an opcode is "Invalid (or STOP)". 71 func (op *operation) HasCost() bool { 72 // Ideally, we'd check this: 73 // return op.execute == opUndefined 74 // However, go-lang does now allow that. So we'll just check some other 75 // 'indicators' that this is an invalid op. Alas, STOP is impossible to 76 // filter out 77 return op.dynamicGas != nil || op.constantGas != 0 78 }