Skip to content

Commit

Permalink
clippy: miscellaneous
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Sep 25, 2020
1 parent bf632b6 commit 37c06ab
Show file tree
Hide file tree
Showing 64 changed files with 180 additions and 173 deletions.
2 changes: 1 addition & 1 deletion algorithms/src/crh/bowe_hopwood_pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<G: Group, S: PedersenSize> CRH for BoweHopwoodPedersenCRH<G, S> {
.map(|(chunk_bits, generator)| {
let mut encoded = *generator;
if chunk_bits[0] {
encoded = encoded + generator;
encoded += generator;
}
if chunk_bits[1] {
encoded += &generator.double();
Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/encryption/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<G: Group + ProjectiveCurve> EncryptionScheme for GroupEncryption<G> {
private_key: &Self::PrivateKey,
ciphertext: &[Self::Text],
) -> Result<Vec<Self::Text>, EncryptionError> {
assert!(ciphertext.len() > 0);
assert!(!ciphertext.is_empty());
let c_0 = &ciphertext[0];

let record_view_key = c_0.mul(&private_key);
Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/fft/polynomial/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<F: Field> DensePolynomial<F> {

/// Checks if the given polynomial is zero.
pub fn is_zero(&self) -> bool {
self.coeffs.len() == 0 || self.coeffs.iter().all(|coeff| coeff.is_zero())
self.coeffs.is_empty() || self.coeffs.iter().all(|coeff| coeff.is_zero())
}

/// Constructs a new polynomial from a list of coefficients.
Expand Down
4 changes: 2 additions & 2 deletions algorithms/src/fft/polynomial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl<F: Field> DenseOrSparsePolynomial<'_, F> {
}

#[inline]
fn iter_with_index<'a>(&'a self) -> Vec<(usize, F)> {
fn iter_with_index(&self) -> Vec<(usize, F)> {
match self {
SPolynomial(p) => p.coeffs.iter().cloned().collect(),
SPolynomial(p) => p.coeffs.to_vec(),
DPolynomial(p) => p.iter().cloned().enumerate().collect(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions algorithms/src/fft/polynomial/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<F: Field> SparsePolynomial<F> {

/// Checks if the given polynomial is zero.
pub fn is_zero(&self) -> bool {
self.coeffs.len() == 0 || self.coeffs.iter().all(|(_, c)| c.is_zero())
self.coeffs.is_empty() || self.coeffs.iter().all(|(_, c)| c.is_zero())
}

/// Constructs a new polynomial from a list of coefficients.
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<F: Field> SparsePolynomial<F> {
let mut result = std::collections::HashMap::new();
for (i, self_coeff) in self.coeffs.iter() {
for (j, other_coeff) in other.coeffs.iter() {
let cur_coeff = result.entry(i + j).or_insert(F::zero());
let cur_coeff = result.entry(i + j).or_insert_with(F::zero);
*cur_coeff += &(*self_coeff * other_coeff);
}
}
Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/signature/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ where
};

// k - xe;
let prover_response = random_scalar - &(verifier_challenge * &private_key);
let prover_response = random_scalar - &(verifier_challenge * private_key);
let signature = SchnorrOutput {
prover_response,
verifier_challenge,
Expand Down
8 changes: 5 additions & 3 deletions consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl ConsensusParameters {
pub fn verify_transactions(
&self,
parameters: &<InstantiatedDPC as DPCScheme<MerkleTreeLedger>>::Parameters,
transactions: &Vec<Tx>,
transactions: &[Tx],
ledger: &MerkleTreeLedger,
) -> Result<bool, ConsensusError> {
for tx in transactions {
Expand Down Expand Up @@ -363,12 +363,13 @@ impl ConsensusParameters {
}

/// Generate a coinbase transaction given candidate block transactions
#[allow(clippy::too_many_arguments)]
pub fn create_coinbase_transaction<R: Rng>(
&self,
block_num: u32,
transactions: &DPCTransactions<Tx>,
parameters: &PublicParameters<Components>,
program_vk_hash: &Vec<u8>,
program_vk_hash: &[u8],
new_birth_program_ids: Vec<Vec<u8>>,
new_death_program_ids: Vec<Vec<u8>>,
recipient: AccountAddress<Components>,
Expand Down Expand Up @@ -421,7 +422,7 @@ impl ConsensusParameters {
old_records.push(old_record);
}

let new_record_owners = vec![recipient.clone(); Components::NUM_OUTPUT_RECORDS];
let new_record_owners = vec![recipient; Components::NUM_OUTPUT_RECORDS];
let new_is_dummy_flags = [vec![false], vec![true; Components::NUM_OUTPUT_RECORDS - 1]].concat();
let new_values = [vec![total_value_balance.0 as u64], vec![
0;
Expand Down Expand Up @@ -450,6 +451,7 @@ impl ConsensusParameters {
}

/// Generate a transaction by spending old records and specifying new record attributes
#[allow(clippy::too_many_arguments)]
pub fn create_transaction<R: Rng>(
&self,
parameters: &<InstantiatedDPC as DPCScheme<MerkleTreeLedger>>::Parameters,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/memory_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<T: Transaction> MemoryPool<T> {

/// Removes transaction from memory pool based on the transaction id.
#[inline]
pub fn remove_by_hash(&mut self, transaction_id: &Vec<u8>) -> Result<Option<Entry<T>>, ConsensusError> {
pub fn remove_by_hash(&mut self, transaction_id: &[u8]) -> Result<Option<Entry<T>>, ConsensusError> {
match self.transactions.clone().get(transaction_id) {
Some(entry) => {
self.total_size -= entry.size;
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ impl Miner {
storage: &Arc<MerkleTreeLedger>,
memory_pool: &Arc<Mutex<MemoryPool<Tx>>>,
) -> Result<(Vec<u8>, Vec<DPCRecord<Components>>), ConsensusError> {
let mut candidate_transactions =
let candidate_transactions =
Self::fetch_memory_pool_transactions(&storage.clone(), memory_pool, self.consensus.max_block_size).await?;

println!("Miner creating block");

let (previous_block_header, transactions, coinbase_records) =
self.establish_block(parameters, storage, &mut candidate_transactions)?;
self.establish_block(parameters, storage, &candidate_transactions)?;

println!("Miner generated coinbase transaction");

Expand Down
4 changes: 1 addition & 3 deletions curves/src/templates/bw6/bw6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ impl<P: BW6Parameters> BW6<P> {
let result18 = result17.square();
let mut tmp8_p3 = f2_4p * &f4_2p_5p * &f9p;
tmp8_p3.conjugate();
let result19 = result18 * &f1_7 * &f5_7p * &f0p * &tmp8_p3;

result19
result18 * &f1_7 * &f5_7p * &f0p * &tmp8_p3
}
}

Expand Down
3 changes: 2 additions & 1 deletion dpc/src/base_dpc/inner_circuit/inner_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl<C: BaseDPCComponents> InnerCircuit<C> {
}
}

#[allow(clippy::too_many_arguments)]
pub fn new(
// Parameters
system_parameters: &SystemParameters<C>,
Expand Down Expand Up @@ -242,7 +243,7 @@ impl<C: BaseDPCComponents> InnerCircuit<C> {
local_data_root: Some(local_data_root.clone()),
local_data_commitment_randomizers: Some(local_data_commitment_randomizers.to_vec()),

memo: Some(memo.clone()),
memo: Some(*memo),

value_balance: Some(value_balance),

Expand Down
6 changes: 4 additions & 2 deletions dpc/src/base_dpc/inner_circuit/inner_circuit_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use snarkos_utilities::{
use snarkos_models::gadgets::utilities::eq::NEqGadget;
use std::ops::Mul;

#[allow(clippy::too_many_arguments)]
pub fn execute_inner_proof_gadget<C: BaseDPCComponents, CS: ConstraintSystem<C::InnerField>>(
cs: &mut CS,
// Parameters
Expand Down Expand Up @@ -146,6 +147,7 @@ pub fn execute_inner_proof_gadget<C: BaseDPCComponents, CS: ConstraintSystem<C::
)
}

#[allow(clippy::too_many_arguments)]
fn base_dpc_execute_gadget_helper<
C,
CS: ConstraintSystem<C::InnerField>,
Expand Down Expand Up @@ -389,7 +391,7 @@ where

let given_commitment =
RecordCommitmentGadget::OutputGadget::alloc(&mut declare_cs.ns(|| "given_commitment"), || {
Ok(record.commitment().clone())
Ok(record.commitment())
})?;
old_record_commitments_gadgets.push(given_commitment.clone());

Expand Down Expand Up @@ -941,7 +943,7 @@ where
);

let fq_high_and_payload_and_value_bits = [
&vec![Boolean::Constant(true)],
&[Boolean::Constant(true)],
&fq_high_bits[..],
&value_bits[..],
&payload_field_bits[..],
Expand Down
16 changes: 9 additions & 7 deletions dpc/src/base_dpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub struct ExecuteContext<Components: BaseDPCComponents> {
}

impl<Components: BaseDPCComponents> ExecuteContext<Components> {
#[allow(clippy::wrong_self_convention)]
pub fn into_local_data(&self) -> LocalData<Components> {
LocalData {
system_parameters: self.system_parameters.clone(),
Expand All @@ -167,7 +168,7 @@ impl<Components: BaseDPCComponents> ExecuteContext<Components> {
local_data_merkle_tree: self.local_data_merkle_tree.clone(),
local_data_commitment_randomizers: self.local_data_commitment_randomizers.clone(),

memorandum: self.memorandum.clone(),
memorandum: self.memorandum,
network_id: self.network_id,
}
}
Expand Down Expand Up @@ -289,15 +290,16 @@ impl<Components: BaseDPCComponents> DPC<Components> {
Ok((sn, sig_and_pk_randomizer))
}

#[allow(clippy::too_many_arguments)]
pub fn generate_record<R: Rng>(
system_parameters: &SystemParameters<Components>,
sn_nonce: &<Components::SerialNumberNonceCRH as CRH>::Output,
owner: &AccountAddress<Components>,
is_dummy: bool,
value: u64,
payload: &RecordPayload,
birth_program_id: &Vec<u8>,
death_program_id: &Vec<u8>,
birth_program_id: &[u8],
death_program_id: &[u8],
rng: &mut R,
) -> Result<DPCRecord<Components>, DPCError> {
let record_time = start_timer!(|| "Generate record");
Expand Down Expand Up @@ -635,7 +637,7 @@ where
local_data_commitment_randomizers,

value_balance,
memorandum: memorandum.clone(),
memorandum: *memorandum,
network_id,
};
Ok(context)
Expand Down Expand Up @@ -796,7 +798,7 @@ where
old_serial_numbers: old_serial_numbers.clone(),
new_commitments: new_commitments.clone(),
new_encrypted_record_hashes: new_encrypted_record_hashes.clone(),
memo: memorandum.clone(),
memo: memorandum,
program_commitment: program_commitment.clone(),
local_data_root: local_data_root.clone(),
value_balance,
Expand Down Expand Up @@ -850,7 +852,7 @@ where
let transaction = Self::Transaction::new(
old_serial_numbers,
new_commitments,
memorandum.clone(),
memorandum,
ledger_digest,
inner_snark_id,
transaction_proof,
Expand Down Expand Up @@ -954,7 +956,7 @@ where
old_serial_numbers: transaction.old_serial_numbers().to_vec(),
new_commitments: transaction.new_commitments().to_vec(),
new_encrypted_record_hashes,
memo: transaction.memorandum().clone(),
memo: *transaction.memorandum(),
program_commitment: transaction.program_commitment().clone(),
local_data_root: transaction.local_data_root().clone(),
value_balance: transaction.value_balance(),
Expand Down
7 changes: 4 additions & 3 deletions dpc/src/base_dpc/outer_circuit/outer_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ impl<C: BaseDPCComponents> OuterCircuit<C> {
}
}

#[allow(clippy::too_many_arguments)]
pub fn new(
system_parameters: &SystemParameters<C>,

// Inner SNARK public inputs
ledger_parameters: &C::MerkleParameters,
ledger_digest: &MerkleTreeDigest<C::MerkleParameters>,
old_serial_numbers: &Vec<<C::AccountSignature as SignatureScheme>::PublicKey>,
new_commitments: &Vec<<C::RecordCommitment as CommitmentScheme>::Output>,
old_serial_numbers: &[<C::AccountSignature as SignatureScheme>::PublicKey],
new_commitments: &[<C::RecordCommitment as CommitmentScheme>::Output],
new_encrypted_record_hashes: &[<C::EncryptedRecordCRH as CRH>::Output],
memo: &[u8; 32],
value_balance: AleoAmount,
Expand Down Expand Up @@ -172,7 +173,7 @@ impl<C: BaseDPCComponents> OuterCircuit<C> {
old_serial_numbers: Some(old_serial_numbers.to_vec()),
new_commitments: Some(new_commitments.to_vec()),
new_encrypted_record_hashes: Some(new_encrypted_record_hashes.to_vec()),
memo: Some(memo.clone()),
memo: Some(*memo),
value_balance: Some(value_balance),
network_id: Some(network_id),

Expand Down
9 changes: 5 additions & 4 deletions dpc/src/base_dpc/outer_circuit/outer_circuit_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use itertools::Itertools;

fn field_element_to_bytes<C: BaseDPCComponents, CS: ConstraintSystem<C::OuterField>>(
cs: &mut CS,
field_elements: &Vec<C::InnerField>,
field_elements: &[C::InnerField],
name: &str,
) -> Result<Vec<Vec<UInt8>>, SynthesisError> {
if field_elements.len() <= 1 {
Expand All @@ -58,6 +58,7 @@ fn field_element_to_bytes<C: BaseDPCComponents, CS: ConstraintSystem<C::OuterFie
}
}

#[allow(clippy::too_many_arguments)]
pub fn execute_outer_proof_gadget<C: BaseDPCComponents, CS: ConstraintSystem<C::OuterField>>(
cs: &mut CS,
// Parameters
Expand All @@ -66,9 +67,9 @@ pub fn execute_outer_proof_gadget<C: BaseDPCComponents, CS: ConstraintSystem<C::
// Inner snark verifier public inputs
ledger_parameters: &C::MerkleParameters,
ledger_digest: &MerkleTreeDigest<C::MerkleParameters>,
old_serial_numbers: &Vec<<C::AccountSignature as SignatureScheme>::PublicKey>,
new_commitments: &Vec<<C::RecordCommitment as CommitmentScheme>::Output>,
new_encrypted_record_hashes: &Vec<<C::EncryptedRecordCRH as CRH>::Output>,
old_serial_numbers: &[<C::AccountSignature as SignatureScheme>::PublicKey],
new_commitments: &[<C::RecordCommitment as CommitmentScheme>::Output],
new_encrypted_record_hashes: &[<C::EncryptedRecordCRH as CRH>::Output],
memo: &[u8; 32],
value_balance: AleoAmount,
network_id: u8,
Expand Down
30 changes: 15 additions & 15 deletions dpc/src/base_dpc/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ impl<C: BaseDPCComponents> NoopProgramSNARKParameters<C> {
// TODO (howardwu): Why are we not preparing the VK here?
pub fn load() -> IoResult<Self> {
let proving_key: <C::NoopProgramSNARK as SNARK>::ProvingParameters =
From::from(FromBytes::read(NoopProgramSNARKPKParameters::load_bytes()?.as_slice())?);
let verification_key = From::from(<C::NoopProgramSNARK as SNARK>::VerificationParameters::read(
FromBytes::read(NoopProgramSNARKPKParameters::load_bytes()?.as_slice())?;
let verification_key = <C::NoopProgramSNARK as SNARK>::VerificationParameters::read(
NoopProgramSNARKVKParameters::load_bytes()?.as_slice(),
)?);
)?;

Ok(Self {
proving_key,
Expand Down Expand Up @@ -189,31 +189,31 @@ impl<C: BaseDPCComponents> PublicParameters<C> {
let inner_snark_parameters = {
let inner_snark_pk = match verify_only {
true => None,
false => Some(From::from(<C::InnerSNARK as SNARK>::ProvingParameters::read(
false => Some(<C::InnerSNARK as SNARK>::ProvingParameters::read(
InnerSNARKPKParameters::load_bytes()?.as_slice(),
)?)),
)?),
};

let inner_snark_vk: <C::InnerSNARK as SNARK>::VerificationParameters =
From::from(<C::InnerSNARK as SNARK>::VerificationParameters::read(
<C::InnerSNARK as SNARK>::VerificationParameters::read(
InnerSNARKVKParameters::load_bytes()?.as_slice(),
)?);
)?;

(inner_snark_pk, inner_snark_vk.into())
};

let outer_snark_parameters = {
let outer_snark_pk = match verify_only {
true => None,
false => Some(From::from(<C::OuterSNARK as SNARK>::ProvingParameters::read(
false => Some(<C::OuterSNARK as SNARK>::ProvingParameters::read(
OuterSNARKPKParameters::load_bytes()?.as_slice(),
)?)),
)?),
};

let outer_snark_vk: <C::OuterSNARK as SNARK>::VerificationParameters =
From::from(<C::OuterSNARK as SNARK>::VerificationParameters::read(
<C::OuterSNARK as SNARK>::VerificationParameters::read(
OuterSNARKVKParameters::load_bytes()?.as_slice(),
)?);
)?;

(outer_snark_pk, outer_snark_vk.into())
};
Expand All @@ -233,18 +233,18 @@ impl<C: BaseDPCComponents> PublicParameters<C> {
let inner_snark_parameters = {
let inner_snark_pk = None;
let inner_snark_vk: <C::InnerSNARK as SNARK>::VerificationParameters =
From::from(<C::InnerSNARK as SNARK>::VerificationParameters::read(
<C::InnerSNARK as SNARK>::VerificationParameters::read(
InnerSNARKVKParameters::load_bytes()?.as_slice(),
)?);
)?;
(inner_snark_pk, inner_snark_vk.into())
};

let outer_snark_parameters = {
let outer_snark_pk = None;
let outer_snark_vk: <C::OuterSNARK as SNARK>::VerificationParameters =
From::from(<C::OuterSNARK as SNARK>::VerificationParameters::read(
<C::OuterSNARK as SNARK>::VerificationParameters::read(
OuterSNARKVKParameters::load_bytes()?.as_slice(),
)?);
)?;
(outer_snark_pk, outer_snark_vk.into())
};

Expand Down
Loading

0 comments on commit 37c06ab

Please sign in to comment.