Skip to content

Commit

Permalink
AVM: Only update the bytec disassembleState for bytecblock opcodes (#…
Browse files Browse the repository at this point in the history
…6154)

Co-authored-by: cce <[email protected]>
  • Loading branch information
nullun and cce authored Oct 22, 2024
1 parent e3c8fc9 commit 54ca0c2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
9 changes: 6 additions & 3 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2873,8 +2873,9 @@ func disassemble(dis *disassembleState, spec *OpSpec) (string, error) {
if err != nil {
return "", err
}

dis.intc = intc
if spec.Name == "intcblock" {
dis.intc = intc
}
for i, iv := range intc {
if i != 0 {
out += " "
Expand All @@ -2887,7 +2888,9 @@ func disassemble(dis *disassembleState, spec *OpSpec) (string, error) {
if err != nil {
return "", err
}
dis.bytec = bytec
if spec.Name == "bytecblock" {
dis.bytec = bytec
}
for i, bv := range bytec {
if i != 0 {
out += " "
Expand Down
46 changes: 46 additions & 0 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,52 @@ label1:
}
}

// TestDisassembleBytecblock asserts correct disassembly for
// uses of bytecblock and intcblock, from examples in #6154
func TestDisassembleBytecblock(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

ver := uint64(AssemblerMaxVersion)
for _, prog := range []string{
`#pragma version %d
intcblock 0 1 2 3 4 5
intc_0 // 0
intc_1 // 1
intc_2 // 2
intc_3 // 3
intc 4 // 4
pushints 6
intc_0 // 0
intc_1 // 1
intc_2 // 2
intc_3 // 3
intc 4 // 4
`,
`#pragma version %d
bytecblock 0x6869 0x414243 0x74657374 0x666f7572 0x6c617374
bytec_0 // "hi"
bytec_1 // "ABC"
bytec_2 // "test"
bytec_3 // "four"
bytec 4 // "last"
pushbytess 0x6576696c
bytec_0 // "hi"
bytec_1 // "ABC"
bytec_2 // "test"
bytec_3 // "four"
bytec 4 // "last"
`,
} {
source := fmt.Sprintf(prog, ver)
ops, err := AssembleStringWithVersion(source, ver)
require.NoError(t, err)
dis, err := Disassemble(ops.Program)
require.NoError(t, err, dis)
require.Equal(t, source, dis)
}
}

func TestAssembleOffsets(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
Expand Down

0 comments on commit 54ca0c2

Please sign in to comment.