pub struct DynamicRecord<N: Network> { /* private fields */ }Expand description
A dynamic record is a fixed-size representation of a record. Like static
Records, a dynamic record contains an owner, nonce, and a version.
However, instead of storing the full data, it only stores the Merkle root of
the data. This ensures that all dynamic records have a constant size,
regardless of the amount of data they contain.
Suppose we have the following record with two data entries:
record foo:
owner as address.private;
microcredits as u64.private;
memo as [u8; 32u32].public;The leaves of its Merkle tree are computed as follows:
L_0 := HashPSD8(ToField(name_0) || ToFields(entry_0))
L_1 := HashPSD8(ToField(name_1) || ToFields(entry_1))where name_i is the field encoding of the entry identifier (e.g. "microcredits" → Field),
and ToFields packs the entry’s mode tag bits (2 bits), plaintext bits, and a terminus 1
bit into field elements. The terminus bit ensures collision-resistance across entries of
different lengths.
The tree has depth RECORD_DATA_TREE_DEPTH = 5 and is constructed with
path hasher HashPSD2 and the padding scheme outlined in
snarkVM’s MerkleTree.
Implementations§
Source§impl<N: Network> DynamicRecord<N>
impl<N: Network> DynamicRecord<N>
Source§impl<N: Network> DynamicRecord<N>
impl<N: Network> DynamicRecord<N>
Sourcepub fn size_in_bits() -> Result<usize>
pub fn size_in_bits() -> Result<usize>
Returns the number of bits in a dynamic record.
Sourcepub fn size_in_bits_raw() -> Result<usize>
pub fn size_in_bits_raw() -> Result<usize>
Returns the number of raw bits in a dynamic record.
Source§impl<N: Network> DynamicRecord<N>
impl<N: Network> DynamicRecord<N>
Sourcepub const fn new_unchecked(
owner: Address<N>,
root: Field<N>,
nonce: Group<N>,
version: U8<N>,
data: Option<RecordData<N>>,
) -> Self
pub const fn new_unchecked( owner: Address<N>, root: Field<N>, nonce: Group<N>, version: U8<N>, data: Option<RecordData<N>>, ) -> Self
Initializes a dynamic record without checking that the root, tree, and data are consistent.
Source§impl<N: Network> DynamicRecord<N>
impl<N: Network> DynamicRecord<N>
Sourcepub const fn data(&self) -> &Option<RecordData<N>>
pub const fn data(&self) -> &Option<RecordData<N>>
Returns the optional record data.
Source§impl<N: Network> DynamicRecord<N>
impl<N: Network> DynamicRecord<N>
Sourcepub fn from_record(record: &Record<N, Plaintext<N>>) -> Result<Self>
pub fn from_record(record: &Record<N, Plaintext<N>>) -> Result<Self>
Creates a dynamic record from a static record.
Sourcepub fn to_record(
&self,
owner_is_private: bool,
) -> Result<Record<N, Plaintext<N>>>
pub fn to_record( &self, owner_is_private: bool, ) -> Result<Record<N, Plaintext<N>>>
Creates a static record from this dynamic record.
Sourcepub fn merkleize_data(
data: &IndexMap<Identifier<N>, Entry<N, Plaintext<N>>>,
) -> Result<RecordDataTree<N>>
pub fn merkleize_data( data: &IndexMap<Identifier<N>, Entry<N, Plaintext<N>>>, ) -> Result<RecordDataTree<N>>
Computes the Merkle tree containing the given (ordered) entries as
leaves. More details on the structure of the tree can be found in
DynamicRecord.
Sourcepub fn initialize_hashers() -> (&'static Poseidon8<N>, &'static Poseidon2<N>)
pub fn initialize_hashers() -> (&'static Poseidon8<N>, &'static Poseidon2<N>)
Returns the leaf and path hashers used to merkleize record entries.
Trait Implementations§
Source§impl<N: Clone + Network> Clone for DynamicRecord<N>
impl<N: Clone + Network> Clone for DynamicRecord<N>
Source§fn clone(&self) -> DynamicRecord<N>
fn clone(&self) -> DynamicRecord<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<N: Network> Debug for DynamicRecord<N>
impl<N: Network> Debug for DynamicRecord<N>
Source§impl<N: Network> Display for DynamicRecord<N>
impl<N: Network> Display for DynamicRecord<N>
Source§impl<N: Network> Equal for DynamicRecord<N>
impl<N: Network> Equal for DynamicRecord<N>
Source§impl<N: Network> From<&DynamicRecord<N>> for Value<N>
impl<N: Network> From<&DynamicRecord<N>> for Value<N>
Source§fn from(dynamic_record: &DynamicRecord<N>) -> Self
fn from(dynamic_record: &DynamicRecord<N>) -> Self
Initializes the value from a dynamic record.
Source§impl<N: Network> From<DynamicRecord<N>> for Value<N>
impl<N: Network> From<DynamicRecord<N>> for Value<N>
Source§fn from(dynamic_record: DynamicRecord<N>) -> Self
fn from(dynamic_record: DynamicRecord<N>) -> Self
Initializes the value from a dynamic record.
Source§impl<N: Network> FromBytes for DynamicRecord<N>
impl<N: Network> FromBytes for DynamicRecord<N>
Source§fn from_bytes_le(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
fn from_bytes_le(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
Self from a byte array in little-endian order.Source§fn from_bytes_le_unchecked(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
fn from_bytes_le_unchecked(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
Self::from_bytes_le but avoids costly checks.
This shall only be called when deserializing from a trusted source, such as local storage. Read moreSource§fn read_le_unchecked<R>(reader: R) -> Result<Self, Error>
fn read_le_unchecked<R>(reader: R) -> Result<Self, Error>
Self::read_le but avoids costly checks.
This shall only be called when deserializing from a trusted source, such as local storage. Read moreSource§impl<N: Network> FromStr for DynamicRecord<N>
impl<N: Network> FromStr for DynamicRecord<N>
Source§impl<N: Network> Parser for DynamicRecord<N>
impl<N: Network> Parser for DynamicRecord<N>
Source§fn parse(string: &str) -> ParserResult<'_, Self>
fn parse(string: &str) -> ParserResult<'_, Self>
Parses a string as a dynamic record: { owner: address, _root: field, _nonce: group, _version: u8 }.
Source§impl<N: Network> PartialEq for DynamicRecord<N>
impl<N: Network> PartialEq for DynamicRecord<N>
Source§impl<N: Network> ToBits for DynamicRecord<N>
impl<N: Network> ToBits for DynamicRecord<N>
Source§fn write_bits_le(&self, vec: &mut Vec<bool>)
fn write_bits_le(&self, vec: &mut Vec<bool>)
Returns the dynamic record as a list of little-endian bits.
Source§fn write_bits_be(&self, vec: &mut Vec<bool>)
fn write_bits_be(&self, vec: &mut Vec<bool>)
Returns the dynamic record as a list of big-endian bits.
Source§fn to_bits_le(&self) -> Vec<bool>
fn to_bits_le(&self) -> Vec<bool>
self as a boolean array in little-endian order.Source§fn to_bits_be(&self) -> Vec<bool>
fn to_bits_be(&self) -> Vec<bool>
self as a boolean array in big-endian order.Source§impl<N: Network> ToBytes for DynamicRecord<N>
impl<N: Network> ToBytes for DynamicRecord<N>
Source§impl<N: Network> ToFields for DynamicRecord<N>
impl<N: Network> ToFields for DynamicRecord<N>
impl<N: Network> Eq for DynamicRecord<N>
Auto Trait Implementations§
impl<N> Freeze for DynamicRecord<N>
impl<N> RefUnwindSafe for DynamicRecord<N>where
<N as Environment>::Field: RefUnwindSafe,
<N as Environment>::Projective: RefUnwindSafe,
N: RefUnwindSafe,
<N as Environment>::Scalar: RefUnwindSafe,
impl<N> Send for DynamicRecord<N>
impl<N> Sync for DynamicRecord<N>
impl<N> Unpin for DynamicRecord<N>where
<N as Environment>::Field: Unpin,
<N as Environment>::Projective: Unpin,
N: Unpin,
<N as Environment>::Scalar: Unpin,
impl<N> UnsafeUnpin for DynamicRecord<N>
impl<N> UnwindSafe for DynamicRecord<N>where
<N as Environment>::Field: UnwindSafe,
<N as Environment>::Projective: UnwindSafe,
N: UnwindSafe,
<N as Environment>::Scalar: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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