Commit graph

22 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
891b3fc8cc
Merge pull request #2575 from Roasbeef/trailing-relax
multi: relax trailing byte handling for DB blocks and PSBT readers
2026-07-21 17:17:23 -07:00
Olaoluwa Osuntokun
e333817d9d psbt: decode base64 packets incrementally
In this commit, we decode base64 PSBT packets as a stream instead of
reading the full encoded input into memory first.

The previous aggregate bound reused wire.MaxMessagePayload, even though
BIP-174 doesn't bind PSBT packet size to the P2P message limit. This made
the base64 path reject packets that the raw path accepted. We now feed
decoded bytes through the same per-field parser used for raw packets,
while retaining strict base64 and trailing-data checks.

We also add a regression test with nine individually valid 4,000,000-byte
unknown values to pin raw and base64 parsing to the same behavior.
2026-07-21 16:06:30 -07:00
Olaoluwa Osuntokun
263ac0eee0
Merge pull request #2539 from 0xjc65eth/fix-2495-nil-taproot-leaf
psbt: reject nil taproot leaf scripts
2026-07-20 18:52:10 -05:00
Olaoluwa Osuntokun
1ead5ba38a psbt: reject nil taproot pointer fields
In this commit, we extend taproot PSBT serialization and finalization to reject nil script spend signatures, leaf scripts, and BIP32 derivations before any sort or dereference. We return wrapped ErrInvalidPsbtFormat errors so callers can identify malformed packet state without parsing strings.

We also make FindLeafScript reject nil inputs and leaf entries. This keeps both the direct finalizer and MaybeFinalize paths from panicking on malformed in-memory packets.
2026-07-20 17:42:19 -05:00
Olaoluwa Osuntokun
aa108a28ff
Merge pull request #2563 from starius/psbt-oom
psbt: compact witness utxo scripts after parsing
2026-07-20 16:34:19 -05:00
Olaoluwa Osuntokun
2ddf73f39e psbt: avoid blocking reads and unbounded allocations in NewFromRawBytes
In this commit, we address two issues with the strict parsing recently
added to NewFromRawBytes.

First, the trailing data check probed the caller supplied reader with a
blocking one byte read. A reader without a Len method (net.Conn,
io.Pipe) that stays open after delivering a complete packet would hang
the parser forever. We now only enforce the check when the reader can
report its remaining length without an additional read, which covers
in-memory readers along with the decoded base64 path. Plain streams are
left positioned directly after the packet, and the reader contract is
now documented on NewFromRawBytes.

Second, the base64 path read the entire input into memory before any
validation ran, so a very large input could force an arbitrarily large
allocation before the first validity check. We now bound the read to
wire.MaxMessagePayload expanded by the base64 encoding overhead.

Along the way, we simplify assertFullyConsumed down to the bytes.Reader
case that all remaining callers use.
2026-07-13 21:21:19 -07:00
Boris Nagaev
c87168eba8
psbt: test final witness trailing data rejection 2026-07-08 00:14:19 -05:00
Boris Nagaev
468853e436
psbt: reject trailing final witness data 2026-07-08 00:14:19 -05:00
Boris Nagaev
b0ab66fe02
psbt: compact witness utxo scripts after parsing
wire.ReadTxOut returns PkScript slices backed by its internal 4 MiB
script slab. PSBT inputs keep parsed WitnessUtxo values, so small
scripts could otherwise keep the whole slab live.

Copy the script before storing the TxOut and assert the parsed witness
script has compact capacity.
2026-07-02 01:15:50 -05:00
Boris Nagaev
0a33ccea29
psbt: test strict base64 packet decoding 2026-06-26 12:17:37 -05:00
Boris Nagaev
70e8ceb921
psbt: decode base64 packets strictly 2026-06-26 12:17:37 -05:00
Boris Nagaev
40ad911752
psbt: test witness utxo txout strict parsing 2026-06-26 12:17:37 -05:00
Boris Nagaev
b4c5cf1660
psbt: parse witness utxo txouts strictly 2026-06-26 12:17:37 -05:00
Boris Nagaev
0a1300ddf6
psbt: test trailing packet data rejection 2026-06-26 12:17:37 -05:00
Boris Nagaev
d1de2bc3ad
psbt: reject trailing packet data 2026-06-26 12:17:37 -05:00
Boris Nagaev
0293b6e0e0
psbt: add strict tx value regression test 2026-06-26 12:17:37 -05:00
Boris Nagaev
f945179f2a
psbt: reject trailing data in tx values 2026-06-26 12:17:37 -05:00
Boris Nagaev
da5792a8ce
psbt: add reader exhaustion helper 2026-06-26 12:17:37 -05:00
Julio Cesar
1a4dea6ab0 psbt: reject nil taproot leaf scripts 2026-06-03 22:15:27 +02:00
Olaoluwa Osuntokun
fdad1fab1f multi: pin new v2 submodule tags and bump to v0.26.0-beta.rc1
In this commit, we strip all of the local `replace ... => ../...`
directives that were introduced as part of #1825 (the v2 module
restructuring), now that proper tags exist for every freshly carved-out
submodule. Every in-tree go.mod is pinned to the newly published tags:
chainhash/v2.0.0, wire/v2.0.0, chaincfg/v2.0.0, address/v2.0.0,
txscript/v2.0.0, btcutil/v2.0.0, psbt/v2.0.0, and btcec is bumped to
v2.5.0 since it now depends on chainhash/v2 (previously
chaincfg/chainhash).

While here, we also unify the Go toolchain to 1.25 across every
submodule so the workspace resolves a consistent set of language
features.

Finally, we bump the main btcd version to v0.26.0-beta.rc1 in
preparation for the upcoming release candidate.
2026-05-14 19:25:06 -07:00
Oliver Gugger
dccea8feba multi: use new v2 modules everywhere 2026-05-14 18:05:33 -07:00
Oliver Gugger
c0db6dfa11 psbt: move to top-level module, use v2, remove btcutil dep 2026-05-14 18:01:00 -07:00