Skip to content

Commit aa0bd35

Browse files
authored
cleanup and update (#86)
* cleanup and update * Cargo fmt
1 parent 8a3625f commit aa0bd35

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,20 @@ cargo doc
285285
To run tests:
286286

287287
```text
288-
RUSTFLAGS="-C target_cpu=native" cargo test
288+
RUSTFLAGS='-C target_cpu=native --cfg curve25519_dalek_backend="BACKEND"' cargo test
289289
```
290290

291291
To build `libspartan`:
292292

293293
```text
294-
RUSTFLAGS="-C target_cpu=native" cargo build --release
294+
RUSTFLAGS='-C target_cpu=native --cfg curve25519_dalek_backend="BACKEND"' cargo build --release
295295
```
296296

297-
> NOTE: We enable SIMD instructions in `curve25519-dalek` by default, so if it fails to build remove the "simd_backend" feature argument in `Cargo.toml`.
297+
> NOTE: We enable SIMD instructions in `curve25519-dalek` by default, so if it fails to build remove the argument passed to curve25519_dalek in the above command.
298298
299299
### Supported features
300300

301301
- `std`: enables std features (enabled by default)
302-
- `simd_backend`: enables `curve25519-dalek`'s simd feature (enabled by default)
303302
- `profile`: enables fine-grained profiling information (see below for its use)
304303

305304
### WASM Support
@@ -327,7 +326,7 @@ getrandom = { version = "0.1", features = ["wasm-bindgen"] }
327326
To run end-to-end benchmarks:
328327

329328
```text
330-
RUSTFLAGS="-C target_cpu=native" cargo bench
329+
RUSTFLAGS='-C target_cpu=native --cfg curve25519_dalek_backend="BACKEND"' cargo bench
331330
```
332331

333332
### Fine-grained profiling

profiler/nizk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn main() {
2525
let num_cons = num_vars;
2626
let num_inputs = 10;
2727

28-
// produce a synthetic R1CSInstance
28+
// produce a synthetic R1CSShape
2929
let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
3030

3131
// produce public generators

profiler/snark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ pub fn main() {
2424
let num_cons = num_vars;
2525
let num_inputs = 10;
2626

27-
// produce a synthetic R1CSInstance
27+
// produce a synthetic R1CSShape
2828
let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
2929

3030
// produce public generators
3131
let gens = SNARKGens::new(num_cons, num_vars, num_inputs, num_cons);
3232

33-
// create a commitment to R1CSInstance
33+
// create a commitment to R1CSShape
3434
let (comm, decomm) = SNARK::encode(&inst, &gens);
3535

3636
// produce a proof of satisfiability

src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod group;
2020
mod math;
2121
mod nizk;
2222
mod product_tree;
23-
mod r1csinstance;
23+
mod r1cs;
2424
mod r1csproof;
2525
mod random;
2626
mod scalar;
@@ -33,9 +33,7 @@ mod unipoly;
3333
use core::cmp::max;
3434
use errors::{ProofVerifyError, R1CSError};
3535
use merlin::Transcript;
36-
use r1csinstance::{
37-
R1CSCommitment, R1CSCommitmentGens, R1CSDecommitment, R1CSEvalProof, R1CSInstance,
38-
};
36+
use r1cs::{R1CSCommitment, R1CSCommitmentGens, R1CSDecommitment, R1CSEvalProof, R1CSShape};
3937
use r1csproof::{R1CSGens, R1CSProof};
4038
use random::RandomTape;
4139
use scalar::Scalar;
@@ -114,7 +112,7 @@ pub type InputsAssignment = Assignment;
114112

115113
/// `Instance` holds the description of R1CS matrices and a hash of the matrices
116114
pub struct Instance {
117-
inst: R1CSInstance,
115+
inst: R1CSShape,
118116
digest: Vec<u8>,
119117
}
120118

@@ -214,7 +212,7 @@ impl Instance {
214212
return Err(C_scalar.err().unwrap());
215213
}
216214

217-
let inst = R1CSInstance::new(
215+
let inst = R1CSShape::new(
218216
num_cons_padded,
219217
num_vars_padded,
220218
num_inputs,
@@ -228,7 +226,7 @@ impl Instance {
228226
Ok(Instance { inst, digest })
229227
}
230228

231-
/// Checks if a given R1CSInstance is satisfiable with a given variables and inputs assignments
229+
/// Checks if a given R1CSShape is satisfiable with a given variables and inputs assignments
232230
pub fn is_sat(
233231
&self,
234232
vars: &VarsAssignment,
@@ -266,7 +264,7 @@ impl Instance {
266264
num_vars: usize,
267265
num_inputs: usize,
268266
) -> (Instance, VarsAssignment, InputsAssignment) {
269-
let (inst, vars, inputs) = R1CSInstance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
267+
let (inst, vars, inputs) = R1CSShape::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
270268
let digest = inst.get_digest();
271269
(
272270
Instance { inst, digest },
@@ -513,7 +511,7 @@ impl NIZK {
513511
let mut random_tape = RandomTape::new(b"proof");
514512

515513
transcript.append_protocol_name(NIZK::protocol_name());
516-
transcript.append_message(b"R1CSInstanceDigest", &inst.digest);
514+
transcript.append_message(b"R1CSShapeDigest", &inst.digest);
517515

518516
let (r1cs_sat_proof, rx, ry) = {
519517
// we might need to pad variables
@@ -558,7 +556,7 @@ impl NIZK {
558556
let timer_verify = Timer::new("NIZK::verify");
559557

560558
transcript.append_protocol_name(NIZK::protocol_name());
561-
transcript.append_message(b"R1CSInstanceDigest", &inst.digest);
559+
transcript.append_message(b"R1CSShapeDigest", &inst.digest);
562560

563561
// We send evaluations of A, B, C at r = (rx, ry) as claims
564562
// to enable the verifier complete the first sum-check
@@ -601,10 +599,10 @@ mod tests {
601599
// produce public generators
602600
let gens = SNARKGens::new(num_cons, num_vars, num_inputs, num_cons);
603601

604-
// produce a synthetic R1CSInstance
602+
// produce a synthetic R1CSShape
605603
let (inst, vars, inputs) = Instance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
606604

607-
// create a commitment to R1CSInstance
605+
// create a commitment to R1CSShape
608606
let (comm, decomm) = SNARK::encode(&inst, &gens);
609607

610608
// produce a proof
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rand::rngs::OsRng;
1616
use serde::{Deserialize, Serialize};
1717

1818
#[derive(Debug, Serialize, Deserialize)]
19-
pub struct R1CSInstance {
19+
pub struct R1CSShape {
2020
num_cons: usize,
2121
num_vars: usize,
2222
num_inputs: usize,
@@ -83,15 +83,15 @@ impl R1CSCommitment {
8383
}
8484
}
8585

86-
impl R1CSInstance {
86+
impl R1CSShape {
8787
pub fn new(
8888
num_cons: usize,
8989
num_vars: usize,
9090
num_inputs: usize,
9191
A: &[(usize, usize, Scalar)],
9292
B: &[(usize, usize, Scalar)],
9393
C: &[(usize, usize, Scalar)],
94-
) -> R1CSInstance {
94+
) -> R1CSShape {
9595
Timer::print(&format!("number_of_constraints {num_cons}"));
9696
Timer::print(&format!("number_of_variables {num_vars}"));
9797
Timer::print(&format!("number_of_inputs {num_inputs}"));
@@ -161,7 +161,7 @@ impl R1CSInstance {
161161
num_cons: usize,
162162
num_vars: usize,
163163
num_inputs: usize,
164-
) -> (R1CSInstance, Vec<Scalar>, Vec<Scalar>) {
164+
) -> (R1CSShape, Vec<Scalar>, Vec<Scalar>) {
165165
Timer::print(&format!("number_of_constraints {num_cons}"));
166166
Timer::print(&format!("number_of_variables {num_vars}"));
167167
Timer::print(&format!("number_of_inputs {num_inputs}"));
@@ -223,7 +223,7 @@ impl R1CSInstance {
223223
let poly_B = SparseMatPolynomial::new(num_poly_vars_x, num_poly_vars_y, B);
224224
let poly_C = SparseMatPolynomial::new(num_poly_vars_x, num_poly_vars_y, C);
225225

226-
let inst = R1CSInstance {
226+
let inst = R1CSShape {
227227
num_cons,
228228
num_vars,
229229
num_inputs,

src/r1csproof.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::errors::ProofVerifyError;
77
use super::group::{CompressedGroup, GroupElement, VartimeMultiscalarMul};
88
use super::math::Math;
99
use super::nizk::{EqualityProof, KnowledgeProof, ProductProof};
10-
use super::r1csinstance::R1CSInstance;
10+
use super::r1cs::R1CSShape;
1111
use super::random::RandomTape;
1212
use super::scalar::Scalar;
1313
use super::sparse_mlpoly::{SparsePolyEntry, SparsePolynomial};
@@ -142,7 +142,7 @@ impl R1CSProof {
142142
}
143143

144144
pub fn prove(
145-
inst: &R1CSInstance,
145+
inst: &R1CSShape,
146146
vars: Vec<Scalar>,
147147
input: &[Scalar],
148148
gens: &R1CSGens,
@@ -495,7 +495,7 @@ mod tests {
495495
use super::*;
496496
use rand::rngs::OsRng;
497497

498-
fn produce_tiny_r1cs() -> (R1CSInstance, Vec<Scalar>, Vec<Scalar>) {
498+
fn produce_tiny_r1cs() -> (R1CSShape, Vec<Scalar>, Vec<Scalar>) {
499499
// three constraints over five variables Z1, Z2, Z3, Z4, and Z5
500500
// rounded to the nearest power of two
501501
let num_cons = 128;
@@ -526,7 +526,7 @@ mod tests {
526526
A.push((2, 4, one));
527527
B.push((2, num_vars, one));
528528

529-
let inst = R1CSInstance::new(num_cons, num_vars, num_inputs, &A, &B, &C);
529+
let inst = R1CSShape::new(num_cons, num_vars, num_inputs, &A, &B, &C);
530530

531531
// compute a satisfying assignment
532532
let mut csprng: OsRng = OsRng;
@@ -561,7 +561,7 @@ mod tests {
561561

562562
#[test]
563563
fn test_synthetic_r1cs() {
564-
let (inst, vars, input) = R1CSInstance::produce_synthetic_r1cs(1024, 1024, 10);
564+
let (inst, vars, input) = R1CSShape::produce_synthetic_r1cs(1024, 1024, 10);
565565
let is_sat = inst.is_sat(&vars, &input);
566566
assert!(is_sat);
567567
}
@@ -571,7 +571,7 @@ mod tests {
571571
let num_vars = 1024;
572572
let num_cons = num_vars;
573573
let num_inputs = 10;
574-
let (inst, vars, input) = R1CSInstance::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
574+
let (inst, vars, input) = R1CSShape::produce_synthetic_r1cs(num_cons, num_vars, num_inputs);
575575

576576
let gens = R1CSGens::new(b"test-m", num_cons, num_vars);
577577

0 commit comments

Comments
 (0)