Skip to content

Commit

Permalink
OP_INVERT
Browse files Browse the repository at this point in the history
This is where the error is being generated. Maybe we can fix lower in the stack if we think about split?

Signed-off-by: Darren Kellenschwiler <[email protected]>
  • Loading branch information
sirdeggen committed Aug 15, 2023
1 parent 51c16ed commit 92ca578
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bscript/interpreter/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,15 +1090,20 @@ func opcodeSize(op *ParsedOpcode, t *thread) error {
//
// Stack transformation: a -> ~a
func opcodeInvert(op *ParsedOpcode, t *thread) error {
ba, err := t.dstack.PeekByteArray(0)
ba, err := t.dstack.PopByteArray()
if err != nil {
return err
}

// We need to invert without modifying the bytes in place.
// If we modify in place then these changes are reflected elsewhere in the stack.
baInverted := make([]byte, len(ba))
for i := range ba {
ba[i] = ba[i] ^ 0xFF
baInverted[i] = ba[i] ^ 0xFF
}

t.dstack.PushByteArray(baInverted)

return nil
}

Expand Down

0 comments on commit 92ca578

Please sign in to comment.