mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 06:43:07 +00:00
Implement Default for DefaultGateSerializer and DefaultGeneratorSerializer (#1531)
* Implement Default for DefaultGateSerializer and DefaultGeneratorSerializer * Apply comments * Update doc * Clippy
This commit is contained in:
parent
3e579b6d43
commit
cfe4448341
@ -66,6 +66,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CustomGeneratorSerializer<C: GenericConfig<D>, const D: usize> {
|
||||
pub _phantom: PhantomData<C>,
|
||||
}
|
||||
@ -131,9 +132,7 @@ fn main() -> Result<()> {
|
||||
// Test serialization
|
||||
{
|
||||
let gate_serializer = DefaultGateSerializer;
|
||||
let generator_serializer = CustomGeneratorSerializer {
|
||||
_phantom: PhantomData::<C>,
|
||||
};
|
||||
let generator_serializer = CustomGeneratorSerializer::<C, D>::default();
|
||||
|
||||
let data_bytes = data
|
||||
.to_bytes(&gate_serializer, &generator_serializer)
|
||||
|
||||
@ -106,7 +106,7 @@ pub trait GenericConfig<const D: usize>:
|
||||
}
|
||||
|
||||
/// Configuration using Poseidon over the Goldilocks field.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize)]
|
||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Serialize)]
|
||||
pub struct PoseidonGoldilocksConfig;
|
||||
impl GenericConfig<2> for PoseidonGoldilocksConfig {
|
||||
type F = GoldilocksField;
|
||||
@ -116,7 +116,7 @@ impl GenericConfig<2> for PoseidonGoldilocksConfig {
|
||||
}
|
||||
|
||||
/// Configuration using truncated Keccak over the Goldilocks field.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
|
||||
pub struct KeccakGoldilocksConfig;
|
||||
impl GenericConfig<2> for KeccakGoldilocksConfig {
|
||||
type F = GoldilocksField;
|
||||
|
||||
@ -114,6 +114,15 @@ pub mod default {
|
||||
use crate::hash::hash_types::RichField;
|
||||
use crate::util::serialization::GateSerializer;
|
||||
|
||||
/// A gate serializer that can be used to serialize all default gates supported
|
||||
/// by the `plonky2` library.
|
||||
/// Being a unit struct, it can be simply called as
|
||||
/// ```rust
|
||||
/// use plonky2::util::serialization::DefaultGateSerializer;
|
||||
/// let gate_serializer = DefaultGateSerializer;
|
||||
/// ```
|
||||
/// Applications using custom gates should define their own serializer implementing
|
||||
/// the `GateSerializer` trait. This can be easily done through the `impl_gate_serializer` macro.
|
||||
pub struct DefaultGateSerializer;
|
||||
impl<F: RichField + Extendable<D>, const D: usize> GateSerializer<F, D> for DefaultGateSerializer {
|
||||
impl_gate_serializer! {
|
||||
|
||||
@ -127,6 +127,20 @@ pub mod default {
|
||||
use crate::recursion::dummy_circuit::DummyProofGenerator;
|
||||
use crate::util::serialization::WitnessGeneratorSerializer;
|
||||
|
||||
/// A generator serializer that can be used to serialize all default generators supported
|
||||
/// by the `plonky2` library. It can simply be called as
|
||||
/// ```rust
|
||||
/// use plonky2::util::serialization::DefaultGeneratorSerializer;
|
||||
/// use plonky2::plonk::config::PoseidonGoldilocksConfig;
|
||||
///
|
||||
/// const D: usize = 2;
|
||||
/// type C = PoseidonGoldilocksConfig;
|
||||
/// let generator_serializer = DefaultGeneratorSerializer::<C, D>::default();
|
||||
/// ```
|
||||
/// Applications using custom generators should define their own serializer implementing
|
||||
/// the `WitnessGeneratorSerializer` trait. This can be easily done through the
|
||||
/// `impl_generator_serializer` macro.
|
||||
#[derive(Default)]
|
||||
pub struct DefaultGeneratorSerializer<C: GenericConfig<D>, const D: usize> {
|
||||
pub _phantom: PhantomData<C>,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user