Skip to content

Commit

Permalink
Merge pull request #39 from lambdaclass/pre_verification
Browse files Browse the repository at this point in the history
Pre-verification
  • Loading branch information
gabrielbosio authored Sep 26, 2024
2 parents 6f61538 + 7d03160 commit 3426bb4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 9 deletions.
58 changes: 58 additions & 0 deletions batcher/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions batcher/aligned-batcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ 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" }
mina-account-verifier-ffi = { path = "../../operator/mina_account/lib" }
47 changes: 38 additions & 9 deletions batcher/aligned-batcher/src/zk_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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_account_verifier_ffi::verify_account_inclusion_ffi;
use mina_state_verifier_ffi::verify_mina_state_ffi;

pub(crate) async fn verify(verification_data: &VerificationData) -> bool {
let verification_data = verification_data.clone();
Expand Down Expand Up @@ -114,19 +116,46 @@ 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
let pub_input = verification_data
.pub_input
.as_ref()
.expect("Public input is required");
true
// TODO(xqft): add basic integrity checks (e.g. length of merkle proof being multiple of 32
// bytes, etc)

const MAX_PROOF_SIZE: usize = 16 * 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_account_inclusion_ffi(&proof_buffer, proof_len, &pub_input_buffer, pub_input_len)
}
}
}

0 comments on commit 3426bb4

Please sign in to comment.