Re-implement serialization (#201)

* Serialization tests now pass again

* Tidy up and test more edge-cases

* Use attributes rather than custom serializer for arrays

* Add JSON Schema support

* Tests for JSON Schema generation and validation

* Add comments

* Support custom predicates

* Clippy fixes

* Make deserialization/constructor functions pub(crate)
This commit is contained in:
Rob Knight 2025-04-22 04:19:20 -07:00 committed by GitHub
parent 26a6b2d143
commit bf6d8aee8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 554 additions and 255 deletions

View file

@ -2,14 +2,14 @@ use std::fmt;
use anyhow::{anyhow, Result};
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};
// use serde::{Deserialize, Serialize};
use crate::{
backends::plonky2::{mainpod::Statement, primitives::merkletree::MerkleClaimAndProof},
middleware::{self, OperationType, Params, ToFields, F},
};
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum OperationArg {
None,
Index(usize),
@ -31,7 +31,7 @@ impl OperationArg {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum OperationAux {
None,
MerkleProofIndex(usize),
@ -47,7 +47,7 @@ impl ToFields for OperationAux {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Operation(pub OperationType, pub Vec<OperationArg>, pub OperationAux);
impl Operation {

View file

@ -1,13 +1,13 @@
use std::fmt;
use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
// use serde::{Deserialize, Serialize};
use crate::middleware::{
self, NativePredicate, Params, Predicate, StatementArg, ToFields, WildcardValue,
};
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Statement(pub Predicate, pub Vec<StatementArg>);
impl Statement {