Skip to content

Commit

Permalink
Merge pull request #2936 from o1-labs/dw/rust-1.78
Browse files Browse the repository at this point in the history
Support Rust 1.78
  • Loading branch information
dannywillems authored Jan 9, 2025
2 parents 2867736 + d1e1320 commit db28894
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
RUST_TOOLCHAIN_COVERAGE_VERSION: "1.74"
strategy:
matrix:
rust_toolchain_version: ["1.72", "1.73", "1.74", "1.75", "1.76", "1.77"]
rust_toolchain_version: ["1.72", "1.73", "1.74", "1.75", "1.76", "1.77", "1.78"]
# FIXME: currently not available for 5.0.0.
# It might be related to boxroot dependency, and we would need to bump
# up the ocaml-rs dependency
Expand Down
14 changes: 7 additions & 7 deletions arrabbiata/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ where
let v = v.mod_floor(&modulus);
match row {
CurrOrNext::Curr => {
self.state[idx] = v.clone();
self.state[idx].clone_from(&v);
}
CurrOrNext::Next => {
self.next_state[idx] = v.clone();
self.next_state[idx].clone_from(&v);
}
}
v
Expand All @@ -269,7 +269,7 @@ where
Fq::modulus_biguint().into()
};
let v = v.mod_floor(&modulus);
self.public_state[idx] = v.clone();
self.public_state[idx].clone_from(&v);
v
}

Expand Down Expand Up @@ -347,7 +347,7 @@ where
fn reset(&mut self) {
// Save the current state in the witness
self.state.iter().enumerate().for_each(|(i, x)| {
self.witness[i][self.current_row] = x.clone();
self.witness[i][self.current_row].clone_from(x);
});
// We increment the row
// TODO: should we check that we are not going over the domain size?
Expand All @@ -357,7 +357,7 @@ where
self.idx_var_next_row = 0;
self.idx_var_pi = 0;
// We keep track of the values we already set.
self.state = self.next_state.clone();
self.state.clone_from(&self.next_state);
// And we reset the next state
self.next_state = std::array::from_fn(|_| BigInt::from(0_usize));
}
Expand All @@ -373,8 +373,8 @@ where
let Column::X(idx) = col else {
unimplemented!("Only works for private columns")
};
self.state[idx] = r.clone();
self.r = r.clone();
self.state[idx].clone_from(&r);
self.r.clone_from(&r);
r
}

