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)
- [BREAKING] Increment minimum supported Rust version to 1.84.
- Removed duplicated check in RpoFalcon512 verification (#368).
- Added parallel implementation of `Smt::compute_mutations` with better performance (#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).
- 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] Increment minimum supported Rust version to 1.85 (#399).
## 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"
categories = ["cryptography", "no-std"]
keywords = ["miden", "crypto", "hash", "merkle"]
edition = "2021"
rust-version = "1.84"
edition = "2024"
rust-version = "1.85"
[[bin]]
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)
[![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)
[![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)
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::{
Felt,
hash::{
blake::Blake3_256,
rpo::{Rpo256, RpoDigest},
rpx::{Rpx256, RpxDigest},
},
Felt,
};
use rand_utils::rand_value;
use winter_crypto::Hasher;

View file

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

View file

@ -1,10 +1,10 @@
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::{
Felt, ONE, Word,
hash::rpo::RpoDigest,
merkle::{build_subtree_for_bench, NodeIndex, SmtLeaf, SubtreeLeaf, SMT_DEPTH},
Felt, Word, ONE,
merkle::{NodeIndex, SMT_DEPTH, SmtLeaf, SubtreeLeaf, build_subtree_for_bench},
};
use rand_utils::prng_array;
use winter_utils::Randomizable;

View file

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

View file

@ -1,9 +1,9 @@
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::{
merkle::{LeafIndex, SimpleSmt},
Felt, Word,
merkle::{LeafIndex, SimpleSmt},
};
use rand_utils::prng_array;
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::{
Felt, Word,
hash::rpo::RpoDigest,
merkle::{
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt,
SMT_MAX_DEPTH,
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SMT_MAX_DEPTH,
SimpleSmt,
},
Felt, Word,
};
use rand_utils::{rand_array, rand_value};

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ use alloc::vec::Vec;
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
// ================================================================================================
@ -43,8 +43,8 @@ pub fn hash_to_point_rpo256(message: Word, nonce: &Nonce) -> Polynomial<FalconFe
#[allow(dead_code)]
pub fn hash_to_point_shake256(message: &[u8], nonce: &Nonce) -> Polynomial<FalconFelt> {
use sha3::{
digest::{ExtendableOutput, Update, XofReader},
Shake256,
digest::{ExtendableOutput, Update, XofReader},
};
let mut data = vec![];

View file

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

View file

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

View file

@ -8,15 +8,15 @@ use rand::Rng;
use 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,
ByteReader, ByteWriter, Deserializable, DeserializationError, Nonce, Serializable,
ShortLatticeBasis, Signature, Word, MODULUS, N, SIGMA, SIG_L2_BOUND,
},
PubKeyPoly, PublicKey,
};
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
@ -66,7 +66,7 @@ impl SecretKey {
/// Generates a secret key from OS-provided randomness.
#[cfg(feature = "std")]
pub fn new() -> Self {
use rand::{rngs::StdRng, SeedableRng};
use rand::{SeedableRng, rngs::StdRng};
let mut rng = StdRng::from_os_rng();
Self::with_rng(&mut rng)
@ -115,7 +115,7 @@ impl SecretKey {
/// Signs a message with this secret key.
#[cfg(feature = "std")]
pub fn sign(&self, message: Word) -> Signature {
use rand::{rngs::StdRng, SeedableRng};
use rand::{SeedableRng, rngs::StdRng};
let mut rng = StdRng::from_os_rng();
self.sign_with_rng(message, &mut rng)

View file

@ -9,7 +9,7 @@ use num::Float;
use num::{One, Zero};
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
/// 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 super::{fft::CyclotomicFourier, Inverse, MODULUS};
use super::{Inverse, MODULUS, fft::CyclotomicFourier};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FalconFelt(u32);

View file

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

View file

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

View file

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

View file

@ -4,11 +4,11 @@ use core::ops::Deref;
use num::Zero;
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,
keys::PubKeyPoly,
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
@ -162,9 +162,9 @@ impl Deserializable for SignatureHeader {
}
if log_n != LOG_N {
return Err(DeserializationError::InvalidValue(
format!("Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided")
));
return Err(DeserializationError::InvalidValue(format!(
"Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided"
)));
}
Ok(Self(header))

View file

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

View file

@ -1,6 +1,6 @@
#[cfg(target_feature = "sve")]
pub mod optimized {
use crate::{hash::rescue::STATE_WIDTH, Felt};
use crate::{Felt, hash::rescue::STATE_WIDTH};
mod ffi {
#[link(name = "rpo_sve", kind = "static")]
@ -50,8 +50,8 @@ mod x86_64_avx2;
pub mod optimized {
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
use crate::{
hash::rescue::{add_constants, STATE_WIDTH},
Felt,
hash::rescue::{STATE_WIDTH, add_constants},
};
#[inline(always)]
@ -81,7 +81,7 @@ pub mod optimized {
#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
pub mod optimized {
use crate::{hash::rescue::STATE_WIDTH, Felt};
use crate::{Felt, hash::rescue::STATE_WIDTH};
#[inline(always)]
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.
let z0 = y.0 + y.2;
let z1 = y.0 - y.2;
let z2 = y.1 .0;
let z3 = -y.1 .1;
let z2 = y.1.0;
let z3 = -y.1.1;
let [x0, x2] = ifft2_real([z0, z2]);
let [x1, x3] = ifft2_real([z1, z3]);
@ -161,7 +161,7 @@ const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
mod tests {
use proptest::prelude::*;
use super::super::{apply_mds, Felt, MDS, ZERO};
use super::super::{Felt, MDS, ZERO, apply_mds};
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};
mod mds;
use mds::{apply_mds, MDS};
use mds::{MDS, apply_mds};
mod rpo;
pub use rpo::{Rpo256, RpoDigest, RpoDigestError};

View file

@ -9,12 +9,12 @@ use core::{
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::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
ByteReader, ByteWriter, Deserializable, 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 to_bool(v: u64) -> Option<bool> {
if v <= 1 {
Some(v == 1)
} else {
None
}
if v <= 1 { Some(v == 1) } else { None }
}
Ok([
@ -528,7 +524,7 @@ mod tests {
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;
#[test]

View file

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

View file

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

View file

@ -3,12 +3,12 @@ use core::{cmp::Ordering, fmt::Display, ops::Deref, slice};
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::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
ByteReader, ByteWriter, Deserializable, 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 to_bool(v: u64) -> Option<bool> {
if v <= 1 {
Some(v == 1)
} else {
None
}
if v <= 1 { Some(v == 1) } else { None }
}
Ok([
@ -516,7 +512,7 @@ mod tests {
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;
#[test]

View file

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

View file

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

View file

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

View file

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

View file

@ -2,11 +2,11 @@ use std::time::Instant;
use clap::Parser;
use miden_crypto::{
EMPTY_WORD, Felt, ONE, Word,
hash::rpo::{Rpo256, RpoDigest},
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;
#[derive(Parser, Debug)]

View file

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

View file

@ -31,6 +31,8 @@ pub enum MerkleError {
NumLeavesNotPowerOfTwo(usize),
#[error("root {0:?} is not in the store")]
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),
}

View file

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

View file

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

View file

@ -14,9 +14,9 @@ use alloc::vec::Vec;
use super::{
super::{InnerNodeInfo, MerklePath},
MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256, RpoDigest,
bit::TrueBitPositionIterator,
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
RpoDigest,
leaf_to_corresponding_tree, nodes_in_forest,
};
// MMR
@ -202,7 +202,10 @@ impl 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> {
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 {
@ -439,9 +442,5 @@ impl Iterator for MmrNodes<'_> {
/// Return a bitmask for the bits including and above the given position.
pub(crate) const fn high_bitmask(bit: u32) -> usize {
if bit > usize::BITS - 1 {
0
} else {
usize::MAX << bit
}
if bit > usize::BITS - 1 { 0 } else { usize::MAX << bit }
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,16 +11,20 @@ use crate::{
#[derive(Debug, Error)]
pub enum SmtLeafError {
#[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 },
#[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 {
key: RpoDigest,
expected_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 {
leaf_index_from_keys: LeafIndex<SMT_DEPTH>,
leaf_index_supplied: LeafIndex<SMT_DEPTH>,

View file

@ -1,7 +1,7 @@
use alloc::{string::ToString, vec::Vec};
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};
#[derive(Clone, Debug, PartialEq, Eq)]

View file

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

View file

@ -1,6 +1,6 @@
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};
/// 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 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::{
ONE, WORD_SIZE, Word,
merkle::{
smt::{NodeMutation, SparseMerkleTree, UnorderedMap},
EmptySubtreeRoots, MerkleStore, MutationSet,
smt::{NodeMutation, SparseMerkleTree, UnorderedMap},
},
utils::{Deserializable, Serializable},
Word, ONE, WORD_SIZE,
};
// SMT
// --------------------------------------------------------------------------------------------

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,10 +12,10 @@ use super::{
PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest,
};
use crate::{
Felt, ONE, WORD_SIZE, Word, ZERO,
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

View file

@ -13,8 +13,8 @@ mod kv_map;
// ================================================================================================
pub use winter_utils::{
uninit_vector, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
uninit_vector,
};
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.
#[derive(Debug, Error)]
pub enum HexParseError {
#[error(
"expected hex data to have length {expected}, including the 0x prefix, found {actual}"
)]
#[error("expected hex data to have length {expected}, including the 0x prefix, found {actual}")]
InvalidLength { expected: usize, actual: usize },
#[error("hex encoded data must start with 0x prefix")]
MissingPrefix,