fix: missing gate and generator for serialization (#369)
Add the missing gates and generator in the serializer that were added with the PublicKeyOf operation. Add a test for CircuitData serialization+deserialization to avoid these kind of bugs in the future.
This commit is contained in:
parent
59c6151dbc
commit
0606a4098b
3 changed files with 32 additions and 4 deletions
|
|
@ -21,7 +21,7 @@ lazy_static = "1.5.0"
|
||||||
thiserror = { version = "2.0.12" }
|
thiserror = { version = "2.0.12" }
|
||||||
# enabled by features:
|
# enabled by features:
|
||||||
plonky2 = { git = "https://github.com/0xPARC/plonky2.git", rev = "3defd60532c8693cf5e9d2e6a8412c77ca58760f", optional = true }
|
plonky2 = { git = "https://github.com/0xPARC/plonky2.git", rev = "3defd60532c8693cf5e9d2e6a8412c77ca58760f", optional = true }
|
||||||
plonky2_u32 = { git = "https://github.com/ax0/plonky2-u32", rev = "7a38240693455d6182210c2efecba99cbf871a6f" }
|
plonky2_u32 = { git = "https://github.com/ax0/plonky2-u32", rev = "e5548e8e4a27d6660b686c65543f0d7d9731aa30" }
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
|
|
|
||||||
|
|
@ -578,7 +578,7 @@ pub(crate) fn rec_main_pod_circuit_data(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cache_get_rec_main_pod_circuit_data(
|
pub(crate) fn cache_get_rec_main_pod_circuit_data(
|
||||||
params: &Params,
|
params: &Params,
|
||||||
) -> CacheEntry<(
|
) -> CacheEntry<(
|
||||||
RecursiveCircuitTarget<MainPodVerifyTarget>,
|
RecursiveCircuitTarget<MainPodVerifyTarget>,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use plonky2::{
|
||||||
get_gate_tag_impl, impl_gate_serializer, read_gate_impl,
|
get_gate_tag_impl, impl_gate_serializer, read_gate_impl,
|
||||||
util::serialization::GateSerializer,
|
util::serialization::GateSerializer,
|
||||||
};
|
};
|
||||||
|
use plonky2_u32::gates::comparison::{ComparisonGate, ComparisonGenerator};
|
||||||
use serde::{de, ser, Deserialize, Serialize};
|
use serde::{de, ser, Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::backends::plonky2::{
|
use crate::backends::plonky2::{
|
||||||
|
|
@ -56,7 +57,8 @@ impl GateSerializer<F, D> for Pod2GateSerializer {
|
||||||
GateAdapter::<NNFMulSimple<5, QuinticExtension<F>>>,
|
GateAdapter::<NNFMulSimple<5, QuinticExtension<F>>>,
|
||||||
RecursiveGateAdapter::<D, NNFMulSimple<5, QuinticExtension<F>>>,
|
RecursiveGateAdapter::<D, NNFMulSimple<5, QuinticExtension<F>>>,
|
||||||
GateAdapter::<ECAddHomogOffset>,
|
GateAdapter::<ECAddHomogOffset>,
|
||||||
RecursiveGateAdapter::<D, ECAddHomogOffset>
|
RecursiveGateAdapter::<D, ECAddHomogOffset>,
|
||||||
|
ComparisonGate::<F, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +129,8 @@ impl WitnessGeneratorSerializer<F, D> for Pod2GeneratorSerializer {
|
||||||
RecursiveGenerator<D, NNFMulSimple<5, QuinticExtension<F>>>,
|
RecursiveGenerator<D, NNFMulSimple<5, QuinticExtension<F>>>,
|
||||||
RecursiveGenerator<1, NNFMulSimple<5, QuinticExtension<F>>>,
|
RecursiveGenerator<1, NNFMulSimple<5, QuinticExtension<F>>>,
|
||||||
RecursiveGenerator<D, ECAddHomogOffset>,
|
RecursiveGenerator<D, ECAddHomogOffset>,
|
||||||
RecursiveGenerator<1, ECAddHomogOffset>
|
RecursiveGenerator<1, ECAddHomogOffset>,
|
||||||
|
ComparisonGenerator<F, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,3 +253,28 @@ impl<'de> Deserialize<'de> for VerifierCircuitDataSerializer {
|
||||||
Ok(VerifierCircuitDataSerializer(circuit_data))
|
Ok(VerifierCircuitDataSerializer(circuit_data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::{
|
||||||
|
backends::plonky2::mainpod::cache_get_rec_main_pod_circuit_data, middleware::Params,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Round trip of CircuitData serialization and deserialization. This test should pass if
|
||||||
|
// we have registered all the gates and generators used in the recursive MainPod
|
||||||
|
// circuit.
|
||||||
|
#[test]
|
||||||
|
fn test_serialize_main_pod_circuit_data() {
|
||||||
|
let params = Params::default();
|
||||||
|
let (_, circuit_data) = &*cache_get_rec_main_pod_circuit_data(¶ms);
|
||||||
|
let gate_serializer = Pod2GateSerializer {};
|
||||||
|
let generator_serializer = Pod2GeneratorSerializer {};
|
||||||
|
let bytes = circuit_data
|
||||||
|
.to_bytes(&gate_serializer, &generator_serializer)
|
||||||
|
.unwrap();
|
||||||
|
let circuit_data_de =
|
||||||
|
CircuitData::from_bytes(&bytes, &gate_serializer, &generator_serializer).unwrap();
|
||||||
|
assert_eq!(circuit_data.0, circuit_data_de);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue