aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-08-08 21:20:28 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-08-08 21:20:28 +0800
commit081642ed255fd939ec186f97fd60a316b51d8b61 (patch)
tree523ae4972884ec302653f376b0cbaf574c1d483e
parent17589aa75fdff7a90b2d783d7289df75f183c164 (diff)
downloadgo-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar.gz
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar.bz2
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar.lz
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar.xz
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.tar.zst
go-tangerine-081642ed255fd939ec186f97fd60a316b51d8b61.zip
Eip 1344 (ChainID opcode) (#19921)
* core/vm: implement EIP 1344 (ChainID opcode) * core/vm: formatting
-rw-r--r--core/vm/eips.go24
-rw-r--r--core/vm/opcodes.go3
2 files changed, 26 insertions, 1 deletions
diff --git a/core/vm/eips.go b/core/vm/eips.go
index 89e76c027..6e7259d40 100644
--- a/core/vm/eips.go
+++ b/core/vm/eips.go
@@ -18,7 +18,7 @@ package vm
import (
"fmt"
-
+
"github.com/ethereum/go-ethereum/params"
)
@@ -29,6 +29,8 @@ func EnableEIP(eipNum int, jt *JumpTable) error {
switch eipNum {
case 1884:
enable1884(jt)
+ case 1344:
+ enable1344(jt)
default:
return fmt.Errorf("undefined eip %d", eipNum)
}
@@ -61,3 +63,23 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract,
stack.push(balance)
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
+}
diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go
index b385fd14a..ba0ba01b8 100644
--- a/core/vm/opcodes.go
+++ b/core/vm/opcodes.go
@@ -101,6 +101,7 @@ const (
NUMBER
DIFFICULTY
GASLIMIT
+ CHAINID = 0x46
SELFBALANCE = 0x47
)
@@ -278,6 +279,7 @@ var opCodeToString = map[OpCode]string{
NUMBER: "NUMBER",
DIFFICULTY: "DIFFICULTY",
GASLIMIT: "GASLIMIT",
+ CHAINID: "CHAINID",
SELFBALANCE: "SELFBALANCE",
// 0x50 range - 'storage' and execution.
@@ -430,6 +432,7 @@ var stringToOp = map[string]OpCode{
"CALLDATALOAD": CALLDATALOAD,
"CALLDATASIZE": CALLDATASIZE,
"CALLDATACOPY": CALLDATACOPY,
+ "CHAINID": CHAINID,
"DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL,
"CODESIZE": CODESIZE,