Complete the verification in MainMockPod (#302)
- Update the `RecursivePod` trait to return `vd_set` instead of `vds_root` - A native verifier requires the entire set to reason about the circuits that have been used in the recursive tree - Implement serialization/deserialization for `VDSet` - Remove `DynError` and use `BackendError` instead for middleware functions that wrap or define trait functions implemented in the backend. This is based on the fact that we will only have a single backend enabled at a time, so there's no need for a `dyn Error` - Move the implementations of `_verify` functions to `verify` and similarly for `_prove` - Complete the verification of a MockMainPod: the verification of input pods was missing. The inclusion of these input pods in the serialization was also missing. With this change a `MockMainPod` will grow after each recursion. This was expected from the design but was not the case because of the missing recursive native verification implementation. * apply feedback from @arnaucube
This commit is contained in:
parent
df8fce76d6
commit
6249406cb2
16 changed files with 427 additions and 350 deletions
|
|
@ -3,14 +3,14 @@ use std::{
|
|||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
||||
use crate::middleware::{DynError, Error, Hash, Params, Pod, PodId, PodType, RecursivePod, Result};
|
||||
use crate::middleware::{BackendError, Params, Pod, PodId, PodType, RecursivePod, Result, VDSet};
|
||||
|
||||
type DeserializeFn = fn(
|
||||
params: Params,
|
||||
data: serde_json::Value,
|
||||
vds_root: Hash,
|
||||
vd_set: VDSet,
|
||||
id: PodId,
|
||||
) -> Result<Box<dyn RecursivePod>, Box<DynError>>;
|
||||
) -> Result<Box<dyn RecursivePod>, BackendError>;
|
||||
|
||||
static DESERIALIZERS: LazyLock<Mutex<HashMap<usize, DeserializeFn>>> =
|
||||
LazyLock::new(backend::deserializers_default);
|
||||
|
|
@ -26,28 +26,27 @@ pub fn deserialize_pod(
|
|||
pod_type: usize,
|
||||
params: Params,
|
||||
id: PodId,
|
||||
vds_root: Hash,
|
||||
vd_set: VDSet,
|
||||
data: serde_json::Value,
|
||||
) -> Result<Box<dyn RecursivePod>> {
|
||||
) -> Result<Box<dyn RecursivePod>, BackendError> {
|
||||
let deserialize_fn: DeserializeFn =
|
||||
*DESERIALIZERS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get(&pod_type)
|
||||
.ok_or(Error::custom(format!(
|
||||
.ok_or(BackendError::custom(format!(
|
||||
"pod deserializer for pod_type={} not registered. See https://github.com/0xPARC/pod2/wiki/PodType for pod type assignments.",
|
||||
pod_type
|
||||
)))?;
|
||||
|
||||
deserialize_fn(params, data, vds_root, id)
|
||||
.map_err(|e| Error::custom(format!("deserialize error: {:?}", e)))
|
||||
deserialize_fn(params, data, vd_set, id)
|
||||
}
|
||||
|
||||
pub fn deserialize_signed_pod(
|
||||
pod_type: usize,
|
||||
id: PodId,
|
||||
data: serde_json::Value,
|
||||
) -> Result<Box<dyn Pod>> {
|
||||
) -> Result<Box<dyn Pod>, BackendError> {
|
||||
backend::deserialize_signed_pod(pod_type, id, data)
|
||||
}
|
||||
|
||||
|
|
@ -74,15 +73,13 @@ mod backend {
|
|||
pod_type: usize,
|
||||
id: PodId,
|
||||
data: serde_json::Value,
|
||||
) -> Result<Box<dyn Pod>> {
|
||||
) -> Result<Box<dyn Pod>, BackendError> {
|
||||
if pod_type == PodType::MockSigned as usize {
|
||||
MockSignedPod::deserialize(id, data)
|
||||
.map_err(|e| Error::custom(format!("deserialize error: {:?}", e)))
|
||||
} else if pod_type == PodType::Signed as usize {
|
||||
SignedPod::deserialize(id, data)
|
||||
.map_err(|e| Error::custom(format!("deserialize error: {:?}", e)))
|
||||
} else {
|
||||
Err(Error::custom(format!(
|
||||
Err(BackendError::custom(format!(
|
||||
"unexpected pod_type={} for deserialize_signed_pod",
|
||||
pod_type
|
||||
)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue