Skip to content

Commit

Permalink
Don't treat any as constant int in loads, stores
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Dec 21, 2023
1 parent 548fbb4 commit cd64d33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 16 additions & 0 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,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()
Expand Down
8 changes: 4 additions & 4 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd64d33

Please sign in to comment.