Skip to content

Commit 37fb58a

Browse files
committed
Deserialize evaluations
1 parent 21b31ef commit 37fb58a

3 files changed

Lines changed: 125 additions & 19 deletions

File tree

operator/mina/lib/src/pickles_preproc/preprocess.rs

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
use kimchi::{circuits::wires::COLUMNS, mina_curves::pasta::Pallas, poly_commitment::PolyComm};
1+
use kimchi::{
2+
circuits::wires::{COLUMNS, PERMUTS},
3+
mina_curves::pasta::{Fq, Pallas},
4+
poly_commitment::PolyComm,
5+
proof::PointEvaluations,
6+
};
27

38
use crate::pickles_preproc::{
4-
state_proof::{Bulletproof, Commitments},
5-
type_aliases::{WrapECPoint, WrapOpeningProof, WrapProverCommitments, WrapScalar},
9+
state_proof::{Bulletproof, Commitments, Evaluations},
10+
type_aliases::{
11+
WrapECPoint, WrapOpeningProof, WrapPointEvaluations, WrapProofEvaluations,
12+
WrapProverCommitments, WrapScalar,
13+
},
614
};
715

816
use super::{
@@ -75,6 +83,85 @@ pub fn deserialize_state_proof(
7583
z2,
7684
};
7785

86+
let Evaluations {
87+
coefficients: hex_coefficients,
88+
complete_add_selector: hex_complete_add_selector,
89+
emul_selector: hex_emul_selector,
90+
endomul_scalar_selector: hex_endomul_scalar_selector,
91+
generic_selector: hex_generic_selector,
92+
mul_selector: hex_mul_selector,
93+
poseidon_selector: hex_poseidon_selector,
94+
s: hex_s,
95+
w: hex_w,
96+
z: hex_z,
97+
} = state_proof.proof.evaluations;
98+
99+
let mut w: [PointEvaluations<Vec<Fq>>; COLUMNS] = std::array::from_fn(|_| PointEvaluations {
100+
zeta: Vec::with_capacity(1),
101+
zeta_omega: Vec::with_capacity(1),
102+
});
103+
for (hex_eval, eval) in hex_w.into_iter().zip(w.iter_mut()) {
104+
*eval = WrapPointEvaluations::try_from(hex_eval)?.0;
105+
}
106+
107+
let z = WrapPointEvaluations::try_from(hex_z)?.0;
108+
109+
let mut s: [PointEvaluations<Vec<Fq>>; PERMUTS - 1] =
110+
std::array::from_fn(|_| PointEvaluations {
111+
zeta: Vec::with_capacity(1),
112+
zeta_omega: Vec::with_capacity(1),
113+
});
114+
for (hex_eval, eval) in hex_s.into_iter().zip(s.iter_mut()) {
115+
*eval = WrapPointEvaluations::try_from(hex_eval)?.0;
116+
}
117+
118+
let mut coefficients: [PointEvaluations<Vec<Fq>>; COLUMNS] =
119+
std::array::from_fn(|_| PointEvaluations {
120+
zeta: Vec::with_capacity(1),
121+
zeta_omega: Vec::with_capacity(1),
122+
});
123+
for (hex_eval, eval) in hex_coefficients.into_iter().zip(coefficients.iter_mut()) {
124+
*eval = WrapPointEvaluations::try_from(hex_eval)?.0;
125+
}
126+
127+
let generic_selector = WrapPointEvaluations::try_from(hex_generic_selector)?.0;
128+
let poseidon_selector = WrapPointEvaluations::try_from(hex_poseidon_selector)?.0;
129+
let complete_add_selector = WrapPointEvaluations::try_from(hex_complete_add_selector)?.0;
130+
let mul_selector = WrapPointEvaluations::try_from(hex_mul_selector)?.0;
131+
let emul_selector = WrapPointEvaluations::try_from(hex_emul_selector)?.0;
132+
let endomul_scalar_selector = WrapPointEvaluations::try_from(hex_endomul_scalar_selector)?.0;
133+
134+
let public = None; // TODO: Calculate public poly evaluations
135+
136+
let _evals = WrapProofEvaluations {
137+
public,
138+
w,
139+
z,
140+
s,
141+
coefficients,
142+
generic_selector,
143+
poseidon_selector,
144+
complete_add_selector,
145+
mul_selector,
146+
emul_selector,
147+
endomul_scalar_selector,
148+
range_check0_selector: None,
149+
range_check1_selector: None,
150+
foreign_field_add_selector: None,
151+
foreign_field_mul_selector: None,
152+
xor_selector: None,
153+
rot_selector: None,
154+
lookup_aggregation: None,
155+
lookup_table: None,
156+
lookup_sorted: std::array::from_fn(|_| None),
157+
runtime_lookup_table: None,
158+
runtime_lookup_table_selector: None,
159+
xor_lookup_selector: None,
160+
lookup_gate_lookup_selector: None,
161+
range_check_lookup_selector: None,
162+
foreign_field_mul_lookup_selector: None,
163+
};
164+
78165
/*
79166
let prover_proof = WrapProverProof {
80167
commitments,

operator/mina/lib/src/pickles_preproc/state_proof.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
use kimchi::mina_curves::pasta::{Fp, Fq, Pallas};
1+
use kimchi::{
2+
mina_curves::pasta::{Fp, Fq, Pallas},
3+
proof::PointEvaluations,
4+
};
25
use o1_utils::FieldHelpers;
36
use serde::Deserialize;
47

5-
use super::type_aliases::{WrapECPoint, WrapScalar};
8+
use super::type_aliases::{WrapECPoint, WrapPointEvaluations, WrapScalar};
69

710
type DecimalSigned = String;
8-
type HexPointCoordinates = [String; 2];
911
type HexScalar = String;
12+
type HexPointCoordinates = [String; 2];
13+
type HexPointEvaluations = [String; 2];
1014

1115
#[derive(Deserialize)]
1216
pub struct StateProof {
@@ -40,16 +44,16 @@ pub struct Commitments {
4044

4145
#[derive(Deserialize)]
4246
pub struct Evaluations {
43-
pub coefficients: [HexPointCoordinates; 15],
44-
pub complete_add_selector: HexPointCoordinates,
45-
pub emul_selector: HexPointCoordinates,
46-
pub endomul_scalar_selector: HexPointCoordinates,
47-
pub generic_selector: HexPointCoordinates,
48-
pub mul_selector: HexPointCoordinates,
49-
pub poseidon_selector: HexPointCoordinates,
50-
pub s: [HexPointCoordinates; 6],
51-
pub w: [HexPointCoordinates; 15],
52-
pub z: HexPointCoordinates,
47+
pub coefficients: [HexPointEvaluations; 15],
48+
pub complete_add_selector: HexPointEvaluations,
49+
pub emul_selector: HexPointEvaluations,
50+
pub endomul_scalar_selector: HexPointEvaluations,
51+
pub generic_selector: HexPointEvaluations,
52+
pub mul_selector: HexPointEvaluations,
53+
pub poseidon_selector: HexPointEvaluations,
54+
pub s: [HexPointEvaluations; 6],
55+
pub w: [HexPointEvaluations; 15],
56+
pub z: HexPointEvaluations,
5357
}
5458

5559
#[derive(Deserialize)]
@@ -143,6 +147,17 @@ impl TryFrom<HexScalar> for WrapScalar {
143147
}
144148
}
145149

150+
impl TryFrom<HexPointEvaluations> for WrapPointEvaluations {
151+
type Error = String;
152+
153+
fn try_from(value: HexPointEvaluations) -> Result<Self, Self::Error> {
154+
let [hex_zeta, hex_zeta_omega] = value;
155+
let zeta = vec![WrapScalar::try_from(hex_zeta)?.0];
156+
let zeta_omega = vec![WrapScalar::try_from(hex_zeta_omega)?.0];
157+
Ok(WrapPointEvaluations(PointEvaluations { zeta, zeta_omega }))
158+
}
159+
}
160+
146161
pub fn parse(mina_state_proof_vk_query_str: &str) -> Result<StateProof, String> {
147162
let mina_state_proof_vk_query: serde_json::Map<String, serde_json::Value> =
148163
serde_json::from_str(mina_state_proof_vk_query_str)
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use kimchi::{
22
mina_curves::pasta::{Fq, Pallas},
3-
poly_commitment::{evaluation_proof::OpeningProof, PolyComm},
4-
proof::{ProverCommitments, ProverProof},
3+
poly_commitment::evaluation_proof::OpeningProof,
4+
proof::{PointEvaluations, ProofEvaluations, ProverCommitments, ProverProof},
55
verifier_index::VerifierIndex,
66
};
77

88
// Wrap circuit specific types
9+
910
pub struct WrapECPoint(pub Pallas);
1011
pub struct WrapScalar(pub Fq);
11-
pub struct WrapPolyComm(pub PolyComm<Pallas>);
12+
pub struct WrapPointEvaluations(pub PointEvaluations<Vec<Fq>>);
13+
1214
pub type WrapVerifierIndex = VerifierIndex<Pallas, WrapOpeningProof>;
15+
1316
pub type WrapProverProof = ProverProof<Pallas, WrapOpeningProof>;
1417
pub type WrapProverCommitments = ProverCommitments<Pallas>;
1518
pub type WrapOpeningProof = OpeningProof<Pallas>;
19+
pub type WrapProofEvaluations = ProofEvaluations<PointEvaluations<Vec<Fq>>>;

0 commit comments

Comments
 (0)