Skip to content

Commit e17b5cf

Browse files
committed
whirlaway: copy utils crate
1 parent 73587fd commit e17b5cf

File tree

17 files changed

+965
-17
lines changed

17 files changed

+965
-17
lines changed

Cargo.toml

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"crates/leanSnark",
1212
"crates/leanVm",
1313
"crates/leanLookup",
14+
"crates/utils",
1415
]
1516
resolver = "3"
1617

@@ -42,22 +43,34 @@ lean-isa = { path = "crates/leanIsa" }
4243
lean-snark = { path = "crates/leanSnark" }
4344
lean-vm = { path = "crates/leanVm" }
4445
lean-lookup = { path = "crates/leanLookup" }
46+
utils = { path = "crates/utils" }
4547

46-
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
47-
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
48-
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
49-
p3-koala-bear = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
50-
p3-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
51-
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
52-
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
53-
p3-poseidon2-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "5ebf8e4" }
54-
55-
whir-p3 = { git = "https://github.com/tcoratger/whir-p3.git", rev = "df2241d" }
56-
48+
rand = "0.9.2"
49+
sha3 = "0.10.8"
50+
rayon = "1.5.1"
51+
serde = { version = "1.0.219", features = ["derive"] }
52+
derive_more = { version = "2.0.1", features = ["full"] }
53+
pest = "2.7"
54+
pest_derive = "2.7"
55+
tracing = "0.1.26"
5756
thiserror = "2.0"
5857
proptest = "1.7"
5958
num-traits = "0.2"
60-
rand = "0.9"
61-
rayon = "1.11"
62-
pest = "2.8"
63-
pest_derive = "2.8"
59+
tracing-subscriber = { version = "0.3.19", features = ["std", "env-filter"] }
60+
tracing-forest = { version = "0.1.6", features = ["ansi", "smallvec"] }
61+
p3-koala-bear = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
62+
p3-baby-bear = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
63+
p3-field = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
64+
p3-poseidon2 = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
65+
p3-matrix = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
66+
p3-blake3 = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
67+
p3-symmetric = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
68+
p3-air = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
69+
p3-uni-stark = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
70+
p3-poseidon2-air = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
71+
p3-goldilocks = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
72+
p3-challenger = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
73+
p3-util = { git = "https://github.com/TomWambsgans/Plonky3.git", branch = "w" }
74+
75+
whir-p3 = { git = "https://github.com/TomWambsgans/whir-p3", branch = "w" }
76+
hashsig = { git = "https://github.com/TomWambsgans/hash-sig", branch = "w" }

crates/leanVm/src/air/dot_product.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ impl<F> BaseAir<F> for DotProductAir {
3535
fn width(&self) -> usize {
3636
DOT_PRODUCT_AIR_COLUMNS
3737
}
38+
39+
fn structured(&self) -> bool {
40+
true
41+
}
42+
43+
fn degree(&self) -> usize {
44+
3
45+
}
3846
}
3947

