core/vm: fix PC increment for EIP-8024 opcodes (#33361)

The EIP says to increment PC by 2 _instead of_ the standard increment by
1. The opcode handlers added in #33095 result in incrementing PC by 3,
because they ignored the increment already present in `interpreter.go`.

Does this need to be better specified in the EIP? I've added a [new test
case](https://github.com/ethereum/EIPs/pull/10859) for it anyway.

Found by @0xriptide.
This commit is contained in:
Francisco Giordano 2025-12-08 13:45:40 -03:00 committed by GitHub
parent 31f9c9ff75
commit 66134b35df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View file

@ -964,7 +964,7 @@ func opDupN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
//The nth stack item is duplicated at the top of the stack. //The nth stack item is duplicated at the top of the stack.
scope.Stack.push(scope.Stack.Back(n - 1)) scope.Stack.push(scope.Stack.Back(n - 1))
*pc += 2 *pc += 1
return nil, nil return nil, nil
} }
@ -993,7 +993,7 @@ func opSwapN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
indexTop := scope.Stack.len() - 1 indexTop := scope.Stack.len() - 1
indexN := scope.Stack.len() - 1 - n indexN := scope.Stack.len() - 1 - n
scope.Stack.data[indexTop], scope.Stack.data[indexN] = scope.Stack.data[indexN], scope.Stack.data[indexTop] scope.Stack.data[indexTop], scope.Stack.data[indexN] = scope.Stack.data[indexN], scope.Stack.data[indexTop]
*pc += 2 *pc += 1
return nil, nil return nil, nil
} }
@ -1025,7 +1025,7 @@ func opExchange(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
indexN := scope.Stack.len() - 1 - n indexN := scope.Stack.len() - 1 - n
indexM := scope.Stack.len() - 1 - m indexM := scope.Stack.len() - 1 - m
scope.Stack.data[indexN], scope.Stack.data[indexM] = scope.Stack.data[indexM], scope.Stack.data[indexN] scope.Stack.data[indexN], scope.Stack.data[indexM] = scope.Stack.data[indexM], scope.Stack.data[indexN]
*pc += 2 *pc += 1
return nil, nil return nil, nil
} }

View file

@ -1107,6 +1107,11 @@ func TestEIP8024_Execution(t *testing.T) {
codeHex: "e8", // no operand codeHex: "e8", // no operand
wantErr: true, wantErr: true,
}, },
{
name: "PC_INCREMENT",
codeHex: "600060006000e80115",
wantVals: []uint64{1, 0, 0},
},
} }
for _, tc := range tests { for _, tc := range tests {
@ -1123,17 +1128,15 @@ func TestEIP8024_Execution(t *testing.T) {
return return
case 0x60: case 0x60:
_, err = opPush1(&pc, evm, scope) _, err = opPush1(&pc, evm, scope)
pc++
case 0x80: case 0x80:
dup1 := makeDup(1) dup1 := makeDup(1)
_, err = dup1(&pc, evm, scope) _, err = dup1(&pc, evm, scope)
pc++
case 0x56: case 0x56:
_, err = opJump(&pc, evm, scope) _, err = opJump(&pc, evm, scope)
pc++
case 0x5b: case 0x5b:
_, err = opJumpdest(&pc, evm, scope) _, err = opJumpdest(&pc, evm, scope)
pc++ case 0x15:
_, err = opIszero(&pc, evm, scope)
case 0xe6: case 0xe6:
_, err = opDupN(&pc, evm, scope) _, err = opDupN(&pc, evm, scope)
case 0xe7: case 0xe7:
@ -1143,6 +1146,7 @@ func TestEIP8024_Execution(t *testing.T) {
default: default:
err = &ErrInvalidOpCode{opcode: OpCode(op)} err = &ErrInvalidOpCode{opcode: OpCode(op)}
} }
pc++
} }
if tc.wantErr { if tc.wantErr {
if err == nil { if err == nil {