Skip to content

Commit

Permalink
fix: added vec and format macro re-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Feb 22, 2024
1 parent 3492b3e commit 9f89b0c
Show file tree
Hide file tree
Showing 46 changed files with 179 additions and 134 deletions.
1 change: 1 addition & 0 deletions benches/smt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::mem::swap;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use miden_crypto::{
merkle::{LeafIndex, SimpleSmt},
Expand Down
11 changes: 7 additions & 4 deletions benches/store.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use miden_crypto::merkle::{
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt, SMT_MAX_DEPTH,
use miden_crypto::{
hash::rpo::RpoDigest,
merkle::{
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt,
SMT_MAX_DEPTH,
},
Felt, Word,
};
use miden_crypto::Word;
use miden_crypto::{hash::rpo::RpoDigest, Felt};
use rand_utils::{rand_array, rand_value};

/// Since MerkleTree can only be created when a power-of-two number of elements is used, the sample
Expand Down
3 changes: 2 additions & 1 deletion src/dsa/rpo_falcon512/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{LOG_N, MODULUS, PK_LEN};
use core::fmt;

use super::{LOG_N, MODULUS, PK_LEN};

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FalconError {
KeyGenerationFailed,
Expand Down
3 changes: 2 additions & 1 deletion src/dsa/rpo_falcon512/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ pub struct Rpo128Context {

#[cfg(all(test, feature = "std"))]
mod tests {
use rand_utils::{rand_array, rand_value, rand_vector};

use super::*;
use crate::dsa::rpo_falcon512::{NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
use rand_utils::{rand_array, rand_value, rand_vector};

#[test]
fn falcon_ffi() {
Expand Down
8 changes: 4 additions & 4 deletions src/dsa/rpo_falcon512/keys.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#[cfg(feature = "std")]
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
use super::{
ByteReader, ByteWriter, Deserializable, DeserializationError, FalconError, Polynomial,
PublicKeyBytes, Rpo256, SecretKeyBytes, Serializable, Signature, Word,
};

#[cfg(feature = "std")]
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};

// PUBLIC KEY
// ================================================================================================

Expand Down Expand Up @@ -182,9 +181,10 @@ impl Deserializable for KeyPair {

#[cfg(all(test, feature = "std"))]
mod tests {
use super::{super::Felt, KeyPair, NonceBytes, Word};
use rand_utils::{rand_array, rand_vector};

use super::{super::Felt, KeyPair, NonceBytes, Word};

#[test]
fn test_falcon_verification() {
// generate random keys
Expand Down
5 changes: 3 additions & 2 deletions src/dsa/rpo_falcon512/polynomial.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{FalconError, Felt, LOG_N, MODULUS, MODULUS_MINUS_1_OVER_TWO, N, PK_LEN};
use core::ops::{Add, Mul, Sub};
use winter_utils::collections::*;

use super::{FalconError, Felt, LOG_N, MODULUS, MODULUS_MINUS_1_OVER_TWO, N, PK_LEN};
use crate::utils::collections::*;

// FALCON POLYNOMIAL
// ================================================================================================
Expand Down
10 changes: 6 additions & 4 deletions src/dsa/rpo_falcon512/signature.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use core::cell::OnceCell;

use super::{
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, NonceBytes, NonceElements,
Polynomial, PublicKeyBytes, Rpo256, Serializable, SignatureBytes, Word, MODULUS, N,
SIG_L2_BOUND, ZERO,
};
use core::cell::OnceCell;
use winter_utils::string::*;
use crate::utils::string::*;

// FALCON SIGNATURE
// ================================================================================================
Expand Down Expand Up @@ -195,12 +196,13 @@ fn decode_nonce(nonce: &NonceBytes) -> NonceElements {

#[cfg(all(test, feature = "std"))]
mod tests {
use libc::c_void;
use rand_utils::rand_vector;

use super::{
super::{ffi::*, KeyPair},
*,
};
use libc::c_void;
use rand_utils::rand_vector;

// Wrappers for unsafe functions
impl Rpo128Context {
Expand Down
12 changes: 6 additions & 6 deletions src/hash/blake/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
use crate::utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
};
use core::{
mem::{size_of, transmute, transmute_copy},
ops::Deref,
slice::from_raw_parts,
};
use winter_utils::string::*;

use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
use crate::utils::{
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
};

#[cfg(test)]
mod tests;
Expand Down
5 changes: 3 additions & 2 deletions src/hash/blake/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use proptest::prelude::*;
use rand_utils::rand_vector;
use winter_utils::collections::*;

use super::*;
use crate::utils::collections::*;

#[test]
fn blake3_hash_elements() {
Expand Down
12 changes: 6 additions & 6 deletions src/hash/rescue/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[cfg(target_feature = "sve")]
pub mod optimized {
use crate::hash::rescue::STATE_WIDTH;
use crate::Felt;
use crate::{hash::rescue::STATE_WIDTH, Felt};

mod ffi {
#[link(name = "rpo_sve", kind = "static")]
Expand Down Expand Up @@ -50,8 +49,10 @@ mod x86_64_avx2;
#[cfg(target_feature = "avx2")]
pub mod optimized {
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
use crate::hash::rescue::{add_constants, STATE_WIDTH};
use crate::Felt;
use crate::{
hash::rescue::{add_constants, STATE_WIDTH},
Felt,
};

#[inline(always)]
pub fn add_constants_and_apply_sbox(
Expand Down Expand Up @@ -80,8 +81,7 @@ pub mod optimized {

#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
pub mod optimized {
use crate::hash::rescue::STATE_WIDTH;
use crate::Felt;
use crate::{hash::rescue::STATE_WIDTH, Felt};

#[inline(always)]
pub fn add_constants_and_apply_sbox(
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/mds/freq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {

#[cfg(test)]
mod tests {
use super::super::{apply_mds, Felt, MDS, ZERO};
use proptest::prelude::*;

use super::super::{apply_mds, Felt, MDS, ZERO};

const STATE_WIDTH: usize = 12;

#[inline(always)]
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use core::ops::Range;

use super::{
CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ONE, ZERO,
};
use core::ops::Range;

mod arch;
pub use arch::optimized::{add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox};
Expand Down
17 changes: 10 additions & 7 deletions src/hash/rescue/rpo/digest.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use core::{cmp::Ordering, fmt::Display, ops::Deref};

use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
use crate::utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
use crate::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
},
};
use core::{cmp::Ordering, fmt::Display, ops::Deref};
use winter_utils::string::*;
use winter_utils::Randomizable;

// DIGEST TRAIT IMPLEMENTATIONS
// ================================================================================================
Expand Down Expand Up @@ -321,9 +323,10 @@ impl IntoIterator for RpoDigest {

#[cfg(test)]
mod tests {
use rand_utils::rand_value;

use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
use crate::utils::{string::*, SliceReader};
use rand_utils::rand_value;

#[test]
fn digest_serialization() {
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/rpo/mod.rs
Original file line number Diff line number Diff line change
@@ -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, ONE, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, ZERO,
};
use core::ops::Range;

mod digest;
pub use digest::RpoDigest;
Expand Down
8 changes: 4 additions & 4 deletions src/hash/rescue/rpo/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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, ONE, STATE_WIDTH, ZERO,
};
use crate::Word;
use proptest::prelude::*;
use rand_utils::rand_value;
use winter_utils::collections::*;
use crate::{utils::collections::*, Word};

#[test]
fn test_sbox() {
Expand Down
17 changes: 10 additions & 7 deletions src/hash/rescue/rpx/digest.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use core::{cmp::Ordering, fmt::Display, ops::Deref};

use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
use crate::utils::{
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
use crate::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
},
};
use core::{cmp::Ordering, fmt::Display, ops::Deref};
use winter_utils::string::*;
use winter_utils::Randomizable;

// DIGEST TRAIT IMPLEMENTATIONS
// ================================================================================================
Expand Down Expand Up @@ -310,9 +312,10 @@ impl Deserializable for RpxDigest {

#[cfg(test)]
mod tests {
use rand_utils::rand_value;

use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
use crate::utils::{string::*, SliceReader};
use rand_utils::rand_value;

#[test]
fn digest_serialization() {
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/rpx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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,
};
use core::ops::Range;

mod digest;
pub use digest::RpxDigest;
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Felt, FieldElement, ALPHA, INV_ALPHA};
use rand_utils::rand_value;

use super::{Felt, FieldElement, ALPHA, INV_ALPHA};

#[test]
fn test_alphas() {
let e: Felt = Felt::new(rand_value());
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::time::Instant;

use clap::Parser;
use miden_crypto::{
hash::rpo::{Rpo256, RpoDigest},
merkle::{MerkleError, Smt},
Felt, Word, ONE,
};
use rand_utils::rand_value;
use std::time::Instant;

#[derive(Parser, Debug)]
#[clap(name = "Benchmark", about = "SMT benchmark", version, rename_all = "kebab-case")]
Expand Down
3 changes: 2 additions & 1 deletion src/merkle/empty_roots.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Felt, RpoDigest, EMPTY_WORD};
use core::slice;

use super::{Felt, RpoDigest, EMPTY_WORD};

// EMPTY NODES SUBTREES
// ================================================================================================

Expand Down
6 changes: 4 additions & 2 deletions src/merkle/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::merkle::{MerklePath, NodeIndex, RpoDigest};
use core::fmt;
use winter_utils::collections::*;

use super::smt::SmtLeafError;
use crate::{
merkle::{MerklePath, NodeIndex, RpoDigest},
utils::collections::*,
};

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MerkleError {
Expand Down
6 changes: 4 additions & 2 deletions src/merkle/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::fmt::Display;

use super::{Felt, MerkleError, RpoDigest};
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
use core::fmt::Display;

// NODE INDEX
// ================================================================================================
Expand Down Expand Up @@ -181,9 +182,10 @@ impl Deserializable for NodeIndex {

#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;

use super::*;

#[test]
fn test_node_index_value_too_high() {
assert_eq!(NodeIndex::new(0, 0).unwrap(), NodeIndex { depth: 0, value: 0 });
Expand Down
Loading

0 comments on commit 9f89b0c

Please sign in to comment.