mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core/vm: changes made to reflect the updates to the spec that specify behavior at the end of code
This commit is contained in:
parent
a9acb3ff93
commit
7a528c2da9
2 changed files with 39 additions and 27 deletions
|
|
@ -945,11 +945,11 @@ func opDupN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
|
|||
code := scope.Contract.Code
|
||||
i := *pc + 1
|
||||
|
||||
// Ensure an immediate byte exists after DUPN
|
||||
if i >= uint64(len(code)) {
|
||||
return nil, &ErrInvalidOpCode{opcode: INVALID}
|
||||
// If the immediate byte is missing, treat as 0x00 (same convention as PUSHn).
|
||||
var x byte
|
||||
if i < uint64(len(code)) {
|
||||
x = code[i]
|
||||
}
|
||||
x := code[i]
|
||||
|
||||
// This range is excluded to preserve compatibility with existing opcodes.
|
||||
if x > 90 && x < 128 {
|
||||
|
|
@ -972,11 +972,11 @@ func opSwapN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
|
|||
code := scope.Contract.Code
|
||||
i := *pc + 1
|
||||
|
||||
// Ensure an immediate byte exists after SWAPN
|
||||
if i >= uint64(len(code)) {
|
||||
return nil, &ErrInvalidOpCode{opcode: INVALID}
|
||||
// If the immediate byte is missing, treat as 0x00 (same convention as PUSHn).
|
||||
var x byte
|
||||
if i < uint64(len(code)) {
|
||||
x = code[i]
|
||||
}
|
||||
x := code[i]
|
||||
|
||||
// This range is excluded to preserve compatibility with existing opcodes.
|
||||
if x > 90 && x < 128 {
|
||||
|
|
@ -1001,11 +1001,11 @@ func opExchange(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
|
|||
code := scope.Contract.Code
|
||||
i := *pc + 1
|
||||
|
||||
// Ensure an immediate byte exists after EXCHANGE
|
||||
if i >= uint64(len(code)) {
|
||||
return nil, &ErrInvalidOpCode{opcode: INVALID}
|
||||
// If the immediate byte is missing, treat as 0x00 (same convention as PUSHn).
|
||||
var x byte
|
||||
if i < uint64(len(code)) {
|
||||
x = code[i]
|
||||
}
|
||||
x := code[i]
|
||||
|
||||
// This range is excluded both to preserve compatibility with existing opcodes
|
||||
// and to keep decode_pair’s 16-aligned arithmetic mapping valid (0–79, 128–255).
|
||||
|
|
|
|||
|
|
@ -1027,6 +1027,15 @@ func TestEIP8024_Execution(t *testing.T) {
|
|||
1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "DUPN_MISSING_IMMEDIATE",
|
||||
codeHex: "60016000808080808080808080808080808080e6",
|
||||
wantVals: []uint64{
|
||||
1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "SWAPN",
|
||||
codeHex: "600160008080808080808080808080808080806002e700",
|
||||
|
|
@ -1036,11 +1045,29 @@ func TestEIP8024_Execution(t *testing.T) {
|
|||
2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "SWAPN_MISSING_IMMEDIATE",
|
||||
codeHex: "600160008080808080808080808080808080806002e7",
|
||||
wantVals: []uint64{
|
||||
1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "EXCHANGE",
|
||||
codeHex: "600060016002e801",
|
||||
wantVals: []uint64{2, 0, 1},
|
||||
},
|
||||
{
|
||||
name: "EXCHANGE_MISSING_IMMEDIATE",
|
||||
codeHex: "600060006000600060006000600060006000600060006000600060006000600060006000600060006000600060006000600060006000600060016002e8",
|
||||
wantVals: []uint64{
|
||||
2,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "INVALID_SWAPN_LOW",
|
||||
codeHex: "e75b",
|
||||
|
|
@ -1092,21 +1119,6 @@ func TestEIP8024_Execution(t *testing.T) {
|
|||
codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "MISSING_IMMEDIATE_DUPN",
|
||||
codeHex: "e6", // no operand
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "MISSING_IMMEDIATE_SWAPN",
|
||||
codeHex: "e7", // no operand
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "MISSING_IMMEDIATE_EXCHANGE",
|
||||
codeHex: "e8", // no operand
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "PC_INCREMENT",
|
||||
codeHex: "600060006000e80115",
|
||||
|
|
|
|||
Loading…
Reference in a new issue