bitcoindevkit / bitcoindevkit/bdk
Canonical view admits conflicting transactions with null prevouts
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 483
- Avg merge
- 20d 3h
- Merged PRs (30d)
- 3
Description
**Describe the bug**
`TxGraph::insert_tx` skips every null previous output when indexing spends. A malformed transaction with a null prevout and a second input is not coinbase, but its null input is still skipped. Two such transactions sharing only the null prevout are therefore missed by `direct_conflicts`, and both remain in `CanonicalView` after recording their last-seen timestamps.
This requires consensus-invalid transaction data.
This issue was found by AI.
**To Reproduce**
Add this as `crates/chain/tests/test_null_outpoint.rs`, then run `cargo test -p bdk_chain --test test_null_outpoint`:
```rust
use bdk_chain::{local_chain::LocalChain, BlockId, TxGraph};
use bitcoin::{absolute, hashes::Hash, transaction, Amount, BlockHash, OutPoint, ScriptBuf,
Transaction, TxIn, TxOut, Txid};
#[test]
fn null_prevout_conflicts_remain_canonical() {
let mut graph = TxGraph::::default();
for tag in [1u8, 2] {
let tx = Transaction {
version: transaction::Version::TWO,
lock_time: absolute::LockTime::ZERO,
input: [OutPoint::null(), OutPoint::new(Txid::from_byte_array([tag; 32]), 0)]
.map(|previous_output| TxIn { previous_output, ..Default::default() })
.to_vec(),
output: vec![TxOut {
value: Amount::from_sat(1),
script_pubkey: ScriptBuf::new(),
}],
};
assert!(!tx.is_coinbase());
let _ = graph.insert_seen_at(tx.compute_txid(), u64::from(tag));
let _ = graph.insert_tx(tx);
}
let chain = LocalChain::from_blocks(
[(0, BlockHash::all_zeros())].into_iter().collect(),
).unwrap();
let view = chain.canonical_view(&graph, chain.tip().block_id(), Default::default());
let count = view.txs().len();
assert!(count <= 1, "canonical spenders of null outpoint: {count}");
}
```
The assertion fails with `canonical spenders of null outpoint: 2`.
**Expected behavior**
Canonicalization should remain conflict-free for accepted non-coinbase transactions, including this malformed-input case.
Contributor guide
Research direction
Add the reproduction as crates/chain/tests/test_null_outpoint.rs and run cargo test -p bdk_chain --test test_null_outpoint. Start by reading TxGraph::insert_tx, direct_conflicts, and CanonicalView handling for null prevouts. Done means the test passes and canonicalization retains at most one of the conflicting malformed transactions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100