Eip 1344 (ChainID opcode) (#19921)
* core/vm: implement EIP 1344 (ChainID opcode) * core/vm: formatting
This commit is contained in:
parent
17589aa75f
commit
081642ed25
@ -18,7 +18,7 @@ package vm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,6 +29,8 @@ func EnableEIP(eipNum int, jt *JumpTable) error {
|
|||||||
switch eipNum {
|
switch eipNum {
|
||||||
case 1884:
|
case 1884:
|
||||||
enable1884(jt)
|
enable1884(jt)
|
||||||
|
case 1344:
|
||||||
|
enable1344(jt)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("undefined eip %d", eipNum)
|
return fmt.Errorf("undefined eip %d", eipNum)
|
||||||
}
|
}
|
||||||
@ -61,3 +63,23 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract,
|
|||||||
stack.push(balance)
|
stack.push(balance)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enable1344 applies EIP-1344 (ChainID Opcode)
|
||||||
|
// - Adds an opcode that returns the current chain’s EIP-155 unique identifier
|
||||||
|
func enable1344(jt *JumpTable) {
|
||||||
|
// New opcode
|
||||||
|
jt[CHAINID] = operation{
|
||||||
|
execute: opChainID,
|
||||||
|
constantGas: GasQuickStep,
|
||||||
|
minStack: minStack(0, 1),
|
||||||
|
maxStack: maxStack(0, 1),
|
||||||
|
valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// opChainID implements CHAINID opcode
|
||||||
|
func opChainID(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||||
|
chainId := interpreter.intPool.get().Set(interpreter.evm.chainConfig.ChainID)
|
||||||
|
stack.push(chainId)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -101,6 +101,7 @@ const (
|
|||||||
NUMBER
|
NUMBER
|
||||||
DIFFICULTY
|
DIFFICULTY
|
||||||
GASLIMIT
|
GASLIMIT
|
||||||
|
CHAINID = 0x46
|
||||||
SELFBALANCE = 0x47
|
SELFBALANCE = 0x47
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -278,6 +279,7 @@ var opCodeToString = map[OpCode]string{
|
|||||||
NUMBER: "NUMBER",
|
NUMBER: "NUMBER",
|
||||||
DIFFICULTY: "DIFFICULTY",
|
DIFFICULTY: "DIFFICULTY",
|
||||||
GASLIMIT: "GASLIMIT",
|
GASLIMIT: "GASLIMIT",
|
||||||
|
CHAINID: "CHAINID",
|
||||||
SELFBALANCE: "SELFBALANCE",
|
SELFBALANCE: "SELFBALANCE",
|
||||||
|
|
||||||
// 0x50 range - 'storage' and execution.
|
// 0x50 range - 'storage' and execution.
|
||||||
@ -430,6 +432,7 @@ var stringToOp = map[string]OpCode{
|
|||||||
"CALLDATALOAD": CALLDATALOAD,
|
"CALLDATALOAD": CALLDATALOAD,
|
||||||
"CALLDATASIZE": CALLDATASIZE,
|
"CALLDATASIZE": CALLDATASIZE,
|
||||||
"CALLDATACOPY": CALLDATACOPY,
|
"CALLDATACOPY": CALLDATACOPY,
|
||||||
|
"CHAINID": CHAINID,
|
||||||
"DELEGATECALL": DELEGATECALL,
|
"DELEGATECALL": DELEGATECALL,
|
||||||
"STATICCALL": STATICCALL,
|
"STATICCALL": STATICCALL,
|
||||||
"CODESIZE": CODESIZE,
|
"CODESIZE": CODESIZE,
|
||||||
|
Loading…
Reference in New Issue
Block a user