Skip to content

Commit

Permalink
Merge pull request #164 from libsv/fix/interpreter-bug-op-code-separator
Browse files Browse the repository at this point in the history
OP_CODESEPARATOR bug fix
  • Loading branch information
deggen authored Jul 28, 2023
2 parents ad06c6a + 9ef4e75 commit 51c16ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions bscript/interpreter/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/libsv/go-bt/v2/bscript/interpreter/scriptflag"
"github.com/libsv/go-bt/v2/sighash"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestBadPC sets the pc to a deliberately bad result then confirms that Step()
Expand Down Expand Up @@ -928,3 +929,31 @@ func TestEngine_WithState(t *testing.T) {
})
}
}

const (
txHex1 = `0100000001abdbd5873fbda1b08c19d899993301fd44c0aa735064ebb2248260b7adadf795000000006b483045022100e7813394c7a55941c1acf3c7032046c2aa5bf3a506b4ee09e4cb5761c1850f960220154769af29eef81d56d69eba1d7a5ab37eed15beb9eadcd2cb608ff2e09b3147c321035941a219bcd9688318028afeef55183634f010a933de9d8469ff6e702d96c238ffffffff010271000000000000220687623971234575ab76a914fbcf31b659334eeb086693fc3b4005ce29e1c21788ac00000000`

txHex2 = `01000000014cc6b457cc6a235b966cec69bc4e4ea1813b71bddb2adf800848e4430e622b3d000000006a47304402201c1b7c535ff8bbee0960e0dad34e0a07857eaae5abc5a556427f4cc95e36cea50220676e3fd4eb69e98d8f9659c3bfceb0cdb34a6926ff644a6d79666e2c8266cc78c321035941a219bcd9688318028afeef55183634f010a933de9d8469ff6e702d96c238ffffffff011671000000000000220687623971234575ab76a914fbcf31b659334eeb086693fc3b4005ce29e1c21788ac00000000`
)

func TestExecute(t *testing.T) {
t.Run("OP_CODESEPARATOR parsing", func(t *testing.T) {

tx, err := bt.NewTxFromString(txHex1)
require.NoError(t, err)

prevTx, err := bt.NewTxFromString(txHex2)
require.NoError(t, err)

inputIdx := 0
input := tx.InputIdx(inputIdx)
prevOutput := prevTx.OutputIdx(int(input.PreviousTxOutIndex))

err = NewEngine().Execute(
WithTx(tx, inputIdx, prevOutput),
WithForkID(),
WithAfterGenesis(),
)
require.NoError(t, err)
})
}
6 changes: 5 additions & 1 deletion bscript/interpreter/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ func (t *thread) SetStack(data [][]byte) {

// subScript returns the script since the last OP_CODESEPARATOR.
func (t *thread) subScript() ParsedScript {
return t.scripts[t.scriptIdx][t.lastCodeSep:]
skip := 0
if t.lastCodeSep > 0 {
skip = t.lastCodeSep + 1 // +1 to skip the opcode separator itself
}
return t.scripts[t.scriptIdx][skip:]
}

// checkHashTypeEncoding returns whether the passed hashtype adheres to
Expand Down

0 comments on commit 51c16ed

Please sign in to comment.