Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eip 1344 (ChainID opcode) #19921

Merged
merged 2 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package vm

import (
"fmt"

"github.com/ethereum/go-ethereum/params"
)

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
karalabe marked this conversation as resolved.
Show resolved Hide resolved
stack.push(chainId)
return nil, nil
}
3 changes: 3 additions & 0 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const (
NUMBER
DIFFICULTY
GASLIMIT
CHAINID = 0x46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "= 0x46" and "= 0x47" could be omitted because of iota effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could, but I dislike the iota effect -- imo it's wrong to use iota to define something that is defined externally, and it should only be used for things where there's no external dependency -- where only internal consistency matters

SELFBALANCE = 0x47
)

Expand Down Expand Up @@ -278,6 +279,7 @@ var opCodeToString = map[OpCode]string{
NUMBER: "NUMBER",
DIFFICULTY: "DIFFICULTY",
GASLIMIT: "GASLIMIT",
CHAINID: "CHAINID",
SELFBALANCE: "SELFBALANCE",

// 0x50 range - 'storage' and execution.
Expand Down Expand Up @@ -430,6 +432,7 @@ var stringToOp = map[string]OpCode{
"CALLDATALOAD": CALLDATALOAD,
"CALLDATASIZE": CALLDATASIZE,
"CALLDATACOPY": CALLDATACOPY,
"CHAINID": CHAINID,
"DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL,
"CODESIZE": CODESIZE,
Expand Down