github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/core/vm/eips.go (about)

     1  package vm
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/neatio-net/neatio/params"
     7  )
     8  
     9  func EnableEIP(eipNum int, jt *JumpTable) error {
    10  	switch eipNum {
    11  	case 2200:
    12  		enable2200(jt)
    13  	case 1884:
    14  		enable1884(jt)
    15  	case 1344:
    16  		enable1344(jt)
    17  	default:
    18  		return fmt.Errorf("undefined eip %d", eipNum)
    19  	}
    20  	return nil
    21  }
    22  
    23  func enable1884(jt *JumpTable) {
    24  
    25  	jt[BALANCE].constantGas = params.BalanceGasEIP1884
    26  	jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884
    27  	jt[SLOAD].constantGas = params.SloadGasEIP1884
    28  
    29  	jt[SELFBALANCE] = operation{
    30  		execute:     opSelfBalance,
    31  		constantGas: GasFastStep,
    32  		minStack:    minStack(0, 1),
    33  		maxStack:    maxStack(0, 1),
    34  		valid:       true,
    35  	}
    36  }
    37  
    38  func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
    39  	balance := interpreter.intPool.get().Set(interpreter.evm.StateDB.GetBalance(contract.Address()))
    40  	stack.push(balance)
    41  	return nil, nil
    42  }
    43  
    44  func enable1344(jt *JumpTable) {
    45  
    46  	jt[CHAINID] = operation{
    47  		execute:     opChainID,
    48  		constantGas: GasQuickStep,
    49  		minStack:    minStack(0, 1),
    50  		maxStack:    maxStack(0, 1),
    51  		valid:       true,
    52  	}
    53  }
    54  
    55  func opChainID(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
    56  	chainId := interpreter.intPool.get().Set(interpreter.evm.chainConfig.ChainId)
    57  	stack.push(chainId)
    58  	return nil, nil
    59  }
    60  
    61  func enable2200(jt *JumpTable) {
    62  	jt[SSTORE].dynamicGas = gasSStoreEIP2200
    63  }