Skip to content

Integrate Merkle Tree implementation from Plonky3 - #140

Merged
frozenspider merged 15 commits into
mainfrom
feature/p3-merkle-tree
Aug 26, 2025
Merged

Integrate Merkle Tree implementation from Plonky3#140
frozenspider merged 15 commits into
mainfrom
feature/p3-merkle-tree

Conversation

@frozenspider

@frozenspider frozenspider commented Aug 23, 2025

Copy link
Copy Markdown
Contributor

Reworked Merkle Tree approach used in Zinc.

Instead of a makeshift implementation, rely on the one designed by https://github.com/Plonky3/Plonky3 - just like https://github.com/tcoratger/whir-p3 does.

This particular MT is designed to commit to matrices, each matrix row becoming an MT leaf that is opened together. This is very convenient for Zinc since we need to open entire columns. For that, we transpose a matrix before committing.

Most changes in this PR are trivial due to required implementation of Copy trait for Integer. Main changes are:

  • Use Plonky3's MT implementation to commit to entire u-hat matrix
  • There's now one MT root hash for a matrix, instead of a one per-row
  • This also makes proof size much smaller due to only one Merkle proof being needed per opening
  • Hash type has been wrapped in MtHash for ease of change
  • Fixed an issue in verify_testing where the result of verify_column was silently ignored
  • In addition, encode_rows and matrix transposal is made using MaybeUninit and a minimal amount of unsafe code, yielding ~10% speedup of a commit operation.

Benchmarked running time changes of zip_benches, single threaded:

  • Zip/EncodeRows: (about the same)
  • Zip/MerkleRoot: +25% (since we're no longer optimizing for committing to individual leaves)
  • Zip/Commit: -58%
  • Zip/Open: -50%
  • Zip/Verify: -55%

Multi-threaded + asm:

@github-actions

github-actions Bot commented Aug 23, 2025

Copy link
Copy Markdown

Coverage (base → head): 75.87% → 75.74% ⬇️ 0.13 pp
Only posts when PR coverage is lower than the base branch's latest push (or freshly computed base).

@frozenspider
frozenspider force-pushed the feature/p3-merkle-tree branch from 46e6e84 to 3df3514 Compare August 23, 2025 12:32
@frozenspider
frozenspider marked this pull request as ready for review August 25, 2025 09:30
@frozenspider frozenspider changed the title [WIP] Integrate Merkle Tree implementation from Plonky3 Integrate Merkle Tree implementation from Plonky3 Aug 25, 2025

@cupicmarko cupicmarko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, I would just like to in depth through transcript, because there might be some mixing of endianness, so it's not going to be completely portable.

Comment thread src/zip/pcs/utils.rs
@frozenspider

frozenspider commented Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

@cupicmarko Good catch! My AsBytes implementation was indeed endianness dependent. Reworked it to AsWords and use fixed endianness while still avoiding unnecessary allocations and materializations (by compiler's virtue).

@NiDimi NiDimi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but there is a small typo

Comment thread src/zip/pcs/commit.rs Outdated
@frozenspider
frozenspider merged commit 0c9ed21 into main Aug 26, 2025
9 checks passed
@frozenspider
frozenspider deleted the feature/p3-merkle-tree branch August 26, 2025 13:02
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.

3 participants