Skip to content

Commit 4f7fea5

Browse files
committed
Tweaks
1 parent cbff2c4 commit 4f7fea5

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

relations/src/r1cs/constraint_system.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#[cfg(feature = "std")]
22
use crate::r1cs::ConstraintTrace;
3-
use crate::r1cs::{ConstraintMatrices, LcIndex, LinearCombination, SynthesisError, Variable};
3+
use crate::r1cs::{
4+
ConstraintMatrices, Instance, LcIndex, LinearCombination, SynthesisError, Variable, Witness,
5+
};
46
use ark_ff::Field;
57
use ark_std::{
68
any::{Any, TypeId},
@@ -924,6 +926,26 @@ impl<F: Field> ConstraintSystemRef<F> {
924926
self.inner().and_then(|cs| cs.borrow().to_matrices())
925927
}
926928

929+
/// This step must be called after constraint generation has completed, and
930+
/// after all symbolic LCs have been inlined into the places that they
931+
/// are used.
932+
#[inline]
933+
pub fn instance_assignment(&self) -> Option<Instance<F>> {
934+
self.inner()
935+
.map(|cs| cs.borrow().instance_assignment.clone())
936+
.map(Instance)
937+
}
938+
939+
/// This step must be called after constraint generation has completed, and
940+
/// after all symbolic LCs have been inlined into the places that they
941+
/// are used.
942+
#[inline]
943+
pub fn witness_assignment(&self) -> Option<Witness<F>> {
944+
self.inner()
945+
.map(|cs| cs.borrow().witness_assignment.clone())
946+
.map(Witness)
947+
}
948+
927949
/// If `self` is satisfied, outputs `Ok(true)`.
928950
/// If `self` is unsatisfied, outputs `Ok(false)`.
929951
/// If `self.is_in_setup_mode()` or if `self == None`, outputs `Err(())`.

snark/src/r1cs.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
1414

1515
/// Generate inputs for the SNARK indexer from [`cs`].
1616
/// These inputs consist of the constraint matrices.
17-
fn indexer_inputs<CG: ConstraintGenerator<F>>(cs: &CG) -> ConstraintMatrices<F>;
17+
fn indexer_inputs<CG: ConstraintGenerator<F>>(
18+
cs: &CG,
19+
) -> Result<ConstraintMatrices<F>, Self::Error>;
1820

1921
/// Generate inputs for the SNARK prover from [`cs`].
2022
/// These inputs consist of the instance and witness. Additionally,
2123
/// if `Self::PROVING_REQUIRES_MATRICES == true`, then this method returns
2224
/// `Some(index)` as well.
2325
fn prover_inputs<WG: WitnessGenerator<F>>(
2426
cs: &WG,
25-
) -> (Option<ConstraintMatrices<F>>, Instance<F>, Witness<F>);
27+
) -> Result<(Option<ConstraintMatrices<F>>, Instance<F>, Witness<F>), Self::Error>;
2628

2729
/// Generate inputs for the SNARK verifier from [`cs`].
2830
/// This input consists of the instance.
29-
fn verifier_inputs<IG: InstanceGenerator<F>>(cs: &IG) -> Instance<F>;
31+
fn verifier_inputs<IG: InstanceGenerator<F>>(cs: &IG) -> Result<Instance<F>, Self::Error>;
3032

3133
/// Indexes the public parameters according to the circuit `circuit`, and
3234
/// outputs circuit-specific proving and verification keys.
@@ -37,7 +39,7 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
3739
where
3840
Self: CircuitSpecificSetupSNARK<R1CS<F>>,
3941
{
40-
let index = Self::indexer_inputs(c);
42+
let index = Self::indexer_inputs(c)?;
4143
Self::circuit_specific_setup(&index, rng)
4244
}
4345

@@ -52,7 +54,7 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
5254
where
5355
Self: UniversalSetupSNARK<R1CS<F>>,
5456
{
55-
let index = Self::indexer_inputs(c);
57+
let index = Self::indexer_inputs(c).map_err(IndexingError::Other)?;
5658
Self::index(pp, &index)
5759
}
5860

@@ -62,7 +64,7 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
6264
c: &WG,
6365
rng: &mut Rng,
6466
) -> Result<Self::Proof, Self::Error> {
65-
let (index, instance, witness) = Self::prover_inputs(c);
67+
let (index, instance, witness) = Self::prover_inputs(c)?;
6668
Self::prove(pk, &index, &instance, &witness, rng)
6769
}
6870

@@ -73,7 +75,7 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
7375
c: &IG,
7476
proof: &Self::Proof,
7577
) -> Result<bool, Self::Error> {
76-
let instance = Self::verifier_inputs(c);
78+
let instance = Self::verifier_inputs(c)?;
7779
Self::verify(vk, &instance, proof)
7880
}
7981

@@ -84,7 +86,7 @@ pub trait SNARKForR1CS<F: Field>: SNARK<R1CS<F>> {
8486
c: &IG,
8587
proof: &Self::Proof,
8688
) -> Result<bool, Self::Error> {
87-
let instance = Self::verifier_inputs(c);
89+
let instance = Self::verifier_inputs(c)?;
8890
Self::verify_with_processed_vk(pvk, &instance, proof)
8991
}
9092
}

0 commit comments

Comments
 (0)