# Merkle Padding Is a Separate Integrity Contract

## Question and contribution
Does leaf/internal-node domain separation eliminate ambiguity caused by duplicating
an odd level's last node? No. This supplements Hesela's existing untagged-leaf
counterexample, not a newly discovered cryptographic vulnerability.

The model hashes leaves as SHA-256(00 || raw entry), and parents as
SHA-256(01 || left digest || right digest). It compares level-wise duplicate-last
padding with the split rule in RFC 9162 section 2.1.1. All letters are one-byte
ASCII entries; roots are displayed in hex but computed over raw bytes.

For ABC and ABCC, both padded constructions evaluate N(N(A,B),N(C,C)), where
A/B/C here denote leaf digests. For ABCDEF and ABCDEFEF, the repeated EF subtree
causes the ambiguity one level above the leaves. Hash functions receive identical
inputs at corresponding nodes. Domain prefixes cannot distinguish two identical
expanded structures.

## Run offline
Python 3.10+ standard library, no packages or network:
```sh
python3 -B model.py --check results.json
python3 -B -m unittest discover -s . -p test_model.py -v
python3 -O -B -m unittest discover -s . -p test_model.py -v
```

Six selected pairs include changed-content, reordered-content and legitimate-
repetition controls. A recursive symbolic expression implementation independently
checks the level-wise builder. A separate stack evaluator checks RFC-shaped roots
through 65 entries. Exhaustion enumerates every nonempty A/B list of length 1-10
(2046 lists); 4092 root/oracle comparisons and equality-class agreement are checked.
This is a finite structural check, not a probability estimate or security proof.

## Interpretation for storage
Bind the construction/version, root and expected entry count to a trusted manifest;
a candidate's self-declared count is not an independent expectation. Root-plus-count
distinguishes the selected substitutions but does not authenticate its own reference,
establish freshness, or prove data availability. For variable-size chunk manifests,
also specify entry encoding, order, lengths and object identity.

A flag for equal sibling hashes is not a general-purpose corruption detector.
A valid storage object can contain repeated chunks; AA is the positive control.
Rejecting all duplicates changes application semantics. A leaf-level equal-pair
check also misses the EF example, whose equal pair appears only at an internal level.

## Primary sources and scope
- RFC 9162, December 2021, section 2.1.1 (shape and prefixes), 2.1.2 (stack
  root computation), 4.9-4.10 (tree size and signed head):
  https://www.rfc-editor.org/rfc/rfc9162.html
- Bitcoin Core v28.0, commit 110183746150428e6385880c79f8c5733b1361ba,
  src/consensus/merkle.cpp: documented historical duplicate-subtree construction
  and pre-padding equal-pair checks:
  https://github.com/bitcoin/bitcoin/blob/110183746150428e6385880c79f8c5733b1361ba/src/consensus/merkle.cpp
- Same revision, src/validation.cpp, CheckMerkleRoot: root agreement and
  mutation rejection are distinct:
  https://github.com/bitcoin/bitcoin/blob/110183746150428e6385880c79f8c5733b1361ba/src/validation.cpp

Accessed 2026-11-11. These sources establish separate construction and validation
contracts; the tagged synthetic vectors and finite enumeration are Hesela's own
computation. No Bitcoin implementation is executed. The model uses single SHA-256
with role tags, not Bitcoin transaction hashes or its double-SHA256 construction.
No claim about a currently exploitable node, CT verifier, storage product,
hardware failure, benchmark or field prevalence is made. No full proof-verifier
or adversarial-input certification is claimed. Review is self-review only.

Generated results are deterministic. capture.json records actual generation time,
runtime, source-file hashes and downloaded primary-source hashes separately.
Public evidence contains original code/results, not republished source documents.
