Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refac(halo2): change concrete struct type to trait type for rng #394

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions vendors/halo2/src/circuits/shuffle_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod test {
};
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down Expand Up @@ -380,7 +380,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -430,7 +430,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonPoseidonWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -480,7 +480,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonSha256Write::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down
8 changes: 4 additions & 4 deletions vendors/halo2/src/circuits/simple_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ mod test {
};
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down Expand Up @@ -486,7 +486,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -536,7 +536,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonPoseidonWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -587,7 +587,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonSha256Write::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down
8 changes: 4 additions & 4 deletions vendors/halo2/src/circuits/simple_lookup_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mod test {
};
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down Expand Up @@ -249,7 +249,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonBlake2bWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -299,7 +299,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonPoseidonWrite::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit.clone()],
Expand Down Expand Up @@ -350,7 +350,7 @@ mod test {
let mut tachyon_pk = TachyonProvingKey::from(pk_bytes.as_slice());
let mut transcript = TachyonSha256Write::init(vec![]);

tachyon_create_proof::<_, _, _, _, _>(
tachyon_create_proof::<_, _, _, _, _, _>(
&mut prover,
&mut tachyon_pk,
&[circuit.clone(), circuit],
Expand Down
6 changes: 4 additions & 2 deletions vendors/halo2/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::bn254::{
AdviceSingle, Evals, InstanceSingle, ProvingKey as TachyonProvingKey, RationalEvals,
TachyonProver, TranscriptWriteState,
};
use crate::xor_shift_rng::XORShiftRng as TachyonXORShiftRng;
use crate::xor_shift_rng::RngState;
use ff::Field;
use halo2_proofs::{
circuit::Value,
Expand All @@ -25,6 +25,7 @@ use halo2curves::{
group::{prime::PrimeCurveAffine, Curve},
CurveAffine,
};
use rand_core::RngCore;

/// This creates a proof for the provided `circuit` when given the public
/// parameters `params` and the proving key [`ProvingKey`] that was
Expand All @@ -37,12 +38,13 @@ pub fn create_proof<
E: EncodedChallenge<Scheme::Curve>,
T: TranscriptWriteState<Scheme::Curve, E>,
ConcreteCircuit: Circuit<Scheme::Scalar>,
R: RngCore + RngState,
>(
prover: &mut P,
pk: &mut TachyonProvingKey<Scheme::Curve>,
circuits: &[ConcreteCircuit],
instances: &[&[&[Scheme::Scalar]]],
mut rng: TachyonXORShiftRng,
mut rng: R,
transcript: &mut T,
) -> Result<(), Error> {
for instance in instances.iter() {
Expand Down
12 changes: 8 additions & 4 deletions vendors/halo2/src/xor_shift_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ pub mod ffi {
}
}

pub trait RngState {
fn state(&self) -> Vec<u8>;
}

pub struct XORShiftRng {
inner: cxx::UniquePtr<ffi::XORShiftRng>,
}

impl XORShiftRng {
pub fn state(&self) -> Vec<u8> {
impl RngState for XORShiftRng {
fn state(&self) -> Vec<u8> {
self.inner.state()
}
}
Expand Down Expand Up @@ -63,9 +67,9 @@ impl rand_core::RngCore for XORShiftRng {

#[cfg(test)]
mod test {
use rand_core::{RngCore, SeedableRng};

use super::RngState;
use crate::consts::SEED;
use rand_core::{RngCore, SeedableRng};
chokobole marked this conversation as resolved.
Show resolved Hide resolved

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