Expand Down
2 changes: 1 addition & 1 deletion folding/src/error_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<CF: FoldingConfig> ExtendedEnv<CF> {
use ExtendedFoldingColumn::*;
let relaxed_witness = self.get_relaxed_witness(side);
match col {
WitnessExtended(i) => relaxed_witness.extended_witness.extended.get(i).is_some(),
WitnessExtended(i) => relaxed_witness.extended_witness.extended.contains_key(i),
Error => panic!("shouldn't happen"),
Inner(_) | Constant(_) | Challenge(_) | Alpha(_) | Selector(_) => true,
}
Expand Down
37 changes: 20 additions & 17 deletions folding/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ use crate::{
};
use ark_ec::AffineRepr;
use ark_ff::One;
use core::{
fmt,
fmt::{Display, Formatter},
};
use derivative::Derivative;
use itertools::Itertools;
use kimchi::circuits::{
Expand Down Expand Up @@ -420,53 +424,52 @@ impl<C: FoldingConfig> std::ops::Mul for FoldingCompatibleExpr<C> {
}

/// Implement a human-readable version of a folding compatible expression.
// FIXME: use Display instead, to follow the recommendation of the trait.
impl<C: FoldingConfig> ToString for FoldingCompatibleExpr<C> {
fn to_string(&self) -> String {
impl<C: FoldingConfig> Display for FoldingCompatibleExpr<C> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
FoldingCompatibleExpr::Atom(c) => match c {
FoldingCompatibleExprInner::Constant(c) => {
if c.is_zero() {
"0".to_string()
write!(f, "0")
} else {
c.to_string()
write!(f, "{}", c)
}
}
FoldingCompatibleExprInner::Challenge(c) => {
format!("{:?}", c)
write!(f, "{:?}", c)
}
FoldingCompatibleExprInner::Cell(cell) => {
let Variable { col, row } = cell;
let next = match row {
CurrOrNext::Curr => "",
CurrOrNext::Next => " * ω",
};
format!("Col({:?}){}", col, next)
write!(f, "Col({:?}){}", col, next)
}
FoldingCompatibleExprInner::Extensions(e) => match e {
ExpExtension::U => "U".to_string(),
ExpExtension::Error => "E".to_string(),
ExpExtension::U => write!(f, "U"),
ExpExtension::Error => write!(f, "E"),
ExpExtension::ExtendedWitness(i) => {
format!("ExWit({})", i)
write!(f, "ExWit({})", i)
}
ExpExtension::Alpha(i) => format!("α_{i}"),
ExpExtension::Selector(s) => format!("Selec({:?})", s),
ExpExtension::Alpha(i) => write!(f, "α_{i}"),
ExpExtension::Selector(s) => write!(f, "Selec({:?})", s),
},
},
FoldingCompatibleExpr::Double(e) => {
format!("2 {}", e.to_string())
write!(f, "2 {}", e)
}
FoldingCompatibleExpr::Square(e) => {
format!("{} ^ 2", e.to_string())
write!(f, "{} ^ 2", e)
}
FoldingCompatibleExpr::Add(e1, e2) => {
format!("{} + {}", e1.to_string(), e2.to_string())
write!(f, "{} + {}", e1, e2)
}
FoldingCompatibleExpr::Sub(e1, e2) => {
format!("{} - {}", e1.to_string(), e2.to_string())
write!(f, "{} - {}", e1, e2)
}
FoldingCompatibleExpr::Mul(e1, e2) => {
format!("({}) ({})", e1.to_string(), e2.to_string())
write!(f, "({}) ({})", e1, e2)
}
FoldingCompatibleExpr::Pow(_, _) => todo!(),
}
Expand Down
4 changes: 2 additions & 2 deletions hasher/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
fn reset(&mut self) -> &mut dyn Hasher<H> {
// Efficient reset
self.sponge.sponge_state = self.sponge_state.clone();
self.sponge.state = self.state.clone();
self.sponge.state.clone_from(&self.state);

self
}
Expand All @@ -83,7 +83,7 @@ where

// Save initial state for efficient reset
self.sponge_state = self.sponge.sponge_state.clone();
self.state = self.sponge.state.clone();
self.state.clone_from(&self.sponge.state);

self
}
Expand Down
3 changes: 0 additions & 3 deletions ivc/src/poseidon_55_0_7_3_2/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub fn poseidon_circuit<
init_state: [Env::Variable; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColWriteCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand All @@ -69,7 +68,6 @@ pub fn apply_permutation<
param: &PARAMETERS,
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand Down Expand Up @@ -122,7 +120,6 @@ fn compute_one_round<
elements: &[PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand Down
3 changes: 0 additions & 3 deletions ivc/src/poseidon_55_0_7_3_7/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub fn poseidon_circuit<
init_state: [Env::Variable; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColWriteCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand All @@ -69,7 +68,6 @@ pub fn apply_permutation<
param: &PARAMETERS,
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand Down Expand Up @@ -120,7 +118,6 @@ fn compute_one_round<
elements: &[PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_FULL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND>>,
Expand Down
3 changes: 0 additions & 3 deletions ivc/src/poseidon_8_56_5_3_2/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub fn poseidon_circuit<
init_state: [Env::Variable; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_TOTAL_ROUND>,
Env: ColWriteCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>,
Expand Down Expand Up @@ -88,7 +87,6 @@ pub fn apply_permutation<
param: &PARAMETERS,
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_TOTAL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>,
Expand Down Expand Up @@ -257,7 +255,6 @@ fn compute_one_partial_round<
state: &[Env::Variable; STATE_SIZE],
) -> [Env::Variable; STATE_SIZE]
where
F: PrimeField,
PARAMETERS: PoseidonParams<F, STATE_SIZE, NB_TOTAL_ROUND>,
Env: ColAccessCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>
+ HybridCopyCap<F, PoseidonColumn<STATE_SIZE, NB_FULL_ROUND, NB_PARTIAL_ROUND>>,
Expand Down
7 changes: 2 additions & 5 deletions ivc/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,7 @@ pub fn heavy_test_simple_add() {
.divide_by_vanishing_poly(domain.d1)
.unwrap_or_else(|| panic!("Cannot divide by vanishing polynomial"));
if !remainder.is_zero() {
panic!(
"Remainder is not zero for expression #{expr_i}: {}",
expr.to_string()
);
panic!("Remainder is not zero for expression #{expr_i}: {}", expr,);
}
}
}
Expand Down Expand Up @@ -924,7 +921,7 @@ pub fn heavy_test_simple_add() {
if !remainder.is_zero() {
panic!(
"ERROR: Remainder is not zero for joint expression: {}",
expr.to_string()
expr
);
} else {
println!("Interpolated expression is divisible by vanishing poly d1");
Expand Down
11 changes: 0 additions & 11 deletions kimchi/src/snarky/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ use ark_ff::PrimeField;

use super::{errors::SnarkyResult, runner::Constraint};

trait OutOfCircuitSnarkyType2<F> {
type InCircuit;
}

impl<F> OutOfCircuitSnarkyType2<F> for bool
where
F: PrimeField,
{
type InCircuit = Boolean<F>;
}

/// A boolean variable.
#[derive(Debug, Clone)]
pub struct Boolean<F: PrimeField>(FieldVar<F>);
Expand Down
2 changes: 1 addition & 1 deletion kimchi/src/snarky/union_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where

pub fn make_set(&mut self, x: T) {
let len = &mut self.set_size;
if self.map.get(&x).is_some() {
if self.map.contains_key(&x) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion kimchi/src/tests/foreign_field_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,6 @@ fn run_test<G: KimchiCurve>(
) -> (CircuitGateResult<()>, [Vec<G::ScalarField>; COLUMNS])
where
G::BaseField: PrimeField,
G: KimchiCurve,
{
let rng = &mut make_test_rng(None);

Expand Down
2 changes: 1 addition & 1 deletion msm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<const N_WIT: usize, T: Zero + Clone> Witness<N_WIT, Vec<T>> {
pub fn to_pub_columns<const NPUB: usize>(&self) -> Witness<NPUB, Vec<T>> {
let mut newcols: [Vec<T>; NPUB] = std::array::from_fn(|_| vec![]);
for (i, vec) in self.cols[0..NPUB].iter().enumerate() {
newcols[i] = vec.clone();
newcols[i].clone_from(vec);
}
Witness {
cols: Box::new(newcols),
Expand Down
10 changes: 7 additions & 3 deletions o1vm/src/cannon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use base64::{engine::general_purpose, Engine as _};

use core::{
fmt,
fmt::{Display, Formatter},
};
use libflate::zlib::{Decoder, Encoder};
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -182,10 +186,10 @@ impl FromStr for StepFrequency {
}
}

impl ToString for State {
impl Display for State {
// A very debatable and incomplete, but serviceable, `to_string` implementation.
fn to_string(&self) -> String {
format!(
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f,
"memory_size (length): {}\nfirst page size: {}\npreimage key: {:#?}\npreimage offset:{}\npc: {}\nlo: {}\nhi: {}\nregisters:{:#?} ",
self.memory.len(),
self.memory[0].data.len(),
Expand Down
1 change: 0 additions & 1 deletion tools/kimchi-visu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ where
{
}

///
pub fn latex_constraints<G>() -> HashMap<&'static str, Vec<Vec<String>>>
where
G: CommitmentCurve,
Expand Down

0 comments on commit db28894

Please sign in to comment.