Skip to content

Fix transaction proofs with duplicate witness ids - #2469

Open
a-shannon wants to merge 1 commit into
ergoplatform:v6.0.6from
a-shannon:fix/transaction-membership-proof
Open

Fix transaction proofs with duplicate witness ids#2469
a-shannon wants to merge 1 commit into
ergoplatform:v6.0.6from
a-shannon:fix/transaction-membership-proof

Conversation

@a-shannon

@a-shannon a-shannon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • return transaction membership proofs for the requested transaction when witness ids repeat
  • traverse the existing Merkle tree with its real ordered leaf count instead of scrypto's deduplicated map length
  • cover duplicate witnesses, padding boundaries, absent ids, and the mandatory-mining consumer

Root cause

For block versions after v1, BlockTransactions commits to txIds ++ witnessIds.
The scrypto tree keeps every leaf in topNode, but its hash-to-index map collapses
duplicate leaf hashes. proofByElement then traverses the real tree using the map's
smaller size, so it can return a proof for another leaf that still validates against
the transaction root.

This change locates the requested transaction in txIds and traverses the existing
tree with n leaves for v1 or 2n leaves for later versions. It also fails closed if
the traversal does not terminate at the requested leaf.

Compatibility

The ordered leaves, Merkle-tree construction, transaction root, block serialization,
JSON schema, and consensus bytes are unchanged. Only membership-proof selection is
corrected. The transaction lookup is intentionally tx-only and uses a bounded linear
scan followed by logarithmic tree traversal.

The generic duplicate-leaf fix is already merged in scrypto #5. This v6.0.6 branch
still resolves scrypto 3.0.0, so the node-local fix remains necessary here.

Validation

  • regression reproduced on the current v6.0.6 base: the test-only BlockTransactionsSpec run passed 1 test and failed the 2 new proof-identity cases
  • sbt "ergoCore/Test/testOnly org.ergoplatform.modifiers.history.BlockTransactionsSpec" — 3 passed
  • sbt "ergoCore/Test/testOnly org.ergoplatform.serialization.SerializationCoreTests -- -z BlockTransactions" — 1 passed
  • sbt "Test/testOnly org.ergoplatform.mining.ErgoMinerSpec" — 5 passed
  • sbt "Test/testOnly org.ergoplatform.http.routes.BlocksApiRouteSpec" — 10 passed
  • GitHub CI — 8/8 jobs passed on 202f762cb38b6ac56c6cc9afdb9bf51aa5208dca
  • independent review of the exact 3-file patch — no findings

Related work

Fixes #2463.

@a-shannon

Copy link
Copy Markdown
Contributor Author

Added an explicit deterministic regression in 30d9c02. It creates three distinct transaction IDs with the same witness ID, first verifies that the proof is valid against the block root, and then verifies that the leaf is the requested transaction ID. On the parent commit the test fails only on the leaf-identity assertion; on this branch it passes. BlockTransactionsSpec is green (3/3).

@a-shannon
a-shannon force-pushed the fix/transaction-membership-proof branch from ca36ced to 202f762 Compare September 2, 2026 20:34
@a-shannon

Copy link
Copy Markdown
Contributor Author

@kushti #2469 is ready for maintainer review. The current head (202f762) is one commit on top of v6.0.6, mergeable, and CI is 8/8 green. It fixes #2463 on the release branch that still resolves scrypto 3.0.0; the ordered leaves, Merkle root, serialization, and consensus bytes are unchanged.

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.

1 participant