2023-03-21 06:14:47 -05:00
|
|
|
// Copyright 2023 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
)
|
|
|
|
|
2023-10-10 03:22:03 -05:00
|
|
|
// LookupInstructionSet returns the instruction set for the fork configured by
|
2023-03-21 06:14:47 -05:00
|
|
|
// the rules.
|
|
|
|
func LookupInstructionSet(rules params.Rules) (JumpTable, error) {
|
|
|
|
switch {
|
2023-06-28 04:08:48 -05:00
|
|
|
case rules.IsVerkle:
|
2023-07-10 13:40:31 -05:00
|
|
|
return newCancunInstructionSet(), errors.New("verkle-fork not defined yet")
|
2023-03-21 06:14:47 -05:00
|
|
|
case rules.IsPrague:
|
2023-07-10 13:40:31 -05:00
|
|
|
return newCancunInstructionSet(), errors.New("prague-fork not defined yet")
|
2023-03-21 06:14:47 -05:00
|
|
|
case rules.IsCancun:
|
2023-07-10 13:40:31 -05:00
|
|
|
return newCancunInstructionSet(), nil
|
2023-03-21 06:14:47 -05:00
|
|
|
case rules.IsShanghai:
|
|
|
|
return newShanghaiInstructionSet(), nil
|
|
|
|
case rules.IsMerge:
|
|
|
|
return newMergeInstructionSet(), nil
|
|
|
|
case rules.IsLondon:
|
|
|
|
return newLondonInstructionSet(), nil
|
|
|
|
case rules.IsBerlin:
|
|
|
|
return newBerlinInstructionSet(), nil
|
|
|
|
case rules.IsIstanbul:
|
|
|
|
return newIstanbulInstructionSet(), nil
|
|
|
|
case rules.IsConstantinople:
|
|
|
|
return newConstantinopleInstructionSet(), nil
|
|
|
|
case rules.IsByzantium:
|
|
|
|
return newByzantiumInstructionSet(), nil
|
|
|
|
case rules.IsEIP158:
|
|
|
|
return newSpuriousDragonInstructionSet(), nil
|
|
|
|
case rules.IsEIP150:
|
|
|
|
return newTangerineWhistleInstructionSet(), nil
|
|
|
|
case rules.IsHomestead:
|
|
|
|
return newHomesteadInstructionSet(), nil
|
|
|
|
}
|
|
|
|
return newFrontierInstructionSet(), nil
|
|
|
|
}
|
|
|
|
|
2023-10-10 03:22:03 -05:00
|
|
|
// Stack returns the minimum and maximum stack requirements.
|
2023-03-21 06:14:47 -05:00
|
|
|
func (op *operation) Stack() (int, int) {
|
|
|
|
return op.minStack, op.maxStack
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasCost returns true if the opcode has a cost. Opcodes which do _not_ have
|
|
|
|
// a cost assigned are one of two things:
|
|
|
|
// - undefined, a.k.a invalid opcodes,
|
|
|
|
// - the STOP opcode.
|
|
|
|
// This method can thus be used to check if an opcode is "Invalid (or STOP)".
|
|
|
|
func (op *operation) HasCost() bool {
|
|
|
|
// Ideally, we'd check this:
|
|
|
|
// return op.execute == opUndefined
|
|
|
|
// However, go-lang does now allow that. So we'll just check some other
|
|
|
|
// 'indicators' that this is an invalid op. Alas, STOP is impossible to
|
|
|
|
// filter out
|
|
|
|
return op.dynamicGas != nil || op.constantGas != 0
|
|
|
|
}
|