Skip to content

feat: implement SPV verification (Transaction#verify)#135

Merged
sgbett merged 4 commits intomasterfrom
feature/95-spv-verify
Mar 7, 2026
Merged

feat: implement SPV verification (Transaction#verify)#135
sgbett merged 4 commits intomasterfrom
feature/95-spv-verify

Conversation

@sgbett
Copy link
Copy Markdown
Owner

@sgbett sgbett commented Mar 7, 2026

Summary

  • Implements Transaction#verify(chain_tracker:, fee_model: nil) for full SPV verification matching all three reference SDKs (TS, Go, Python)
  • Queue-based ancestry traversal with merkle path short-circuit, script execution, optional fee validation, output ≤ input constraint, and txid deduplication
  • 25 new specs (17 unit + 8 conformance) validating all verification paths

Changes

  • lib/bsv/transaction/transaction.rb — Added #verify public method and private helpers (verify_input_requirements, verify_fee, verify_output_constraint)
  • spec/bsv/transaction/transaction_verify_spec.rb — 17 unit/integration specs
  • spec/conformance/spv_verify_spec.rb — 8 cross-SDK conformance specs

Closes #95, #132, #133, #134

Test plan

  • All 1464 examples pass, 0 failures
  • RuboCop clean
  • Merkle path short-circuit verified (sabotaged inputs still pass)
  • Script execution failure correctly raises ScriptError
  • Fee validation only on root transaction
  • Output overflow detected
  • Deduplication confirmed via mock expectation

🤖 Generated with Claude Code

sgbett and others added 3 commits March 7, 2026 02:25
Queue-based SPV verification matching TS/Go/Python reference SDKs:
- Merkle path short-circuit for proven transactions
- Recursive source transaction verification via queue
- Script execution via interpreter for each input
- Optional fee model validation (root tx only)
- Output ≤ input constraint check
- Deduplication via verified txid set

Implements sub-task #132 of HLR #95.

Co-Authored-By: Claude <noreply@anthropic.com>
17 specs covering all SPV verification paths: merkle path
short-circuit, script execution, recursive ancestry, fee validation,
output constraint, deduplication, missing requirements, and error
reporting.

Implements sub-task #133 of HLR #95.

Co-Authored-By: Claude <noreply@anthropic.com>
8 conformance specs validating against all three reference SDKs:
merkle path short-circuit, invalid proof handling, fee-only-on-root,
output ≤ input constraint, deduplication, script execution, recursive
ancestry, and FeeModel integration.

Implements sub-task #134 of HLR #95.

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Add BSV::Transaction::VerificationError with typed error codes
  (:invalid_merkle_proof, :insufficient_fee, :output_overflow)
  matching Go SDK's typed error pattern
- Replace `|| 0` in verify_output_constraint with total_input_satoshis
  (nil inputs already caught by verify_input_requirements)
- Update all specs to expect VerificationError

Co-Authored-By: Claude <noreply@anthropic.com>
@sgbett sgbett merged commit 3f62596 into master Mar 7, 2026
7 checks passed
@sgbett sgbett deleted the feature/95-spv-verify branch March 24, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HLR] Implement SPV verification (Transaction#verify)

1 participant