Skip to content

Commit

Permalink
Add formatting to scarb.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson committed Oct 12, 2024
1 parent 943b3b8 commit 5f80b28
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 101 deletions.
3 changes: 3 additions & 0 deletions stwo_cairo_verifier/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024_07"
[lib]
casm = true

[tool.fmt]
sort-module-level-items = true

[dependencies]

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions stwo_cairo_verifier/src/channel.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use core::array::SpanTrait;
use core::poseidon::{poseidon_hash_span, hades_permutation};
use core::traits::DivRem;

use stwo_cairo_verifier::{BaseField, SecureField};
use stwo_cairo_verifier::fields::qm31::QM31Trait;
use stwo_cairo_verifier::utils::pack4;

use stwo_cairo_verifier::{BaseField, SecureField};

const M31_SHIFT: felt252 = 0x80000000; // 2**31.
const M31_SHIFT_NZ_U256: NonZero<u256> = 0x80000000; // 2**31.
pub const EXTENSION_FELTS_PER_HASH: usize = 2;
Expand Down Expand Up @@ -155,8 +155,8 @@ fn extract_m31<const N: usize>(ref num: u256) -> BaseField {

#[cfg(test)]
mod tests {
use super::{Channel, ChannelTrait};
use stwo_cairo_verifier::fields::qm31::qm31;
use super::ChannelTrait;

#[test]
fn test_initialize_channel() {
Expand Down
21 changes: 11 additions & 10 deletions stwo_cairo_verifier/src/circle.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use stwo_cairo_verifier::fields::m31::{M31, M31Impl};
use core::num::traits::one::One;
use core::num::traits::zero::Zero;
use core::num::traits::{WrappingAdd, WideMul};
use stwo_cairo_verifier::fields::cm31::CM31;
use stwo_cairo_verifier::fields::m31::{M31, M31Impl};
use stwo_cairo_verifier::fields::qm31::{QM31Impl, QM31, QM31Trait};
use super::utils::pow;
use core::num::traits::zero::Zero;
use core::num::traits::one::One;

pub const M31_CIRCLE_GEN: CirclePoint<M31> =
CirclePoint { x: M31 { inner: 2 }, y: M31 { inner: 1268011823 }, };
Expand Down Expand Up @@ -123,10 +124,10 @@ pub impl CosetImpl of CosetTrait {
}

fn index_at(self: @Coset, index: usize) -> usize {
let index_times_step = (core::integer::u32_wide_mul(*self.step_size, index) & U32_BIT_MASK)
let index_times_step = ((*self.step_size).wide_mul(index) & U32_BIT_MASK)
.try_into()
.unwrap();
let result = core::integer::u32_wrapping_add(*self.initial_index, index_times_step);
let result = (*self.initial_index).wrapping_add(index_times_step);
result & CIRCLE_ORDER_BIT_MASK
}

Expand Down Expand Up @@ -178,14 +179,14 @@ pub impl CosetImpl of CosetTrait {

#[cfg(test)]
mod tests {
use super::{M31_CIRCLE_GEN, CIRCLE_ORDER, CirclePoint, CirclePointM31Impl, Coset, CosetImpl};
use core::option::OptionTrait;
use core::array::ArrayTrait;
use core::option::OptionTrait;
use core::traits::TryInto;
use super::{CirclePointQM31Impl, QM31_CIRCLE_GEN};
use stwo_cairo_verifier::fields::m31::{m31, M31};
use stwo_cairo_verifier::fields::qm31::{qm31, QM31, QM31One};
use stwo_cairo_verifier::fields::m31::m31;
use stwo_cairo_verifier::fields::qm31::QM31One;
use stwo_cairo_verifier::utils::pow;
use super::{CirclePointQM31Impl, QM31_CIRCLE_GEN};
use super::{M31_CIRCLE_GEN, CIRCLE_ORDER, CirclePoint, CirclePointM31Impl, Coset, CosetImpl};

#[test]
fn test_add_1() {
Expand Down
2 changes: 1 addition & 1 deletion stwo_cairo_verifier/src/fields.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod m31;
pub mod cm31;
pub mod m31;
pub mod qm31;

pub type BaseField = m31::M31;
Expand Down
2 changes: 1 addition & 1 deletion stwo_cairo_verifier/src/fields/cm31.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub fn cm31(a: u32, b: u32) -> CM31 {

#[cfg(test)]
mod tests {
use super::{cm31};
use super::super::m31::{m31, P};
use super::{cm31};

#[test]
fn test_cm31() {
Expand Down
8 changes: 4 additions & 4 deletions stwo_cairo_verifier/src/fields/m31.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::num::traits::{WideMul, CheckedSub};
use core::option::OptionTrait;
use core::traits::TryInto;
use core::result::ResultTrait;

pub const P: u32 = 0x7fffffff;
const P32NZ: NonZero<u32> = 0x7fffffff;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub impl M31Impl of M31Trait {
pub impl M31Add of core::traits::Add<M31> {
fn add(lhs: M31, rhs: M31) -> M31 {
let res = lhs.inner + rhs.inner;
let res = core::integer::u32_overflowing_sub(res, P).unwrap_or(res);
let res = res.checked_sub(P).unwrap_or(res);
M31 { inner: res }
}
}
Expand All @@ -56,7 +56,7 @@ pub impl M31Sub of core::traits::Sub<M31> {
}
pub impl M31Mul of core::traits::Mul<M31> {
fn mul(lhs: M31, rhs: M31) -> M31 {
M31Impl::reduce_u64(core::integer::u32_wide_mul(lhs.inner, rhs.inner))
M31Impl::reduce_u64(lhs.inner.wide_mul(rhs.inner))
}
}
pub impl M31Zero of core::num::traits::Zero<M31> {
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn m31(val: u32) -> M31 {

#[cfg(test)]
mod tests {
use super::{m31, P, M31, M31Trait};
use super::{m31, P, M31Trait};
const POW2_15: u32 = 0b1000000000000000;
const POW2_16: u32 = 0b10000000000000000;

Expand Down
10 changes: 5 additions & 5 deletions stwo_cairo_verifier/src/fields/qm31.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::m31::{M31, m31, M31Impl};
use super::cm31::{CM31, cm31, CM31Trait};
use core::num::traits::zero::Zero;
use core::num::traits::one::One;
use core::num::traits::zero::Zero;
use super::cm31::{CM31, cm31, CM31Trait};
use super::m31::{M31, M31Impl};

pub const R: CM31 = CM31 { a: M31 { inner: 2 }, b: M31 { inner: 1 } };

Expand Down Expand Up @@ -113,9 +113,9 @@ pub fn qm31(a: u32, b: u32, c: u32, d: u32) -> QM31 {

#[cfg(test)]
mod tests {
use super::{QM31, qm31, QM31Trait, QM31Impl};
use super::{CM31, cm31};
use super::CM31;
use super::super::m31::{m31, P, M31Trait};
use super::{QM31, qm31, QM31Trait, QM31Impl};

#[test]
fn test_QM31() {
Expand Down
51 changes: 22 additions & 29 deletions stwo_cairo_verifier/src/fri.cairo
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use core::dict::Felt252Dict;
use stwo_cairo_verifier::fields::m31::M31Trait;
use stwo_cairo_verifier::circle::{Coset, CosetImpl};
use stwo_cairo_verifier::poly::line::{LineDomain, LineDomainImpl};
use stwo_cairo_verifier::fields::qm31::{QM31, qm31, QM31Trait};
use stwo_cairo_verifier::queries::SparseSubCircleDomain;
use stwo_cairo_verifier::channel::{Channel, ChannelTrait};
use stwo_cairo_verifier::circle::CosetImpl;
use stwo_cairo_verifier::fields::m31::M31;
use stwo_cairo_verifier::utils::{bit_reverse_index, pow, pow_qm31, qm31_zero_array, find};
use stwo_cairo_verifier::poly::line::{
LineEvaluation, LineEvaluationImpl, SparseLineEvaluation, SparseLineEvaluationImpl
};
use stwo_cairo_verifier::fields::m31::M31Trait;
use stwo_cairo_verifier::fields::qm31::{QM31, QM31Trait};
use stwo_cairo_verifier::poly::circle::CircleDomainImpl;
use stwo_cairo_verifier::poly::circle::{
CircleEvaluation, SparseCircleEvaluation, SparseCircleEvaluationImpl
};
use stwo_cairo_verifier::poly::circle::{CircleDomain, CircleDomainImpl};
use stwo_cairo_verifier::poly::line::{
LineEvaluation, LineEvaluationImpl, SparseLineEvaluation, SparseLineEvaluationImpl
};
use stwo_cairo_verifier::poly::line::{LineDomain, LineDomainImpl};
use stwo_cairo_verifier::poly::line::{LinePoly, LinePolyImpl};
use stwo_cairo_verifier::queries::SparseSubCircleDomain;
use stwo_cairo_verifier::queries::{Queries, QueriesImpl};
use stwo_cairo_verifier::vcs::verifier::{MerkleDecommitment, MerkleVerifier, MerkleVerifierTrait};
use stwo_cairo_verifier::utils::{bit_reverse_index, pow, pow_qm31, qm31_zero_array, find};
use stwo_cairo_verifier::vcs::hasher::PoseidonMerkleHasher;
use stwo_cairo_verifier::poly::line::{LinePoly, LinePolyImpl};
use stwo_cairo_verifier::channel::{Channel, ChannelTrait};
use stwo_cairo_verifier::vcs::verifier::{MerkleDecommitment, MerkleVerifier, MerkleVerifierTrait};

pub const CIRCLE_TO_LINE_FOLD_STEP: u32 = 1;
pub const FOLD_STEP: u32 = 1;
Expand Down Expand Up @@ -531,27 +531,20 @@ pub fn ibutterfly(v0: QM31, v1: QM31, itwid: M31) -> (QM31, QM31) {

#[cfg(test)]
mod test {
use stwo_cairo_verifier::poly::line::{
LineEvaluation, SparseLineEvaluation, SparseLineEvaluationImpl
};
use stwo_cairo_verifier::fields::m31::M31Trait;
use stwo_cairo_verifier::channel::ChannelTrait;
use stwo_cairo_verifier::circle::{Coset, CosetImpl};
use stwo_cairo_verifier::poly::line::{LineDomain, LineDomainImpl};
use stwo_cairo_verifier::fields::qm31::{QM31, qm31};
use stwo_cairo_verifier::fields::m31::M31;
use stwo_cairo_verifier::utils::{bit_reverse_index, pow};
use stwo_cairo_verifier::fields::qm31::qm31;
use stwo_cairo_verifier::poly::circle::{
CircleEvaluation, CircleEvaluationTrait, CircleDomain, CircleEvaluationImpl,
SparseCircleEvaluation, SparseCircleEvaluationImpl
CircleDomain, CircleEvaluationImpl, SparseCircleEvaluation, SparseCircleEvaluationImpl
};
use stwo_cairo_verifier::queries::{Queries, QueriesImpl};
use stwo_cairo_verifier::channel::ChannelTrait;
use stwo_cairo_verifier::poly::line::LineDomainImpl;
use stwo_cairo_verifier::poly::line::LinePoly;
use stwo_cairo_verifier::vcs::verifier::MerkleDecommitment;
use super::{
FOLD_STEP, CIRCLE_TO_LINE_FOLD_STEP, FriConfig, FriProof, FriVerifierImpl,
FriVerificationError, FriLayerProof
use stwo_cairo_verifier::poly::line::{
LineEvaluation, SparseLineEvaluation, SparseLineEvaluationImpl
};
use stwo_cairo_verifier::queries::{Queries, QueriesImpl};
use stwo_cairo_verifier::vcs::verifier::MerkleDecommitment;
use super::{FriConfig, FriProof, FriVerifierImpl, FriVerificationError, FriLayerProof};

#[test]
fn test_fold_line_1() {
Expand Down
6 changes: 3 additions & 3 deletions stwo_cairo_verifier/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod channel;
mod circle;
mod fields;
mod fri;
mod poly;
mod queries;
mod sort;
mod utils;
mod vcs;
mod fri;
mod sort;
mod queries;

pub use fields::{BaseField, SecureField};

Expand Down
19 changes: 8 additions & 11 deletions stwo_cairo_verifier/src/poly/circle.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use core::num::traits::ops::wrapping::WrappingSub;
use stwo_cairo_verifier::circle::CirclePointTrait;
use core::option::OptionTrait;
use core::clone::Clone;
use core::result::ResultTrait;
use stwo_cairo_verifier::fields::qm31::{QM31, qm31};
use stwo_cairo_verifier::fields::m31::{M31, m31};
use stwo_cairo_verifier::utils::pow;
use stwo_cairo_verifier::circle::{
Coset, CosetImpl, CirclePoint, CirclePointM31Impl, M31_CIRCLE_GEN, CIRCLE_ORDER
};
use stwo_cairo_verifier::fields::m31::M31;
use stwo_cairo_verifier::fields::qm31::QM31;
use stwo_cairo_verifier::fri::fold_circle_into_line;
use core::num::traits::ops::wrapping::WrappingSub;
use stwo_cairo_verifier::utils::pow;

/// A valid domain for circle polynomial interpolation and evaluation.
///
Expand Down Expand Up @@ -127,13 +124,13 @@ pub impl SparseCircleEvaluationImpl of SparseCircleEvaluationImplTrait {

#[cfg(test)]
mod tests {
use super::{
CircleDomain, CircleDomainTrait, CircleEvaluation, CircleEvaluationImpl,
SparseCircleEvaluation, SparseCircleEvaluationImplTrait
};
use stwo_cairo_verifier::circle::{Coset, CosetImpl, CirclePoint};
use stwo_cairo_verifier::fields::m31::m31;
use stwo_cairo_verifier::fields::qm31::qm31;
use super::{
CircleDomain, CircleDomainTrait, CircleEvaluationImpl, SparseCircleEvaluation,
SparseCircleEvaluationImplTrait
};

#[test]
fn test_circle_domain_at_1() {
Expand Down
18 changes: 7 additions & 11 deletions stwo_cairo_verifier/src/poly/line.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use core::option::OptionTrait;
use core::clone::Clone;
use core::result::ResultTrait;
use stwo_cairo_verifier::poly::utils::fold;
use stwo_cairo_verifier::fields::SecureField;
use stwo_cairo_verifier::fields::m31::{M31, m31, M31Trait};
use stwo_cairo_verifier::fields::qm31::{QM31, qm31, QM31Zero};
use stwo_cairo_verifier::utils::pow;
use stwo_cairo_verifier::circle::{Coset, CosetImpl, CirclePointTrait, M31_CIRCLE_GEN};
use stwo_cairo_verifier::fields::SecureField;
use stwo_cairo_verifier::fields::m31::{M31, m31};
use stwo_cairo_verifier::fields::qm31::{QM31, QM31Zero};
use stwo_cairo_verifier::fri::fold_line;
use stwo_cairo_verifier::poly::utils::fold;

/// A univariate polynomial defined on a [LineDomain].
#[derive(Debug, Drop, Clone)]
Expand Down Expand Up @@ -138,11 +134,11 @@ pub impl SparseLineEvaluationImpl of SparseLineEvaluationTrait {

#[cfg(test)]
mod tests {
use super::{LinePoly, LinePolyTrait, LineDomain, LineDomainImpl};
use stwo_cairo_verifier::fields::qm31::qm31;
use stwo_cairo_verifier::circle::{CosetImpl, CIRCLE_LOG_ORDER};
use stwo_cairo_verifier::fields::m31::m31;
use stwo_cairo_verifier::circle::{Coset, CosetImpl, CIRCLE_LOG_ORDER};
use stwo_cairo_verifier::fields::qm31::qm31;
use stwo_cairo_verifier::utils::pow;
use super::{LinePoly, LinePolyTrait, LineDomainImpl};

#[test]
#[should_panic]
Expand Down
11 changes: 4 additions & 7 deletions stwo_cairo_verifier/src/queries.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::utils::{pow, bit_reverse_index, find};
use core::traits::Copy;
use core::nullable::{NullableTrait, match_nullable, FromNullableResult};
use core::dict::Felt252DictEntryTrait;
use stwo_cairo_verifier::poly::circle::{CircleDomain, CircleDomainImpl};
use stwo_cairo_verifier::circle::{Coset, CosetImpl};
use stwo_cairo_verifier::channel::{Channel, ChannelTrait};
use stwo_cairo_verifier::circle::CosetImpl;
use stwo_cairo_verifier::poly::circle::{CircleDomain, CircleDomainImpl};
use stwo_cairo_verifier::sort::MinimumToMaximumSortedIterator;
use super::utils::{pow, bit_reverse_index, find};


/// An ordered set of query indices over a bit reversed [CircleDomain].
Expand Down Expand Up @@ -161,8 +158,8 @@ pub impl SparseSubCircleDomainImpl of SparseSubCircleDomainTrait {

#[cfg(test)]
mod test {
use stwo_cairo_verifier::channel::ChannelTrait;
use super::{Queries, QueriesImpl};
use stwo_cairo_verifier::channel::{Channel, ChannelTrait};

#[test]
fn test_fold_1() {
Expand Down
2 changes: 1 addition & 1 deletion stwo_cairo_verifier/src/sort.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::array::ToSpanTrait;
use core::array::ArrayTrait;
use core::array::ToSpanTrait;
use core::option::OptionTrait;

trait Compare<T, C> {
Expand Down
10 changes: 4 additions & 6 deletions stwo_cairo_verifier/src/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use core::array::SpanTrait;
use core::dict::Felt252Dict;
use core::traits::PanicDestruct;
use core::option::OptionTrait;
use core::box::BoxTrait;
use core::dict::Felt252Dict;
use core::dict::Felt252DictEntryTrait;
use core::dict::Felt252DictTrait;
use core::iter::Iterator;
use core::num::traits::BitSize;
use stwo_cairo_verifier::fields::qm31::{QM31, qm31};
use stwo_cairo_verifier::BaseField;
use core::traits::DivRem;
use core::traits::PanicDestruct;
use stwo_cairo_verifier::BaseField;
use stwo_cairo_verifier::fields::qm31::{QM31, qm31};

#[generate_trait]
pub impl DictImpl<T, +Felt252DictValue<T>, +PanicDestruct<T>> of DictTrait<T> {
Expand Down
4 changes: 1 addition & 3 deletions stwo_cairo_verifier/src/vcs/hasher.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use core::array::ArrayTrait;
use core::option::OptionTrait;
use core::poseidon::poseidon_hash_span;
use stwo_cairo_verifier::BaseField;
use core::hash::HashStateTrait;
use core::poseidon::{hades_permutation, HashState};

// A Merkle node hash is a hash of:
// [left_child_hash, right_child_hash], column0_value, column1_value, ...
Expand Down Expand Up @@ -65,8 +63,8 @@ pub impl PoseidonMerkleHasher of MerkleHasher {

#[cfg(test)]
mod tests {
use super::PoseidonMerkleHasher;
use stwo_cairo_verifier::fields::m31::{m31};
use super::PoseidonMerkleHasher;

#[test]
fn test_m31() {
Expand Down
Loading

0 comments on commit 5f80b28

Please sign in to comment.