chore: update to Rust 2024 edition (#399)

This commit is contained in:
Santiago Pittella 2025-03-13 17:36:22 -03:00 committed by GitHub
parent d5b38a8b35
commit b5c568eb12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 170 additions and 176 deletions

View file

@ -1,6 +1,5 @@
## 0.14.0 (TBD) ## 0.14.0 (TBD)
- [BREAKING] Increment minimum supported Rust version to 1.84.
- Removed duplicated check in RpoFalcon512 verification (#368). - Removed duplicated check in RpoFalcon512 verification (#368).
- Added parallel implementation of `Smt::compute_mutations` with better performance (#365). - Added parallel implementation of `Smt::compute_mutations` with better performance (#365).
- Implemented parallel leaf hashing in `Smt::process_sorted_pairs_to_leaves` (#365). - Implemented parallel leaf hashing in `Smt::process_sorted_pairs_to_leaves` (#365).
@ -13,6 +12,7 @@
- Add range checks to `ntru_gen` for Falcon DSA (#391). - Add range checks to `ntru_gen` for Falcon DSA (#391).
- Optimized duplicate key detection in `Smt::with_entries_concurrent` (#395). - Optimized duplicate key detection in `Smt::with_entries_concurrent` (#395).
- [BREAKING] Moved `rand` to version `0.9` removing the `try_fill_bytes` method (#398). - [BREAKING] Moved `rand` to version `0.9` removing the `try_fill_bytes` method (#398).
- [BREAKING] Increment minimum supported Rust version to 1.85 (#399).
## 0.13.3 (2025-02-18) ## 0.13.3 (2025-02-18)

View file

@ -9,8 +9,8 @@ repository = "https://github.com/0xPolygonMiden/crypto"
documentation = "https://docs.rs/miden-crypto/0.14.0" documentation = "https://docs.rs/miden-crypto/0.14.0"
categories = ["cryptography", "no-std"] categories = ["cryptography", "no-std"]
keywords = ["miden", "crypto", "hash", "merkle"] keywords = ["miden", "crypto", "hash", "merkle"]
edition = "2021" edition = "2024"
rust-version = "1.84" rust-version = "1.85"
[[bin]] [[bin]]
name = "miden-crypto" name = "miden-crypto"

View file

@ -3,7 +3,7 @@
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/0xPolygonMiden/crypto/blob/main/LICENSE) [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/0xPolygonMiden/crypto/blob/main/LICENSE)
[![test](https://github.com/0xPolygonMiden/crypto/actions/workflows/test.yml/badge.svg)](https://github.com/0xPolygonMiden/crypto/actions/workflows/test.yml) [![test](https://github.com/0xPolygonMiden/crypto/actions/workflows/test.yml/badge.svg)](https://github.com/0xPolygonMiden/crypto/actions/workflows/test.yml)
[![build](https://github.com/0xPolygonMiden/crypto/actions/workflows/build.yml/badge.svg)](https://github.com/0xPolygonMiden/crypto/actions/workflows/build.yml) [![build](https://github.com/0xPolygonMiden/crypto/actions/workflows/build.yml/badge.svg)](https://github.com/0xPolygonMiden/crypto/actions/workflows/build.yml)
[![RUST_VERSION](https://img.shields.io/badge/rustc-1.84+-lightgray.svg)](https://www.rust-lang.org/tools/install) [![RUST_VERSION](https://img.shields.io/badge/rustc-1.85+-lightgray.svg)](https://www.rust-lang.org/tools/install)
[![CRATE](https://img.shields.io/crates/v/miden-crypto)](https://crates.io/crates/miden-crypto) [![CRATE](https://img.shields.io/crates/v/miden-crypto)](https://crates.io/crates/miden-crypto)
This crate contains cryptographic primitives used in Polygon Miden. This crate contains cryptographic primitives used in Polygon Miden.

View file

@ -1,11 +1,11 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main};
use miden_crypto::{ use miden_crypto::{
Felt,
hash::{ hash::{
blake::Blake3_256, blake::Blake3_256,
rpo::{Rpo256, RpoDigest}, rpo::{Rpo256, RpoDigest},
rpx::{Rpx256, RpxDigest}, rpx::{Rpx256, RpxDigest},
}, },
Felt,
}; };
use rand_utils::rand_value; use rand_utils::rand_value;
use winter_crypto::Hasher; use winter_crypto::Hasher;

View file

@ -7,8 +7,8 @@
//! `benches/smt-subtree.rs`. //! `benches/smt-subtree.rs`.
use std::{hint, mem, time::Duration}; use std::{hint, mem, time::Duration};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use miden_crypto::{merkle::MerkleTree, Felt, Word, ONE}; use miden_crypto::{Felt, ONE, Word, merkle::MerkleTree};
use rand_utils::prng_array; use rand_utils::prng_array;
fn balanced_merkle_even(c: &mut Criterion) { fn balanced_merkle_even(c: &mut Criterion) {

View file

@ -1,10 +1,10 @@
use std::{fmt::Debug, hint, mem, time::Duration}; use std::{fmt::Debug, hint, mem, time::Duration};
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
use miden_crypto::{ use miden_crypto::{
Felt, ONE, Word,
hash::rpo::RpoDigest, hash::rpo::RpoDigest,
merkle::{build_subtree_for_bench, NodeIndex, SmtLeaf, SubtreeLeaf, SMT_DEPTH}, merkle::{NodeIndex, SMT_DEPTH, SmtLeaf, SubtreeLeaf, build_subtree_for_bench},
Felt, Word, ONE,
}; };
use rand_utils::prng_array; use rand_utils::prng_array;
use winter_utils::Randomizable; use winter_utils::Randomizable;

View file

@ -1,7 +1,7 @@
use std::{fmt::Debug, hint, mem, time::Duration}; use std::{fmt::Debug, hint, mem, time::Duration};
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
use miden_crypto::{hash::rpo::RpoDigest, merkle::Smt, Felt, Word, ONE}; use miden_crypto::{Felt, ONE, Word, hash::rpo::RpoDigest, merkle::Smt};
use rand_utils::prng_array; use rand_utils::prng_array;
use winter_utils::Randomizable; use winter_utils::Randomizable;

View file

@ -1,9 +1,9 @@
use core::mem::swap; use core::mem::swap;
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{Criterion, black_box, criterion_group, criterion_main};
use miden_crypto::{ use miden_crypto::{
merkle::{LeafIndex, SimpleSmt},
Felt, Word, Felt, Word,
merkle::{LeafIndex, SimpleSmt},
}; };
use rand_utils::prng_array; use rand_utils::prng_array;
use seq_macro::seq; use seq_macro::seq;

View file

@ -1,11 +1,11 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use criterion::{BatchSize, BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
use miden_crypto::{ use miden_crypto::{
Felt, Word,
hash::rpo::RpoDigest, hash::rpo::RpoDigest,
merkle::{ merkle::{
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt, DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SMT_MAX_DEPTH,
SMT_MAX_DEPTH, SimpleSmt,
}, },
Felt, Word,
}; };
use rand_utils::{rand_array, rand_value}; use rand_utils::{rand_array, rand_value};

View file

@ -2,7 +2,7 @@
name = "miden-crypto-fuzz" name = "miden-crypto-fuzz"
version = "0.0.0" version = "0.0.0"
publish = false publish = false
edition = "2021" edition = "2024"
[package.metadata] [package.metadata]
cargo-fuzz = true cargo-fuzz = true

View file

@ -1,5 +1,5 @@
[toolchain] [toolchain]
channel = "1.84" channel = "1.85"
components = ["rustfmt", "rust-src", "clippy"] components = ["rustfmt", "rust-src", "clippy"]
targets = ["wasm32-unknown-unknown"] targets = ["wasm32-unknown-unknown"]
profile = "minimal" profile = "minimal"

View file

@ -1,4 +1,4 @@
edition = "2021" edition = "2024"
array_width = 80 array_width = 80
attr_fn_like_width = 80 attr_fn_like_width = 80
chain_width = 80 chain_width = 80

View file

@ -2,7 +2,7 @@ use alloc::vec::Vec;
use num::Zero; use num::Zero;
use super::{math::FalconFelt, Nonce, Polynomial, Rpo256, Word, MODULUS, N, ZERO}; use super::{MODULUS, N, Nonce, Polynomial, Rpo256, Word, ZERO, math::FalconFelt};
// HASH-TO-POINT FUNCTIONS // HASH-TO-POINT FUNCTIONS
// ================================================================================================ // ================================================================================================
@ -43,8 +43,8 @@ pub fn hash_to_point_rpo256(message: Word, nonce: &Nonce) -> Polynomial<FalconFe
#[allow(dead_code)] #[allow(dead_code)]
pub fn hash_to_point_shake256(message: &[u8], nonce: &Nonce) -> Polynomial<FalconFelt> { pub fn hash_to_point_shake256(message: &[u8], nonce: &Nonce) -> Polynomial<FalconFelt> {
use sha3::{ use sha3::{
digest::{ExtendableOutput, Update, XofReader},
Shake256, Shake256,
digest::{ExtendableOutput, Update, XofReader},
}; };
let mut data = vec![]; let mut data = vec![];

View file

@ -1,7 +1,7 @@
use super::{ use super::{
math::{FalconFelt, Polynomial},
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, Serializable, Signature, ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, Serializable, Signature,
Word, Word,
math::{FalconFelt, Polynomial},
}; };
mod public_key; mod public_key;
@ -21,7 +21,7 @@ mod tests {
use winter_math::FieldElement; use winter_math::FieldElement;
use winter_utils::{Deserializable, Serializable}; use winter_utils::{Deserializable, Serializable};
use crate::{dsa::rpo_falcon512::SecretKey, Word, ONE}; use crate::{ONE, Word, dsa::rpo_falcon512::SecretKey};
#[test] #[test]
fn test_falcon_verification() { fn test_falcon_verification() {

View file

@ -4,7 +4,7 @@ use core::ops::Deref;
use num::Zero; use num::Zero;
use super::{ use super::{
super::{Rpo256, LOG_N, N, PK_LEN}, super::{LOG_N, N, PK_LEN, Rpo256},
ByteReader, ByteWriter, Deserializable, DeserializationError, FalconFelt, Felt, Polynomial, ByteReader, ByteWriter, Deserializable, DeserializationError, FalconFelt, Felt, Polynomial,
Serializable, Signature, Word, Serializable, Signature, Word,
}; };

View file

@ -8,15 +8,15 @@ use rand::Rng;
use super::{ use super::{
super::{ super::{
math::{ffldl, ffsampling, gram, normalize_tree, FalconFelt, FastFft, LdlTree, Polynomial}, ByteReader, ByteWriter, Deserializable, DeserializationError, MODULUS, N, Nonce,
SIG_L2_BOUND, SIGMA, Serializable, ShortLatticeBasis, Signature, Word,
math::{FalconFelt, FastFft, LdlTree, Polynomial, ffldl, ffsampling, gram, normalize_tree},
signature::SignaturePoly, signature::SignaturePoly,
ByteReader, ByteWriter, Deserializable, DeserializationError, Nonce, Serializable,
ShortLatticeBasis, Signature, Word, MODULUS, N, SIGMA, SIG_L2_BOUND,
}, },
PubKeyPoly, PublicKey, PubKeyPoly, PublicKey,
}; };
use crate::dsa::rpo_falcon512::{ use crate::dsa::rpo_falcon512::{
hash_to_point::hash_to_point_rpo256, math::ntru_gen, SIG_NONCE_LEN, SK_LEN, SIG_NONCE_LEN, SK_LEN, hash_to_point::hash_to_point_rpo256, math::ntru_gen,
}; };
// CONSTANTS // CONSTANTS
@ -66,7 +66,7 @@ impl SecretKey {
/// Generates a secret key from OS-provided randomness. /// Generates a secret key from OS-provided randomness.
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub fn new() -> Self { pub fn new() -> Self {
use rand::{rngs::StdRng, SeedableRng}; use rand::{SeedableRng, rngs::StdRng};
let mut rng = StdRng::from_os_rng(); let mut rng = StdRng::from_os_rng();
Self::with_rng(&mut rng) Self::with_rng(&mut rng)
@ -115,7 +115,7 @@ impl SecretKey {
/// Signs a message with this secret key. /// Signs a message with this secret key.
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub fn sign(&self, message: Word) -> Signature { pub fn sign(&self, message: Word) -> Signature {
use rand::{rngs::StdRng, SeedableRng}; use rand::{SeedableRng, rngs::StdRng};
let mut rng = StdRng::from_os_rng(); let mut rng = StdRng::from_os_rng();
self.sign_with_rng(message, &mut rng) self.sign_with_rng(message, &mut rng)

View file

@ -9,7 +9,7 @@ use num::Float;
use num::{One, Zero}; use num::{One, Zero};
use num_complex::Complex64; use num_complex::Complex64;
use super::{field::FalconFelt, polynomial::Polynomial, Inverse}; use super::{Inverse, field::FalconFelt, polynomial::Polynomial};
/// Implements Cyclotomic FFT without bitreversing the outputs, and using precomputed powers of the /// Implements Cyclotomic FFT without bitreversing the outputs, and using precomputed powers of the
/// 2n-th primitive root of unity. /// 2n-th primitive root of unity.

View file

@ -3,7 +3,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAss
use num::{One, Zero}; use num::{One, Zero};
use super::{fft::CyclotomicFourier, Inverse, MODULUS}; use super::{Inverse, MODULUS, fft::CyclotomicFourier};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FalconFelt(u32); pub struct FalconFelt(u32);

View file

@ -15,8 +15,8 @@ use num_complex::Complex64;
use rand::Rng; use rand::Rng;
use super::{ use super::{
keys::{WIDTH_BIG_POLY_COEFFICIENT, WIDTH_SMALL_POLY_COEFFICIENT},
MODULUS, MODULUS,
keys::{WIDTH_BIG_POLY_COEFFICIENT, WIDTH_SMALL_POLY_COEFFICIENT},
}; };
mod fft; mod fft;
@ -26,7 +26,7 @@ mod field;
pub use field::FalconFelt; pub use field::FalconFelt;
mod ffsampling; mod ffsampling;
pub use ffsampling::{ffldl, ffsampling, gram, normalize_tree, LdlTree}; pub use ffsampling::{LdlTree, ffldl, ffsampling, gram, normalize_tree};
mod samplerz; mod samplerz;
use self::samplerz::sampler_z; use self::samplerz::sampler_z;

View file

@ -7,10 +7,10 @@ use core::{
use num::{One, Zero}; use num::{One, Zero};
use super::{field::FalconFelt, Inverse}; use super::{Inverse, field::FalconFelt};
use crate::{ use crate::{
dsa::rpo_falcon512::{MODULUS, N},
Felt, Felt,
dsa::rpo_falcon512::{MODULUS, N},
}; };
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
@ -27,9 +27,8 @@ where
} }
} }
impl< impl<F: Mul<Output = F> + Sub<Output = F> + AddAssign + Zero + Div<Output = F> + Clone + Inverse>
F: Mul<Output = F> + Sub<Output = F> + AddAssign + Zero + Div<Output = F> + Clone + Inverse, Polynomial<F>
> Polynomial<F>
{ {
pub fn hadamard_mul(&self, other: &Self) -> Self { pub fn hadamard_mul(&self, other: &Self) -> Self {
Polynomial::new( Polynomial::new(
@ -84,16 +83,16 @@ impl<F: Zero + PartialEq + Clone> Polynomial<F> {
/// The following implementations are specific to cyclotomic polynomial rings, /// The following implementations are specific to cyclotomic polynomial rings,
/// i.e., F\[ X \] / <X^n + 1>, and are used extensively in Falcon. /// i.e., F\[ X \] / <X^n + 1>, and are used extensively in Falcon.
impl< impl<
F: One F: One
+ Zero + Zero
+ Clone + Clone
+ Neg<Output = F> + Neg<Output = F>
+ MulAssign + MulAssign
+ AddAssign + AddAssign
+ Div<Output = F> + Div<Output = F>
+ Sub<Output = F> + Sub<Output = F>
+ PartialEq, + PartialEq,
> Polynomial<F> > Polynomial<F>
{ {
/// Reduce the polynomial by X^n + 1. /// Reduce the polynomial by X^n + 1.
pub fn reduce_by_cyclotomic(&self, n: usize) -> Self { pub fn reduce_by_cyclotomic(&self, n: usize) -> Self {
@ -617,7 +616,7 @@ impl Polynomial<i16> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{FalconFelt, Polynomial, N}; use super::{FalconFelt, N, Polynomial};
#[test] #[test]
fn test_negacyclic_reduction() { fn test_negacyclic_reduction() {

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
Felt, Word, ZERO,
hash::rpo::Rpo256, hash::rpo::Rpo256,
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}, utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
Felt, Word, ZERO,
}; };
mod hash_to_point; mod hash_to_point;

View file

@ -4,11 +4,11 @@ use core::ops::Deref;
use num::Zero; use num::Zero;
use super::{ use super::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, LOG_N, MODULUS, N, Nonce,
Rpo256, SIG_L2_BOUND, SIG_POLY_BYTE_LEN, Serializable, Word,
hash_to_point::hash_to_point_rpo256, hash_to_point::hash_to_point_rpo256,
keys::PubKeyPoly, keys::PubKeyPoly,
math::{FalconFelt, FastFft, Polynomial}, math::{FalconFelt, FastFft, Polynomial},
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, Nonce, Rpo256,
Serializable, Word, LOG_N, MODULUS, N, SIG_L2_BOUND, SIG_POLY_BYTE_LEN,
}; };
// FALCON SIGNATURE // FALCON SIGNATURE
@ -162,9 +162,9 @@ impl Deserializable for SignatureHeader {
} }
if log_n != LOG_N { if log_n != LOG_N {
return Err(DeserializationError::InvalidValue( return Err(DeserializationError::InvalidValue(format!(
format!("Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided") "Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided"
)); )));
} }
Ok(Self(header)) Ok(Self(header))

View file

@ -7,8 +7,8 @@ use core::{
use super::{Digest, ElementHasher, Felt, FieldElement, Hasher}; use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
use crate::utils::{ use crate::utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable, ByteReader, ByteWriter, Deserializable, DeserializationError, HexParseError, Serializable,
DeserializationError, HexParseError, Serializable, bytes_to_hex_string, hex_to_bytes,
}; };
#[cfg(test)] #[cfg(test)]

View file

@ -1,6 +1,6 @@
#[cfg(target_feature = "sve")] #[cfg(target_feature = "sve")]
pub mod optimized { pub mod optimized {
use crate::{hash::rescue::STATE_WIDTH, Felt}; use crate::{Felt, hash::rescue::STATE_WIDTH};
mod ffi { mod ffi {
#[link(name = "rpo_sve", kind = "static")] #[link(name = "rpo_sve", kind = "static")]
@ -50,8 +50,8 @@ mod x86_64_avx2;
pub mod optimized { pub mod optimized {
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox}; use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
use crate::{ use crate::{
hash::rescue::{add_constants, STATE_WIDTH},
Felt, Felt,
hash::rescue::{STATE_WIDTH, add_constants},
}; };
#[inline(always)] #[inline(always)]
@ -81,7 +81,7 @@ pub mod optimized {
#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))] #[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
pub mod optimized { pub mod optimized {
use crate::{hash::rescue::STATE_WIDTH, Felt}; use crate::{Felt, hash::rescue::STATE_WIDTH};
#[inline(always)] #[inline(always)]
pub fn add_constants_and_apply_sbox( pub fn add_constants_and_apply_sbox(

View file

@ -85,8 +85,8 @@ const fn ifft4_real(y: (i64, (i64, i64), i64)) -> [u64; 4] {
// the MDS matrix constants. // the MDS matrix constants.
let z0 = y.0 + y.2; let z0 = y.0 + y.2;
let z1 = y.0 - y.2; let z1 = y.0 - y.2;
let z2 = y.1 .0; let z2 = y.1.0;
let z3 = -y.1 .1; let z3 = -y.1.1;
let [x0, x2] = ifft2_real([z0, z2]); let [x0, x2] = ifft2_real([z0, z2]);
let [x1, x3] = ifft2_real([z1, z3]); let [x1, x3] = ifft2_real([z1, z3]);
@ -161,7 +161,7 @@ const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
mod tests { mod tests {
use proptest::prelude::*; use proptest::prelude::*;
use super::super::{apply_mds, Felt, MDS, ZERO}; use super::super::{Felt, MDS, ZERO, apply_mds};
const STATE_WIDTH: usize = 12; const STATE_WIDTH: usize = 12;

View file

@ -6,7 +6,7 @@ mod arch;
pub use arch::optimized::{add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox}; pub use arch::optimized::{add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox};
mod mds; mod mds;
use mds::{apply_mds, MDS}; use mds::{MDS, apply_mds};
mod rpo; mod rpo;
pub use rpo::{Rpo256, RpoDigest, RpoDigestError}; pub use rpo::{Rpo256, RpoDigest, RpoDigestError};

View file

@ -9,12 +9,12 @@ use core::{
use thiserror::Error; use thiserror::Error;
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO}; use super::{DIGEST_BYTES, DIGEST_SIZE, Digest, Felt, StarkField, ZERO};
use crate::{ use crate::{
rand::Randomizable, rand::Randomizable,
utils::{ utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable, ByteReader, ByteWriter, Deserializable, DeserializationError, HexParseError, Serializable,
DeserializationError, HexParseError, Serializable, bytes_to_hex_string, hex_to_bytes,
}, },
}; };
@ -162,11 +162,7 @@ impl TryFrom<RpoDigest> for [bool; DIGEST_SIZE] {
fn try_from(value: RpoDigest) -> Result<Self, Self::Error> { fn try_from(value: RpoDigest) -> Result<Self, Self::Error> {
fn to_bool(v: u64) -> Option<bool> { fn to_bool(v: u64) -> Option<bool> {
if v <= 1 { if v <= 1 { Some(v == 1) } else { None }
Some(v == 1)
} else {
None
}
} }
Ok([ Ok([
@ -528,7 +524,7 @@ mod tests {
use rand_utils::rand_value; use rand_utils::rand_value;
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE}; use super::{DIGEST_BYTES, DIGEST_SIZE, Deserializable, Felt, RpoDigest, Serializable};
use crate::utils::SliceReader; use crate::utils::SliceReader;
#[test] #[test]

View file

@ -1,10 +1,11 @@
use core::ops::Range; use core::ops::Range;
use super::{ use super::{
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox, ARK1, ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, DIGEST_BYTES, DIGEST_RANGE, DIGEST_SIZE, Digest,
apply_mds, apply_sbox, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ARK1, ElementHasher, Felt, FieldElement, Hasher, INPUT1_RANGE, INPUT2_RANGE, MDS, NUM_ROUNDS,
ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, DIGEST_BYTES, DIGEST_RANGE, DIGEST_SIZE, INPUT1_RANGE, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, StarkField, ZERO, add_constants,
INPUT2_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, ZERO, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox, apply_mds,
apply_sbox,
}; };
mod digest; mod digest;

View file

@ -4,12 +4,12 @@ use proptest::prelude::*;
use rand_utils::rand_value; use rand_utils::rand_value;
use super::{ use super::{
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA}, super::{ALPHA, INV_ALPHA, apply_inv_sbox, apply_sbox},
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, STATE_WIDTH, ZERO, Felt, FieldElement, Hasher, Rpo256, RpoDigest, STATE_WIDTH, StarkField, ZERO,
}; };
use crate::{ use crate::{
ONE, Word,
hash::rescue::{BINARY_CHUNK_SIZE, CAPACITY_RANGE, RATE_WIDTH}, hash::rescue::{BINARY_CHUNK_SIZE, CAPACITY_RANGE, RATE_WIDTH},
Word, ONE,
}; };
#[test] #[test]

View file

@ -3,12 +3,12 @@ use core::{cmp::Ordering, fmt::Display, ops::Deref, slice};
use thiserror::Error; use thiserror::Error;
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO}; use super::{DIGEST_BYTES, DIGEST_SIZE, Digest, Felt, StarkField, ZERO};
use crate::{ use crate::{
rand::Randomizable, rand::Randomizable,
utils::{ utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable, ByteReader, ByteWriter, Deserializable, DeserializationError, HexParseError, Serializable,
DeserializationError, HexParseError, Serializable, bytes_to_hex_string, hex_to_bytes,
}, },
}; };
@ -150,11 +150,7 @@ impl TryFrom<RpxDigest> for [bool; DIGEST_SIZE] {
fn try_from(value: RpxDigest) -> Result<Self, Self::Error> { fn try_from(value: RpxDigest) -> Result<Self, Self::Error> {
fn to_bool(v: u64) -> Option<bool> { fn to_bool(v: u64) -> Option<bool> {
if v <= 1 { if v <= 1 { Some(v == 1) } else { None }
Some(v == 1)
} else {
None
}
} }
Ok([ Ok([
@ -516,7 +512,7 @@ mod tests {
use rand_utils::rand_value; use rand_utils::rand_value;
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE}; use super::{DIGEST_BYTES, DIGEST_SIZE, Deserializable, Felt, RpxDigest, Serializable};
use crate::utils::SliceReader; use crate::utils::SliceReader;
#[test] #[test]

View file

@ -1,11 +1,11 @@
use core::ops::Range; use core::ops::Range;
use super::{ use super::{
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox, ARK1, ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, CubeExtension, DIGEST_BYTES, DIGEST_RANGE,
apply_mds, apply_sbox, CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher, DIGEST_SIZE, Digest, ElementHasher, Felt, FieldElement, Hasher, INPUT1_RANGE, INPUT2_RANGE,
StarkField, ARK1, ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, DIGEST_BYTES, DIGEST_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, StarkField, ZERO, add_constants,
DIGEST_SIZE, INPUT1_RANGE, INPUT2_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox, apply_mds,
ZERO, apply_sbox,
}; };
mod digest; mod digest;

View file

@ -4,7 +4,7 @@ use proptest::prelude::*;
use rand_utils::rand_value; use rand_utils::rand_value;
use super::{Felt, Hasher, Rpx256, StarkField, ZERO}; use super::{Felt, Hasher, Rpx256, StarkField, ZERO};
use crate::{hash::rescue::RpxDigest, ONE}; use crate::{ONE, hash::rescue::RpxDigest};
#[test] #[test]
fn hash_elements_vs_merge() { fn hash_elements_vs_merge() {

View file

@ -1,6 +1,6 @@
use rand_utils::rand_value; use rand_utils::rand_value;
use super::{Felt, FieldElement, ALPHA, INV_ALPHA}; use super::{ALPHA, Felt, FieldElement, INV_ALPHA};
#[test] #[test]
fn test_alphas() { fn test_alphas() {

View file

@ -16,8 +16,8 @@ pub mod utils;
// ================================================================================================ // ================================================================================================
pub use winter_math::{ pub use winter_math::{
fields::{f64::BaseElement as Felt, CubeExtension, QuadExtension},
FieldElement, StarkField, FieldElement, StarkField,
fields::{CubeExtension, QuadExtension, f64::BaseElement as Felt},
}; };
// TYPE ALIASES // TYPE ALIASES

View file

@ -2,11 +2,11 @@ use std::time::Instant;
use clap::Parser; use clap::Parser;
use miden_crypto::{ use miden_crypto::{
EMPTY_WORD, Felt, ONE, Word,
hash::rpo::{Rpo256, RpoDigest}, hash::rpo::{Rpo256, RpoDigest},
merkle::{MerkleError, Smt}, merkle::{MerkleError, Smt},
Felt, Word, EMPTY_WORD, ONE,
}; };
use rand::{prelude::IteratorRandom, rng, Rng}; use rand::{Rng, prelude::IteratorRandom, rng};
use rand_utils::rand_value; use rand_utils::rand_value;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]

View file

@ -1,6 +1,6 @@
use core::slice; use core::slice;
use super::{smt::InnerNode, Felt, RpoDigest, EMPTY_WORD}; use super::{EMPTY_WORD, Felt, RpoDigest, smt::InnerNode};
// EMPTY NODES SUBTREES // EMPTY NODES SUBTREES
// ================================================================================================ // ================================================================================================

View file

@ -31,6 +31,8 @@ pub enum MerkleError {
NumLeavesNotPowerOfTwo(usize), NumLeavesNotPowerOfTwo(usize),
#[error("root {0:?} is not in the store")] #[error("root {0:?} is not in the store")]
RootNotInStore(RpoDigest), RootNotInStore(RpoDigest),
#[error("partial smt does not track the merkle path for key {0} so updating it would produce a different root compared to the same update in the full tree")] #[error(
"partial smt does not track the merkle path for key {0} so updating it would produce a different root compared to the same update in the full tree"
)]
UntrackedKey(RpoDigest), UntrackedKey(RpoDigest),
} }

View file

@ -290,8 +290,8 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
merkle::{digests_to_words, int_to_leaf, int_to_node},
Felt, WORD_SIZE, Felt, WORD_SIZE,
merkle::{digests_to_words, int_to_leaf, int_to_node},
}; };
const LEAVES4: [RpoDigest; WORD_SIZE] = const LEAVES4: [RpoDigest; WORD_SIZE] =

View file

@ -10,9 +10,7 @@ pub enum MmrError {
PositionNotFound(usize), PositionNotFound(usize),
#[error("mmr peaks are invalid: {0}")] #[error("mmr peaks are invalid: {0}")]
InvalidPeaks(String), InvalidPeaks(String),
#[error( #[error("mmr peak does not match the computed merkle root of the provided authentication path")]
"mmr peak does not match the computed merkle root of the provided authentication path"
)]
PeakPathMismatch, PeakPathMismatch,
#[error("requested peak index is {peak_idx} but the number of peaks is {peaks_len}")] #[error("requested peak index is {peak_idx} but the number of peaks is {peaks_len}")]
PeakOutOfBounds { peak_idx: usize, peaks_len: usize }, PeakOutOfBounds { peak_idx: usize, peaks_len: usize },

View file

@ -14,9 +14,9 @@ use alloc::vec::Vec;
use super::{ use super::{
super::{InnerNodeInfo, MerklePath}, super::{InnerNodeInfo, MerklePath},
MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256, RpoDigest,
bit::TrueBitPositionIterator, bit::TrueBitPositionIterator,
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256, leaf_to_corresponding_tree, nodes_in_forest,
RpoDigest,
}; };
// MMR // MMR
@ -202,7 +202,10 @@ impl Mmr {
/// that have been merged together, followed by the new peaks of the [Mmr]. /// that have been merged together, followed by the new peaks of the [Mmr].
pub fn get_delta(&self, from_forest: usize, to_forest: usize) -> Result<MmrDelta, MmrError> { pub fn get_delta(&self, from_forest: usize, to_forest: usize) -> Result<MmrDelta, MmrError> {
if to_forest > self.forest || from_forest > to_forest { if to_forest > self.forest || from_forest > to_forest {
return Err(MmrError::InvalidPeaks(format!("to_forest {to_forest} exceeds the current forest {} or from_forest {from_forest} exceeds to_forest", self.forest))); return Err(MmrError::InvalidPeaks(format!(
"to_forest {to_forest} exceeds the current forest {} or from_forest {from_forest} exceeds to_forest",
self.forest
)));
} }
if from_forest == to_forest { if from_forest == to_forest {
@ -439,9 +442,5 @@ impl Iterator for MmrNodes<'_> {
/// Return a bitmask for the bits including and above the given position. /// Return a bitmask for the bits including and above the given position.
pub(crate) const fn high_bitmask(bit: u32) -> usize { pub(crate) const fn high_bitmask(bit: u32) -> usize {
if bit > usize::BITS - 1 { if bit > usize::BITS - 1 { 0 } else { usize::MAX << bit }
0
} else {
usize::MAX << bit
}
} }

View file

@ -7,8 +7,8 @@ use winter_utils::{Deserializable, Serializable};
use super::{MmrDelta, MmrProof, Rpo256, RpoDigest}; use super::{MmrDelta, MmrProof, Rpo256, RpoDigest};
use crate::merkle::{ use crate::merkle::{
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks, InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
}; };
// TYPE ALIASES // TYPE ALIASES
@ -645,10 +645,10 @@ mod tests {
use winter_utils::{Deserializable, Serializable}; use winter_utils::{Deserializable, Serializable};
use super::{ use super::{
forest_to_rightmost_index, forest_to_root_index, InOrderIndex, MmrPeaks, PartialMmr, InOrderIndex, MmrPeaks, PartialMmr, RpoDigest, forest_to_rightmost_index,
RpoDigest, forest_to_root_index,
}; };
use crate::merkle::{int_to_node, MerkleStore, Mmr, NodeIndex}; use crate::merkle::{MerkleStore, Mmr, NodeIndex, int_to_node};
const LEAVES: [RpoDigest; 7] = [ const LEAVES: [RpoDigest; 7] = [
int_to_node(0), int_to_node(0),

View file

@ -2,13 +2,14 @@ use alloc::vec::Vec;
use super::{ use super::{
super::{InnerNodeInfo, Rpo256, RpoDigest}, super::{InnerNodeInfo, Rpo256, RpoDigest},
Mmr, MmrPeaks, PartialMmr,
bit::TrueBitPositionIterator, bit::TrueBitPositionIterator,
full::high_bitmask, full::high_bitmask,
leaf_to_corresponding_tree, nodes_in_forest, Mmr, MmrPeaks, PartialMmr, leaf_to_corresponding_tree, nodes_in_forest,
}; };
use crate::{ use crate::{
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
Felt, Word, Felt, Word,
merkle::{InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex, int_to_node},
}; };
#[test] #[test]

View file

@ -1,8 +1,8 @@
//! Data structures related to Merkle trees based on RPO256 hash function. //! Data structures related to Merkle trees based on RPO256 hash function.
use super::{ use super::{
EMPTY_WORD, Felt, Word, ZERO,
hash::rpo::{Rpo256, RpoDigest}, hash::rpo::{Rpo256, RpoDigest},
Felt, Word, EMPTY_WORD, ZERO,
}; };
// REEXPORTS // REEXPORTS
@ -15,18 +15,18 @@ mod index;
pub use index::NodeIndex; pub use index::NodeIndex;
mod merkle_tree; mod merkle_tree;
pub use merkle_tree::{path_to_text, tree_to_text, MerkleTree}; pub use merkle_tree::{MerkleTree, path_to_text, tree_to_text};
mod path; mod path;
pub use path::{MerklePath, RootPath, ValuePath}; pub use path::{MerklePath, RootPath, ValuePath};
mod smt; mod smt;
#[cfg(feature = "internal")]
pub use smt::{build_subtree_for_bench, SubtreeLeaf};
pub use smt::{ pub use smt::{
InnerNode, LeafIndex, MutationSet, NodeMutation, PartialSmt, SimpleSmt, Smt, SmtLeaf, InnerNode, LeafIndex, MutationSet, NodeMutation, PartialSmt, SMT_DEPTH, SMT_MAX_DEPTH,
SmtLeafError, SmtProof, SmtProofError, SMT_DEPTH, SMT_MAX_DEPTH, SMT_MIN_DEPTH, SMT_MIN_DEPTH, SimpleSmt, Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError,
}; };
#[cfg(feature = "internal")]
pub use smt::{SubtreeLeaf, build_subtree_for_bench};
mod mmr; mod mmr;
pub use mmr::{InOrderIndex, Mmr, MmrDelta, MmrError, MmrPeaks, MmrProof, PartialMmr}; pub use mmr::{InOrderIndex, Mmr, MmrDelta, MmrError, MmrPeaks, MmrProof, PartialMmr};

View file

@ -6,11 +6,11 @@ use alloc::{
use core::fmt; use core::fmt;
use super::{ use super::{
InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Word, EMPTY_WORD, InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath,
EMPTY_WORD, Word,
}; };
use crate::utils::{ use crate::utils::{
word_to_hex, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, word_to_hex,
}; };
#[cfg(test)] #[cfg(test)]

View file

@ -2,8 +2,8 @@ use alloc::{collections::BTreeMap, vec::Vec};
use super::{ use super::{
super::{ super::{
digests_to_words, int_to_node, DefaultMerkleStore as MerkleStore, MerkleTree, NodeIndex, DefaultMerkleStore as MerkleStore, MerkleTree, NodeIndex, PartialMerkleTree,
PartialMerkleTree, digests_to_words, int_to_node,
}, },
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath, Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath,
}; };

View file

@ -3,8 +3,8 @@ use core::ops::{Deref, DerefMut};
use super::{InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest}; use super::{InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest};
use crate::{ use crate::{
utils::{ByteReader, Deserializable, DeserializationError, Serializable},
Word, Word,
utils::{ByteReader, Deserializable, DeserializationError, Serializable},
}; };
// MERKLE PATH // MERKLE PATH
@ -264,7 +264,7 @@ impl Deserializable for RootPath {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::merkle::{int_to_node, MerklePath}; use crate::merkle::{MerklePath, int_to_node};
#[test] #[test]
fn test_inner_nodes() { fn test_inner_nodes() {

View file

@ -5,8 +5,8 @@ use num::Integer;
use rayon::prelude::*; use rayon::prelude::*;
use super::{ use super::{
leaf, EmptySubtreeRoots, InnerNode, InnerNodes, Leaves, MerkleError, MutationSet, NodeIndex, EmptySubtreeRoots, InnerNode, InnerNodes, Leaves, MerkleError, MutationSet, NodeIndex,
RpoDigest, Smt, SmtLeaf, SparseMerkleTree, Word, SMT_DEPTH, RpoDigest, SMT_DEPTH, Smt, SmtLeaf, SparseMerkleTree, Word, leaf,
}; };
use crate::merkle::smt::{NodeMutation, NodeMutations, UnorderedMap}; use crate::merkle::smt::{NodeMutation, NodeMutations, UnorderedMap};

View file

@ -5,16 +5,16 @@ use alloc::{
use assert_matches::assert_matches; use assert_matches::assert_matches;
use proptest::prelude::*; use proptest::prelude::*;
use rand::{prelude::IteratorRandom, rng, Rng}; use rand::{Rng, prelude::IteratorRandom, rng};
use super::{ use super::{
build_subtree, InnerNode, NodeIndex, NodeMutations, PairComputations, RpoDigest, Smt, SmtLeaf, COLS_PER_SUBTREE, InnerNode, NodeIndex, NodeMutations, PairComputations, RpoDigest, SMT_DEPTH,
SparseMerkleTree, SubtreeLeaf, SubtreeLeavesIter, UnorderedMap, COLS_PER_SUBTREE, SMT_DEPTH, SUBTREE_DEPTH, Smt, SmtLeaf, SparseMerkleTree, SubtreeLeaf, SubtreeLeavesIter, UnorderedMap,
SUBTREE_DEPTH, build_subtree,
}; };
use crate::{ use crate::{
merkle::{smt::Felt, LeafIndex, MerkleError}, EMPTY_WORD, ONE, Word, ZERO,
Word, EMPTY_WORD, ONE, ZERO, merkle::{LeafIndex, MerkleError, smt::Felt},
}; };
fn smtleaf_to_subtree_leaf(leaf: &SmtLeaf) -> SubtreeLeaf { fn smtleaf_to_subtree_leaf(leaf: &SmtLeaf) -> SubtreeLeaf {

View file

@ -11,16 +11,20 @@ use crate::{
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum SmtLeafError { pub enum SmtLeafError {
#[error( #[error(
"multiple leaf requires all keys to map to the same leaf index but key1 {key_1} and key2 {key_2} map to different indices" "multiple leaf requires all keys to map to the same leaf index but key1 {key_1} and key2 {key_2} map to different indices"
)] )]
InconsistentMultipleLeafKeys { key_1: RpoDigest, key_2: RpoDigest }, InconsistentMultipleLeafKeys { key_1: RpoDigest, key_2: RpoDigest },
#[error("single leaf key {key} maps to {actual_leaf_index:?} but was expected to map to {expected_leaf_index:?}")] #[error(
"single leaf key {key} maps to {actual_leaf_index:?} but was expected to map to {expected_leaf_index:?}"
)]
InconsistentSingleLeafIndices { InconsistentSingleLeafIndices {
key: RpoDigest, key: RpoDigest,
expected_leaf_index: LeafIndex<SMT_DEPTH>, expected_leaf_index: LeafIndex<SMT_DEPTH>,
actual_leaf_index: LeafIndex<SMT_DEPTH>, actual_leaf_index: LeafIndex<SMT_DEPTH>,
}, },
#[error("supplied leaf index {leaf_index_supplied:?} does not match {leaf_index_from_keys:?} for multiple leaf")] #[error(
"supplied leaf index {leaf_index_supplied:?} does not match {leaf_index_from_keys:?} for multiple leaf"
)]
InconsistentMultipleLeafIndices { InconsistentMultipleLeafIndices {
leaf_index_from_keys: LeafIndex<SMT_DEPTH>, leaf_index_from_keys: LeafIndex<SMT_DEPTH>,
leaf_index_supplied: LeafIndex<SMT_DEPTH>, leaf_index_supplied: LeafIndex<SMT_DEPTH>,

View file

@ -1,7 +1,7 @@
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use core::cmp::Ordering; use core::cmp::Ordering;
use super::{Felt, LeafIndex, Rpo256, RpoDigest, SmtLeafError, Word, EMPTY_WORD, SMT_DEPTH}; use super::{EMPTY_WORD, Felt, LeafIndex, Rpo256, RpoDigest, SMT_DEPTH, SmtLeafError, Word};
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}; use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]

View file

@ -1,8 +1,8 @@
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use super::{ use super::{
EmptySubtreeRoots, Felt, InnerNode, InnerNodeInfo, InnerNodes, LeafIndex, MerkleError, EMPTY_WORD, EmptySubtreeRoots, Felt, InnerNode, InnerNodeInfo, InnerNodes, LeafIndex,
MerklePath, MutationSet, NodeIndex, Rpo256, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD, MerkleError, MerklePath, MutationSet, NodeIndex, Rpo256, RpoDigest, SparseMerkleTree, Word,
}; };
mod error; mod error;
@ -19,7 +19,7 @@ use winter_utils::{ByteReader, ByteWriter, Deserializable, DeserializationError,
#[cfg(feature = "concurrent")] #[cfg(feature = "concurrent")]
mod concurrent; mod concurrent;
#[cfg(feature = "internal")] #[cfg(feature = "internal")]
pub use concurrent::{build_subtree_for_bench, SubtreeLeaf}; pub use concurrent::{SubtreeLeaf, build_subtree_for_bench};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View file

@ -1,6 +1,6 @@
use alloc::string::ToString; use alloc::string::ToString;
use super::{MerklePath, RpoDigest, SmtLeaf, SmtProofError, Word, SMT_DEPTH}; use super::{MerklePath, RpoDigest, SMT_DEPTH, SmtLeaf, SmtProofError, Word};
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable}; use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
/// A proof which can be used to assert membership (or non-membership) of key-value pairs in a /// A proof which can be used to assert membership (or non-membership) of key-value pairs in a

View file

@ -1,13 +1,13 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use super::{Felt, LeafIndex, NodeIndex, Rpo256, RpoDigest, Smt, SmtLeaf, EMPTY_WORD, SMT_DEPTH}; use super::{EMPTY_WORD, Felt, LeafIndex, NodeIndex, Rpo256, RpoDigest, SMT_DEPTH, Smt, SmtLeaf};
use crate::{ use crate::{
ONE, WORD_SIZE, Word,
merkle::{ merkle::{
smt::{NodeMutation, SparseMerkleTree, UnorderedMap},
EmptySubtreeRoots, MerkleStore, MutationSet, EmptySubtreeRoots, MerkleStore, MutationSet,
smt::{NodeMutation, SparseMerkleTree, UnorderedMap},
}, },
utils::{Deserializable, Serializable}, utils::{Deserializable, Serializable},
Word, ONE, WORD_SIZE,
}; };
// SMT // SMT
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------

View file

@ -5,14 +5,14 @@ use winter_utils::{ByteReader, ByteWriter, Deserializable, DeserializationError,
use super::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, NodeIndex}; use super::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, NodeIndex};
use crate::{ use crate::{
EMPTY_WORD, Felt, Word,
hash::rpo::{Rpo256, RpoDigest}, hash::rpo::{Rpo256, RpoDigest},
Felt, Word, EMPTY_WORD,
}; };
mod full; mod full;
pub use full::{SMT_DEPTH, Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError};
#[cfg(feature = "internal")] #[cfg(feature = "internal")]
pub use full::{build_subtree_for_bench, SubtreeLeaf}; pub use full::{SubtreeLeaf, build_subtree_for_bench};
pub use full::{Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError, SMT_DEPTH};
mod simple; mod simple;
pub use simple::SimpleSmt; pub use simple::SimpleSmt;

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
EMPTY_WORD, Word,
hash::rpo::RpoDigest, hash::rpo::RpoDigest,
merkle::{smt::SparseMerkleTree, InnerNode, MerkleError, MerklePath, Smt, SmtLeaf, SmtProof}, merkle::{InnerNode, MerkleError, MerklePath, Smt, SmtLeaf, SmtProof, smt::SparseMerkleTree},
Word, EMPTY_WORD,
}; };
/// A partial version of an [`Smt`]. /// A partial version of an [`Smt`].

View file

@ -1,9 +1,9 @@
use alloc::collections::BTreeSet; use alloc::collections::BTreeSet;
use super::{ use super::{
super::ValuePath, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes, LeafIndex, super::ValuePath, EMPTY_WORD, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes,
MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD, LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH,
SMT_MAX_DEPTH, SMT_MIN_DEPTH, SMT_MIN_DEPTH, SparseMerkleTree, Word,
}; };
#[cfg(test)] #[cfg(test)]

View file

@ -7,12 +7,12 @@ use super::{
NodeIndex, NodeIndex,
}; };
use crate::{ use crate::{
EMPTY_WORD, Word,
hash::rpo::Rpo256, hash::rpo::Rpo256,
merkle::{ merkle::{
digests_to_words, int_to_leaf, int_to_node, smt::SparseMerkleTree, EmptySubtreeRoots, EmptySubtreeRoots, InnerNodeInfo, LeafIndex, MerkleTree, digests_to_words, int_to_leaf,
InnerNodeInfo, LeafIndex, MerkleTree, int_to_node, smt::SparseMerkleTree,
}, },
Word, EMPTY_WORD,
}; };
// TEST DATA // TEST DATA

View file

@ -2,12 +2,12 @@ use alloc::{collections::BTreeMap, vec::Vec};
use core::borrow::Borrow; use core::borrow::Borrow;
use super::{ use super::{
mmr::Mmr, EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, MerkleTree, NodeIndex, EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, MerkleTree, NodeIndex,
PartialMerkleTree, RootPath, Rpo256, RpoDigest, SimpleSmt, Smt, ValuePath, PartialMerkleTree, RootPath, Rpo256, RpoDigest, SimpleSmt, Smt, ValuePath, mmr::Mmr,
}; };
use crate::utils::{ use crate::utils::{
collections::{KvMap, RecordingMap},
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
collections::{KvMap, RecordingMap},
}; };
#[cfg(test)] #[cfg(test)]

View file

@ -12,10 +12,10 @@ use super::{
PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest, PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest,
}; };
use crate::{ use crate::{
Felt, ONE, WORD_SIZE, Word, ZERO,
merkle::{ merkle::{
digests_to_words, int_to_leaf, int_to_node, LeafIndex, MerkleTree, SimpleSmt, SMT_MAX_DEPTH, LeafIndex, MerkleTree, SMT_MAX_DEPTH, SimpleSmt, digests_to_words, int_to_leaf, int_to_node,
}, },
Felt, Word, ONE, WORD_SIZE, ZERO,
}; };
// TEST DATA // TEST DATA

View file

@ -13,8 +13,8 @@ mod kv_map;
// ================================================================================================ // ================================================================================================
pub use winter_utils::{ pub use winter_utils::{
uninit_vector, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
SliceReader, uninit_vector,
}; };
pub mod collections { pub mod collections {
@ -50,9 +50,7 @@ pub fn bytes_to_hex_string<const N: usize>(data: [u8; N]) -> String {
/// Defines errors which can occur during parsing of hexadecimal strings. /// Defines errors which can occur during parsing of hexadecimal strings.
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum HexParseError { pub enum HexParseError {
#[error( #[error("expected hex data to have length {expected}, including the 0x prefix, found {actual}")]
"expected hex data to have length {expected}, including the 0x prefix, found {actual}"
)]
InvalidLength { expected: usize, actual: usize }, InvalidLength { expected: usize, actual: usize },
#[error("hex encoded data must start with 0x prefix")] #[error("hex encoded data must start with 0x prefix")]
MissingPrefix, MissingPrefix,