Skip to content

Commit

Permalink
chore: handle deprecations in winterfell 0.8.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Mar 17, 2024
1 parent 4bc4bea commit 999a64f
Show file tree
Hide file tree
Showing 36 changed files with 93 additions and 84 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ serde = ["dep:serde", "serde?/alloc", "winter_math/serde"]
std = [
"blake3/std",
"dep:cc",
"dep:libc",
"winter_crypto/std",
"winter_math/std",
"winter_utils/std",
Expand All @@ -47,9 +46,10 @@ std = [
[dependencies]
blake3 = { version = "1.5", default-features = false }
clap = { version = "4.5", features = ["derive"], optional = true }
libc = { version = "0.2", default-features = false, optional = true }
rand_utils = { version = "0.8", package = "winter-rand-utils", optional = true }
serde = { version = "1.0", features = ["derive"], default-features = false, optional = true }
serde = { version = "1.0", features = [
"derive",
], default-features = false, optional = true }
winter_crypto = { version = "0.8", package = "winter-crypto", default-features = false }
winter_math = { version = "0.8", package = "winter-math", default-features = false }
winter_utils = { version = "0.8", package = "winter-utils", default-features = false }
Expand Down
10 changes: 7 additions & 3 deletions src/dsa/rpo_falcon512/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libc::c_int;
use core::ffi::c_int;

// C IMPLEMENTATION INTERFACE
// ================================================================================================
Expand Down Expand Up @@ -77,8 +77,11 @@ extern "C" {
#[cfg(test)]
pub fn rpo128_absorb(
sc: *mut Rpo128Context,
data: *const ::std::os::raw::c_void,
len: libc::size_t,
data: *const core::ffi::c_void,
// TODO: When #![feature(c_size_t)] stabilizes, switch this to `core::ffi::size_t` to be
// more accurate. Currently, however, all Rust targets as of this writing are such that
// `core::ffi::size_t` and `usize` are the same size.
len: usize,
);

#[cfg(test)]
Expand All @@ -96,6 +99,7 @@ pub struct Rpo128Context {

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

use super::*;
Expand Down
7 changes: 5 additions & 2 deletions src/dsa/rpo_falcon512/keys.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#[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},
alloc::vec::Vec,
};

// PUBLIC KEY
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/dsa/rpo_falcon512/polynomial.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::vec::Vec;
use core::ops::{Add, Mul, Sub};

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

// FALCON POLYNOMIAL
// ================================================================================================
Expand Down
9 changes: 6 additions & 3 deletions src/dsa/rpo_falcon512/signature.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloc::string::ToString;
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 crate::utils::string::*;

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

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

use super::{
Expand Down Expand Up @@ -236,7 +236,10 @@ mod tests {
fn test_hash_to_point() {
// Create a random message and transform it into a u8 vector
let msg_felts: Word = rand_vector::<Felt>(4).try_into().unwrap();
let msg_bytes = msg_felts.iter().flat_map(|e| e.as_int().to_le_bytes()).collect::<Vec<_>>();
let msg_bytes = msg_felts
.iter()
.flat_map(|e| e.as_int().to_le_bytes())
.collect::<alloc::vec::Vec<_>>();

// Create a nonce i.e. a [u8; 40] array and pack into a [Felt; 8] array.
let nonce: [u8; 40] = rand_vector::<u8>(40).try_into().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/hash/blake/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::string::String;
use core::{
mem::{size_of, transmute, transmute_copy},
ops::Deref,
Expand All @@ -6,7 +7,7 @@ use core::{

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

Expand Down
2 changes: 1 addition & 1 deletion src/hash/blake/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use proptest::prelude::*;
use rand_utils::rand_vector;

use super::*;
use crate::utils::collections::*;
use alloc::vec::Vec;

#[test]
fn blake3_hash_elements() {
Expand Down
6 changes: 4 additions & 2 deletions src/hash/rescue/rpo/digest.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use alloc::string::String;
use core::{cmp::Ordering, fmt::Display, ops::Deref};

use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
use crate::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
},
};
Expand Down Expand Up @@ -323,10 +324,11 @@ impl IntoIterator for RpoDigest {

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

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

#[test]
fn digest_serialization() {
Expand Down
3 changes: 2 additions & 1 deletion src/hash/rescue/rpo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use super::{
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA},
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, ONE, STATE_WIDTH, ZERO,
};
use crate::{utils::collections::*, Word};
use crate::Word;
use alloc::{collections::BTreeSet, vec::Vec};

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

use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
use crate::{
rand::Randomizable,
utils::{
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
DeserializationError, HexParseError, Serializable,
},
};
Expand Down Expand Up @@ -312,10 +313,11 @@ impl Deserializable for RpxDigest {

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

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

#[test]
fn digest_serialization() {
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[cfg(not(feature = "std"))]
#[cfg_attr(test, macro_use)]
#[macro_use]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

pub mod dsa;
pub mod hash;
pub mod merkle;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> {
println!(
"An average insertion time measured by 20 inserts into a SMT with {} key-value pairs is {:.3} milliseconds\n",
size,
// calculate the average by dividing by 20 and convert to milliseconds by multiplying by
// calculate the average by dividing by 20 and convert to milliseconds by multiplying by
// 1000. As a result, we can only multiply by 50
insertion_times.iter().sum::<f32>() * 50f32,
);
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::vec::Vec;
use core::fmt;

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

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MerkleError {
Expand Down
3 changes: 2 additions & 1 deletion src/merkle/merkle_tree.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use alloc::{string::String, vec::Vec};
use core::{fmt, ops::Deref, slice};

use winter_math::log2;

use super::{InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, Word};
use crate::utils::{collections::*, string::*, uninit_vector, word_to_hex};
use crate::utils::{uninit_vector, word_to_hex};

// MERKLE TREE
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/mmr/delta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::super::RpoDigest;
use crate::utils::collections::*;
use alloc::vec::Vec;

/// Container for the update data of a [super::PartialMmr]
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/mmr/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
RpoDigest,
};
use crate::utils::collections::*;
use alloc::vec::Vec;

// MMR
// ===============================================================================================
Expand Down
19 changes: 9 additions & 10 deletions src/merkle/mmr/partial.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::{MmrDelta, MmrProof, Rpo256, RpoDigest};
use crate::{
merkle::{
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
},
utils::{collections::*, vec},
use crate::merkle::{
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
};
use alloc::{
collections::{BTreeMap, BTreeSet},
vec::Vec,
};

// TYPE ALIASES
Expand Down Expand Up @@ -616,10 +617,8 @@ mod tests {
forest_to_rightmost_index, forest_to_root_index, InOrderIndex, MmrPeaks, PartialMmr,
RpoDigest,
};
use crate::{
merkle::{int_to_node, MerkleStore, Mmr, NodeIndex},
utils::collections::*,
};
use crate::merkle::{int_to_node, MerkleStore, Mmr, NodeIndex};
use alloc::{collections::BTreeSet, vec::Vec};

const LEAVES: [RpoDigest; 7] = [
int_to_node(0),
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/mmr/peaks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{super::ZERO, Felt, MmrError, MmrProof, Rpo256, RpoDigest, Word};
use crate::utils::collections::*;
use alloc::vec::Vec;

// MMR PEAKS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/mmr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use super::{
};
use crate::{
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
utils::collections::*,
Felt, Word,
};
use alloc::vec::Vec;

#[test]
fn test_position_equal_or_higher_than_leafs_is_never_contained() {
Expand Down
5 changes: 1 addition & 4 deletions src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ pub use error::MerkleError;
// HELPER FUNCTIONS
// ================================================================================================

#[cfg(test)]
use crate::utils::collections::*;

#[cfg(test)]
const fn int_to_node(value: u64) -> RpoDigest {
RpoDigest::new([Felt::new(value), ZERO, ZERO, ZERO])
Expand All @@ -58,6 +55,6 @@ const fn int_to_leaf(value: u64) -> Word {
}

#[cfg(test)]
fn digests_to_words(digests: &[RpoDigest]) -> Vec<Word> {
fn digests_to_words(digests: &[RpoDigest]) -> alloc::vec::Vec<Word> {
digests.iter().map(|d| d.into()).collect()
}
8 changes: 6 additions & 2 deletions src/merkle/partial_mt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use alloc::{
collections::{BTreeMap, BTreeSet},
string::String,
vec::Vec,
};
use core::fmt;

use super::{
InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Word,
EMPTY_WORD,
};
use crate::utils::{
collections::*, format, string::*, vec, word_to_hex, ByteReader, ByteWriter, Deserializable,
DeserializationError, Serializable,
word_to_hex, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
};

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/partial_mt/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
},
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath,
};
use crate::utils::collections::*;
use alloc::{collections::BTreeMap, vec::Vec};

// TEST DATA
// ================================================================================================
Expand Down
5 changes: 3 additions & 2 deletions src/merkle/path.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use alloc::vec::Vec;
use core::ops::{Deref, DerefMut};

use super::{InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest};
use crate::{
utils::{collections::*, ByteReader, Deserializable, DeserializationError, Serializable},
utils::{ByteReader, Deserializable, DeserializationError, Serializable},
Word,
};

Expand Down Expand Up @@ -128,7 +129,7 @@ impl FromIterator<RpoDigest> for MerklePath {

impl IntoIterator for MerklePath {
type Item = RpoDigest;
type IntoIter = vec::IntoIter<RpoDigest>;
type IntoIter = alloc::vec::IntoIter<RpoDigest>;

fn into_iter(self) -> Self::IntoIter {
self.nodes.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/smt/full/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alloc::vec::Vec;
use core::fmt;

use crate::{
hash::rpo::RpoDigest,
merkle::{LeafIndex, SMT_DEPTH},
utils::collections::*,
Word,
};

Expand Down
6 changes: 2 additions & 4 deletions src/merkle/smt/full/leaf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use alloc::{string::ToString, vec::Vec};
use core::cmp::Ordering;

use super::{Felt, LeafIndex, Rpo256, RpoDigest, SmtLeafError, Word, EMPTY_WORD, SMT_DEPTH};
use crate::utils::{
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable, DeserializationError,
Serializable,
};
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down
Loading

0 comments on commit 999a64f

Please sign in to comment.