Skip to content

Commit 41c5588

Browse files
authored
r1cs: lease transcript from CS to bind proof to the data made available later (#269)
This adds method `transcript()` to the `ConstraintSystem` trait. The motivation is to allow higher-level protocol to bind the R1CS proof to data that's made available _during_ CS construction, but _not before_. Example: in [ZkVM](https://github.com/interstellar/slingshot/blob/5377925ac10b13e0f6c958c4d037e13504cc21ce/zkvm/src/prover.rs#L108-L114) the transaction ID is computed via program execution that's also constructing a CS state. By the end of the execution, both the txid and set of constraints are known, and it's safer to bind the proof to the txid, but the transcript is exclusively held by the CS prover. This API allows to borrow the transcript from the CS prover to commit txid, and then complete computation of the R1CS proof.
1 parent 938b348 commit 41c5588

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/r1cs/constraint_system.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::{LinearCombination, R1CSError, Variable};
44
use curve25519_dalek::scalar::Scalar;
5+
use merlin::Transcript;
56

67
/// The interface for a constraint system, abstracting over the prover
78
/// and verifier's roles.
@@ -19,6 +20,11 @@ pub trait ConstraintSystem {
1920
/// Represents a concrete type for the CS in a randomization phase.
2021
type RandomizedCS: RandomizedConstraintSystem;
2122

23+
/// Leases the proof transcript to the user, so they can
24+
/// add extra data to which the proof must be bound, but which
25+
/// is not available before creation of the constraint system.
26+
fn transcript(&mut self) -> &mut Transcript;
27+
2228
/// Allocate and constrain multiplication variables.
2329
///
2430
/// Allocate variables `left`, `right`, and `out`

src/r1cs/prover.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl<'t, 'g> Drop for Prover<'t, 'g> {
8585
impl<'t, 'g> ConstraintSystem for Prover<'t, 'g> {
8686
type RandomizedCS = RandomizingProver<'t, 'g>;
8787

88+
fn transcript(&mut self) -> &mut Transcript {
89+
self.transcript
90+
}
91+
8892
fn multiply(
8993
&mut self,
9094
mut left: LinearCombination,
@@ -171,6 +175,10 @@ impl<'t, 'g> ConstraintSystem for Prover<'t, 'g> {
171175
impl<'t, 'g> ConstraintSystem for RandomizingProver<'t, 'g> {
172176
type RandomizedCS = Self;
173177

178+
fn transcript(&mut self) -> &mut Transcript {
179+
self.prover.transcript
180+
}
181+
174182
fn multiply(
175183
&mut self,
176184
left: LinearCombination,

src/r1cs/verifier.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub struct RandomizingVerifier<'t> {
5959
impl<'t> ConstraintSystem for Verifier<'t> {
6060
type RandomizedCS = RandomizingVerifier<'t>;
6161

62+
fn transcript(&mut self) -> &mut Transcript {
63+
self.transcript
64+
}
65+
6266
fn multiply(
6367
&mut self,
6468
mut left: LinearCombination,
@@ -130,6 +134,10 @@ impl<'t> ConstraintSystem for Verifier<'t> {
130134
impl<'t> ConstraintSystem for RandomizingVerifier<'t> {
131135
type RandomizedCS = Self;
132136

137+
fn transcript(&mut self) -> &mut Transcript {
138+
self.verifier.transcript
139+
}
140+
133141
fn multiply(
134142
&mut self,
135143
left: LinearCombination,

0 commit comments

Comments
 (0)