Add Python deserialisation for Merkle tree mini-trees#7676
Merged
Conversation
Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
…e comments Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add parsing for public:ccf.internal.tree in Python
Add Python deserialisation for Merkle tree mini-trees
Feb 17, 2026
eddyashton
reviewed
Feb 17, 2026
Extract repeated buffer[position:position+N] pattern into read_bytes() helper function to reduce error-prone code duplication. Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
eddyashton
reviewed
Feb 17, 2026
eddyashton
reviewed
Feb 17, 2026
- Remove pytest test file (project doesn't use pytest) - Remove example script (not needed) - Add proper validation test in run_read_ledger_on_testdata - Test compares accumulated merkle tree (via add_leaf) with deserialized trees - Uses real ledger data from testdata directories Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements Python deserialization of Merkle tree mini-trees from signature transactions, enabling validation of isolated ledger chunks without requiring full ledger context.
Changes:
- Added
MerkleTree.deserialise()method to parse compact Merkle tree format frompublic:ccf.internal.treetable - Fixed edge case in
get_merkle_root()to handle empty trees correctly - Added temporary validation test in
run_read_ledger_on_testdatato verify deserialization against real ledger data
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/src/ccf/merkletree.py | Core implementation of deserialise() method and empty tree fix |
| tests/e2e_operations.py | Temporary validation test comparing accumulated vs. deserialized tree roots |
…parse-public-ccf-internal-tree
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cjen1-msft
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Python parsing of serialized Merkle trees from
public:ccf.internal.treeto enable isolated chunk validation without full ledger context.Changes
Added
MerkleTree.deserialise(buffer, position=0): Parses compact mini-tree format from signature transactions[uint64 num_leaves][uint64 num_flushed][32-byte hashes...][32-byte extra_hashes...]merklecpp::deserialise)get_merkle_root()read_bytes()helper function to safely read buffer segments and advance positionFixed edge case:
get_merkle_root()now handles empty trees correctlyAdded validation test: Integrated into
run_read_ledger_on_testdataintests/e2e_operations.pyMerkleTreeviaadd_leaf()for each transactiontests/testdata/Ledgerconstructor (future PR)Implementation Details
The deserialization correctly reconstructs the Merkle tree structure by:
num_flushedbitmask to insert extra hashes on the left edgeadd_leaf()behavior)Files Changed
python/src/ccf/merkletree.py: Core implementation ofdeserialise()methodtests/e2e_operations.py: Validation test integrated into existing e2e test infrastructureOriginal prompt
public:ccf.internal.treein Python #7675💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.