Skip to content

Commit

Permalink
Add pre-verification of Mina account inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 23, 2024
1 parent 50ed685 commit ec5800e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
30 changes: 30 additions & 0 deletions batcher/Cargo.lock

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

1 change: 1 addition & 0 deletions batcher/aligned-batcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ 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" }
23 changes: 19 additions & 4 deletions batcher/aligned-batcher/src/zk_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::risc_zero::verify_risc_zero_proof;
use crate::sp1::verify_sp1_proof;
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 {
Expand Down Expand Up @@ -134,13 +135,27 @@ fn verify_internal(verification_data: &VerificationData) -> bool {
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 ec5800e

Please sign in to comment.