diff --git a/pkg/compiler/emit.go b/pkg/compiler/emit.go index 56cffb237..c27a06701 100644 --- a/pkg/compiler/emit.go +++ b/pkg/compiler/emit.go @@ -7,7 +7,7 @@ import ( "math/big" "github.com/CityOfZion/neo-go/pkg/io" - "github.com/CityOfZion/neo-go/pkg/util" + "github.com/CityOfZion/neo-go/pkg/vm" "github.com/CityOfZion/neo-go/pkg/vm/opcode" ) @@ -47,7 +47,7 @@ func emitInt(w *io.BinWriter, i int64) { } bInt := big.NewInt(i) - val := util.ArrayReverse(bInt.Bytes()) + val := vm.IntToBytes(bInt) emitBytes(w, val) } diff --git a/pkg/compiler/limit_test.go b/pkg/compiler/limit_test.go new file mode 100644 index 000000000..b80282dd5 --- /dev/null +++ b/pkg/compiler/limit_test.go @@ -0,0 +1,26 @@ +package compiler_test + +import ( + "bytes" + "fmt" + "math/big" + "testing" +) + +// Test for #605, #623. +// Codegen should emit integers in proper format. +func TestManyVariables(t *testing.T) { + // any number with MSB=1 is suitable + // 155 was in the contract where this bug was first found. + const count = 155 + + buf := bytes.NewBufferString("package main\n") + for i := 0; i < count; i++ { + buf.WriteString(fmt.Sprintf("var a%d = %d\n", i, i)) + } + buf.WriteString("func Main() int {\nreturn 7\n}\n") + + src := buf.String() + + eval(t, src, big.NewInt(7)) +}