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:
parent
05c21ebe6a
commit
a37b96ab4f
8 changed files with 262 additions and 39 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use std::fmt;
|
||||
|
||||
use crate::middleware::{self, NativePredicate, StatementArg, ToFields};
|
||||
use crate::middleware::{self, NativePredicate, Params, StatementArg, ToFields};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Statement(pub NativePredicate, pub Vec<StatementArg>);
|
||||
|
|
@ -21,12 +21,13 @@ impl Statement {
|
|||
}
|
||||
|
||||
impl ToFields for Statement {
|
||||
fn to_fields(self) -> (Vec<middleware::F>, usize) {
|
||||
let (native_statement_f, native_statement_f_len) = self.0.to_fields();
|
||||
fn to_fields(&self, params: Params) -> (Vec<middleware::F>, usize) {
|
||||
let (native_statement_f, native_statement_f_len) = self.0.to_fields(params);
|
||||
let (vec_statementarg_f, vec_statementarg_f_len) = self
|
||||
.1
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|statement_arg| statement_arg.to_fields())
|
||||
.map(|statement_arg| statement_arg.to_fields(params))
|
||||
.fold((Vec::new(), 0), |mut acc, (f, l)| {
|
||||
acc.0.extend(f);
|
||||
acc.1 += l;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue