Skip to main content

MerkleGate

Struct MerkleGate 

Source
pub struct MerkleGate { /* private fields */ }
Expand description

Merkle Mountain Range (MMR) accumulator.

An MMR maintains a forest of perfect binary trees. Appending a leaf is O(log n) amortized: binary representations of the leaf count determine which existing peaks must be merged. The “bagged” root (fold of all peaks) changes with every write.

Compared to HashChainGate:

  • Same tamper-evidence guarantee (mutating any leaf changes the root).
  • Supports Merkle inclusion proofs (proof that leaf N is in the set) without replaying the entire chain.
  • Slightly higher per-write overhead due to peak management.

Memory: ~2n * 32 bytes (peaks + leaf hashes stored for membership proofs).

Implementations§

Source§

impl MerkleGate

Source

pub fn new() -> Self

Source

pub fn verify_leaf(&self, sequence: u64, payload_hash: &[u8; 32]) -> bool

Verify that the leaf at sequence matches the stored leaf hash. Full inclusion proof generation is left for the production crate.

Trait Implementations§

Source§

impl Default for MerkleGate

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl WriteGate for MerkleGate

Source§

fn admit(&mut self, payload: &WritePayload) -> Result<WriteReceipt, GateError>

Admit a payload and return a tamper-evident receipt.
Source§

fn verify_receipt(&self, receipt: &WriteReceipt) -> bool

Verify that a receipt is consistent with the gate’s internal state.
Source§

fn chain_root(&self) -> [u8; 32]

Current chain commitment (root or chain head). Changes after every successful admit().
Source§

fn len(&self) -> usize

Number of writes admitted so far.
Source§

fn variant(&self) -> GateVariant

Gate variant identifier.
Source§

fn is_empty(&self) -> bool

Returns true if no writes have been admitted.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.