Skip to content

Commit

Permalink
Revert "refactor: Refactor R1CS for in-place operations and Vec inputs (
Browse files Browse the repository at this point in the history
argumentcomputer#121)" (argumentcomputer#125)

This reverts commit fdf8296.

This should allow us to investigate the effects of components of argumentcomputer#118 without noise.
We can re-apply this later if we see it as an improvement.
  • Loading branch information
huitseeker authored Nov 15, 2023
1 parent beb408e commit 4b968f3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ tracing-texray = "0.2.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
cfg-if = "1.0.0"
once_cell = "1.18.0"
vecshard = "0.2.1"

[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]
pasta-msm = { git="https://github.com/lurk-lab/pasta-msm", branch="dev", version = "0.1.4" }
Expand Down
14 changes: 5 additions & 9 deletions src/bellpepper/r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ use crate::{
};
use bellpepper_core::{Index, LinearCombination};
use ff::PrimeField;
use vecshard::ShardExt;

/// `NovaWitness` provide a method for acquiring an `R1CSInstance` and `R1CSWitness` from implementers.
pub trait NovaWitness<G: Group> {
/// Return an instance and witness, given a shape and ck.
fn r1cs_instance_and_witness(
self,
&self,
shape: &R1CSShape<G>,
ck: &CommitmentKey<G>,
) -> Result<(R1CSInstance<G>, R1CSWitness<G>), NovaError>;
Expand All @@ -40,19 +39,16 @@ pub trait NovaShape<G: Group> {

impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G> {
fn r1cs_instance_and_witness(
self,
&self,
shape: &R1CSShape<G>,
ck: &CommitmentKey<G>,
) -> Result<(R1CSInstance<G>, R1CSWitness<G>), NovaError> {
let (input_assignment, aux_assignment) = self.to_assignments();

let W = R1CSWitness::<G>::new(shape, aux_assignment)?;

let (_, X) = input_assignment.split_inplace_at(1);
let W = R1CSWitness::<G>::new(shape, self.aux_assignment())?;
let X = &self.input_assignment()[1..];

let comm_W = W.commit(ck);

let instance = R1CSInstance::<G>::new(shape, &comm_W, X.into())?;
let instance = R1CSInstance::<G>::new(shape, &comm_W, X)?;

Ok((instance, W))
}
Expand Down
4 changes: 2 additions & 2 deletions src/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,13 @@ mod tests {
};

let W = {
let res = R1CSWitness::new(&S, vars);
let res = R1CSWitness::new(&S, &vars);
assert!(res.is_ok());
res.unwrap()
};
let U = {
let comm_W = W.commit(ck);
let res = R1CSInstance::new(&S, &comm_W, X);
let res = R1CSInstance::new(&S, &comm_W, &X);
assert!(res.is_ok());
res.unwrap()
};
Expand Down
11 changes: 7 additions & 4 deletions src/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ impl<G: Group> R1CSShape<G> {

impl<G: Group> R1CSWitness<G> {
/// A method to create a witness object using a vector of scalars
pub fn new(S: &R1CSShape<G>, W: Vec<G::Scalar>) -> Result<R1CSWitness<G>, NovaError> {
pub fn new(S: &R1CSShape<G>, W: &[G::Scalar]) -> Result<R1CSWitness<G>, NovaError> {
if S.num_vars != W.len() {
Err(NovaError::InvalidWitnessLength)
} else {
Ok(R1CSWitness { W })
Ok(R1CSWitness { W: W.to_owned() })
}
}

Expand All @@ -405,12 +405,15 @@ impl<G: Group> R1CSInstance<G> {
pub fn new(
S: &R1CSShape<G>,
comm_W: &Commitment<G>,
X: Vec<G::Scalar>,
X: &[G::Scalar],
) -> Result<R1CSInstance<G>, NovaError> {
if S.num_io != X.len() {
Err(NovaError::InvalidInputLength)
} else {
Ok(R1CSInstance { comm_W: *comm_W, X })
Ok(R1CSInstance {
comm_W: *comm_W,
X: X.to_owned(),
})
}
}
}
Expand Down

0 comments on commit 4b968f3

Please sign in to comment.