Skip to content

Commit

Permalink
Merge branch 'succinctlabs:main' into teek_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
meekteek authored Sep 19, 2023
2 parents c18c4bc + ccec577 commit 1e4fd30
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 409 deletions.
120 changes: 60 additions & 60 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plonky2x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ ci = []

[dependencies]
plonky2 = { git = "https://github.com/mir-protocol/plonky2.git", default-features = false }
curta = { git = "https://github.com/succinctlabs/curta.git", branch = "tamir/serialization" }
curta = { git = "https://github.com/succinctlabs/curta.git" }
plonky2x-derive = { path = "../plonky2x-derive" }

num = { version = "0.4", default-features = false }
sha2 = "0.10.7"
curve25519-dalek = { git = "https://github.com/succinctlabs/curve25519-dalek.git", branch = "feature/edwards-point-getters" }
ff = {package="ff" , version="0.13", features = ["derive"]}
ff = { package = "ff", version = "0.13", features = ["derive"] }

ethers = { version = "2.0" }

Expand Down
24 changes: 6 additions & 18 deletions plonky2x/src/backend/circuit/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ use crate::frontend::eth::beacon::vars::{
use crate::frontend::eth::storage::generators::{
EthBlockGenerator, EthLogGenerator, EthStorageKeyGenerator, EthStorageProofGenerator,
};
use crate::frontend::generator::function::HintFn;
use crate::frontend::generator::general::{HintGenerator, HintSerializer};
use crate::frontend::generator::hint::{Hint, SateHintSerializer};
use crate::frontend::generator::simple::hint::Hint;
use crate::frontend::generator::simple::serializer::SimpleHintSerializer;
use crate::frontend::hash::bit_operations::{XOR3Gate, XOR3Generator};
use crate::frontend::hash::keccak::keccak256::Keccak256Generator;
use crate::frontend::num::biguint::BigUintDivRemGenerator;
Expand All @@ -71,7 +70,7 @@ use crate::frontend::num::u32::gates::arithmetic_u32::{U32ArithmeticGate, U32Ari
use crate::frontend::num::u32::gates::comparison::{ComparisonGate, ComparisonGenerator};
use crate::frontend::uint::uint256::U256Variable;
use crate::frontend::uint::uint64::U64Variable;
use crate::frontend::vars::{Bytes32Variable, ValueStream};
use crate::frontend::vars::Bytes32Variable;

/// A registry to store serializers for witness generators.
///
Expand Down Expand Up @@ -211,21 +210,10 @@ impl<L: PlonkParameters<D>, const D: usize> WitnessGeneratorRegistry<L, D> {
self.register_generator::<SimpleGeneratorAdapter<L::Field, SG, D>>(id)
}

pub fn register_hint_serializer<S: HintSerializer<L, D>>(&mut self, serializer: S) {
let id = serializer.id();
self.0.register(id, serializer).unwrap()
}

pub fn register_hint<H: Hint<L, D>>(&mut self) {
let serializer = SateHintSerializer::<L, H>::new();
self.register_hint_serializer(serializer)
}

pub fn register_hint_function(
&mut self,
hint_fn: fn(&mut ValueStream<L, D>, &mut ValueStream<L, D>),
) {
self.register_hint_serializer(HintFn(hint_fn).serializer())
let serializer = SimpleHintSerializer::<L, H>::new();
let id = H::id();
self.0.register(id, serializer).unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion plonky2x/src/frontend/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use plonky2::plonk::circuit_data::CircuitConfig;
use tokio::runtime::Runtime;

pub use self::io::CircuitIO;
use super::generator::general::HintRef;
use super::generator::HintRef;
use super::vars::EvmVariable;
use crate::backend::circuit::{CircuitBuild, DefaultParameters, MockCircuitBuild, PlonkParameters};
use crate::frontend::vars::{BoolVariable, CircuitVariable, Variable};
Expand Down
138 changes: 0 additions & 138 deletions plonky2x/src/frontend/generator/function.rs

This file was deleted.

15 changes: 12 additions & 3 deletions plonky2x/src/frontend/generator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use super::vars::VariableStream;
use crate::prelude::{CircuitBuilder, PlonkParameters};

pub mod asynchronous;
pub mod function;
pub mod general;
pub mod hint;
pub mod simple;
pub mod synchronous;

pub trait HintRef<L: PlonkParameters<D>, const D: usize> {
/// returns a mutable reference to the output stream.
fn output_stream_mut(&mut self) -> &mut VariableStream;

/// adds the hint type to the circuit builder.
fn register(&self, builder: &mut CircuitBuilder<L, D>);
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
use core::fmt::Debug;
use core::marker::PhantomData;

use plonky2::iop::generator::{GeneratedValues, SimpleGenerator, WitnessGeneratorRef};
use plonky2::iop::generator::{GeneratedValues, SimpleGenerator};
use plonky2::iop::target::Target;
use plonky2::iop::witness::PartitionWitness;
use plonky2::plonk::circuit_data::CommonCircuitData;
use plonky2::util::serialization::{Buffer, IoResult};
use plonky2::util::serialization::{Buffer, IoError, IoResult};

use crate::backend::circuit::{PlonkParameters, Serializer};
use crate::frontend::vars::{OutputVariableStream, ValueStream, VariableStream};
use crate::prelude::{CircuitBuilder, CircuitVariable};

pub trait HintGenerator<L: PlonkParameters<D>, const D: usize>:
'static + Debug + Clone + Send + Sync
{
type Serializer: HintSerializer<L, D>;
fn hint(&self, input_stream: &mut ValueStream<L, D>, output_stream: &mut ValueStream<L, D>);

fn serializer(&self) -> Self::Serializer;
}

pub trait HintSerializer<L: PlonkParameters<D>, const D: usize>:
Serializer<L::Field, WitnessGeneratorRef<L::Field, D>, D>
{
fn id(&self) -> String;
}

pub trait HintRef<L: PlonkParameters<D>, const D: usize> {
fn output_stream(&mut self) -> &mut VariableStream;
fn register(&self, builder: &mut CircuitBuilder<L, D>);
}
use super::hint::Hint;
use crate::frontend::generator::HintRef;
use crate::frontend::vars::{ValueStream, VariableStream};
use crate::prelude::{CircuitBuilder, CircuitVariable, PlonkParameters};
use crate::utils::serde::BufferWrite;

#[derive(Debug, Clone)]
pub struct HintSimpleGenerator<L, H> {
Expand All @@ -50,10 +31,10 @@ impl<L, H> HintSimpleGenerator<L, H> {
}
}

impl<L: PlonkParameters<D>, const D: usize, H: HintGenerator<L, D>> HintRef<L, D>
impl<L: PlonkParameters<D>, const D: usize, H: Hint<L, D>> HintRef<L, D>
for HintSimpleGenerator<L, H>
{
fn output_stream(&mut self) -> &mut VariableStream {
fn output_stream_mut(&mut self) -> &mut VariableStream {
&mut self.output_stream
}

Expand All @@ -62,32 +43,11 @@ impl<L: PlonkParameters<D>, const D: usize, H: HintGenerator<L, D>> HintRef<L, D
}
}

impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
pub fn hint_generator<H: HintGenerator<L, D>>(
&mut self,
input_stream: VariableStream,
hint: H,
) -> OutputVariableStream<L, D> {
let output_stream = VariableStream::new();

let hint = HintSimpleGenerator::<L, H> {
input_stream,
output_stream,
hint,
_marker: PhantomData,
};
let hint_id = self.hints.len();
self.hints.push(Box::new(hint));

OutputVariableStream::new(hint_id)
}
}

impl<L: PlonkParameters<D>, const D: usize, H: HintGenerator<L, D>> SimpleGenerator<L::Field, D>
impl<L: PlonkParameters<D>, const D: usize, H: Hint<L, D>> SimpleGenerator<L::Field, D>
for HintSimpleGenerator<L, H>
{
fn id(&self) -> String {
self.hint.serializer().id()
H::id()
}

fn dependencies(&self) -> Vec<Target> {
Expand Down Expand Up @@ -125,7 +85,10 @@ impl<L: PlonkParameters<D>, const D: usize, H: HintGenerator<L, D>> SimpleGenera
_common_data: &CommonCircuitData<L::Field, D>,
) -> IoResult<()> {
self.input_stream.serialize_to_writer(dst)?;
self.output_stream.serialize_to_writer(dst)
self.output_stream.serialize_to_writer(dst)?;

let bytes = bincode::serialize(&self.hint).map_err(|_| IoError)?;
dst.write_bytes(&bytes)
}

fn deserialize(
Expand Down
Loading

0 comments on commit 1e4fd30

Please sign in to comment.