Skip to content

Commit 892c4f8

Browse files
committed
core/vm: update EXCHANGE decodePair and tests per EIP-8024 spec revision
1 parent 598625c commit 892c4f8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

core/vm/instructions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,9 @@ func decodePair(x byte) (int, int) {
936936
}
937937
q, r := k/16, k%16
938938
if q < r {
939-
return q + 2, r + 2
939+
return q + 1, r + 1
940940
}
941-
return r + 2, 30 - q
941+
return r + 1, 29 - q
942942
}
943943

944944
func opDupN(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {

core/vm/instructions_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,9 @@ func TestEIP8024_Execution(t *testing.T) {
10371037
},
10381038
},
10391039
{
1040-
//NOTE: Spec test seems wrong. Added additional stack item to make it pass.
10411040
name: "EXCHANGE",
1042-
codeHex: "6000600160026003e801",
1043-
wantVals: []uint64{3, 2, 0, 1},
1041+
codeHex: "600060016002e801",
1042+
wantVals: []uint64{2, 0, 1},
10441043
},
10451044
{
10461045
name: "INVALID_SWAPN_LOW",
@@ -1080,18 +1079,17 @@ func TestEIP8024_Execution(t *testing.T) {
10801079
},
10811080
{
10821081
name: "UNDERFLOW_DUPN",
1083-
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items have 16)
1082+
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items, have 16)
10841083
wantErr: true,
10851084
},
10861085
{
10871086
name: "UNDERFLOW_SWAPN",
1088-
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items have 17)
1087+
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items, have 17)
10891088
wantErr: true,
10901089
},
10911090
{
1092-
// Note: This is the spec test case, but we expect it to fail
10931091
name: "UNDERFLOW_EXCHANGE",
1094-
codeHex: "600060016002e801", // (n,m=2,3 need at least 4 items have 3)
1092+
codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2
10951093
wantErr: true,
10961094
},
10971095
{

0 commit comments

Comments
 (0)