pub struct CpuMerkleTree<F, Digest> { /* private fields */ }Expand description
Merkle tree with row-major codeword backing.
Each leaf corresponds to a row of backing_matrix (or a batch of rows when
rows_per_query > 1). The digest_layers are built exactly as in
MerkleTree, so
proof construction and verification are identical.
Implementations§
Source§impl<F, Digest> CpuMerkleTree<F, Digest>
impl<F, Digest> CpuMerkleTree<F, Digest>
Sourcepub unsafe fn from_raw_parts(
backing_matrix: RowMajorMatrix<F>,
digest_layers: Vec<Vec<Digest>>,
rows_per_query: usize,
) -> Self
pub unsafe fn from_raw_parts( backing_matrix: RowMajorMatrix<F>, digest_layers: Vec<Vec<Digest>>, rows_per_query: usize, ) -> Self
Construct a CpuMerkleTree from pre-computed parts without validation.
§Safety
The caller must guarantee:
digest_layersform a valid Merkle tree overbacking_matrix: the leaf layer contains correct hashes of the matrix rows and each subsequent layer contains correct compressions of consecutive pairs from the previous layer, terminating in a single root digest.rows_per_queryis a power of two and does not exceed the number of leaves (i.e.,backing_matrix.height().next_power_of_two()).- The leaf layer length equals
backing_matrix.height().next_power_of_two() / rows_per_query.
Violating these invariants will produce incorrect Merkle proofs or panics in downstream query/verification code.
Sourcepub fn backing_matrix(&self) -> &RowMajorMatrix<F>
pub fn backing_matrix(&self) -> &RowMajorMatrix<F>
Returns a reference to the row-major codeword matrix.
Sourcepub fn digest_layers(&self) -> &Vec<Vec<Digest>>
pub fn digest_layers(&self) -> &Vec<Vec<Digest>>
Returns a reference to the digest layers.
Sourcepub fn rows_per_query(&self) -> usize
pub fn rows_per_query(&self) -> usize
Number of rows batched into each Merkle leaf.
Sourcepub fn query_stride(&self) -> usize
pub fn query_stride(&self) -> usize
Number of distinct query indices (= number of entries in the bottom digest layer).
Sourcepub fn proof_depth(&self) -> usize
pub fn proof_depth(&self) -> usize
Depth of a Merkle proof (number of sibling digests).
Source§impl<F, Digest: Clone> CpuMerkleTree<F, Digest>
impl<F, Digest: Clone> CpuMerkleTree<F, Digest>
Sourcepub fn root(&self) -> Result<Digest, StackedPcsError>
pub fn root(&self) -> Result<Digest, StackedPcsError>
Returns the Merkle root (the single element of the topmost digest layer).
Sourcepub fn query_merkle_proof(
&self,
query_idx: usize,
) -> Result<Vec<Digest>, StackedPcsError>
pub fn query_merkle_proof( &self, query_idx: usize, ) -> Result<Vec<Digest>, StackedPcsError>
Returns the Merkle authentication path for the given query_idx.
Source§impl<F: Copy, Digest> CpuMerkleTree<F, Digest>
impl<F: Copy, Digest> CpuMerkleTree<F, Digest>
Sourcepub fn get_opened_rows(
&self,
index: usize,
) -> Result<Vec<Vec<F>>, StackedPcsError>
pub fn get_opened_rows( &self, index: usize, ) -> Result<Vec<Vec<F>>, StackedPcsError>
Returns the opened rows for the given query index.
The rows are { index + t * query_stride() } for t in 0..rows_per_query.
Because the backing matrix is row-major, each row is a contiguous slice — no scatter-gather is needed (unlike the column-major variant).
Trait Implementations§
Auto Trait Implementations§
impl<F, Digest> Freeze for CpuMerkleTree<F, Digest>
impl<F, Digest> RefUnwindSafe for CpuMerkleTree<F, Digest>where
F: RefUnwindSafe,
Digest: RefUnwindSafe,
impl<F, Digest> Send for CpuMerkleTree<F, Digest>
impl<F, Digest> Sync for CpuMerkleTree<F, Digest>
impl<F, Digest> Unpin for CpuMerkleTree<F, Digest>
impl<F, Digest> UnsafeUnpin for CpuMerkleTree<F, Digest>
impl<F, Digest> UnwindSafe for CpuMerkleTree<F, Digest>where
F: UnwindSafe,
Digest: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more