Skip to content

Commit a88bb48

Browse files
authored
Merge pull request #1 from lambdaclass/pickles
Start implementing pickles preproc
2 parents 5dd2dcd + 4580057 commit a88bb48

11 files changed

Lines changed: 244 additions & 0 deletions

File tree

batcher/aligned/test_files/mina/mina_state_proof_vk_query.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

operator/mina/lib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use kimchi::{
1313
verifier_index::VerifierIndex,
1414
};
1515

16+
mod pickles_preproc;
17+
1618
const MAX_PROOF_SIZE: usize = 10 * 1024;
1719
const MAX_PUB_INPUT_SIZE: usize = 50 * 1024;
1820

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target/
2+
3+
protocolStateProof.json
4+
blockchainVerificationKey.json
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::fs;
2+
3+
use state_proof::parse;
4+
// use verifier::verify;
5+
6+
pub mod preprocess;
7+
pub mod state_proof;
8+
pub mod type_aliases;
9+
pub mod verifier;
10+
11+
pub fn parse_and_verify(proof_file_path: &str) -> Result<(), String> {
12+
let proof_query_str = fs::read_to_string(proof_file_path)
13+
.map_err(|err| format!("Could not read proof file: {err}"))?;
14+
let proof_query: serde_json::Map<String, serde_json::Value> =
15+
serde_json::from_str(&proof_query_str)
16+
.map_err(|err| format!("Could not parse proof file as JSON: {err}"))?;
17+
let protocol_state_proof_json = proof_query
18+
.get("data")
19+
.and_then(|d| d.get("bestChain"))
20+
.and_then(|d| d.get(0))
21+
.and_then(|d| d.get("protocolStateProof"))
22+
.and_then(|d| d.get("json")).ok_or("Could not parse protocol state proof: JSON structure upto protocolStateProof is unexpected")?;
23+
let _protocol_state_proof = parse(protocol_state_proof_json)?;
24+
25+
Ok(())
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use pickles::parse_and_verify;
2+
3+
fn main() -> Result<(), String> {
4+
let args: Vec<String> = std::env::args().collect();
5+
let proof_file_path = args.get(1).ok_or("Error: No proof file path provided")?;
6+
7+
parse_and_verify(proof_file_path)
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod preprocess;
2+
pub mod state_proof;
3+
pub mod type_aliases;
4+
pub mod verifier;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::{
2+
state_proof::StateProof,
3+
type_aliases::{WrapProverCommitments, WrapProverProof, WrapVerifierIndex},
4+
};
5+
6+
pub fn preprocess_state_proof(
7+
state_proof_json: StateProof,
8+
) -> (WrapVerifierIndex, WrapProverProof) {
9+
let commitments = WrapProverCommitments {};
10+
11+
let prover_proof = WrapProverProof {
12+
commitments,
13+
proof,
14+
evals,
15+
ft_eval1,
16+
prev_challenges,
17+
};
18+
todo!()
19+
}
20+
21+
pub fn compute_prev_challenges() {
22+
todo!()
23+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
use kimchi::mina_curves::pasta::Pallas;
2+
use serde::Deserialize;
3+
4+
use crate::type_aliases::WrapPolyComm;
5+
6+
#[derive(Deserialize)]
7+
pub struct StateProof {
8+
pub proof: Proof,
9+
pub statement: Statement,
10+
}
11+
12+
#[derive(Deserialize)]
13+
pub struct Proof {
14+
pub bulletproof: Bulletproof,
15+
}
16+
17+
#[derive(Deserialize)]
18+
pub struct Bulletproof {
19+
pub challenge_polynomial_commitment: Point,
20+
pub delta: Point,
21+
pub lr: [[Point; 2]; 15],
22+
pub z_1: Scalar,
23+
pub z_2: Scalar,
24+
}
25+
26+
#[derive(Deserialize)]
27+
pub struct Commitments {
28+
pub t_comm: [Point; 7],
29+
pub w_comm: [Point; 15],
30+
pub z_comm: Point,
31+
}
32+
33+
#[derive(Deserialize)]
34+
pub struct Evaluations {
35+
pub coefficients: [Point; 15],
36+
pub complete_add_selector: Point,
37+
pub emul_selector: Point,
38+
pub endomul_scalar_selector: Point,
39+
pub generic_selector: Point,
40+
pub mul_selector: Point,
41+
pub poseidon_selector: Point,
42+
pub s: [Point; 6],
43+
pub w: [Point; 15],
44+
pub z: Point,
45+
pub ft_eval1: Scalar,
46+
}
47+
48+
#[derive(Deserialize)]
49+
pub struct Statement {
50+
pub messages_for_next_step_proof: MessagesForNextStepProof,
51+
}
52+
53+
#[derive(Deserialize)]
54+
pub struct MessagesForNextStepProof {
55+
pub challenge_polynomial_commitments: [Point; 2],
56+
pub old_bulletproof_challenges: [[BulletproofChallenge; 16]; 2],
57+
}
58+
59+
#[derive(Deserialize)]
60+
pub struct BulletproofChallenge {
61+
pub prechallenge: Prechallenge,
62+
}
63+
64+
#[derive(Deserialize)]
65+
pub struct Prechallenge {
66+
// OCaml doesn't support unsigned integers, these should
67+
// be two u64 limbs but are encoded with a sign.
68+
// We just need to do a cast to u64.
69+
pub inner: [I64; 2],
70+
}
71+
72+
#[derive(Deserialize)]
73+
pub struct ProofState {
74+
pub deferred_values: DeferredValues,
75+
pub messages_for_next_wrap_proof: MessagesForNextWrapProof,
76+
pub sponge_digest_before_evaluations: [Scalar; 4],
77+
}
78+
79+
#[derive(Deserialize)]
80+
pub struct DeferredValues {
81+
pub branch_data: BranchData,
82+
pub bulletproof_challenges: [BulletproofChallenge; 16],
83+
pub plonk: Plonk,
84+
}
85+
86+
#[derive(Deserialize)]
87+
pub struct BranchData {
88+
pub domain_log2: String,
89+
pub proofs_verified: [String; 1],
90+
}
91+
92+
#[derive(Deserialize)]
93+
pub struct Plonk {
94+
pub alpha: Prechallenge,
95+
pub beta: Point,
96+
pub feature_flags: FeatureFlags,
97+
pub gamma: Point,
98+
pub zeta: Prechallenge,
99+
}
100+
101+
#[derive(Deserialize)]
102+
pub struct FeatureFlags {
103+
pub foreign_field_add: bool,
104+
pub foreign_field_mul: bool,
105+
pub lookup: bool,
106+
pub range_check0: bool,
107+
pub range_check1: bool,
108+
pub rot: bool,
109+
pub runtime_tables: bool,
110+
pub xor: bool,
111+
}
112+
113+
#[derive(Deserialize)]
114+
pub struct MessagesForNextWrapProof {
115+
pub challenge_polynomial_commitment: Point,
116+
pub old_bulletproof_challenges: [[BulletproofChallenge; 16]; 2],
117+
}
118+
119+
pub type Point = [String; 2]; // hex
120+
pub type Scalar = String; // hex
121+
pub type I64 = String; // decimal signed
122+
123+
pub fn parse(proof_json: &serde_json::Value) -> Result<StateProof, String> {
124+
serde_json::from_value(proof_json.to_owned())
125+
.map_err(|err| format!("Could not parse proof: {err}"))
126+
}
127+
128+
impl Into<WrapPolyComm> for Point {
129+
fn into(self) -> WrapPolyComm {
130+
from hex
131+
basefield from big endian
132+
Pallas
133+
}
134+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use kimchi::{
2+
mina_curves::pasta::Pallas,
3+
poly_commitment::{evaluation_proof::OpeningProof, PolyComm},
4+
proof::{ProverCommitments, ProverProof},
5+
verifier_index::VerifierIndex,
6+
};
7+
8+
// Wrap circuit specific types
9+
pub type WrapPolyComm = PolyComm<Pallas>;
10+
pub type WrapVerifierIndex = VerifierIndex<Pallas, WrapOpeningProof>;
11+
pub type WrapProverProof = ProverProof<Pallas, WrapOpeningProof>;
12+
pub type WrapProverCommitments = ProverCommitments<Pallas>;
13+
pub type WrapOpeningProof = OpeningProof<Pallas>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// use kimchi::{
2+
// groupmap::GroupMap,
3+
// mina_curves::pasta::{Fp, Fq, Pallas, PallasParameters},
4+
// mina_poseidon::{
5+
// constants::PlonkSpongeConstantsKimchi,
6+
// sponge::{DefaultFqSponge, DefaultFrSponge},
7+
// },
8+
// verifier::batch_verify,
9+
// };
10+
11+
// pub fn verify() -> Result<(), String> {
12+
// let group_map = GroupMap::<Fp>::setup();
13+
14+
// batch_verify::<
15+
// Pallas,
16+
// DefaultFqSponge<PallasParameters, PlonkSpongeConstantsKimchi>,
17+
// DefaultFrSponge<Fq, PlonkSpongeConstantsKimchi>,
18+
// >(group_map, proofs)
19+
// .map_err(|err| format!("Could not verify Kimchi proof: {err}"))
20+
// }

0 commit comments

Comments
 (0)