Skip to content

Commit

Permalink
compiling pass
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jul 11, 2024
1 parent 698d806 commit 24fd98f
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 110 deletions.
4 changes: 3 additions & 1 deletion gkr/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{
use ff_ext::ExtensionField;
use goldilocks::SmallField;
use multilinear_extensions::{
mle::ArcDenseMultilinearExtension, virtual_poly_v2::ArcMultilinearExtension,
mle::{ArcDenseMultilinearExtension, DenseMultilinearExtension},
util::ceil_log2,
virtual_poly_v2::ArcMultilinearExtension,
};
use serde::{Deserialize, Serialize, Serializer};
use simple_frontend::structs::{CellId, ChallengeConst, ConstantType, LayerId};
Expand Down
27 changes: 27 additions & 0 deletions multilinear_extensions/src/mle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ impl<E: ExtensionField> Debug for dyn MultilinearExtension<E, Output = DenseMult
}
}

impl<E: ExtensionField> Into<DenseMultilinearExtension<E>> for Vec<Vec<E::BaseField>> {
fn into(self) -> DenseMultilinearExtension<E> {
let per_instance_size = self[0].len();
let next_pow2_per_instance_size = ceil_log2(per_instance_size);
let evaluations = self
.into_iter()
.enumerate()
.map(|(i, mut instance)| {
assert_eq!(
instance.len(),
per_instance_size,
"{}th instance with length {} != {} ",
i,
instance.len(),
per_instance_size
);
instance.resize(1 << next_pow2_per_instance_size, E::BaseField::ZERO);
instance
})
.flatten()
.collect::<Vec<E::BaseField>>();
assert!(evaluations.len().is_power_of_two());
let num_vars = ceil_log2(evaluations.len());
DenseMultilinearExtension::from_evaluations_vec(num_vars, evaluations)
}
}

#[derive(Clone, PartialEq, Eq, Hash, Default, Debug, Serialize, Deserialize)]
#[serde(untagged)]
/// Differentiate inner vector on base/extension field.
Expand Down
12 changes: 6 additions & 6 deletions singer/benches/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use const_env::from_env;
use criterion::*;

use ff_ext::{ff::Field, ExtensionField};
use gkr::structs::LayerWitness;
use goldilocks::GoldilocksExt2;
use itertools::Itertools;

Expand Down Expand Up @@ -51,7 +50,9 @@ fn bench_add(c: &mut Criterion) {
if !is_power_of_2(RAYON_NUM_THREADS) {
#[cfg(not(feature = "non_pow2_rayon_thread"))]
{
panic!("add --features non_pow2_rayon_thread to enable unsafe feature which support non pow of 2 rayon thread pool");
panic!(
"add --features non_pow2_rayon_thread to enable unsafe feature which support non pow of 2 rayon thread pool"
);
}

#[cfg(feature = "non_pow2_rayon_thread")]
Expand Down Expand Up @@ -87,8 +88,7 @@ fn bench_add(c: &mut Criterion) {
},
|(mut rng,mut singer_builder, real_challenges)| {
let size = AddInstruction::phase0_size();
let phase0: CircuitWiresIn<<GoldilocksExt2 as ff_ext::ExtensionField>::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<GoldilocksExt2> = vec![(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| {
Expand All @@ -98,8 +98,8 @@ fn bench_add(c: &mut Criterion) {
})
.collect_vec()
})
.collect_vec(),
}];
.collect_vec().into(),
];


let timer = Instant::now();
Expand Down
13 changes: 6 additions & 7 deletions singer/examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{collections::BTreeMap, time::Instant};

use ark_std::test_rng;
use ff_ext::{ff::Field, ExtensionField};
use gkr::structs::LayerWitness;
use gkr_graph::structs::CircuitGraphAuxInfo;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
Expand Down Expand Up @@ -143,12 +142,12 @@ fn main() {
}
}

