calculate MainPod id in a dynamic-friendly way (#241)

* calculate MainPod id in a dynamic-friendly way

The MainPod id is now calculated with front padding and a fixed size
independent of max_public_statements so that introduction gadgets can be
verified by a MainPod while paying only for the number of statements
they use.  This is because with front padding of none-statements we can
precompute the poseidon state corresponding to absorbing all the padding
statements and only pay constraints for the non-padding statements.

The id is calculated as follows:
`id = hash(serialize(reverse(statements || none-statements)))`

* fix test
This commit is contained in:
Eduard S. 2025-05-23 10:12:28 +02:00 committed by GitHub
parent 82481e88d7
commit d3fef8392e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 245 additions and 26 deletions

View file

@ -11,7 +11,7 @@ use crate::{
backends::plonky2::{
error::{Error, Result},
mainpod::{
extract_merkle_proofs, hash_statements, layout_statements, normalize_statement,
calculate_id, extract_merkle_proofs, layout_statements, normalize_statement,
process_private_statements_operations, process_public_statements_operations, Operation,
Statement,
},
@ -163,7 +163,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, params));
let id: PodId = PodId(calculate_id(&public_statements, params));
Ok(Self {
params: params.clone(),
@ -197,7 +197,7 @@ impl MockMainPod {
// get the input_statements from the self.statements
let input_statements = &self.statements[input_statement_offset..];
// 2. 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, &self.params));
let ids_match = self.id == PodId(calculate_id(&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.public_statements.iter().any(|s| {
@ -351,8 +351,7 @@ pub mod tests {
#[test]
fn test_mock_main_great_boy() -> frontend::Result<()> {
let params = middleware::Params::default();
let great_boy_builder = great_boy_pod_full_flow()?;
let (params, great_boy_builder) = great_boy_pod_full_flow()?;
let mut prover = MockProver {};
let great_boy_pod = great_boy_builder.prove(&mut prover, &params)?;