Skip to content

Commit

Permalink
feat: extend range of possible implementations of bytereader/bytewrit…
Browse files Browse the repository at this point in the history
…er (#262)

* fix: set up winter-utils as a no-std crate

This commit tweaks winter-utils so that rather than being a std-using
crate that conditionally becomes a no-std crate, it becomes a no-std
crate which conditionally adds functionality from libstd when the `std`
feature is enabled

NOTE: This makes the `boxed`, `collections`, and `string` modules
redundant (they technically were before too, but due to how the crate
was being built, it wasn't obvious). A subsequent commit will mark those
deprecated, and update all downstream crates to use stuff from liballoc
or libstd directly (the latter for crates which are never built no-std).

* feat: implement byte(reader|writer) for libstd read/write traits

This commit provides implementations of the ByteReader and ByteWriter
traits for any implementation of `std::io::Read` and `std::io::Write` as
follows:

* The new `ReadAdapter` type can be instantiated with any implementation
  of `std::io::Read` to use that reader as a `ByteReader`. We do not
  automatically implement `ByteReader` for any `std::io` traits/types
  due to differences in the APIs (and the fact that some useful APIs are
  still unstable). The `ReadAdapter` type addresses those discrepancies.
  See the documentation for more details.
* We automatically implement `ByteWriter` for all `std::io::Write`
  implementations, this includes things like `Vec`.

* feat: implement serializable for slices and str

* fix: deprecate re-exported standard library modules

winter-utils no longer has any use of these modules, and downstream
crates should depend on liballoc or libstd directly, depending on
whether they need to support no-std environments (same as is done in
winter-utils itself).

These deprecation warnings will ensure that any downstream users are
aware that these modules are going away, that they know how to fix it,
and gives them an opportunity to remove usages over time, rather than
simply removing these modules and breaking all downstream users.

* chore: remove deprecated usage of re-exported libstd items

This commit addresses all of the usages of re-exported libstd items from
winter-utils by using liballoc items directly.
  • Loading branch information
bitwalker authored Mar 15, 2024
1 parent a40dc2c commit bc1692c
Show file tree
Hide file tree
Showing 89 changed files with 731 additions and 156 deletions.
2 changes: 1 addition & 1 deletion air/src/air/assertions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// LICENSE file in the root directory of this source tree.

use crate::errors::AssertionError;
use alloc::vec::Vec;
use core::{
cmp::Ordering,
fmt::{Display, Formatter},
};
use math::FieldElement;
use utils::collections::*;

#[cfg(test)]
mod tests;
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/assertions/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.

use super::{Assertion, AssertionError};
use alloc::vec::Vec;
use math::{fields::f128::BaseElement, FieldElement};
use rand_utils::{rand_value, rand_vector};
use utils::collections::*;

// SINGLE ASSERTIONS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/boundary/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// LICENSE file in the root directory of this source tree.

use super::{Assertion, ExtensionOf, FieldElement};
use alloc::{collections::BTreeMap, vec::Vec};
use math::{fft, polynom};
use utils::collections::*;

// BOUNDARY CONSTRAINT
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/boundary/constraint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// LICENSE file in the root directory of this source tree.

use super::{Assertion, BoundaryConstraint, ConstraintDivisor, ExtensionOf, FieldElement};
use utils::collections::*;
use alloc::{collections::BTreeMap, vec::Vec};

// BOUNDARY CONSTRAINT GROUP
// ================================================================================================
Expand Down
5 changes: 4 additions & 1 deletion air/src/air/boundary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
// LICENSE file in the root directory of this source tree.

use super::{AirContext, Assertion, ConstraintDivisor};
use alloc::{
collections::{BTreeMap, BTreeSet},
vec::Vec,
};
use math::{ExtensionOf, FieldElement};
use utils::collections::*;

mod constraint;
pub use constraint::BoundaryConstraint;
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/boundary/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use super::{
super::tests::{build_prng, build_sequence_poly},
Assertion, BoundaryConstraint,
};
use alloc::{collections::BTreeMap, vec::Vec};
use crypto::{hashers::Blake3_256, DefaultRandomCoin, RandomCoin};
use math::{fields::f64::BaseElement, polynom, FieldElement, StarkField};
use rand_utils::{rand_value, rand_vector, shuffle};
use utils::collections::*;

// BOUNDARY CONSTRAINT TESTS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/coefficients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::vec::Vec;
use math::FieldElement;
use utils::collections::*;

// AUXILIARY TRACE SEGMENT RANDOMNESS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.

use crate::{air::TransitionConstraintDegree, ProofOptions, TraceInfo};
use alloc::vec::Vec;
use core::cmp;
use math::StarkField;
use utils::collections::*;

// AIR CONTEXT
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/divisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.

use crate::air::Assertion;
use alloc::vec::Vec;
use core::fmt::{Display, Formatter};
use math::{FieldElement, StarkField};
use utils::collections::*;

// CONSTRAINT DIVISOR
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.

use crate::ProofOptions;
use alloc::{collections::BTreeMap, vec::Vec};
use crypto::{RandomCoin, RandomCoinError};
use math::{fft, ExtensibleField, ExtensionOf, FieldElement, StarkField, ToElements};
use utils::collections::*;

mod trace_info;
pub use trace_info::{TraceInfo, TraceLayout};
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::{
TransitionConstraintDegree,
};
use crate::{AuxTraceRandElements, FieldExtension};
use alloc::{collections::BTreeMap, vec::Vec};
use crypto::{hashers::Blake3_256, DefaultRandomCoin, RandomCoin};
use math::{fields::f64::BaseElement, get_power_series, polynom, FieldElement, StarkField};
use utils::collections::*;

// PERIODIC COLUMNS
// ================================================================================================
Expand Down
6 changes: 2 additions & 4 deletions air/src/air/trace_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::{string::ToString, vec::Vec};
use math::{StarkField, ToElements};
use utils::{
collections::*, string::*, ByteReader, ByteWriter, Deserializable, DeserializationError,
Serializable,
};
use utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};

// CONSTANTS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/transition/degree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// LICENSE file in the root directory of this source tree.

use super::{super::super::ProofOptions, MIN_CYCLE_LENGTH};
use alloc::vec::Vec;
use core::cmp;
use utils::collections::*;

// TRANSITION CONSTRAINT DEGREE
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/transition/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// LICENSE file in the root directory of this source tree.

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

// EVALUATION FRAME
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// LICENSE file in the root directory of this source tree.

use super::{AirContext, ConstraintDivisor, ExtensionOf, FieldElement};
use utils::collections::*;
use alloc::vec::Vec;

mod frame;
pub use frame::EvaluationFrame;
Expand Down
3 changes: 1 addition & 2 deletions air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
//! This crate also contains components describing STARK protocol parameters ([ProofOptions]) and
//! proof structure ([StarkProof](proof::StarkProof)).

#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

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

Expand Down
5 changes: 2 additions & 3 deletions air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::vec::Vec;
use fri::FriOptions;
use math::{StarkField, ToElements};
use utils::{
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
};
use utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};

