Skip to content

Correct Binohash FindAndDelete boundary semantics - #293

Open
adrienlacombe wants to merge 3 commits into
solving-bitcoin:mainfrom
adrienlacombe:codex/binohash-findanddelete-boundaries
Open

adrienlacombe wants to merge 3 commits into
solving-bitcoin:mainfrom
adrienlacombe:codex/binohash-findanddelete-boundaries

Conversation

@adrienlacombe

Copy link
Copy Markdown
Contributor

The Bitcoin Script reference currently says legacy FindAndDelete can remove matching signature bytes from the middle of an unrelated push. Pinned Bitcoin Core v30.3 instead compares at parsed opcode boundaries. This corrects that consensus-mechanics description and separates OP_CODESEPARATOR stripping, which occurs during legacy sighash serialization.

Focused tests cover canonical direct, PUSHDATA1 and PUSHDATA2 pushes; duplicate signature pushes; identical bytes embedded inside another push; nonminimal push encodings; and a malformed trailing push. The malformed case checks host-parser parity only and is explicitly excluded from consensus-valid claims. The implementation behavior is linked to exact Core source lines and catalog/documentation evidence is updated.

Validation: seven focused Binohash library tests; python3 tools/kb.py validate; cargo fmt --all -- --check; git diff --check; and CARGO_PROFILE_TEST_OPT_LEVEL=1 cargo test --locked -- --skip 'fields::' (all non-field library, integration and doc tests passed).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T19:14:18.528434Z d9d4fc2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62f4a4348f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/introspection/README.md Outdated
Comment on lines +13 to +14
`49faec4f87f5cd19c88db01a82e5c68b087c8227`; malformed trailing-push coverage
checks parser parity only and is not consensus-valid Script evidence.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop scanning incomplete PUSHDATA length fields

When a malformed script ends partway through an OP_PUSHDATA2/OP_PUSHDATA4 length field, this parity claim does not hold: next_sop falls through after only the opcode and then treats the remaining length bytes as new opcode boundaries, while Core's GetOp fails and stops scanning. For example, with script bytes [0x4d, 0x00] and an empty selected signature (canonical target [0x00]), the helper deletes the final byte and returns [0x4d], but Core leaves the malformed script untouched; the new test only truncates a payload after a complete PUSHDATA1 header. Make incomplete length fields terminate scanning (and add that regression) before stating malformed parser parity.

AGENTS.md reference: AGENTS.md:L53-L54

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Leaving this open: the new malformed-tail test covers a truncated payload, but not a truncated PUSHDATA2/PUSHDATA4 length header. The helper still disagrees with Core's stop-on-GetOp-failure behavior on those inputs.

Reproducer at current head 62f4a4348f7a8dce4547b7dfa66ee5fd1c302c57:

let script = ScriptBuf::from_bytes(vec![0x4d, 0x00]);
assert_eq!(find_and_delete(&script, &[vec![]]), script);

Expected: unchanged 4d00; actual: 4d. The guarded 0x4d arm in next_sop falls through when the length header is incomplete, exposing its remaining 00 as another opcode boundary and deleting it as the canonical empty-signature push. The same problem occurs for 4e00, 4e0000, and 4e000000 (all currently become 4e). I reproduced all four directly against the helper implementation.

Please stop scanning when any push length header is incomplete and add these empty-signature regression cases, alongside the existing truncated-payload test. This is a pre-existing helper defect, but this PR's parser-parity coverage and documentation should not leave that boundary untested. It does not imply that malformed scripts are consensus-valid.

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.

2 participants