Serialize and hash custom predicates (#90)

* Print pods from SignedPodBuilder

* Add additional print to test printing SignedPodBuilder

* Mock-prove and print MainPod

* Implement ToFields for custom predicates and dependencies

* Test: print serialization of a recursive batch

* Rearrange serialization of CustomPredicate so args_len is always in the same position

* Serialize predicates with first entry nonzero to avoid collision with padding

* Off by one error in ethdos test BatchSelf(2)

* cargo fmt

* not a typo

* Typos, trying again
This commit is contained in:
tideofwords 2025-02-26 11:28:27 -08:00 committed by GitHub
parent 05c21ebe6a
commit a37b96ab4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 262 additions and 39 deletions

View file

@ -96,6 +96,16 @@ pub struct SignedPodBuilder {
pub kvs: HashMap<String, Value>,
}
impl fmt::Display for SignedPodBuilder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "SignedPodBuilder:")?;
for (k, v) in self.kvs.iter().sorted_by_key(|kv| kv.0) {
writeln!(f, " - {}: {}", k, v)?;
}
Ok(())
}
}
impl SignedPodBuilder {
pub fn new(params: &Params) -> Self {
Self {
@ -347,6 +357,22 @@ pub struct MainPod {
// TODO: metadata
}
impl fmt::Display for MainPod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "MainPod: {}", self.pod.id())?;
writeln!(f, " valid? {}", self.pod.verify())?;
writeln!(f, " statements:")?;
for st in &self.pod.pub_statements() {
writeln!(f, " - {}", st)?;
}
writeln!(f, " kvs:")?;
for (k, v) in &self.pod.kvs() {
writeln!(f, " - {}: {}", k, v)?;
}
Ok(())
}
}
impl MainPod {
pub fn id(&self) -> PodId {
self.pod.id()
@ -487,6 +513,7 @@ pub mod build_utils {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::backends::mock_main::MockProver;
use crate::backends::mock_signed::MockSigner;
use crate::examples::{
great_boy_pod_full_flow, tickets_pod_full_flow, zu_kyc_pod_builder,
@ -498,7 +525,8 @@ pub mod tests {
let params = Params::default();
let (gov_id, pay_stub) = zu_kyc_sign_pod_builders(&params);
// TODO: print pods from the builder
println!("{}", gov_id);
println!("{}", pay_stub);
let mut signer = MockSigner {
pk: "ZooGov".into(),
@ -515,7 +543,11 @@ pub mod tests {
let kyc = zu_kyc_pod_builder(&params, &gov_id, &pay_stub)?;
println!("{}", kyc);
let mut prover = MockProver {};
let kyc = kyc.prove(&mut prover)?;
// TODO: prove kyc with MockProver and print it
println!("{}", kyc);
Ok(())
}