// CONSTANTS
// ================================================================================================
Expand Down
4 changes: 2 additions & 2 deletions air/src/proof/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::vec::Vec;
use crypto::Hasher;
use utils::{
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
};

// COMMITMENTS
Expand Down
6 changes: 2 additions & 4 deletions air/src/proof/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
// LICENSE file in the root directory of this source tree.

use crate::{ProofOptions, TraceInfo, TraceLayout};
use alloc::{string::ToString, vec::Vec};
use math::{StarkField, ToElements};
use utils::{
collections::*, string::*, ByteReader, ByteWriter, Deserializable, DeserializationError,
Serializable,
};
use utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};

// PROOF CONTEXT
// ================================================================================================
Expand Down
5 changes: 2 additions & 3 deletions air/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//! Contains STARK proof struct and associated components.

use crate::{ProofOptions, TraceInfo, TraceLayout};
use alloc::vec::Vec;
use core::cmp;
use crypto::Hasher;
use fri::FriProof;
use math::FieldElement;
use utils::{
collections::*, ByteReader, Deserializable, DeserializationError, Serializable, SliceReader,
};
use utils::{ByteReader, Deserializable, DeserializationError, Serializable, SliceReader};

mod context;
pub use context::Context;
Expand Down
4 changes: 2 additions & 2 deletions air/src/proof/ood_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::vec::Vec;
use math::FieldElement;
use utils::{
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
};

// TYPE ALIASES
Expand Down
4 changes: 2 additions & 2 deletions air/src/proof/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// LICENSE file in the root directory of this source tree.

