Skip to content

Commit

Permalink
Fix opBytesLt for len(rhs) < len(lhs) (#5051)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti authored Jan 24, 2023
1 parent 2594c32 commit 92bb3ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,14 @@ func opBytesLt(cx *EvalContext) error {
rhs := nonzero(cx.stack[last].Bytes)
lhs := nonzero(cx.stack[prev].Bytes)

cx.stack[prev] = boolToSV(len(lhs) < len(rhs) || bytes.Compare(lhs, rhs) < 0)
switch {
case len(lhs) < len(rhs):
cx.stack[prev] = boolToSV(true)
case len(lhs) > len(rhs):
cx.stack[prev] = boolToSV(false)
default:
cx.stack[prev] = boolToSV(bytes.Compare(lhs, rhs) < 0)
}

cx.stack = cx.stack[:last]
return nil
Expand Down
3 changes: 3 additions & 0 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4918,6 +4918,9 @@ func TestBytesCompare(t *testing.T) {
testPanics(t, "byte 0x10; int 65; bzero; b>", 4)
testAccepts(t, "byte 0x1010; byte 0x10; b<; !", 4)

testAccepts(t, "byte 0x2000; byte 0x70; b<; !", 4)
testAccepts(t, "byte 0x7000; byte 0x20; b<; !", 4)

// All zero input are interesting, because they lead to bytes.Compare being
// called with nils. Show that is correct.
testAccepts(t, "byte 0x10; byte 0x00; b<; !", 4)
Expand Down

0 comments on commit 92bb3ce

Please sign in to comment.