core/vm: update EXCHANGE decodePair and tests per EIP-8024 spec revision

This commit is contained in:
jonny rhea 2025-11-03 22:16:36 -06:00
parent 598625c2aa
commit 892c4f8aa5
2 changed files with 7 additions and 9 deletions

View file

@ -936,9 +936,9 @@ func decodePair(x byte) (int, int) {
}
q, r := k/16, k%16
if q < r {
return q + 2, r + 2
return q + 1, r + 1
}
return r + 2, 30 - q
return r + 1, 29 - q
}
func opDupN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {

View file

@ -1037,10 +1037,9 @@ func TestEIP8024_Execution(t *testing.T) {
},
},
{
//NOTE: Spec test seems wrong. Added additional stack item to make it pass.
name: "EXCHANGE",
codeHex: "6000600160026003e801",
wantVals: []uint64{3, 2, 0, 1},
codeHex: "600060016002e801",
wantVals: []uint64{2, 0, 1},
},
{
name: "INVALID_SWAPN_LOW",
@ -1080,18 +1079,17 @@ func TestEIP8024_Execution(t *testing.T) {
},
{
name: "UNDERFLOW_DUPN",
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items have 16)
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items, have 16)
wantErr: true,
},
{
name: "UNDERFLOW_SWAPN",
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items have 17)
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items, have 17)
wantErr: true,
},
{
// Note: This is the spec test case, but we expect it to fail
name: "UNDERFLOW_EXCHANGE",
codeHex: "600060016002e801", // (n,m=2,3 need at least 4 items have 3)
codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2
wantErr: true,
},
{