Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVM: Don't treat any as constant int in loads, stores #5884

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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