Skip to content

Commit 02eacd1

Browse files
authored
report substring missing immediates properly (#2287)
Fixes crash that should be a clean error report for using substring wrong. Unit tests added to confirm and prevent regression.
1 parent ff9f69d commit 02eacd1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

data/transactions/logic/assembler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,10 @@ func assembleBranch(ops *OpStream, spec *OpSpec, args []string) error {
747747
}
748748

749749
func assembleSubstring(ops *OpStream, spec *OpSpec, args []string) error {
750-
asmDefault(ops, spec, args)
750+
err := asmDefault(ops, spec, args)
751+
if err != nil {
752+
return err
753+
}
751754
// Having run asmDefault, only need to check extra constraints.
752755
start, _ := strconv.ParseUint(args[0], 0, 64)
753756
end, _ := strconv.ParseUint(args[1], 0, 64)
@@ -1010,7 +1013,7 @@ type assembleFunc func(*OpStream, *OpSpec, []string) error
10101013
// Basic assembly. Any extra bytes of opcode are encoded as byte immediates.
10111014
func asmDefault(ops *OpStream, spec *OpSpec, args []string) error {
10121015
if len(args) != spec.Details.Size-1 {
1013-
ops.errorf("%s expects %d immediate arguments", spec.Name, spec.Details.Size-1)
1016+
return ops.errorf("%s expects %d immediate arguments", spec.Name, spec.Details.Size-1)
10141017
}
10151018
ops.pending.WriteByte(spec.Opcode)
10161019
for i := 0; i < spec.Details.Size-1; i++ {

data/transactions/logic/eval_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,16 @@ dup; concat // 4096
19811981

19821982
func TestSubstringFlop(t *testing.T) {
19831983
t.Parallel()
1984+
// fails in compiler
1985+
testProg(t, `byte 0xf000000000000000
1986+
substring
1987+
len`, 2, expect{2, "substring expects 2 immediate arguments"})
1988+
1989+
// fails in compiler
1990+
testProg(t, `byte 0xf000000000000000
1991+
substring 1
1992+
len`, 2, expect{2, "substring expects 2 immediate arguments"})
1993+
19841994
// fails in compiler
19851995
testProg(t, `byte 0xf000000000000000
19861996
substring 4 2

0 commit comments

Comments
 (0)