Repository navigation
Describe a too-wide sequence, header version and median time past (closes #3001) (closes #3003) - #3007
Conversation
…oses #3001) (closes #3003) Three refusals wrote a caller's int with a plain f-string, outside `utils._message_text` and `utils._message_field`, so a 256-bit key passed in the int's place reached the message. With `k` such a key: - `op_checksequenceverify` wrote the low 16 bits of an unchecked input sequence: `relative lock time 65535 > 54713`, 54713 being `k & 0xFFFF`; - `Block.assert_valid_contextual` wrote the low four bytes of an unchecked header version `-k` as `0xdff42a47` in `invalid version (outdated)`; - `ChainStart` wrote `invalid median_time_past: <digits of k>`. Section 7 of the btclib-org standard, *A refusal carries no secret*, says an argument in the wrong place may be a key. The relative lock time is now written only where the sequence fits its four bytes, and the header version only where it fits its four signed bytes; a wider value is described by its sign and bit length. A median time past is refused only above four bytes, so it is always described. What this breaks: `ChainStart(..., median_time_past=2**32)` reads `invalid median_time_past: an int of 33 bits`, no longer `4294967296`. The census read each f-string field in `src/` outside the two helpers, with an `ast` walk, and judged it against a caller's int: - fixed: `script_op_codes.py` CSV relative lock time, `block.py` header version, `headers_sync.py` median time past; - a script number of at most 5 bytes, a parsed number or a value already bounded, left: the CLTV and CSV operands, OP_PICK and OP_ROLL depths, the script engine's multisig counts, the BIP137 recovery flag checked to 27..42, the block filter delta sum, total input and output amounts, a transaction version already checked to four bytes, a header's timestamp read from its `datetime`; - the leaf version of `engine/__init__.py:205`, left: BIP341 calls `c[0] & 0xfe` of the control block the leaf version, and this one is read after the control block's commitment to the script was verified; - sizes, counts, positions and indexes, left; - a `datetime`, a `str` or a `Decimal`, left: no int, and a str, Decimal or float quoted whole is ISS #3002; - `script_pub_key.py:435`, `:455` and `:480`, left: a byte of refused octets, not an int a caller passes. It is not one of the values the format defines, so section 7 bars it, as it bars the length markers beside it and the other byte-echoing refusals ISS #3005 lists; - `var_int.py:56` and `:93` and `utreexo.py:578`, `:582` and `:755`, left: each writes up to eight bytes of refused octets read as a number, the shape ISS #3005 tracks. `tests/huge_int_message_test.py` has a case for each fixed site, run with `_HUGE` and with the scalar. The scalar test also looks for the low two and four bytes of the scalar, in decimal and in hex, which the pieces `assert_secret_free` looks for are too long to catch. Edge cases check that the least header version is written and the version below it, and a sequence one bit past four bytes, are described. A test in `tests/script_engine/script_test.py` checks the low 16 bits are still written for a sequence that fits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Three refusals wrote a caller's int through a plain f-string, outside the helpers #3004 changed, so a key passed in the int's place was printed in part or whole.
op_checksequenceverifyprinted the low 16 bits of the input's sequence (relative lock time 65535 > 54713, where 54713 isk & 0xFFFF);invalid version (outdated)printed-k & 0xFFFFFFFF, the low four bytes of a negative scalar;ChainStartprintedmedian_time_pastin full above four bytes. Each now writes its value only where it fits its four bytes (a sequence in0..2**32-1, a version in the signed four-byte range) and otherwise describes it by sign and bit length with_message_text. A value that fits reads as before.What it breaks:
ChainStart(median_time_past=2**32)now readsan int of 33 bits; the other two change only past their four bytes. The census behind #3003 read every f-string field ofsrc/that is not already routed through a helper (419 fields); the rest are script numbers of at most five bytes, values already checked, sizes, counts, positions anddatetimes. The refusals that write a byte of the octets they refuse (script_pub_key.py,var_int.py,utreexo.py) are #3005, a different rule: the byte must be one the format defines. The scalar test now also looks for the low two and four bytes of the scalar, which a 12-character piece cannot match.Evidence
-n 3, coverage floorpre-commit run --all-filessphinx-build -n -Wgit log --format='%h %G? %GS' 7a0ba29b..4e579c50 G7a0ba29b..4e579c50CHANGES REQUESTEDon29eb0e38(a docstring restatedWINDOW; boundary rows missing), thenCLEARED 4e579c50ERROR: Your workspace is out of credits. Add credits to continue., 2026-11-08 09:18 CETThe dedicated reviewer's
CLEAREDof the head stands in for the fresh review.Closes #3001
Closes #3003
🤖 Generated with Claude Code