Skip to content

Commit 43e81f8

Browse files
committed
Add pre verification steps
1 parent 4537d70 commit 43e81f8

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

batcher/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/aligned-batcher/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ bytes = "1.6.0"
1919
hex = "0.4.3"
2020
dotenv = "0.15.0"
2121
anyhow = "1.0.83"
22-
ethers = { tag = "v2.0.15-fix-reconnections", features = ["ws", "rustls"], git = "https://github.com/yetanotherco/ethers-rs.git" }
22+
ethers = { tag = "v2.0.15-fix-reconnections", features = [
23+
"ws",
24+
"rustls",
25+
], git = "https://github.com/yetanotherco/ethers-rs.git" }
2326
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
2427
serde_yaml = "0.9.34"
2528
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "v1.0.5-testnet" }
26-
risc0-zkvm = { git = "https://github.com/risc0/risc0", tag="v1.0.1" }
29+
risc0-zkvm = { git = "https://github.com/risc0/risc0", tag = "v1.0.1" }
2730
halo2curves = { version = "0.6.0", default-features = false }
28-
halo2_backend = { git = "https://github.com/yetanotherco/yet-another-halo2-fork.git", branch = "feat/serde_constraint_system"}
31+
halo2_backend = { git = "https://github.com/yetanotherco/yet-another-halo2-fork.git", branch = "feat/serde_constraint_system" }
2932
halo2_proofs = { git = "https://github.com/yetanotherco/yet-another-halo2-fork.git", branch = "feat/serde_constraint_system" }
33+
aligned-batcher-lib = { path = "../aligned-batcher-lib" }
3034
lazy_static = "1.4.0"
3135
bincode = "1.3.3"
32-
aligned-batcher-lib = { path = "../aligned-batcher-lib"}
36+
base64 = "0.22.1"
37+
bs58 = "0.5.1"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use base64::prelude::*;
2+
use log::{debug, warn};
3+
4+
pub fn verify_protocol_state_proof_integrity(proof: &[u8], public_input: &[u8]) -> bool {
5+
debug!("Reading Mina protocol state proof base64");
6+
let protocol_state_proof_base64 =
7+
if let Ok(protocol_state_proof_base64) = std::str::from_utf8(&proof) {
8+
protocol_state_proof_base64
9+
} else {
10+
return false;
11+
};
12+
debug!("Reading Mina protocol state hash base58");
13+
let protocol_state_hash_base58 =
14+
if let Ok(protocol_state_hash_base58) = std::str::from_utf8(&public_input) {
15+
protocol_state_hash_base58
16+
} else {
17+
return false;
18+
};
19+
20+
debug!("Decoding Mina protocol state proof base64");
21+
if BASE64_URL_SAFE
22+
.decode(protocol_state_proof_base64.trim_end())
23+
.is_err()
24+
{
25+
warn!("Failed to decode Mina protocol state proof base64");
26+
return false;
27+
}
28+
29+
debug!("Decoding Mina protocol state hash base58");
30+
if bs58::decode(protocol_state_hash_base58.trim_end())
31+
.into_vec()
32+
.is_err()
33+
{
34+
warn!("Failed to decode Mina protocol state hash base58");
35+
return false;
36+
}
37+
38+
true
39+
}
40+
41+
#[cfg(test)]
42+
mod test {
43+
use super::verify_protocol_state_proof_integrity;
44+
45+
const PROTOCOL_STATE_PROOF_BYTES: &[u8] =
46+
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_proof.proof");
47+
const PROTOCOL_STATE_HASH_BYTES: &[u8] =
48+
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_hash.pub");
49+
50+
#[test]
51+
fn verify_protocol_state_proof_integrity_does_not_fail() {
52+
assert!(verify_protocol_state_proof_integrity(
53+
PROTOCOL_STATE_PROOF_BYTES,
54+
PROTOCOL_STATE_HASH_BYTES,
55+
));
56+
}
57+
}

batcher/aligned-batcher/src/zk_utils/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::gnark::verify_gnark;
21
use crate::halo2::ipa::verify_halo2_ipa;
32
use crate::halo2::kzg::verify_halo2_kzg;
43
use crate::risc_zero::verify_risc_zero_proof;
54
use crate::sp1::verify_sp1_proof;
5+
use crate::{gnark::verify_gnark, mina::verify_protocol_state_proof_integrity};
66
use aligned_batcher_lib::types::{ProvingSystemId, VerificationData};
77
use log::{debug, warn};
88

@@ -78,7 +78,10 @@ pub(crate) fn verify(verification_data: &VerificationData) -> bool {
7878
.pub_input
7979
.as_ref()
8080
.expect("Public input is required");
81-
true // FIXME: pre-verify proof before submitting
81+
verify_protocol_state_proof_integrity(&verification_data.proof, pub_input)
82+
// TODO(xqft): add Pickles aggregator checks which are run alongside the Kimchi
83+
// verifier. These checks are fast and if they aren't successful then the Pickles proof
84+
// isn't valid.
8285
}
8386
}
8487
}

0 commit comments

Comments
 (0)