diff options
author | John Jannotti <jannotti@gmail.com> | 2023-12-21 11:04:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-21 11:04:41 -0500 |
commit | a4fcdfa0d216fe9b0a60d57acc76e92131cfbfbd (patch) | |
tree | 53d6df633e2009e2579ba29c068129f8454b3d94 | |
parent | 9eaebc0ef295b56ff966d50a312f6e77f9dcaa17 (diff) |
AVM: Don't treat `any` as constant int in `loads`, `stores` (#5884)
-rw-r--r-- | data/transactions/logic/assembler.go | 4 | ||||
-rw-r--r-- | data/transactions/logic/assembler_test.go | 16 | ||||
-rw-r--r-- | data/transactions/logic/eval.go | 8 |
3 files changed, 22 insertions, 6 deletions
diff --git a/data/transactions/logic/assembler.go b/data/transactions/logic/assembler.go index e8011fd81..182b3e9dd 100644 --- a/data/transactions/logic/assembler.go +++ b/data/transactions/logic/assembler.go @@ -1481,7 +1481,7 @@ func typeStores(pgm *ProgramKnowledge, args []token) (StackTypes, StackTypes, er // If the index of the scratch slot is a const // we can modify only that scratch slots type if top >= 1 { - if idx, isConst := pgm.stack[top-1].constant(); isConst { + if idx, isConst := pgm.stack[top-1].constInt(); isConst { pgm.scratchSpace[idx] = pgm.stack[top] return nil, nil, nil } @@ -1524,7 +1524,7 @@ func typeLoads(pgm *ProgramKnowledge, args []token) (StackTypes, StackTypes, err return nil, nil, nil } - if val, isConst := pgm.stack[top].constant(); isConst { + if val, isConst := pgm.stack[top].constInt(); isConst { return nil, StackTypes{pgm.scratchSpace[val]}, nil } diff --git a/data/transactions/logic/assembler_test.go b/data/transactions/logic/assembler_test.go index c45c0af77..ffa7598c8 100644 --- a/data/transactions/logic/assembler_test.go +++ b/data/transactions/logic/assembler_test.go @@ -2955,6 +2955,22 @@ done: `, LogicVersion, exp(5, "concat arg 1 wanted type []byte...")) } +func TestTypeTrackingRegression(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + testProg(t, ` +callsub end // wipes out initial program knowledge, makes scratch "any" +label1: + load 1 + byte 0x01 + stores // we had a bug in which the "any" seemed constant + load 0 + load 0 + + +end: +`, LogicVersion) +} + func TestMergeProtos(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() diff --git a/data/transactions/logic/eval.go b/data/transactions/logic/eval.go index 836b8cb85..971fffa72 100644 --- a/data/transactions/logic/eval.go +++ b/data/transactions/logic/eval.go @@ -879,11 +879,11 @@ func (st StackType) widened() StackType { } } -func (st StackType) constant() (uint64, bool) { - if st.Bound[0] == st.Bound[1] { - return st.Bound[0], true +func (st StackType) constInt() (uint64, bool) { + if st.AVMType != avmUint64 || st.Bound[0] != st.Bound[1] { + return 0, false } - return 0, false + return st.Bound[0], true } // overlaps checks if there is enough overlap |