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

@ -327,7 +327,7 @@ impl MockMainPod {
statements[statements.len() - params.max_public_statements..].to_vec();
// get the id out of the public statements
let id: PodId = PodId(hash_statements(&public_statements));
let id: PodId = PodId(hash_statements(&public_statements, *params));
Ok(Self {
params: params.clone(),
@ -362,10 +362,10 @@ impl MockMainPod {
}
}
pub fn hash_statements(statements: &[Statement]) -> middleware::Hash {
pub fn hash_statements(statements: &[Statement], params: Params) -> middleware::Hash {
let field_elems = statements
.into_iter()
.flat_map(|statement| statement.clone().to_fields().0)
.flat_map(|statement| statement.clone().to_fields(params).0)
.collect::<Vec<_>>();
Hash(PoseidonHash::hash_no_pad(&field_elems).elements)
}
@ -376,7 +376,7 @@ impl Pod for MockMainPod {
// get the input_statements from the self.statements
let input_statements = &self.statements[input_statement_offset..];
// get the id out of the public statements, and ensure it is equal to self.id
let ids_match = self.id == PodId(hash_statements(&self.public_statements));
let ids_match = self.id == PodId(hash_statements(&self.public_statements, self.params));
// find a ValueOf statement from the public statements with key=KEY_TYPE and check that the
// value is PodType::MockMainPod
let has_type_statement = self