Skip to content

Commit

Permalink
Swap order of stores args
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Sep 8, 2021
1 parent b465587 commit fa7c144
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/transactions/logic/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var opDocByName = map[string]string{
"load": "copy a value from scratch space to the stack",
"store": "pop value X. store X to the Ith scratch space",
"loads": "copy a value from the Xth scratch space to the stack",
"stores": "pop indexes A and B. store A to the Bth scratch space",
"stores": "pop indexes A and B. store B to the Ath scratch space",
"gload": "push Ith scratch space index of the Tth transaction in the current group",
"gloads": "push Ith scratch space index of the Xth transaction in the current group",
"gaid": "push the ID of the asset or application created in the Tth transaction of the current group",
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,12 +2551,12 @@ func opStore(cx *EvalContext) {
func opStores(cx *EvalContext) {
last := len(cx.stack) - 1
prev := last - 1
n := cx.stack[last].Uint
n := cx.stack[prev].Uint
if n >= uint64(len(cx.scratch)) {
cx.err = fmt.Errorf("invalid Scratch index %d", n)
return
}
cx.scratch[n] = cx.stack[prev]
cx.scratch[n] = cx.stack[last]
cx.stack = cx.stack[:prev]
}

Expand Down
9 changes: 7 additions & 2 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2343,15 +2343,16 @@ func TestLoadStoreStack(t *testing.T) {

t.Parallel()
testAccepts(t, `int 37
int 37
int 1
int 37
stores
byte 0xabbacafe
int 42
byte 0xabbacafe
stores
int 37
==
int 0
swap
stores
int 42
loads
Expand Down Expand Up @@ -4348,6 +4349,7 @@ func testEvaluation(t *testing.T, program string, introduced uint64, tester eval
var outer error
for v := uint64(1); v <= AssemblerMaxVersion; v++ {
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) {
t.Helper()
if v < introduced {
testProg(t, obfuscate(program), v, expect{0, "...was introduced..."})
return
Expand Down Expand Up @@ -4389,17 +4391,20 @@ func testEvaluation(t *testing.T, program string, introduced uint64, tester eval
}

func testAccepts(t *testing.T, program string, introduced uint64) {
t.Helper()
testEvaluation(t, program, introduced, func(pass bool, err error) bool {
return pass && err == nil
})
}
func testRejects(t *testing.T, program string, introduced uint64) {
t.Helper()
testEvaluation(t, program, introduced, func(pass bool, err error) bool {
// Returned False, but didn't panic
return !pass && err == nil
})
}
func testPanics(t *testing.T, program string, introduced uint64) error {
t.Helper()
return testEvaluation(t, program, introduced, func(pass bool, err error) bool {
// TEAL panic! not just reject at exit
return !pass && err != nil
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ var OpSpecs = []OpSpec{

// Like load/store, but scratch slot taken from TOS instead of immediate
{0x3e, "loads", opLoads, asmDefault, disDefault, oneInt, oneAny, 5, modeAny, opDefault},
{0x3f, "stores", opStores, asmDefault, disDefault, oneAny.plus(oneInt), nil, 5, modeAny, opDefault},
{0x3f, "stores", opStores, asmDefault, disDefault, oneInt.plus(oneAny), nil, 5, modeAny, opDefault},

{0x40, "bnz", opBnz, assembleBranch, disBranch, oneInt, nil, 1, modeAny, opBranch},
{0x41, "bz", opBz, assembleBranch, disBranch, oneInt, nil, 2, modeAny, opBranch},
Expand Down

0 comments on commit fa7c144

Please sign in to comment.