diff --git a/.cargo/config b/.cargo/config index a29c398498..49d9f3e214 100644 --- a/.cargo/config +++ b/.cargo/config @@ -8,4 +8,5 @@ xclippy = [ "-Wclippy::all", "-Wclippy::disallowed_methods", "-Wclippy::match_same_arms", + "-Wclippy::cast_lossless", ] diff --git a/examples/#sha256.rs# b/examples/#sha256.rs# deleted file mode 100644 index 228b38d514..0000000000 --- a/examples/#sha256.rs# +++ /dev/null @@ -1,292 +0,0 @@ -use std::env; -use std::marker::PhantomData; -use std::sync::Arc; -use std::time::Instant; - -use lurk::circuit::gadgets::constraints::alloc_equal; -use lurk::circuit::gadgets::data::{allocate_constant, GlobalAllocations}; -use lurk::circuit::gadgets::pointer::{AllocatedContPtr, AllocatedPtr}; -use lurk::coprocessor::{CoCircuit, Coprocessor}; -use lurk::eval::{empty_sym_env, lang::Lang}; -use lurk::field::LurkField; -use lurk::proof::{nova::NovaProver, Prover}; -use lurk::ptr::Ptr; -use lurk::public_parameters::with_public_params; -use lurk::state::user_sym; -use lurk::store::Store; -use lurk_macros::Coproc; - -use bellperson::gadgets::boolean::{AllocatedBit, Boolean}; -use bellperson::gadgets::multipack::pack_bits; -use bellperson::gadgets::num::AllocatedNum; -use bellperson::gadgets::sha256::sha256; -use bellperson::{ConstraintSystem, SynthesisError}; - -use pasta_curves::pallas::Scalar as Fr; -use serde::{Deserialize, Serialize}; -use sha2::{Digest, Sha256}; - -const REDUCTION_COUNT: usize = 100; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub(crate) struct Sha256Coprocessor { - n: usize, - expected: [u128; 2], - pub(crate) _p: PhantomData, -} - -impl CoCircuit for Sha256Coprocessor { - fn arity(&self) -> usize { - 0 - } - - fn synthesize>( - &self, - cs: &mut CS, - _g: &GlobalAllocations, - store: &Store, - _input_exprs: &[AllocatedPtr], - input_env: &AllocatedPtr, - input_cont: &AllocatedContPtr, - ) -> Result<(AllocatedPtr, AllocatedPtr, AllocatedContPtr), SynthesisError> { - let false_bool = Boolean::from(AllocatedBit::alloc( - cs.namespace(|| "false bit"), - Some(false), - )?); - - cs.enforce( - || "enforce zero preimage", - |lc| lc, - |lc| lc, - |_| false_bool.lc(CS::one(), F::ONE), - ); - - let preimage = vec![false_bool; self.n * 8]; - - let mut bits = sha256(cs.namespace(|| "SHAhash"), &preimage)?; - - bits.reverse(); - - let nums: Vec> = (0..2) - .map(|i| { - pack_bits( - cs.namespace(|| format!("num{i}")), - &bits[(128 * i)..(128 * (i + 1))], - ) - .unwrap() - }) - .collect(); - - let eqs: Vec = (0..2) - .map(|i| { - let num = allocate_constant( - &mut cs.namespace(|| format!("allocate result {i}")), - F::from_u128(self.expected[i]), - ) - .unwrap(); - - let eq = alloc_equal( - cs.namespace(|| format!("equate numbers {i}")), - &num, - &nums[i], - ) - .unwrap(); - - eq - }) - .collect(); - - let both_eq = Boolean::and(cs.namespace(|| "both equal"), &eqs[0], &eqs[1])?; - - let result_ptr = - AllocatedPtr::as_lurk_boolean(cs.namespace(|| "result ptr"), store, &both_eq)?; - - Ok((result_ptr, input_env.clone(), input_cont.clone())) - } -} - -impl Coprocessor for Sha256Coprocessor { - fn eval_arity(&self) -> usize { - 0 - } - - fn simple_evaluate(&self, s: &mut Store, _args: &[Ptr]) -> Ptr { - let mut hasher = Sha256::new(); - - let input = vec![0u8; self.n]; - - hasher.update(input); - let result = hasher.finalize(); - - let mut u: Vec = (0..2) - .map(|i| { - let a: [u8; 16] = result[(16 * i)..(16 * (i + 1))].try_into().unwrap(); - u128::from_be_bytes(a) - }) - .collect(); - - u.reverse(); - - s.as_lurk_boolean(u == self.expected) - } - - fn has_circuit(&self) -> bool { - true - } -} - -impl Sha256Coprocessor { - pub(crate) fn new(n: usize, expected: [u128; 2]) -> Self { - Self { - n, - expected, - _p: Default::default(), - } - } -} - -#[derive(Clone, Debug, Coproc, Serialize, Deserialize)] -enum Sha256Coproc { - SC(Sha256Coprocessor), -} - -/// Run the example in this file with -/// `cargo run --release --example sha256 1 f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b false` -fn main() { - pretty_env_logger::init(); - let args: Vec = env::args().collect(); - - let num_of_64_bytes = args[1].parse::().unwrap(); - let expect = hex::decode(args[2].parse::().unwrap()).unwrap(); - let setup_only = args[3].parse::().unwrap(); - - let input_size = 64 * num_of_64_bytes; - - let mut u: [u128; 2] = [0u128; 2]; - for i in 0..2 { - u[i] = u128::from_be_bytes(expect[(i * 16)..(i + 1) * 16].try_into().unwrap()) - } - - u.reverse(); - - let store = &mut Store::::new(); - let cproc_sym = user_sym(&format!("sha256-{input_size}-zero-bytes")); - let cproc_sym_ptr = store.intern_symbol(&cproc_sym); - - let lang = Lang::>::new_with_bindings( - store, - vec![(cproc_sym, Sha256Coprocessor::new(input_size, u).into())], - ); - let lang_rc = Arc::new(lang.clone()); - - let cproc_call = store.list(&[cproc_sym_ptr]); - - let nova_prover = NovaProver::>::new(REDUCTION_COUNT, lang.clone()); - - println!("Setting up public parameters (rc = {REDUCTION_COUNT})..."); - - let pp_start = Instant::now(); - - // see the documentation on `with_public_params` - with_public_params(REDUCTION_COUNT, lang_rc.clone(), |pp| { - let pp_end = pp_start.elapsed(); - println!("Public parameters took {:?}", pp_end); - - if setup_only { - return; - } - - println!("Beginning proof step..."); - let proof_start = Instant::now(); - let (proof, z0, zi, num_steps) = nova_prover - .evaluate_and_prove(pp, ptr, empty_sym_env(store), store, 10000, lang_rc) - .unwrap(); - let proof_end = proof_start.elapsed(); - - println!("Proofs took {:?}", proof_end); - - println!("Verifying proof..."); - - let verify_start = Instant::now(); - let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap(); - let verify_end = verify_start.elapsed(); - - println!("Verify took {:?}", verify_end); - - if res { - println!( - "Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!", - pp_end + proof_end + verify_end - ); - } - }) - .unwrap(); -<<<<<<< HEAD - let pp_end = pp_start.elapsed(); - - println!("Public parameters took {:?}", pp_end); - - if setup_only { - return; - } - - println!("Beginning proof step..."); - - let proof_start = Instant::now(); - let (proof, z0, zi, num_steps) = nova_prover - .evaluate_and_prove(&pp, cproc_call, empty_sym_env(store), store, 10000, lang_rc) - .unwrap(); - let proof_end = proof_start.elapsed(); - - println!("Proofs took {:?}", proof_end); - - println!("Verifying proof..."); - - let verify_start = Instant::now(); - let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap(); - let verify_end = verify_start.elapsed(); - - println!("Verify took {:?}", verify_end); - - if res { - println!( - "Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!", - pp_end + proof_end + verify_end - ); - } -||||||| parent of 1d3adc4b (Unsafe Serialization for Faster Public Parameter Caching (#474)) - let pp_end = pp_start.elapsed(); - - println!("Public parameters took {:?}", pp_end); - - if setup_only { - return; - } - - println!("Beginning proof step..."); - - let proof_start = Instant::now(); - let (proof, z0, zi, num_steps) = nova_prover - .evaluate_and_prove(&pp, ptr, empty_sym_env(store), store, 10000, lang_rc) - .unwrap(); - let proof_end = proof_start.elapsed(); - - println!("Proofs took {:?}", proof_end); - - println!("Verifying proof..."); - - let verify_start = Instant::now(); - let res = proof.verify(&pp, num_steps, &z0, &zi).unwrap(); - let verify_end = verify_start.elapsed(); - - println!("Verify took {:?}", verify_end); - - if res { - println!( - "Congratulations! You proved and verified a SHA256 hash calculation in {:?} time!", - pp_end + proof_end + verify_end - ); - } -======= ->>>>>>> 1d3adc4b (Unsafe Serialization for Faster Public Parameter Caching (#474)) -} diff --git a/fcomm/src/lib.rs b/fcomm/src/lib.rs index 11f741e659..510c283259 100644 --- a/fcomm/src/lib.rs +++ b/fcomm/src/lib.rs @@ -941,7 +941,7 @@ impl<'a> Proof<'a, S1> { let chunk_frame_count = self.reduction_count.count(); let expected_steps = - (iterations / chunk_frame_count) + (iterations % chunk_frame_count != 0) as usize; + (iterations / chunk_frame_count) + usize::from(iterations % chunk_frame_count != 0); expected_steps == num_steps } else { diff --git a/src/#hash_witness.rs# b/src/#hash_witness.rs# deleted file mode 100644 index 5a1ec6cb1b..0000000000 --- a/src/#hash_witness.rs# +++ /dev/null @@ -1,501 +0,0 @@ -use std::collections::HashMap; -use std::fmt::Debug; -use std::marker::PhantomData; - -use crate::cont::Continuation; -use crate::error::ReductionError; -use crate::field::LurkField; -use crate::lurk_sym_ptr; -use crate::ptr::{ContPtr, Ptr}; -use crate::state::State; -use crate::store::{self, Store}; -use crate::tag::ExprTag; - -pub const MAX_CONSES_PER_REDUCTION: usize = 11; -pub const MAX_CONTS_PER_REDUCTION: usize = 2; - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Stub { - Dummy, - Blank, - Value(T), -} - -impl Stub { - fn is_dummy(&self) -> bool { - matches!(self, Self::Dummy) - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct Cons { - pub car: Ptr, - pub cdr: Ptr, - pub cons: Ptr, -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct Cont { - pub cont_ptr: ContPtr, - pub continuation: Continuation, -} - -pub type ConsStub = Stub>; -pub type ContStub = Stub>; - -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)] -pub enum ConsName { - #[default] - NeverUsed, - Env, - EnvCar, - EnvCaar, - Expr, - ExprCdr, - ExprCadr, - ExprCaadr, - ExprCaaadr, - ExprCddr, - UnopConsLike, - FunBody, - NewRec, - NewRecCadr, - ExtendedRec, - UnevaledArgs, - UnevaledArgsCdr, - Begin, - EnvToUse, - InnerBody, - Lambda, - InnerLambda, - TheCons, - FunExpanded, - ExtendedClosureEnv, - Binding, - ClosedEnv, - ExpandedInner0, - ExpandedInner, - Expanded, -} - -pub trait HashName { - fn index(&self) -> usize; -} - -impl HashName for ConsName { - fn index(&self) -> usize { - #[allow(clippy::match_same_arms)] - match self { - Self::NeverUsed => MAX_CONSES_PER_REDUCTION + 1, - Self::Expr => 0, - Self::ExprCdr => 1, - Self::UnevaledArgsCdr => 1, - Self::ExprCadr => 2, - Self::ExprCddr => 3, - Self::UnopConsLike => 3, - Self::Lambda => 3, - Self::ExprCaadr => 4, - Self::Begin => 4, - Self::InnerBody => 4, - Self::ExtendedClosureEnv => 4, - Self::UnevaledArgs => 5, - Self::ExprCaaadr => 5, - Self::ExtendedRec => 5, - Self::EnvToUse => 5, - Self::Binding => 5, - Self::FunBody => 6, - Self::NewRecCadr => 6, - Self::NewRec => 7, - Self::ClosedEnv => 7, - Self::Env => 8, - Self::ExpandedInner0 => 8, - Self::FunExpanded => 9, - Self::Expanded => 9, - Self::EnvCar => 9, - Self::InnerLambda => 10, - Self::TheCons => 10, - Self::EnvCaar => 10, - Self::ExpandedInner => 10, - } - } -} - -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)] -pub enum ContName { - #[default] - NeverUsed, - ApplyContinuation, - LetLike, - NewerCont, - NewerCont2, - MakeThunk, - Lookup, -} - -impl HashName for ContName { - fn index(&self) -> usize { - #[allow(clippy::match_same_arms)] - match self { - Self::NeverUsed => MAX_CONTS_PER_REDUCTION + 1, - Self::ApplyContinuation => 0, - Self::Lookup => 0, - Self::NewerCont => 1, - Self::NewerCont2 => 1, - Self::LetLike => 1, - Self::MakeThunk => 1, - } - } -} - -impl ConsStub { - pub fn car_cdr( - &mut self, - s: &Store, - cons: &Ptr, - ) -> Result<(Ptr, Ptr), store::Error> { - match self { - Self::Dummy => { - let (car, cdr) = Cons::get_car_cdr(s, cons)?; - - *self = Self::Value(Cons { - car, - cdr, - cons: *cons, - }); - - Ok((car, cdr)) - } - Self::Blank => unreachable!("Blank ConsStub should be used only in blank circuits."), - Self::Value(h) => Ok(h.car_cdr(cons)), - } - } - - pub fn car_cdr_mut( - &mut self, - s: &mut Store, - cons: &Ptr, - ) -> Result<(Ptr, Ptr), store::Error> { - match self { - Self::Dummy => { - let (car, cdr) = Cons::get_car_cdr_mut(s, cons)?; - - *self = Self::Value(Cons { - car, - cdr, - cons: *cons, - }); - - Ok((car, cdr)) - } - Self::Blank => unreachable!("Blank ConsStub should be used only in blank circuits."), - Self::Value(h) => Ok(h.car_cdr(cons)), - } - } - - pub fn cons(&mut self, store: &mut Store, car: Ptr, cdr: Ptr) -> Ptr { - match self { - Self::Dummy => { - let cons = Cons::cons(store, car, cdr); - - *self = Self::Value(Cons { car, cdr, cons }); - - cons - } - Self::Blank => unreachable!("Blank ConsStub should be used only in blank circuits."), - Self::Value(_) => Cons::cons(store, car, cdr), - } - } - pub fn strcons(&mut self, store: &mut Store, car: Ptr, cdr: Ptr) -> Ptr { - match self { - Self::Dummy => { - let cons = Cons::strcons(store, car, cdr); - - *self = Self::Value(Cons { car, cdr, cons }); - - cons - } - Self::Blank => unreachable!("Blank ConsStub should be used only in blank circuits."), - Self::Value(_) => Cons::strcons(store, car, cdr), - } - } -} - -impl ContStub {} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct HashWitness { - pub slots: [(Name, Stub); L], - _f: PhantomData, -} - -impl HashWitness { - pub fn length() -> usize { - L - } -} - -pub type ConsWitness = HashWitness, MAX_CONSES_PER_REDUCTION, F>; -pub type ContWitness = HashWitness, MAX_CONTS_PER_REDUCTION, F>; - -impl HashWitness, MAX_CONSES_PER_REDUCTION, F> { - #[allow(dead_code)] - fn assert_specific_invariants(&self, store: &Store, state: &State) { - // Use the commented code below to search for (non-nil) duplicated conses, which could indicate that two - // different Cons are being used to reference the identical structural value. In that case, they could be - // coalesced, potentially leading to fewer slots being required. - // - // As of the initial optimization pass, Env and ExtendedClosureEnv appear to be duplicated in this way. However, - // it's not clear why that is, and coalescing them does not obviously lead to a potential savings, so we will - // leave them distinct for now. - - let mut digests = HashMap::new(); - - for (name, p) in self.slots.iter() { -254 ~ if let Stub::Value(hash) = p { -255 + if let Some(existing_name) = digests.insert(hash.cons, name) { -256 + let nil = lurk_sym_ptr!(store, nil); -257 + if !store.ptr_eq(&hash.cons, &nil).unwrap() { -258 + use crate::writer::Write; -259 + let cons = hash.cons.fmt_to_string(store, state); -260 + dbg!(hash.cons, cons, name, existing_name); -261 + panic!("duplicate"); -262 + } -263 + }; -264 ~ }; match p { - Stubnn::Value(hash) => { - if let Some(existing_name) = digests.insert(hash.cons, name) { - let nil = lurk_sym_ptr!(store, nil); - if !store.ptr_eq(&hash.cons, &nil).unwrap() { - use crate::writer::Write; - let cons = hash.cons.fmt_to_string(store, state); - dbg!(hash.cons, cons, name, existing_name); - panic!("duplicate"); - } - }; - } - _ => (), - }; - } - } -} - -impl< - Name: HashName + Default + Copy + Eq + Debug, - T: Copy, - const MAX_T_PER_REDUCTION: usize, - F: LurkField, - > HashWitness -{ - pub fn new_from_stub(stub: Stub) -> Self { - Self { - slots: [(Name::default(), stub); MAX_T_PER_REDUCTION], - _f: Default::default(), - } - } - - pub fn new_dummy() -> Self { - Self::new_from_stub(Stub::Dummy) - } - - pub fn new_blank() -> Self { - Self::new_from_stub(Stub::Blank) - } - - pub fn get_assigned_slot(&mut self, name: Name) -> &mut Stub { - let i = name.index(); - let (slot_name, p) = self.slots[i]; - if p.is_dummy() { - self.slots[i].0 = name; - return &mut self.slots[i].1; - } - if slot_name == name { - &mut self.slots[i].1 - } else { - panic!( - "double booked: found {:?} when getting {:?}", - &slot_name, &name - ); - } - } - - pub fn assert_invariants(&self, _store: &Store) { - // TODO: Figure out how to make this work. - // self.assert_specific_invariants(store); - assert!(self.stubs_used_count() <= MAX_T_PER_REDUCTION); - } - - fn all_stubs(&self) -> Vec> { - self.slots.iter().map(|x| x.1).collect() - } - - pub fn all_names(&self) -> Vec { - self.slots.iter().map(|x| x.0).collect() - } - - pub fn stubs_used(&self) -> Vec> { - self.all_stubs() - .into_iter() - .filter(|c| !c.is_dummy()) - .collect() - } - - pub fn stubs_used_count(&self) -> usize { - self.all_stubs().iter().filter(|c| !c.is_dummy()).count() - } - - pub fn total_stub(&self) -> usize { - self.all_stubs().len() - } -} - -impl ConsWitness { - pub fn car_cdr_named( - &mut self, - name: ConsName, - store: &Store, - cons: &Ptr, - ) -> Result<(Ptr, Ptr), ReductionError> { - if !matches!(cons.tag, ExprTag::Cons | ExprTag::Nil) { - return Err(ReductionError::CarCdrType(name)); - }; - self.get_assigned_slot(name) - .car_cdr(store, cons) - .map_err(|e| e.into()) - } - - pub fn cons_named( - &mut self, - name: ConsName, - store: &mut Store, - car: Ptr, - cdr: Ptr, - ) -> Ptr { - self.get_assigned_slot(name).cons(store, car, cdr) - } - - pub fn strcons_named( - &mut self, - name: ConsName, - store: &mut Store, - car: Ptr, - cdr: Ptr, - ) -> Ptr { - self.get_assigned_slot(name).strcons(store, car, cdr) - } - - pub fn car_cdr_mut_named( - &mut self, - name: ConsName, - store: &mut Store, - cons: &Ptr, - ) -> Result<(Ptr, Ptr), store::Error> { - self.get_assigned_slot(name).car_cdr_mut(store, cons) - } - - pub fn extend_named( - &mut self, - name: ConsName, - env: Ptr, - var: Ptr, - val: Ptr, - store: &mut Store, - ) -> Ptr { - let binding = self.cons_named(ConsName::Binding, store, var, val); - - self.cons_named(name, store, binding, env) - } -} - -impl Cons { - fn cons(store: &mut Store, car: Ptr, cdr: Ptr) -> Ptr { - store.cons(car, cdr) - } - - fn strcons(store: &mut Store, car: Ptr, cdr: Ptr) -> Ptr { - store.strcons(car, cdr) - } - - fn car_cdr(&self, cons: &Ptr) -> (Ptr, Ptr) { - assert_eq!(cons, &self.cons, "wrong cons found when destructuring"); - - (self.car, self.cdr) - } - - fn get_car_cdr(s: &Store, cons: &Ptr) -> Result<(Ptr, Ptr), store::Error> { - s.car_cdr(cons) - } - - fn get_car_cdr_mut(s: &mut Store, cons: &Ptr) -> Result<(Ptr, Ptr), store::Error> { - s.car_cdr(cons) - } -} - -impl ContWitness { - pub fn fetch_named_cont( - &mut self, - name: ContName, - store: &mut Store, - cont: &ContPtr, - ) -> Option> { - self.get_assigned_slot(name).fetch_cont(store, cont) - } - - pub fn intern_named_cont( - &mut self, - name: ContName, - store: &mut Store, - continuation: Continuation, - ) -> ContPtr { - self.get_assigned_slot(name) - .intern_cont(store, continuation) - } -} - -impl ContStub { - pub fn fetch_cont( - &mut self, - store: &mut Store, - cont: &ContPtr, - ) -> Option> { - match self { - Self::Dummy => { - let continuation = store.fetch_cont(cont)?; - // dbg!("overwriting dummy", continuation, store.hash_cont(&cont)); - *self = Self::Value(Cont { - cont_ptr: *cont, - continuation, - }); - - Some(continuation) - } - Self::Blank => unreachable!("Blank ContStub should be used only in blank circuits."), - Self::Value(h) => Some(h.fetch_cont(cont)), - } - } - pub fn intern_cont( - &mut self, - store: &mut Store, - continuation: Continuation, - ) -> ContPtr { - match self { - Self::Dummy => { - let cont_ptr = continuation.intern_aux(store); - *self = Self::Value(Cont { - cont_ptr, - continuation, - }); - cont_ptr - } - Self::Blank => unreachable!("Blank ContStub should be used only in blank circuits."), - Self::Value(h) => h.cont_ptr, - } - } -} - -impl Cont { - fn fetch_cont(&mut self, cont: &ContPtr) -> Continuation { - assert_eq!(cont, &self.cont_ptr); - - self.continuation - } -} diff --git a/src/circuit/circuit_frame.rs b/src/circuit/circuit_frame.rs index b875487329..fd3b0402f1 100644 --- a/src/circuit/circuit_frame.rs +++ b/src/circuit/circuit_frame.rs @@ -109,7 +109,7 @@ impl<'a, F: LurkField, T: Clone + Copy + std::cmp::PartialEq, W: Copy, C: Coproc ) -> Vec { // `count` is the number of `Frames` to include per `MultiFrame`. let total_frames = frames.len(); - let n = total_frames / count + (total_frames % count != 0) as usize; + let n = total_frames / count + usize::from(total_frames % count != 0); let mut multi_frames = Vec::with_capacity(n); for chunk in frames.chunks(count) { @@ -5860,7 +5860,7 @@ mod tests { .unwrap(); let popcount_result = AllocatedNum::alloc(&mut cs.namespace(|| format!("alloc popcount {x}")), || { - Ok(Fr::from(x.count_ones() as u64)) + Ok(Fr::from(u64::from(x.count_ones()))) }) .unwrap(); diff --git a/src/coprocessor/trie/mod.rs b/src/coprocessor/trie/mod.rs index ab47f464bd..c8d70d299b 100644 --- a/src/coprocessor/trie/mod.rs +++ b/src/coprocessor/trie/mod.rs @@ -361,7 +361,7 @@ impl<'a, F: LurkField, const ARITY: usize, const HEIGHT: usize> Trie<'a, F, ARIT None => { let field_significant_bits = F::NUM_BITS as usize; let height_needed_for_field = field_significant_bits / arity_bits - + ((field_significant_bits % arity_bits != 0) as usize); + + usize::from(field_significant_bits % arity_bits != 0); // HEIGHT must be exactly the minimum required so that every field element has a unique path. assert_eq!(height_needed_for_field, HEIGHT); diff --git a/src/field.rs b/src/field.rs index 4ef83d6622..32a4a3c6bb 100644 --- a/src/field.rs +++ b/src/field.rs @@ -162,11 +162,11 @@ pub trait LurkField: PrimeField + PrimeFieldBits { /// Constructs a field element from a u32 fn from_u32(x: u32) -> Self { - (x as u64).into() + u64::from(x).into() } /// Constructs a field element from a u16 fn from_u16(x: u16) -> Self { - (x as u64).into() + u64::from(x).into() } /// Constructs a field element from a char fn from_char(x: char) -> Self { @@ -377,7 +377,7 @@ pub mod tests { let mut res = F::ZERO; let mut bs = bs.iter().rev().peekable(); while let Some(b) = bs.next() { - let b: F = (*b as u64).into(); + let b: F = u64::from(*b).into(); if bs.peek().is_none() { res.add_assign(b) } else { diff --git a/src/lib.rs b/src/lib.rs index d63b5a73d6..a8b03d7bb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,4 @@ -#![deny(unreachable_pub)] -#![allow(clippy::uninlined_format_args)] -#![warn(rust_2018_idioms, unreachable_pub)] - +#![deny(rust_2018_idioms, unreachable_pub)] #[macro_use] extern crate alloc; diff --git a/src/parser/syntax.rs b/src/parser/syntax.rs index 9a764d9d29..90f228c4e6 100644 --- a/src/parser/syntax.rs +++ b/src/parser/syntax.rs @@ -230,7 +230,7 @@ fn f_from_le_bytes(bs: &[u8]) -> F { let mut res = F::ZERO; let mut bs = bs.iter().rev().peekable(); while let Some(b) = bs.next() { - let b: F = (*b as u64).into(); + let b: F = u64::from(*b).into(); if bs.peek().is_none() { res.add_assign(b) } else { diff --git a/src/proof/mod.rs b/src/proof/mod.rs index 2fb4216220..2ac5155c75 100644 --- a/src/proof/mod.rs +++ b/src/proof/mod.rs @@ -91,7 +91,7 @@ pub trait Prover<'a, 'b, F: LurkField, C: Coprocessor> { let full_multiframe_count = raw_iterations / cfc; let unfull_multiframe_frame_count = raw_iterations % cfc; let raw_multiframe_count = - full_multiframe_count + (unfull_multiframe_frame_count != 0) as usize; + full_multiframe_count + usize::from(unfull_multiframe_frame_count != 0); raw_multiframe_count + self.multiframe_padding_count(raw_multiframe_count) }