Skip to main content

ProofCalculator

Struct ProofCalculator 

Source
pub struct ProofCalculator<TC, HC, VE: LeafValueEncoder> { /* private fields */ }
Expand description

A proof calculator that generates Merkle proofs from leaf data and cached branch hashes.

The hashed cursor supplies leaves, while the trie cursor supplies cached branch hashes to skip subtries. Subtries containing proof targets or keys in the configured prefix set are recalculated.

The calculator:

  • Accepts proof targets in any order and sorts them in place by parent context, then key.
  • Returns proof nodes in depth-first post-order (children before parents).
  • Automatically resets after each calculation
  • Re-uses cursors from one calculation to the next

Implementations§

Source§

impl<TC, HC, VE: LeafValueEncoder> ProofCalculator<TC, HC, VE>

Source

pub fn new(trie_cursor: TC, hashed_cursor: HC) -> Self

Create a new ProofCalculator instance for calculating account proofs.

Source

pub fn with_prefix_set(self, prefix_set: PrefixSet) -> Self

Sets the prefix set and returns self.

When given, all cached hashes matching the PrefixSet will be invalidated and their subtries recalculated.

Source§

impl<TC, HC, VE> ProofCalculator<TC, HC, VE>
where TC: TrieCursor, HC: HashedCursor, VE: LeafValueEncoder<Value = HC::Value>,

Source

pub fn proof( &mut self, value_encoder: &mut VE, targets: &mut [ProofV2Target], ) -> Result<Vec<ProofTrieNodeV2>, StateProofError>

Generate a proof for the given targets.

Given a set of ProofV2Targets, returns nodes whose paths are a prefix of any target. The returned nodes are sorted in depth-first post-order (children before parents).

Targets may be supplied in any order. Calculation sorts the slice in place by known parent context, then by key within each group.

Source

pub fn compute_root_hash( &mut self, proof_nodes: &[ProofTrieNodeV2], ) -> Result<Option<B256>, StateProofError>

Computes the root hash from a set of proof nodes.

Returns None if there is no root node (partial proof), otherwise returns the hash of the root node.

This method reuses the internal RLP encode buffer for efficiency.

Source

pub fn root_node( &mut self, value_encoder: &mut VE, ) -> Result<ProofTrieNodeV2, StateProofError>

Calculates the root node of the trie.

This method does not accept targets nor retain proofs. Returns the root node which can be used to compute the root hash via Self::compute_root_hash.

Source§

impl<TC, HC> ProofCalculator<TC, HC, StorageValueEncoder>
where TC: TrieStorageCursor, HC: HashedStorageCursor<Value = U256>,

Source

pub fn new_storage(trie_cursor: TC, hashed_cursor: HC) -> Self

Create a new StorageProofCalculator instance.

Source

pub fn storage_proof( &mut self, hashed_address: B256, targets: &mut [ProofV2Target], ) -> Result<Vec<ProofTrieNodeV2>, StateProofError>

Generate a proof for a storage trie at the given hashed address.

Given a set of ProofV2Targets, returns nodes whose paths are a prefix of any target. The returned nodes are sorted in depth-first post-order (children before parents).

Targets may be supplied in any order. Calculation sorts the slice in place by known parent context, then by key within each group.

Source

pub fn storage_root_node( &mut self, hashed_address: B256, ) -> Result<ProofTrieNodeV2, StateProofError>

Calculates the root node of a storage trie.

This method does not accept targets nor retain proofs. Returns the root node which can be used to compute the root hash via Self::compute_root_hash.

Source

pub fn storage_root( &mut self, hashed_address: B256, ) -> Result<B256, StateProofError>

Calculates the storage root hash of the account at hashed_address.

Trait Implementations§

Source§

impl<TC: Debug, HC: Debug, VE: Debug + LeafValueEncoder> Debug for ProofCalculator<TC, HC, VE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TC, HC, VE> Freeze for ProofCalculator<TC, HC, VE>
where TC: Freeze, HC: Freeze, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Freeze,

§

impl<TC, HC, VE> RefUnwindSafe for ProofCalculator<TC, HC, VE>
where TC: RefUnwindSafe, HC: RefUnwindSafe, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: RefUnwindSafe,

§

impl<TC, HC, VE> Send for ProofCalculator<TC, HC, VE>
where TC: Send, HC: Send, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Send,

§

impl<TC, HC, VE> Sync for ProofCalculator<TC, HC, VE>
where TC: Sync, HC: Sync, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Sync,

§

impl<TC, HC, VE> Unpin for ProofCalculator<TC, HC, VE>
where TC: Unpin, HC: Unpin, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Unpin,

§

impl<TC, HC, VE> UnsafeUnpin for ProofCalculator<TC, HC, VE>
where TC: UnsafeUnpin, HC: UnsafeUnpin, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: UnsafeUnpin,

§

impl<TC, HC, VE> UnwindSafe for ProofCalculator<TC, HC, VE>
where TC: UnwindSafe, HC: UnwindSafe, Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> MaybeDebug for T
where T: Debug,

§

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

§

fn type_id(&self) -> TypeId

Returns the lifetime-erased type ID of self.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.