Skip to content

Commit c6776d8

Browse files
committed
Add a way to verify constraints without producing proof
1 parent 85bc62e commit c6776d8

File tree

7 files changed

+156
-53
lines changed

7 files changed

+156
-53
lines changed

ledger/src/proofs/block.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use super::{
4747
to_field_elements::ToFieldElements,
4848
transaction::{
4949
transaction_snark::{checked_hash, CONSTRAINT_CONSTANTS},
50-
Check, Prover,
50+
Check, ProofError, Prover,
5151
},
5252
witness::Witness,
5353
wrap::WrapProof,
@@ -1718,6 +1718,9 @@ pub struct BlockParams<'a> {
17181718
pub block_step_prover: &'a Prover<Fp>,
17191719
pub block_wrap_prover: &'a Prover<Fq>,
17201720
pub tx_wrap_prover: &'a Prover<Fq>,
1721+
/// When set to `true`, `generate_block_proof` will not create a proof, but only
1722+
/// verify constraints in the step witnesses
1723+
pub only_verify_constraints: bool,
17211724
/// For debugging only
17221725
pub expected_step_proof: Option<&'static str>,
17231726
/// For debugging only
@@ -1726,7 +1729,10 @@ pub struct BlockParams<'a> {
17261729

17271730
const BLOCK_N_PREVIOUS_PROOFS: usize = 2;
17281731

1729-
pub(super) fn generate_block_proof(params: BlockParams, w: &mut Witness<Fp>) -> WrapProof {
1732+
pub(super) fn generate_block_proof(
1733+
params: BlockParams,
1734+
w: &mut Witness<Fp>,
1735+
) -> Result<WrapProof, ProofError> {
17301736
let BlockParams {
17311737
input:
17321738
v2::ProverExtendBlockchainInputStableV2 {
@@ -1740,6 +1746,7 @@ pub(super) fn generate_block_proof(params: BlockParams, w: &mut Witness<Fp>) ->
17401746
block_step_prover,
17411747
block_wrap_prover,
17421748
tx_wrap_prover,
1749+
only_verify_constraints,
17431750
expected_step_proof,
17441751
ocaml_wrap_witness,
17451752
} = params;
@@ -1805,9 +1812,10 @@ pub(super) fn generate_block_proof(params: BlockParams, w: &mut Witness<Fp>) ->
18051812
hack_feature_flags: OptFlag::No,
18061813
wrap_prover: block_wrap_prover,
18071814
step_prover: block_step_prover,
1815+
only_verify_constraints,
18081816
},
18091817
w,
1810-
);
1818+
)?;
18111819

18121820
if let Some(expected) = expected_step_proof {
18131821
let proof_json = serde_json::to_vec(&proof).unwrap();

ledger/src/proofs/merge.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::{
2828
step::{
2929
extract_recursion_challenges, InductiveRule, OptFlag, PreviousProofStatement, StepProof,
3030
},
31-
transaction::{PlonkVerificationKeyEvals, Prover},
31+
transaction::{PlonkVerificationKeyEvals, ProofError, Prover},
3232
witness::Witness,
3333
wrap::WrapProof,
3434
};
@@ -140,6 +140,9 @@ pub struct MergeParams<'a> {
140140
pub message: &'a SokMessage,
141141
pub step_prover: &'a Prover<Fp>,
142142
pub wrap_prover: &'a Prover<Fq>,
143+
/// When set to `true`, `generate_block_proof` will not create a proof, but only
144+
/// verify constraints in the step witnesses
145+
pub only_verify_constraints: bool,
143146
/// For debugging only
144147
pub expected_step_proof: Option<&'static str>,
145148
/// For debugging only
@@ -148,13 +151,17 @@ pub struct MergeParams<'a> {
148151

149152
const MERGE_N_PREVIOUS_PROOFS: usize = 2;
150153

151-
pub(super) fn generate_merge_proof(params: MergeParams, w: &mut Witness<Fp>) -> WrapProof {
154+
pub(super) fn generate_merge_proof(
155+
params: MergeParams,
156+
w: &mut Witness<Fp>,
157+
) -> Result<WrapProof, ProofError> {
152158
let MergeParams {
153159
statement,
154160
proofs,
155161
message,
156162
step_prover,
157163
wrap_prover,
164+
only_verify_constraints,
158165
expected_step_proof,
159166
ocaml_wrap_witness,
160167
} = params;
@@ -217,9 +224,10 @@ pub(super) fn generate_merge_proof(params: MergeParams, w: &mut Witness<Fp>) ->
217224
prev_challenge_polynomial_commitments,
218225
step_prover,
219226
hack_feature_flags: OptFlag::No,
227+
only_verify_constraints,
220228
},
221229
w,
222-
);
230+
)?;
223231

224232
if let Some(expected) = expected_step_proof {
225233
let proof_json = serde_json::to_vec(&proof).unwrap();

ledger/src/proofs/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ pub mod zkapp;
2626
pub const BACKEND_TICK_ROUNDS_N: usize = 16;
2727
pub const BACKEND_TOCK_ROUNDS_N: usize = 15;
2828

29-
pub fn generate_tx_proof(params: transaction::TransactionParams) -> wrap::WrapProof {
29+
pub fn generate_tx_proof(
30+
params: transaction::TransactionParams,
31+
) -> Result<wrap::WrapProof, transaction::ProofError> {
3032
use {mina_hasher::Fp, witness::Witness};
3133
let mut w: Witness<Fp> = Witness::new::<constants::StepTransactionProof>();
3234
transaction::generate_tx_proof(params, &mut w)
3335
}
34-
pub fn generate_merge_proof(params: merge::MergeParams) -> wrap::WrapProof {
36+
pub fn generate_merge_proof(
37+
params: merge::MergeParams,
38+
) -> Result<wrap::WrapProof, transaction::ProofError> {
3539
use {mina_hasher::Fp, witness::Witness};
3640
let mut w: Witness<Fp> = Witness::new::<constants::StepMergeProof>();
3741
merge::generate_merge_proof(params, &mut w)
3842
}
39-
pub fn generate_block_proof(params: block::BlockParams) -> wrap::WrapProof {
43+
pub fn generate_block_proof(
44+
params: block::BlockParams,
45+
) -> Result<wrap::WrapProof, transaction::ProofError> {
4046
use {mina_hasher::Fp, witness::Witness};
4147
let mut w: Witness<Fp> = Witness::new::<constants::StepBlockProof>();
4248
block::generate_block_proof(params, &mut w)

ledger/src/proofs/step.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ use super::{
5252
to_field_elements::{ToFieldElements, ToFieldElementsDebug},
5353
transaction::{
5454
create_proof, make_group, messages_for_next_wrap_proof_padding,
55-
scalar_challenge::to_field_checked, Check, CircuitPlonkVerificationKeyEvals, InnerCurve,
56-
MessagesForNextStepProof, PlonkVerificationKeyEvals, Prover,
57-
ReducedMessagesForNextStepProof, StepStatement,
55+
scalar_challenge::to_field_checked, Check, CircuitPlonkVerificationKeyEvals,
56+
CreateProofParams, InnerCurve, MessagesForNextStepProof, PlonkVerificationKeyEvals,
57+
ProofError, Prover, ReducedMessagesForNextStepProof, StepStatement,
5858
},
5959
unfinalized::{evals_from_p2p, AllEvals, EvalsWithPublicInput, Unfinalized},
6060
util::extract_bulletproof,
@@ -2532,6 +2532,7 @@ pub struct StepParams<'a, const N_PREVIOUS: usize> {
25322532
pub hack_feature_flags: OptFlag,
25332533
pub step_prover: &'a Prover<Fp>,
25342534
pub wrap_prover: &'a Prover<Fq>,
2535+
pub only_verify_constraints: bool,
25352536
}
25362537

25372538
pub struct StepProof {
@@ -2543,7 +2544,7 @@ pub struct StepProof {
25432544
pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
25442545
params: StepParams<N_PREVIOUS>,
25452546
w: &mut Witness<Fp>,
2546-
) -> StepProof {
2547+
) -> Result<StepProof, ProofError> {
25472548
let StepParams {
25482549
app_state,
25492550
rule,
@@ -2553,6 +2554,7 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
25532554
hack_feature_flags,
25542555
step_prover,
25552556
wrap_prover,
2557+
only_verify_constraints,
25562558
} = params;
25572559

25582560
let dlog_plonk_index = w.exists(super::merge::dlog_plonk_index(wrap_prover));
@@ -2708,7 +2710,14 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
27082710

27092711
w.primary = statement.to_field_elements_owned();
27102712

2711-
let proof = create_proof::<C, Fp>(step_prover, prev_challenge_polynomial_commitments, w);
2713+
let proof = create_proof::<C, Fp>(
2714+
CreateProofParams {
2715+
prover: step_prover,
2716+
prev_challenges: prev_challenge_polynomial_commitments,
2717+
only_verify_constraints,
2718+
},
2719+
w,
2720+
)?;
27122721

27132722
let proofs: [&v2::PicklesProofProofsVerified2ReprStableV2; N_PREVIOUS] =
27142723
std::array::from_fn(|i| rule.previous_proof_statements[i].proof);
@@ -2767,9 +2776,9 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
27672776
messages_for_next_wrap_proof,
27682777
};
27692778

2770-
StepProof {
2779+
Ok(StepProof {
27712780
statement: step_statement,
27722781
prev_evals,
27732782
proof,
2774-
}
2783+
})
27752784
}

0 commit comments

Comments
 (0)