github.com/calmw/ethereum@v0.1.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/calmw/ethereum/params" 23 ) 24 25 // LookupInstructionSet returns the instructionset for the fork configured by 26 // the rules. 27 func LookupInstructionSet(rules params.Rules) (JumpTable, error) { 28 switch { 29 case rules.IsPrague: 30 return newShanghaiInstructionSet(), errors.New("prague-fork not defined yet") 31 case rules.IsCancun: 32 return newShanghaiInstructionSet(), errors.New("cancun-fork not defined yet") 33 case rules.IsShanghai: 34 return newShanghaiInstructionSet(), nil 35 case rules.IsMerge: 36 return newMergeInstructionSet(), nil 37 case rules.IsLondon: 38 return newLondonInstructionSet(), nil 39 case rules.IsBerlin: 40 return newBerlinInstructionSet(), nil 41 case rules.IsIstanbul: 42 return newIstanbulInstructionSet(), nil 43 case rules.IsConstantinople: 44 return newConstantinopleInstructionSet(), nil 45 case rules.IsByzantium: 46 return newByzantiumInstructionSet(), nil 47 case rules.IsEIP158: 48 return newSpuriousDragonInstructionSet(), nil 49 case rules.IsEIP150: 50 return newTangerineWhistleInstructionSet(), nil 51 case rules.IsHomestead: 52 return newHomesteadInstructionSet(), nil 53 } 54 return newFrontierInstructionSet(), nil 55 } 56 57 // Stack returns the mininum and maximum stack requirements. 58 func (op *operation) Stack() (int, int) { 59 return op.minStack, op.maxStack 60 } 61 62 // HasCost returns true if the opcode has a cost. Opcodes which do _not_ have 63 // a cost assigned are one of two things: 64 // - undefined, a.k.a invalid opcodes, 65 // - the STOP opcode. 66 // This method can thus be used to check if an opcode is "Invalid (or STOP)". 67 func (op *operation) HasCost() bool { 68 // Ideally, we'd check this: 69 // return op.execute == opUndefined 70 // However, go-lang does now allow that. So we'll just check some other 71 // 'indicators' that this is an invalid op. Alas, STOP is impossible to 72 // filter out 73 return op.dynamicGas != nil || op.constantGas != 0 74 }