github.com/theQRL/go-zond@v0.2.1/core/vm/eips.go (about)

     1  // Copyright 2019 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  	"fmt"
    21  	"sort"
    22  
    23  	"github.com/holiman/uint256"
    24  )
    25  
    26  var activators = map[int]func(*JumpTable){}
    27  
    28  // EnableEIP enables the given EIP on the config.
    29  // This operation writes in-place, and callers need to ensure that the globally
    30  // defined jump tables are not polluted.
    31  func EnableEIP(eipNum int, jt *JumpTable) error {
    32  	enablerFn, ok := activators[eipNum]
    33  	if !ok {
    34  		return fmt.Errorf("undefined eip %d", eipNum)
    35  	}
    36  	enablerFn(jt)
    37  	return nil
    38  }
    39  
    40  func ValidEip(eipNum int) bool {
    41  	_, ok := activators[eipNum]
    42  	return ok
    43  }
    44  func ActivateableEips() []string {
    45  	var nums []string
    46  	for k := range activators {
    47  		nums = append(nums, fmt.Sprintf("%d", k))
    48  	}
    49  	sort.Strings(nums)
    50  	return nums
    51  }
    52  
    53  func opSelfBalance(pc *uint64, interpreter *ZVMInterpreter, scope *ScopeContext) ([]byte, error) {
    54  	balance, _ := uint256.FromBig(interpreter.zvm.StateDB.GetBalance(scope.Contract.Address()))
    55  	scope.Stack.push(balance)
    56  	return nil, nil
    57  }
    58  
    59  // opChainID implements CHAINID opcode
    60  func opChainID(pc *uint64, interpreter *ZVMInterpreter, scope *ScopeContext) ([]byte, error) {
    61  	chainId, _ := uint256.FromBig(interpreter.zvm.chainConfig.ChainID)
    62  	scope.Stack.push(chainId)
    63  	return nil, nil
    64  }
    65  
    66  // opBaseFee implements BASEFEE opcode
    67  func opBaseFee(pc *uint64, interpreter *ZVMInterpreter, scope *ScopeContext) ([]byte, error) {
    68  	baseFee, _ := uint256.FromBig(interpreter.zvm.Context.BaseFee)
    69  	scope.Stack.push(baseFee)
    70  	return nil, nil
    71  }
    72  
    73  // opPush0 implements the PUSH0 opcode
    74  func opPush0(pc *uint64, interpreter *ZVMInterpreter, scope *ScopeContext) ([]byte, error) {
    75  	scope.Stack.push(new(uint256.Int))
    76  	return nil, nil
    77  }