mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 06:43:07 +00:00
Serialize impls, and use in Fibonacci example
This commit is contained in:
parent
ea82d68084
commit
34a0354507
@ -33,6 +33,7 @@ rand_chacha = "0.3.1"
|
|||||||
rlp = "0.5.1"
|
rlp = "0.5.1"
|
||||||
rlp-derive = "0.1.0"
|
rlp-derive = "0.1.0"
|
||||||
serde = { version = "1.0.144", features = ["derive"] }
|
serde = { version = "1.0.144", features = ["derive"] }
|
||||||
|
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
hashbrown = { version = "0.12.3" }
|
hashbrown = { version = "0.12.3" }
|
||||||
tiny-keccak = "2.0.2"
|
tiny-keccak = "2.0.2"
|
||||||
|
|||||||
@ -31,6 +31,7 @@ plonky2_util = { version = "0.1.0", default-features = false }
|
|||||||
rand = { version = "0.8.4", default-features = false }
|
rand = { version = "0.8.4", default-features = false }
|
||||||
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
|
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
|
||||||
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
static_assertions = { version = "1.1.0", default-features = false }
|
static_assertions = { version = "1.1.0", default-features = false }
|
||||||
unroll = { version = "0.1.5", default-features = false }
|
unroll = { version = "0.1.5", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#![allow(clippy::upper_case_acronyms)]
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
|
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
|
||||||
@ -40,6 +42,10 @@ fn main() -> Result<()> {
|
|||||||
pw.set_target(initial_b, F::ONE);
|
pw.set_target(initial_b, F::ONE);
|
||||||
|
|
||||||
let data = builder.build::<C>();
|
let data = builder.build::<C>();
|
||||||
|
|
||||||
|
let common_circuit_data_serialized = serde_json::to_string(&data.common).unwrap();
|
||||||
|
fs::write("common_circuit_data.json", common_circuit_data_serialized).expect("Unable to write file");
|
||||||
|
|
||||||
let proof = data.prove(pw)?;
|
let proof = data.prove(pw)?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::fri::reduction_strategies::FriReductionStrategy;
|
use crate::fri::reduction_strategies::FriReductionStrategy;
|
||||||
|
|
||||||
mod challenges;
|
mod challenges;
|
||||||
@ -13,7 +15,7 @@ mod validate_shape;
|
|||||||
pub mod verifier;
|
pub mod verifier;
|
||||||
pub mod witness_util;
|
pub mod witness_util;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
||||||
pub struct FriConfig {
|
pub struct FriConfig {
|
||||||
/// `rate = 2^{-rate_bits}`.
|
/// `rate = 2^{-rate_bits}`.
|
||||||
pub rate_bits: usize,
|
pub rate_bits: usize,
|
||||||
@ -56,7 +58,7 @@ impl FriConfig {
|
|||||||
|
|
||||||
/// FRI parameters, including generated parameters which are specific to an instance size, in
|
/// FRI parameters, including generated parameters which are specific to an instance size, in
|
||||||
/// contrast to `FriConfig` which is user-specified and independent of instance size.
|
/// contrast to `FriConfig` which is user-specified and independent of instance size.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
||||||
pub struct FriParams {
|
pub struct FriParams {
|
||||||
/// User-specified FRI configuration.
|
/// User-specified FRI configuration.
|
||||||
pub config: FriConfig,
|
pub config: FriConfig,
|
||||||
|
|||||||
@ -4,9 +4,10 @@ use alloc::vec::Vec;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
/// A method for deciding what arity to use at each reduction layer.
|
/// A method for deciding what arity to use at each reduction layer.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
||||||
pub enum FriReductionStrategy {
|
pub enum FriReductionStrategy {
|
||||||
/// Specifies the exact sequence of arities (expressed in bits) to use.
|
/// Specifies the exact sequence of arities (expressed in bits) to use.
|
||||||
Fixed(Vec<usize>),
|
Fixed(Vec<usize>),
|
||||||
|
|||||||
@ -2,6 +2,8 @@ use alloc::string::String;
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use alloc::{format, vec};
|
use alloc::{format, vec};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::field::extension::Extendable;
|
use crate::field::extension::Extendable;
|
||||||
use crate::field::packed::PackedField;
|
use crate::field::packed::PackedField;
|
||||||
use crate::gates::gate::Gate;
|
use crate::gates::gate::Gate;
|
||||||
@ -18,7 +20,7 @@ use crate::plonk::vars::{
|
|||||||
use crate::util::serialization::{Buffer, IoResult, Read, Write};
|
use crate::util::serialization::{Buffer, IoResult, Read, Write};
|
||||||
|
|
||||||
/// A gate which takes a single constant parameter and outputs that value.
|
/// A gate which takes a single constant parameter and outputs that value.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct ConstantGate {
|
pub struct ConstantGate {
|
||||||
pub(crate) num_consts: usize,
|
pub(crate) num_consts: usize,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use core::hash::{Hash, Hasher};
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
use serde::{Serialize, Serializer};
|
||||||
|
|
||||||
use crate::field::batch_util::batch_multiply_inplace;
|
use crate::field::batch_util::batch_multiply_inplace;
|
||||||
use crate::field::extension::{Extendable, FieldExtension};
|
use crate::field::extension::{Extendable, FieldExtension};
|
||||||
@ -239,6 +240,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<F: RichField + Extendable<D>, const D: usize> Serialize for GateRef<F, D> {
|
||||||
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
serializer.serialize_str(&self.0.id())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Map between gate parameters and available slots.
|
/// Map between gate parameters and available slots.
|
||||||
/// An available slot is of the form `(row, op)`, meaning the current available slot
|
/// An available slot is of the form `(row, op)`, meaning the current available slot
|
||||||
/// is at gate index `row` in the `op`-th operation.
|
/// is at gate index `row` in the `op`-th operation.
|
||||||
|
|||||||
@ -2,6 +2,8 @@ use alloc::vec;
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::field::extension::Extendable;
|
use crate::field::extension::Extendable;
|
||||||
use crate::field::polynomial::PolynomialValues;
|
use crate::field::polynomial::PolynomialValues;
|
||||||
use crate::gates::gate::{GateInstance, GateRef};
|
use crate::gates::gate::{GateInstance, GateRef};
|
||||||
@ -10,7 +12,7 @@ use crate::hash::hash_types::RichField;
|
|||||||
/// Placeholder value to indicate that a gate doesn't use a selector polynomial.
|
/// Placeholder value to indicate that a gate doesn't use a selector polynomial.
|
||||||
pub(crate) const UNUSED_SELECTOR: usize = u32::MAX as usize;
|
pub(crate) const UNUSED_SELECTOR: usize = u32::MAX as usize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
||||||
pub struct SelectorsInfo {
|
pub struct SelectorsInfo {
|
||||||
pub(crate) selector_indices: Vec<usize>,
|
pub(crate) selector_indices: Vec<usize>,
|
||||||
pub(crate) groups: Vec<Range<usize>>,
|
pub(crate) groups: Vec<Range<usize>>,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use alloc::vec::Vec;
|
|||||||
use core::ops::{Range, RangeFrom};
|
use core::ops::{Range, RangeFrom};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::field::extension::Extendable;
|
use crate::field::extension::Extendable;
|
||||||
use crate::field::fft::FftRootTable;
|
use crate::field::fft::FftRootTable;
|
||||||
@ -35,7 +36,7 @@ use crate::util::serialization::{
|
|||||||
};
|
};
|
||||||
use crate::util::timing::TimingTree;
|
use crate::util::timing::TimingTree;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||||
pub struct CircuitConfig {
|
pub struct CircuitConfig {
|
||||||
pub num_wires: usize,
|
pub num_wires: usize,
|
||||||
pub num_routed_wires: usize,
|
pub num_routed_wires: usize,
|
||||||
@ -370,7 +371,7 @@ impl<C: GenericConfig<D>, const D: usize> VerifierOnlyCircuitData<C, D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Circuit data required by both the prover and the verifier.
|
/// Circuit data required by both the prover and the verifier.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
||||||
pub struct CommonCircuitData<F: RichField + Extendable<D>, const D: usize> {
|
pub struct CommonCircuitData<F: RichField + Extendable<D>, const D: usize> {
|
||||||
pub config: CircuitConfig,
|
pub config: CircuitConfig,
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user