Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-verification #39

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Loading