4048
impl<AB: AirBuilder> Air<AB> for DotProductAir {

crates/leanVm/src/air/vm.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ impl<F> BaseAir<F> for VMAir {
2121
fn width(&self) -> usize {
2222
N_EXEC_AIR_COLUMNS
2323
}
24+
25+
fn structured(&self) -> bool {
26+
true
27+
}
28+
fn degree(&self) -> usize {
29+
5
30+
}
2431
}
2532

2633
impl<AB: AirBuilder> Air<AB> for VMAir {

crates/leanVm/src/bytecode/instruction/multilinear_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use p3_field::BasedVectorSpace;
2-
use whir_p3::poly::{coeffs::CoefficientList, multilinear::MultilinearPoint};
2+
use whir_p3::poly::{evals::EvaluationsList, multilinear::MultilinearPoint};
33

44
use crate::{
55
bytecode::operand::{MemOrConstant, MemOrFp},
@@ -65,7 +65,7 @@ impl MultilinearEvalInstruction {
6565
.get_vectorized_slice_extension(ptr_point, self.n_vars)?;
6666

6767
// Evaluate the multilinear polynomial.
68-
let eval = CoefficientList::new(slice_coeffs).evaluate(&MultilinearPoint(point));
68+
let eval = slice_coeffs.evaluate(&MultilinearPoint(point));
6969

7070
// Write the resulting vector back to memory.
7171
memory_manager.load_data::<F>(ptr_res, eval.as_basis_coefficients_slice())?;

crates/utils/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "utils"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
8+
[lints]
9+
workspace = true
10+
11+
[dependencies]
12+
p3-field.workspace = true
13+
rayon.workspace = true
14+
p3-air.workspace = true
15+
p3-matrix.workspace = true
16+
p3-challenger.workspace = true
17+
whir-p3.workspace = true
18+
tracing.workspace = true
19+
p3-symmetric.workspace = true
20+
p3-koala-bear.workspace = true
21+
rand.workspace = true
22+
tracing-forest.workspace = true
23+
p3-poseidon2.workspace = true
24+
p3-poseidon2-air.workspace = true
25+
tracing-subscriber.workspace = true
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use std::marker::PhantomData;
2+
3+
use p3_air::AirBuilder;
4+
use p3_field::ExtensionField;
5+
use p3_matrix::dense::RowMajorMatrixView;
6+
7+
use crate::PF;
8+
9+
/*
10+
Debug purpose
11+
*/
12+
13+
#[derive(Debug)]
14+
pub struct ConstraintChecker<'a, IF, EF> {
15+
pub main: RowMajorMatrixView<'a, IF>,
16+
pub constraint_index: usize,
17+
pub errors: Vec<usize>,
18+
pub field: PhantomData<EF>,
19+
}
20+
21+
impl<'a, EF: ExtensionField<PF<EF>> + ExtensionField<IF>, IF: ExtensionField<PF<EF>>> AirBuilder
22+
for ConstraintChecker<'a, IF, EF>
23+
{
24+
type F = PF<EF>;
25+
type I = PF<EF>;
26+
type Expr = IF;
27+
type Var = IF;
28+
type M = RowMajorMatrixView<'a, IF>;
29+
30+
#[inline]
31+
fn main(&self) -> Self::M {
32+
self.main
33+
}
34+
35+
#[inline]
36+
fn is_first_row(&self) -> Self::Expr {
37+
unreachable!()
38+
}
39+
40+
#[inline]
41+
fn is_last_row(&self) -> Self::Expr {
42+
unreachable!()
43+
}
44+
45+
#[inline]
46+
fn is_transition_window(&self, _: usize) -> Self::Expr {
47+
unreachable!()
48+
}
49+
50+
#[inline]
51+
fn assert_zero<I: Into<Self::Expr>>(&mut self, x: I) {
52+
let x: IF = x.into();
53+
if !x.is_zero() {
54+
self.errors.push(self.constraint_index);
55+
}
56+
self.constraint_index += 1;
57+
}
58+
59+
#[inline]
60+
fn assert_zeros<const N: usize, I: Into<Self::Expr>>(&mut self, _: [I; N]) {
61+
unreachable!()
62+
}
63+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use p3_air::AirBuilder;
2+
use p3_field::{ExtensionField, Field};
3+
use p3_matrix::dense::RowMajorMatrixView;
4+
5+
use crate::PF;
6+
7+
#[derive(Debug)]
8+
pub struct ConstraintFolder<'a, NF, EF>
9+
where
10+
NF: ExtensionField<PF<EF>>,
11+
EF: ExtensionField<NF>,
12+
{
13+
pub main: RowMajorMatrixView<'a, NF>,
14+
pub alpha_powers: &'a [EF],
15+
pub accumulator: EF,
16+
pub constraint_index: usize,
17+
}
18+
19+
impl<'a, NF, EF> AirBuilder for ConstraintFolder<'a, NF, EF>
20+
where
21+
NF: ExtensionField<PF<EF>>,
22+
EF: Field + ExtensionField<NF>,
23+
{
24+
type F = PF<EF>;
25+
type I = Self::F;
26+
type Expr = NF;
27+
type Var = NF;
28+
type M = RowMajorMatrixView<'a, NF>;
29+
30+
#[inline]
31+
fn main(&self) -> Self::M {
32+
self.main
33+
}
34+
35+
#[inline]
36+
fn is_first_row(&self) -> Self::Expr {
37+
unreachable!()
38+
}
39+
40+
#[inline]
41+
fn is_last_row(&self) -> Self::Expr {
42+
unreachable!()
43+
}
44+
45+
#[inline]
46+
fn is_transition_window(&self, _: usize) -> Self::Expr {
47+
unreachable!()
48+
}
49+
50+
#[inline]
51+
fn assert_zero<I: Into<Self::Expr>>(&mut self, x: I) {
52+
let x: NF = x.into();
53+
let alpha_power = self.alpha_powers[self.constraint_index];
54+
self.accumulator += alpha_power * x;
55+
self.constraint_index += 1;
56+
}
57+
58+
#[inline]
59+
fn assert_zeros<const N: usize, I: Into<Self::Expr>>(&mut self, _: [I; N]) {
60+
unreachable!()
61+
}
62+
}

crates/utils/src/display.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn pretty_integer(i: usize) -> String {
2+
// ex: 123456789 -> "123,456,789"
3+
let s = i.to_string();
4+
let chars: Vec<char> = s.chars().collect();
5+
let mut result = String::new();
6+
7+
for (index, ch) in chars.iter().enumerate() {
8+
if index > 0 && (chars.len() - index) % 3 == 0 {
9+
result.push(',');
10+
}
11+
result.push(*ch);
12+
}
13+
14+
result
15+
}

crates/utils/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
2+
3+
mod misc;
4+
pub use misc::*;
5+
6+
mod constraints_folder;
7+
pub use constraints_folder::*;
8+
9+
mod univariate;
10+
pub use univariate::*;
11+
12+
mod multilinear;
13+
pub use multilinear::*;
14+
15+
mod packed_constraints_folder;
16+
pub use packed_constraints_folder::*;
17+
18+
mod wrappers;
19+
pub use wrappers::*;
20+
21+
mod display;
22+
pub use display::*;
23+
24+
mod point;
25+
pub use point::*;
26+
27+
mod logs;
28+
pub use logs::*;
29+
30+
mod constraints_checker;
31+
pub use constraints_checker::*;
32+
33+
mod poseidon2;
34+
pub use poseidon2::*;

crates/utils/src/logs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use tracing_forest::{ForestLayer, util::LevelFilter};
2+
use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, util::SubscriberInitExt};
3+
4+
pub fn init_tracing() {
5+
let env_filter = EnvFilter::builder()
6+
.with_default_directive(LevelFilter::INFO.into())
7+
.from_env_lossy();
8+
9+
Registry::default()
10+
.with(env_filter)
11+
.with(ForestLayer::default())
12+
.init();
13+
}

0 commit comments

Comments
 (0)