[refactorings] Leftovers (pot-pourri?) (#184)

* test: compute_path

* refactor: path computation

- Improve path concatenation by utilizing built-in `join` method

* refactor: replace `PartialEq` with derived instance

- Derive `PartialEq` for `SatisfyingAssignment` struct
- Remove redundant manual implementation of `PartialEq`

Cargo-expand generates:
```
        #[automatically_derived]
        impl<G: ::core::cmp::PartialEq + Group> ::core::cmp::PartialEq
        for SatisfyingAssignment<G>
        where
            G::Scalar: PrimeField,
            G::Scalar: ::core::cmp::PartialEq,
            G::Scalar: ::core::cmp::PartialEq,
            G::Scalar: ::core::cmp::PartialEq,
            G::Scalar: ::core::cmp::PartialEq,
            G::Scalar: ::core::cmp::PartialEq,
        {
            #[inline]
            fn eq(&self, other: &SatisfyingAssignment<G>) -> bool {
                self.a_aux_density == other.a_aux_density
                    && self.b_input_density == other.b_input_density
                    && self.b_aux_density == other.b_aux_density && self.a == other.a
                    && self.b == other.b && self.c == other.c
                    && self.input_assignment == other.input_assignment
                    && self.aux_assignment == other.aux_assignment
            }
        }
```

* refactor: avoid default for PhantomData Unit type

* refactor: replace fold with sum where applicable

- Simplify code by replacing `fold` with `sum` in various instances

* refactor: decompression method in sumcheck.rs

* refactor: test functions to use slice instead of vector conversion

* refactor: use more references in functions

- Update parameter types to use references instead of owned values in various functions that do not need them
- Replace cloning instances with references
This commit is contained in:
François Garillot
2023-06-19 19:11:42 -04:00
committed by GitHub
parent ff0370f506
commit 1e6bf942e2
15 changed files with 110 additions and 124 deletions

View File

@@ -308,17 +308,36 @@ fn compute_path(ns: &[String], this: &str) -> String {
"'/' is not allowed in names"
);
let mut name = String::new();
let mut needs_separation = false;
for ns in ns.iter().chain(Some(this.to_string()).iter()) {
if needs_separation {
name += "/";
}
name += ns;
needs_separation = true;
let mut name = ns.join("/");
if !name.is_empty() {
name.push('/');
}
name.push_str(this);
name
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compute_path() {
let ns = vec!["path".to_string(), "to".to_string(), "dir".to_string()];
let this = "file";
assert_eq!(compute_path(&ns, this), "path/to/dir/file");
let ns = vec!["".to_string(), "".to_string(), "".to_string()];
let this = "file";
assert_eq!(compute_path(&ns, this), "///file");
}
#[test]
#[should_panic(expected = "'/' is not allowed in names")]
fn test_compute_path_invalid() {
let ns = vec!["path".to_string(), "to".to_string(), "dir".to_string()];
let this = "fi/le";
compute_path(&ns, this);
}
}

View File

@@ -8,6 +8,7 @@ use bellperson::{
};
/// A `ConstraintSystem` which calculates witness values for a concrete instance of an R1CS circuit.
#[derive(PartialEq)]
pub struct SatisfyingAssignment<G: Group>
where
G::Scalar: PrimeField,
@@ -68,22 +69,6 @@ where
}
}
impl<G: Group> PartialEq for SatisfyingAssignment<G>
where
G::Scalar: PrimeField,
{
fn eq(&self, other: &SatisfyingAssignment<G>) -> bool {
self.a_aux_density == other.a_aux_density
&& self.b_input_density == other.b_input_density
&& self.b_aux_density == other.b_aux_density
&& self.a == other.a
&& self.b == other.b
&& self.c == other.c
&& self.input_assignment == other.input_assignment
&& self.aux_assignment == other.aux_assignment
}
}
impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G>
where
G::Scalar: PrimeField,