Add clippy (#191)
* Organize imports Use rustfmt to organize imports. Resolve #162 * remove unused imports * Fix clippy complaints * add clippy github action * remove comment for @arnaucube
This commit is contained in:
parent
24ff82dd3d
commit
0759d6e165
27 changed files with 217 additions and 339 deletions
|
|
@ -7,10 +7,7 @@ use plonky2::field::types::Field;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use super::merkletree_circuit::*;
|
||||
use crate::backends::{
|
||||
counter,
|
||||
plonky2::basetypes::{hash_fields, Hash, Value, EMPTY_HASH, F},
|
||||
};
|
||||
use crate::backends::plonky2::basetypes::{hash_fields, Hash, Value, EMPTY_HASH, F};
|
||||
|
||||
/// Implements the MerkleTree specified at
|
||||
/// https://0xparc.github.io/pod2/merkletree.html
|
||||
|
|
@ -30,7 +27,7 @@ impl MerkleTree {
|
|||
.collect::<Result<_>>()?;
|
||||
|
||||
// Start with a leaf or conclude with an empty node as root.
|
||||
let mut root = leaves.pop().map(|l| Node::Leaf(l)).unwrap_or(Node::None);
|
||||
let mut root = leaves.pop().map(Node::Leaf).unwrap_or(Node::None);
|
||||
|
||||
// Iterate over remaining leaves (if any) and add them.
|
||||
for leaf in leaves.into_iter() {
|
||||
|
|
@ -81,8 +78,6 @@ impl MerkleTree {
|
|||
/// the tree. It returns the `value` of the leaf at the given `key`, and the
|
||||
/// `MerkleProof`.
|
||||
pub fn prove(&self, key: &Value) -> Result<(Value, MerkleProof)> {
|
||||
counter::count_tree_proof_gen();
|
||||
|
||||
let path = keypath(self.max_depth, *key)?;
|
||||
|
||||
let mut siblings: Vec<Hash> = Vec::new();
|
||||
|
|
@ -108,8 +103,6 @@ impl MerkleTree {
|
|||
/// the key-value pair in the leaf reached as a result of
|
||||
/// resolving `key` as well as a `MerkleProof`.
|
||||
pub fn prove_nonexistence(&self, key: &Value) -> Result<MerkleProof> {
|
||||
counter::count_tree_proof_gen();
|
||||
|
||||
let path = keypath(self.max_depth, *key)?;
|
||||
|
||||
let mut siblings: Vec<Hash> = Vec::new();
|
||||
|
|
@ -373,8 +366,6 @@ impl Node {
|
|||
|
||||
// adds the leaf at the tree from the current node (self), without computing any hash
|
||||
pub(crate) fn add_leaf(&mut self, lvl: usize, max_depth: usize, leaf: Leaf) -> Result<()> {
|
||||
counter::count_tree_insert();
|
||||
|
||||
if lvl >= max_depth {
|
||||
return Err(anyhow!("max depth reached"));
|
||||
}
|
||||
|
|
@ -610,11 +601,8 @@ pub mod tests {
|
|||
let (v, proof) = tree.prove(&Value::from(13))?;
|
||||
assert_eq!(v, Value::from(1013));
|
||||
println!("{}", proof);
|
||||
println!("after proof generation, {}", counter::counter_get());
|
||||
|
||||
counter::counter_reset();
|
||||
MerkleTree::verify(32, tree.root(), &proof, &key, &value)?;
|
||||
println!("after verify, {}", counter::counter_get());
|
||||
|
||||
// Exclusion checks
|
||||
let key = Value::from(12);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! offers two different circuits:
|
||||
//!
|
||||
//! - `MerkleProofCircuit`: allows to verify both proofs of existence and proofs
|
||||
//! non-existence with the same circuit.
|
||||
//! non-existence with the same circuit.
|
||||
//! - `MerkleProofExistenceCircuit`: allows to verify proofs of existence only.
|
||||
//!
|
||||
//! If only proofs of existence are needed, use `MerkleProofExistenceCircuit`,
|
||||
|
|
@ -154,6 +154,7 @@ impl MerkleProofGadget {
|
|||
|
||||
impl MerkleClaimAndProofTarget {
|
||||
/// assigns the given values to the targets
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn set_targets(
|
||||
&self,
|
||||
pw: &mut PartialWitness<F>,
|
||||
|
|
@ -293,9 +294,9 @@ impl MerkleProofExistenceTarget {
|
|||
fn compute_root_from_leaf(
|
||||
max_depth: usize,
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
path: &Vec<BoolTarget>,
|
||||
path: &[BoolTarget],
|
||||
leaf_hash: &HashOutTarget,
|
||||
siblings: &Vec<HashOutTarget>,
|
||||
siblings: &[HashOutTarget],
|
||||
) -> Result<HashOutTarget> {
|
||||
assert_eq!(siblings.len(), max_depth);
|
||||
// Convenience constants
|
||||
|
|
@ -322,7 +323,7 @@ fn compute_root_from_leaf(
|
|||
.rev()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut h = leaf_hash.clone();
|
||||
let mut h = *leaf_hash;
|
||||
for (i, (sibling, selector)) in std::iter::zip(siblings, &sibling_selectors)
|
||||
.enumerate()
|
||||
.rev()
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub struct Signature(pub(crate) Proof);
|
|||
|
||||
/// Implements the key generation and the computation of proof-based signatures.
|
||||
impl SecretKey {
|
||||
pub fn new() -> Self {
|
||||
pub fn new_rand() -> Self {
|
||||
// note: the `F::rand()` internally uses `rand::rngs::OsRng`
|
||||
Self(Value(std::array::from_fn(|_| F::rand())))
|
||||
}
|
||||
|
|
@ -189,9 +189,9 @@ impl SignatureInternalCircuit {
|
|||
msg: Value,
|
||||
s: Value,
|
||||
) -> Result<()> {
|
||||
pw.set_target_arr(&self.sk_targ, &sk.0 .0.to_vec())?;
|
||||
pw.set_target_arr(&self.sk_targ, sk.0 .0.as_ref())?;
|
||||
pw.set_hash_target(self.pk_targ, HashOut::<F>::from_vec(pk.0 .0.to_vec()))?;
|
||||
pw.set_target_arr(&self.msg_targ, &msg.0.to_vec())?;
|
||||
pw.set_target_arr(&self.msg_targ, msg.0.as_ref())?;
|
||||
pw.set_hash_target(self.s_targ, HashOut::<F>::from_vec(s.0.to_vec()))?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -205,7 +205,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_signature() -> Result<()> {
|
||||
let sk = SecretKey::new();
|
||||
let sk = SecretKey::new_rand();
|
||||
let pk = sk.public_key();
|
||||
|
||||
let msg = Value::from(42);
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_signature_gadget() -> Result<()> {
|
||||
// generate a valid signature
|
||||
let sk = SecretKey::new();
|
||||
let sk = SecretKey::new_rand();
|
||||
let pk = sk.public_key();
|
||||
let msg = Value::from(42);
|
||||
let sig = sk.sign(msg)?;
|
||||
|
|
@ -206,7 +206,7 @@ pub mod tests {
|
|||
#[test]
|
||||
fn test_signature_gadget_disabled() -> Result<()> {
|
||||
// generate a valid signature
|
||||
let sk = SecretKey::new();
|
||||
let sk = SecretKey::new_rand();
|
||||
let pk = sk.public_key();
|
||||
let msg = Value::from(42);
|
||||
let sig = sk.sign(msg)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue