Skip to content

Commit

Permalink
feat(BUX-172): add tests for valid but inccorect BUMP
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain committed Nov 21, 2023
1 parent de1f869 commit 13260cd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions spv/merkle_path_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func existsInBumps(ancestorTx *paymail.TxData, bumps paymail.BUMPs) bool {
if len(bumps) > bumpIdx {
leafs := bumps[bumpIdx].Path[0]

for _, l := range leafs {
if parentTxID == l.Hash {
for _, lf := range leafs {
if parentTxID == lf.Hash {
return true
}
}
Expand Down
17 changes: 7 additions & 10 deletions spv/scripts_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spv

import (
"errors"
"fmt"

"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript/interpreter"
Expand All @@ -17,8 +16,8 @@ func validateScripts(dBeef *paymail.DecodedBEEF) error {
return errors.New("invalid parent transactions, no matching trasactions for input")
}

result := verifyScripts(dBeef.ProcessedTxData, inputParentTx.Transaction, i)
if !result {
err := verifyScripts(dBeef.ProcessedTxData, inputParentTx.Transaction, i)
if err != nil {
return errors.New("invalid script")
}
}
Expand All @@ -27,17 +26,15 @@ func validateScripts(dBeef *paymail.DecodedBEEF) error {
}

// Verify locking and unlocking scripts pair
func verifyScripts(tx, prevTx *bt.Tx, inputIdx int) bool {
func verifyScripts(tx, prevTx *bt.Tx, inputIdx int) error {
input := tx.InputIdx(inputIdx)
prevOutput := prevTx.OutputIdx(int(input.PreviousTxOutIndex))

if err := interpreter.NewEngine().Execute(
err := interpreter.NewEngine().Execute(
interpreter.WithTx(tx, inputIdx, prevOutput),
interpreter.WithForkID(),
interpreter.WithAfterGenesis(),
); err != nil {
fmt.Println(err)
return false
}
return true
)

return err
}
3 changes: 1 addition & 2 deletions spv/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"errors"

"github.com/libsv/go-bt/v2"

"github.com/bitcoin-sv/go-paymail"
"github.com/libsv/go-bt/v2"
)

type MerkleRootVerifier interface {
Expand Down
Loading

0 comments on commit 13260cd

Please sign in to comment.