Skip to content

Commit b96b171

Browse files
authored
Fix BIP-119 Typo + Clarify the reasons for 32 bit lengths
when drafting the BIP I attempted to triangulate what the width of the fields for number of inputs/outputs should be from various sources in the codebase, and made an error in looking at the signing and encoding logic, and not the _decoding_ logic which restricts vectors (vin, vout) to MAX_SIZE which is 33554432. This fully justifies not using a wider type (uint64_t). Also clarified arguments for not using a narrower type (uint16_t) which would be possible just for the vIn based on block size, because it's a leaky abstraction (you can still encode and decode such a transaction, just not mine it). thanks to @roconnor-blockstream for pointing this out
1 parent a3a397c commit b96b171

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

bip-0119.mediawiki

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,15 @@ spent. In general, using CHECKTEMPLATEVERIFY with more than one input is difficu
326326
and exposes subtle issues, so multiple inputs should not be used except in
327327
specific applications.
328328

329-
In principal, committing to the Sequences Hash (below) implicitly commits to the number of inputs,
329+
In principle, committing to the Sequences Hash (below) implicitly commits to the number of inputs,
330330
making this field strictly redundant. However, separately committing to this number makes it easier
331331
to construct DefaultCheckTemplateVerifyHash from script.
332332

333-
We treat the number of inputs as a `uint32_t` because signature checking code expects nIn to be an
334-
`unsigned int`, even though in principal a transaction can encode more than a `uint32_t`'s worth of
335-
inputs.
333+
We treat the number of inputs as a `uint32_t` because Bitcoin's consensus decoding logic limits vectors
334+
to `MAX_SIZE=33554432` and that is larger than `uint16_t` and smaller than `uint32_t`. 32 bits is also
335+
friendly for manipulation using Bitcoin's current math opcodes, should `OP_CAT` be added. Note that
336+
the max inputs in a block is further restricted by the block size to around 25,000, which would fit
337+
into a `uint16_t`, but that is an uneccessary abstraction leak.
336338

337339
=====Committing to the Sequences Hash=====
338340

@@ -348,12 +350,14 @@ script.
348350

349351
=====Committing to the Number of Outputs=====
350352

351-
In principal, committing to the Outputs Hash (below) implicitly commits to the number of outputs,
353+
In principle, committing to the Outputs Hash (below) implicitly commits to the number of outputs,
352354
making this field strictly redundant. However, separately committing to this number makes it easier
353355
to construct DefaultCheckTemplateVerifyHash from script.
354356

355-
We treat the number of outputs as a `uint32_t` because a `COutpoint` index is a `uint32_t`, even
356-
though in principal a transaction could encode more outputs.
357+
We treat the number of outputs as a `uint32_t` because a `COutpoint` index is a `uint32_t`.
358+
Further, Bitcoin's consensus decoding logic limits vectors to `MAX_SIZE=33554432` and that is
359+
larger than `uint16_t` and smaller than `uint32_t`. 32 bits is also friendly for manipulation using
360+
Bitcoin's current math opcodes, should `OP_CAT` be added.
357361

358362
=====Committing to the outputs hash=====
359363

0 commit comments

Comments
 (0)