From 50ed6852bbe2ac05e504ee8ad7802cffd8ebcf2b Mon Sep 17 00:00:00 2001 From: gabrielbosio Date: Mon, 23 Sep 2024 17:32:59 -0300 Subject: [PATCH] Add pre-verification of Mina state --- batcher/Cargo.lock | 28 +++++++++++++++++++++ batcher/aligned-batcher/Cargo.toml | 1 + batcher/aligned-batcher/src/zk_utils/mod.rs | 24 ++++++++++++++---- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/batcher/Cargo.lock b/batcher/Cargo.lock index 991de0969..83c45f6fb 100644 --- a/batcher/Cargo.lock +++ b/batcher/Cargo.lock @@ -126,6 +126,7 @@ dependencies = [ "lambdaworks-crypto", "lazy_static", "log", + "mina-state-verifier-ffi", "mina_bridge_core", "priority-queue", "risc0-zkvm", @@ -5061,6 +5062,33 @@ dependencies = [ "thiserror", ] +[[package]] +name = "mina-state-verifier-ffi" +version = "0.1.0" +dependencies = [ + "ark-ec 0.3.0", + "ark-ff 0.3.0", + "ark-poly 0.3.0", + "ark-serialize 0.3.0", + "base64 0.22.1", + "bincode", + "blake2", + "bs58 0.5.1", + "hex", + "kimchi", + "lazy_static", + "mina-curves", + "mina-p2p-messages", + "mina-tree", + "mina_bridge_core", + "o1-utils 0.1.0 (git+https://github.com/lambdaclass/proof-systems?branch=add-verifier-serializations)", + "once_cell", + "poly-commitment", + "rmp-serde", + "serde", + "serde_json", +] + [[package]] name = "mina-tree" version = "0.6.0" diff --git a/batcher/aligned-batcher/Cargo.toml b/batcher/aligned-batcher/Cargo.toml index 963a95088..3523eb01d 100644 --- a/batcher/aligned-batcher/Cargo.toml +++ b/batcher/aligned-batcher/Cargo.toml @@ -38,3 +38,4 @@ ciborium = "=0.2.2" base64 = "0.22.1" bs58 = "0.5.1" priority-queue = "2.1.0" +mina-state-verifier-ffi = { path = "../../operator/mina/lib" } diff --git a/batcher/aligned-batcher/src/zk_utils/mod.rs b/batcher/aligned-batcher/src/zk_utils/mod.rs index f7b092ddf..9dce55394 100644 --- a/batcher/aligned-batcher/src/zk_utils/mod.rs +++ b/batcher/aligned-batcher/src/zk_utils/mod.rs @@ -1,10 +1,11 @@ +use crate::gnark::verify_gnark; use crate::halo2::ipa::verify_halo2_ipa; use crate::halo2::kzg::verify_halo2_kzg; use crate::risc_zero::verify_risc_zero_proof; use crate::sp1::verify_sp1_proof; -use crate::{gnark::verify_gnark, mina::verify_proof_integrity}; use aligned_sdk::core::types::{ProvingSystemId, VerificationData}; use log::{debug, warn}; +use mina_state_verifier_ffi::verify_mina_state_ffi; pub(crate) async fn verify(verification_data: &VerificationData) -> bool { let verification_data = verification_data.clone(); @@ -114,10 +115,23 @@ fn verify_internal(verification_data: &VerificationData) -> bool { .pub_input .as_ref() .expect("Public input is required"); - verify_proof_integrity(&verification_data.proof, pub_input) - // TODO(xqft): add Pickles aggregator checks which are run alongside the Kimchi - // verifier. These checks are fast and if they aren't successful then the Pickles proof - // isn't valid. + + const MAX_PROOF_SIZE: usize = 48 * 1024; + const MAX_PUB_INPUT_SIZE: usize = 6 * 1024; + + let mut proof_buffer = [0; MAX_PROOF_SIZE]; + for (buffer_item, proof_item) in proof_buffer.iter_mut().zip(&verification_data.proof) { + *buffer_item = *proof_item; + } + let proof_len = verification_data.proof.len(); + + let mut pub_input_buffer = [0; MAX_PUB_INPUT_SIZE]; + for (buffer_item, pub_input_item) in pub_input_buffer.iter_mut().zip(pub_input) { + *buffer_item = *pub_input_item; + } + let pub_input_len = pub_input.len(); + + verify_mina_state_ffi(&proof_buffer, proof_len, &pub_input_buffer, pub_input_len) } ProvingSystemId::MinaAccount => { verification_data