let phase0: CircuitWiresIn<<GoldilocksExt2 as ff_ext::ExtensionField>::BaseField> =
vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
.map(|_| single_witness_in.clone())
.collect_vec(),
}];
let phase0: CircuitWiresIn<GoldilocksExt2> = vec![
(0..(1 << instance_num_vars))
.map(|_| single_witness_in.clone())
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
7 changes: 4 additions & 3 deletions singer/examples/push_and_pop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
let real_challenges = vec![];
let singer_params = SingerParams::default();

let (proof, singer_aux_info) = {
let (proof, singer_aux_info, singer_wire_out_values) = {
let real_n_instances = singer_wires_in
.instructions
.iter()
Expand All @@ -40,7 +40,7 @@ fn main() {
)
.expect("construct failed");

let (proof, graph_aux_info) =
let (proof, graph_aux_info, singer_wire_out_values) =
prove(&circuit, &witness, &wires_out_id, &mut prover_transcript).expect("prove failed");
let aux_info = SingerAuxInfo {
graph_aux_info,
Expand All @@ -49,7 +49,7 @@ fn main() {
bytecode_len: bytecode.len(),
..Default::default()
};
(proof, aux_info)
(proof, aux_info, singer_wire_out_values)
};

// 4. Verify.
Expand All @@ -61,6 +61,7 @@ fn main() {
verify(
&circuit,
proof,
singer_wire_out_values,
&singer_aux_info,
&real_challenges,
&mut verifier_transcript,
Expand Down
10 changes: 5 additions & 5 deletions singer/src/instructions/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
use singer_utils::{
Expand Down Expand Up @@ -336,15 +335,16 @@ mod test {

let mut rng = test_rng();
let size = AddInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
10 changes: 5 additions & 5 deletions singer/src/instructions/calldataload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
use singer_utils::{constants::RANGE_CHIP_BIT_WIDTH, structs::TSUInt};
Expand Down Expand Up @@ -269,15 +268,16 @@ mod test {

let mut rng = test_rng();
let size = CalldataloadInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
9 changes: 5 additions & 4 deletions singer/src/instructions/dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,16 @@ mod test {

let mut rng = test_rng();
let size = DupInstruction::<N>::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
10 changes: 5 additions & 5 deletions singer/src/instructions/gt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
use singer_utils::{constants::RANGE_CHIP_BIT_WIDTH, structs::TSUInt};
Expand Down Expand Up @@ -304,15 +303,16 @@ mod test {

let mut rng = test_rng();
let size = GtInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
10 changes: 5 additions & 5 deletions singer/src/instructions/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
use singer_utils::{constants::RANGE_CHIP_BIT_WIDTH, structs::TSUInt};
Expand Down Expand Up @@ -219,15 +218,16 @@ mod test {

let mut rng = test_rng();
let size = JumpInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
10 changes: 5 additions & 5 deletions singer/src/instructions/jumpdest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::{Goldilocks, GoldilocksExt2};
use itertools::Itertools;
use std::{collections::BTreeMap, time::Instant};
Expand Down Expand Up @@ -174,15 +173,16 @@ mod test {

let mut rng = test_rng();
let size = JumpdestInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
36 changes: 18 additions & 18 deletions singer/src/instructions/mstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<E: ExtensionField> InstructionGraph<E> for MstoreInstruction {
graph_builder: &mut CircuitGraphBuilder<E>,
chip_builder: &mut SingerChipBuilder<E>,
inst_circuits: &[InstCircuit<E>],
mut sources: Vec<CircuitWiresIn<E::BaseField>>,
mut sources: Vec<CircuitWiresIn<E>>,
real_challenges: &[E],
real_n_instances: usize,
_: &SingerParams,
Expand Down Expand Up @@ -384,9 +384,9 @@ mod test {
use ark_std::test_rng;
use ff::Field;
use ff_ext::ExtensionField;
use gkr::structs::LayerWitness;
use goldilocks::GoldilocksExt2;
use itertools::Itertools;
use multilinear_extensions::mle::DenseMultilinearExtension;
use singer_utils::structs::ChipChallenges;
use std::time::Instant;
use transcript::Transcript;
Expand Down Expand Up @@ -508,28 +508,28 @@ mod test {

let mut rng = test_rng();
let inst_phase0_size = MstoreInstruction::phase0_size();
let inst_wit: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let inst_wit: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..inst_phase0_size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];
let acc_phase0_size = MstoreAccessory::phase0_size();
let acc_wit: CircuitWiresIn<E::BaseField> = vec![
LayerWitness { instances: vec![] },
LayerWitness { instances: vec![] },
LayerWitness {
instances: (0..(1 << instance_num_vars) * 32)
.map(|_| {
(0..acc_phase0_size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
},
let acc_wit: CircuitWiresIn<E> = vec![
DenseMultilinearExtension::default(),
DenseMultilinearExtension::default(),
(0..(1 << instance_num_vars) * 32)
.map(|_| {
(0..acc_phase0_size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];
Expand Down
9 changes: 5 additions & 4 deletions singer/src/instructions/pop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,16 @@ mod test {

let mut rng = test_rng();
let size = PopInstruction::phase0_size();
let phase0: CircuitWiresIn<E::BaseField> = vec![LayerWitness {
instances: (0..(1 << instance_num_vars))
let phase0: CircuitWiresIn<E> = vec![
(0..(1 << instance_num_vars))
.map(|_| {
(0..size)
.map(|_| E::BaseField::random(&mut rng))
.collect_vec()
})
.collect_vec(),
}];
.collect_vec()
.into(),
];

let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)];

Expand Down
Loading

0 comments on commit 24fd98f

Please sign in to comment.