Skip to content

Commit 3b967d1

Browse files
authored
core/vm: implement EIP-3855: PUSH0 instruction (#24039)
* core/vm: Implement PUSH0 * Move PUSH0 to enable3855 * Add method doc
1 parent 1941c5e commit 3b967d1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

core/vm/eips.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
)
2626

2727
var activators = map[int]func(*JumpTable){
28+
3855: enable3855,
2829
3529: enable3529,
2930
3198: enable3198,
3031
2929: enable2929,
@@ -174,3 +175,20 @@ func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
174175
scope.Stack.push(baseFee)
175176
return nil, nil
176177
}
178+
179+
// enable3855 applies EIP-3855 (PUSH0 opcode)
180+
func enable3855(jt *JumpTable) {
181+
// New opcode
182+
jt[PUSH0] = &operation{
183+
execute: opPush0,
184+
constantGas: GasQuickStep,
185+
minStack: minStack(0, 1),
186+
maxStack: maxStack(0, 1),
187+
}
188+
}
189+
190+
// opPush0 implements the PUSH0 opcode
191+
func opPush0(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
192+
scope.Stack.push(new(uint256.Int))
193+
return nil, nil
194+
}

core/vm/opcodes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const (
116116
MSIZE OpCode = 0x59
117117
GAS OpCode = 0x5a
118118
JUMPDEST OpCode = 0x5b
119+
PUSH0 OpCode = 0x5f
119120
)
120121

121122
// 0x60 range - pushes.
@@ -297,6 +298,7 @@ var opCodeToString = map[OpCode]string{
297298
MSIZE: "MSIZE",
298299
GAS: "GAS",
299300
JUMPDEST: "JUMPDEST",
301+
PUSH0: "PUSH0",
300302

301303
// 0x60 range - push.
302304
PUSH1: "PUSH1",
@@ -460,6 +462,7 @@ var stringToOp = map[string]OpCode{
460462
"MSIZE": MSIZE,
461463
"GAS": GAS,
462464
"JUMPDEST": JUMPDEST,
465+
"PUSH0": PUSH0,
463466
"PUSH1": PUSH1,
464467
"PUSH2": PUSH2,
465468
"PUSH3": PUSH3,

0 commit comments

Comments
 (0)