use super::Table;
use alloc::vec::Vec;
use crypto::{BatchMerkleProof, ElementHasher, Hasher};
use math::FieldElement;
use utils::{
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
};

// QUERIES
Expand Down
2 changes: 1 addition & 1 deletion air/src/proof/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// LICENSE file in the root directory of this source tree.

use super::{DeserializationError, SliceReader};
use alloc::vec::Vec;
use core::iter::FusedIterator;
use math::FieldElement;
use utils::collections::*;
use utils::ByteReader;

// CONSTANTS
Expand Down
3 changes: 1 addition & 2 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
//! [RandomCoin] implementation uses a cryptographic hash function to generate pseudo-random
//! elements form a seed.

#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

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

Expand Down
3 changes: 2 additions & 1 deletion crypto/src/merkle/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// LICENSE file in the root directory of this source tree.

use crate::Hasher;
use alloc::vec::Vec;
use core::slice;
use utils::{collections::*, iterators::*, rayon};
use utils::{iterators::*, rayon};

// CONSTANTS
// ================================================================================================
Expand Down
5 changes: 4 additions & 1 deletion crypto/src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
// LICENSE file in the root directory of this source tree.

use crate::{errors::MerkleTreeError, hash::Hasher};
use alloc::{
collections::{BTreeMap, BTreeSet},
vec::Vec,
};
use core::slice;
use utils::collections::*;

mod proofs;
pub use proofs::BatchMerkleProof;
Expand Down
3 changes: 2 additions & 1 deletion crypto/src/merkle/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// LICENSE file in the root directory of this source tree.

use crate::{errors::MerkleTreeError, Hasher};
use utils::{collections::*, string::*, ByteReader, DeserializationError, Serializable};
use alloc::{collections::BTreeMap, string::ToString, vec::Vec};
use utils::{ByteReader, DeserializationError, Serializable};

// CONSTANTS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/random/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// LICENSE file in the root directory of this source tree.

use crate::{errors::RandomCoinError, Digest, ElementHasher, RandomCoin};
use alloc::vec::Vec;
use math::{FieldElement, StarkField};
use utils::collections::*;

// DEFAULT RANDOM COIN IMPLEMENTATION
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// LICENSE file in the root directory of this source tree.

use crate::{errors::RandomCoinError, ElementHasher, Hasher};
use alloc::vec::Vec;
use math::{FieldElement, StarkField};
use utils::collections::*;

mod default;
pub use default::DefaultRandomCoin;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/rescue_raps/custom_trace_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use core_utils::{collections::*, uninit_vector};
use core_utils::uninit_vector;
use winterfell::{
math::{FieldElement, StarkField},
matrix::ColMatrix,
Expand Down
3 changes: 2 additions & 1 deletion fri/src/folding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#[cfg(feature = "concurrent")]
use utils::iterators::*;

use alloc::vec::Vec;
use math::{
fft::{get_inv_twiddles, serial_fft},
get_power_series_with_offset, polynom, FieldElement, StarkField,
};
use utils::{collections::*, iter_mut, uninit_vector};
use utils::{iter_mut, uninit_vector};

// DEGREE-RESPECTING PROJECTION
// ================================================================================================
Expand Down
3 changes: 1 addition & 2 deletions fri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
//! * [DEEP-FRI: Sampling Outside the Box Improves Soundness](https://eprint.iacr.org/2019/336)
//! * Swastik Kooparty's [talk on DEEP-FRI](https://www.youtube.com/watch?v=txo_kPSn59Y&list=PLcIyXLwiPilWvjvNkhMn283LV370Pk5CT&index=6)

#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

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

Expand Down
4 changes: 2 additions & 2 deletions fri/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::{string::ToString, vec::Vec};
use crypto::{BatchMerkleProof, ElementHasher, Hasher};
use math::FieldElement;
use utils::{
collections::*, string::*, ByteReader, ByteWriter, Deserializable, DeserializationError,
Serializable, SliceReader,
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable, SliceReader,
};

// FRI PROOF
Expand Down
2 changes: 1 addition & 1 deletion fri/src/prover/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use alloc::vec::Vec;
use core::marker::PhantomData;
use crypto::{ElementHasher, Hasher, RandomCoin};
use math::FieldElement;
use utils::collections::*;

// PROVER CHANNEL TRAIT
// ================================================================================================
Expand Down
Loading

0 comments on commit bc1692c

Please sign in to comment.