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