Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Sep 18, 2023
1 parent 193f529 commit 9787e88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
23 changes: 12 additions & 11 deletions src/gadgets/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::BTreeMap;

use bellpepper::gadgets::Assignment;
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, LinearCombination, SynthesisError};
use std::cmp::Ord;

use crate::constants::NUM_CHALLENGE_BITS;
use crate::gadgets::nonnative::util::Num;
Expand All @@ -27,7 +28,7 @@ pub enum RWTrace<T> {
}

/// Lookup in R1CS
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum TableType {
/// read only
ReadOnly,
Expand Down Expand Up @@ -55,7 +56,7 @@ impl<'a, G: Group> LookupTransactionSimulate<'a, G> {
/// read value from table
pub fn read(&mut self, addr: G::Base) -> G::Base
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let key = &addr;
let (value, _) = self.map_aux.entry(*key).or_insert_with(|| {
Expand All @@ -72,7 +73,7 @@ impl<'a, G: Group> LookupTransactionSimulate<'a, G> {
/// write value to lookup table
pub fn write(&mut self, addr: G::Base, value: G::Base)
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let _ = self.map_aux.insert(
addr,
Expand All @@ -86,7 +87,7 @@ impl<'a, G: Group> LookupTransactionSimulate<'a, G> {
/// commit rw_trace to lookup
pub fn commit(&mut self, ro_consts: ROConstants<G>, prev_intermediate_gamma: G::Base) -> G::Base
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let mut hasher = <G as Group>::RO::new(ro_consts, 1 + self.rw_trace.len() * 3);
hasher.absorb(prev_intermediate_gamma);
Expand Down Expand Up @@ -129,7 +130,7 @@ impl<'a, G: Group> LookupTransaction<'a, G> {
addr: &AllocatedNum<G::Base>,
) -> Result<AllocatedNum<G::Base>, SynthesisError>
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let key = &addr.get_value().unwrap_or_default();
let (value, _) = self.map_aux.entry(*key).or_insert_with(|| {
Expand All @@ -155,7 +156,7 @@ impl<'a, G: Group> LookupTransaction<'a, G> {
value: &AllocatedNum<G::Base>,
) -> Result<(), SynthesisError>
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let _ = self.map_aux.insert(
addr.get_value().unwrap_or_default(),
Expand Down Expand Up @@ -191,7 +192,7 @@ impl<'a, G: Group> LookupTransaction<'a, G> {
SynthesisError,
>
where
<G as Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
let mut ro = G::ROCircuit::new(
ro_const,
Expand Down Expand Up @@ -276,7 +277,7 @@ impl<F: PrimeField> Lookup<F> {
initial_table: Vec<(F, F)>,
) -> Lookup<F>
where
F: std::cmp::Ord,
F: Ord,
{
let max_cap_rwcounter_log2 = max_cap_rwcounter.log_2();
Self {
Expand All @@ -293,7 +294,7 @@ impl<F: PrimeField> Lookup<F> {

fn rw_operation(&mut self, is_read: bool, addr: F, external_value: F) -> (F, F)
where
F: std::cmp::Ord,
F: Ord,
{
// write operations
if !is_read {
Expand Down Expand Up @@ -344,7 +345,7 @@ impl<F: PrimeField> Lookup<F> {
SynthesisError,
>
where
F: std::cmp::Ord,
F: Ord,
{
// extract challenge
// get content from map
Expand Down Expand Up @@ -556,7 +557,7 @@ pub fn less_than<F: PrimeField + PartialOrd, CS: ConstraintSystem<F>>(
let lt = AllocatedNum::alloc(cs.namespace(|| "lt"), || {
a.get_value()
.zip(b.get_value())
.map(|(a, b)| F::from((a < b) as u64))
.map(|(a, b)| F::from(u64::from(a < b)))
.ok_or(SynthesisError::AssignmentMissing)
})?;
cs.enforce(
Expand Down
42 changes: 18 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,10 +1529,10 @@ mod tests {
z0_secondary.clone(),
);

for mut circuit_primary in roots.iter_mut().take(num_steps) {
for circuit_primary in roots.iter_mut().take(num_steps) {
let res = recursive_snark.prove_step(
&pp,
&mut circuit_primary,
circuit_primary,
&mut circuit_secondary.clone(),
z0_primary.clone(),
z0_secondary.clone(),
Expand Down Expand Up @@ -1636,12 +1636,11 @@ mod tests {
test_ivc_base_with::<secp256k1::Point, secq256k1::Point>();
}

fn print_constraints_name_on_error_index<G1, G2, C1, C2>(err: &NovaError, mut c_primary: C1)
fn print_constraints_name_on_error_index<G1, G2, C1>(err: &NovaError, mut c_primary: C1)
where
G1: Group<Base = <G2 as Group>::Scalar>,
G2: Group<Base = <G1 as Group>::Scalar>,
C1: StepCircuit<G1::Scalar>,
C2: StepCircuit<G2::Scalar>,
{
match err {
NovaError::UnSatIndex(index) => {
Expand All @@ -1654,7 +1653,7 @@ mod tests {
&augmented_circuit_params_primary,
None,
&mut c_primary,
ro_consts_circuit_primary.clone(),
ro_consts_circuit_primary,
);
// let mut cs: ShapeCS<G1> = ShapeCS::new();
// let _ = circuit_primary.synthesize(&mut cs);
Expand Down Expand Up @@ -1683,7 +1682,7 @@ mod tests {

impl<G: Group> HeapifyCircuit<G>
where
<G as traits::Group>::Base: std::cmp::Ord,
<G as Group>::Base: Ord,
{
fn new(heap_size: usize, ro_consts: ROConstantsCircuit<G>) -> (Self, Vec<G::Base>) {
let n = heap_size; // assume complement binary tree
Expand All @@ -1706,11 +1705,8 @@ mod tests {
);

// TODO challenge should include final table (final table values + counters) commitment
let gamma = Self::pre_compute_global_challenge(
initial_intermediate_gamma,
((n - 4) / 2) as usize,
&lookup,
);
let gamma =
Self::pre_compute_global_challenge(initial_intermediate_gamma, (n - 4) / 2, &lookup);

(
HeapifyCircuit { lookup, ro_consts },
Expand Down Expand Up @@ -1739,7 +1735,7 @@ mod tests {
let num_steps = initial_index;
let mut intermediate_gamma = initial_intermediate_gamma;
// simulate folding step lookup io
for i in (0..num_steps + 1).into_iter() {
for i in 0..num_steps + 1 {
let mut lookup_transaction =
LookupTransactionSimulate::<G>::start_transaction(&mut lookup);
let addr = G::Base::from((num_steps - i) as u64);
Expand All @@ -1759,9 +1755,9 @@ mod tests {
}
}

impl<F: PrimeField, G: Group + traits::Group<Base = F>> StepCircuit<F> for HeapifyCircuit<G>
impl<F: PrimeField, G: Group + Group<Base = F>> StepCircuit<F> for HeapifyCircuit<G>
where
G::Base: std::cmp::Ord,
G::Base: Ord,
{
fn arity(&self) -> usize {
6
Expand Down Expand Up @@ -1804,7 +1800,7 @@ mod tests {
|lc| lc + CS::one(),
|lc| lc + right_child_index.get_variable(),
);
let parent = lookup_transaction.read(cs.namespace(|| "parent"), &index)?;
let parent = lookup_transaction.read(cs.namespace(|| "parent"), index)?;
let left_child =
lookup_transaction.read(cs.namespace(|| "left_child"), &left_child_index)?;
let right_child =
Expand Down Expand Up @@ -1838,15 +1834,15 @@ mod tests {
&is_right_child_smaller,
)?;

lookup_transaction.write(&index, &smallest)?;
lookup_transaction.write(index, &smallest)?;

// commit the rw change
let (next_R, next_W, next_rw_counter, next_intermediate_gamma) = lookup_transaction
.commit(
cs.namespace(|| "commit"),
self.ro_consts.clone(),
prev_intermediate_gamma,
&gamma,
gamma,
prev_W,
prev_R,
prev_rw_counter,
Expand Down Expand Up @@ -1914,7 +1910,7 @@ mod tests {
z0_secondary.clone(),
);

for i in (0..num_steps).into_iter() {
for i in 0..num_steps {
println!("step i {}", i);
let res = recursive_snark.prove_step(
&pp,
Expand All @@ -1934,12 +1930,10 @@ mod tests {
res
.clone()
.map_err(|err| {
print_constraints_name_on_error_index::<
G1,
G2,
HeapifyCircuit<G2>,
TrivialTestCircuit<<G2 as Group>::Scalar>,
>(&err, circuit_primary.clone())
print_constraints_name_on_error_index::<G1, G2, HeapifyCircuit<G2>>(
&err,
circuit_primary.clone(),
)
})
.unwrap();
assert!(res.is_ok());
Expand Down

0 comments on commit 9787e88

Please sign in to comment.