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
|
|
@ -79,11 +79,7 @@ impl StatementArgTarget {
|
|||
}
|
||||
|
||||
fn new(first: ValueTarget, second: ValueTarget) -> Self {
|
||||
let elements: Vec<_> = first
|
||||
.elements
|
||||
.into_iter()
|
||||
.chain(second.elements.into_iter())
|
||||
.collect();
|
||||
let elements: Vec<_> = first.elements.into_iter().chain(second.elements).collect();
|
||||
StatementArgTarget {
|
||||
elements: elements.try_into().expect("size STATEMENT_ARG_F_LEN"),
|
||||
}
|
||||
|
|
@ -91,12 +87,12 @@ impl StatementArgTarget {
|
|||
|
||||
pub fn none(builder: &mut CircuitBuilder<F, D>) -> Self {
|
||||
let empty = builder.constant_value(EMPTY_VALUE);
|
||||
Self::new(empty.clone(), empty)
|
||||
Self::new(empty, empty)
|
||||
}
|
||||
|
||||
pub fn literal(builder: &mut CircuitBuilder<F, D>, value: &ValueTarget) -> Self {
|
||||
let empty = builder.constant_value(EMPTY_VALUE);
|
||||
Self::new(value.clone(), empty)
|
||||
Self::new(*value, empty)
|
||||
}
|
||||
|
||||
pub fn anchored_key(
|
||||
|
|
@ -104,7 +100,7 @@ impl StatementArgTarget {
|
|||
pod_id: &ValueTarget,
|
||||
key: &ValueTarget,
|
||||
) -> Self {
|
||||
Self::new(pod_id.clone(), key.clone())
|
||||
Self::new(*pod_id, *key)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +246,7 @@ impl Flattenable for MerkleClaimTarget {
|
|||
fn from_flattened(vs: &[Target]) -> Self {
|
||||
Self {
|
||||
enabled: BoolTarget::new_unsafe(vs[0]),
|
||||
root: HashOutTarget::from_vec((&vs[1..1 + NUM_HASH_OUT_ELTS]).to_vec()),
|
||||
root: HashOutTarget::from_vec(vs[1..1 + NUM_HASH_OUT_ELTS].to_vec()),
|
||||
key: ValueTarget::from_slice(
|
||||
&vs[1 + NUM_HASH_OUT_ELTS..1 + NUM_HASH_OUT_ELTS + VALUE_SIZE],
|
||||
),
|
||||
|
|
@ -439,7 +435,7 @@ impl CircuitBuilderPod<F, D> for CircuitBuilder<F, D> {
|
|||
let matrix_row_ref = |builder: &mut CircuitBuilder<F, D>, m: &[Vec<Target>], i| {
|
||||
let num_rows = m.len();
|
||||
let num_columns = m
|
||||
.get(0)
|
||||
.first()
|
||||
.map(|row| {
|
||||
let row_len = row.len();
|
||||
assert!(m.iter().all(|row| row.len() == row_len));
|
||||
|
|
|
|||
|
|
@ -45,14 +45,14 @@ impl OperationVerifyGadget {
|
|||
op: &OperationTarget,
|
||||
prev_statements: &[StatementTarget],
|
||||
merkle_claims: &[MerkleClaimTarget],
|
||||
) -> Result<OperationVerifyTarget> {
|
||||
) -> Result<()> {
|
||||
let _true = builder._true();
|
||||
let _false = builder._false();
|
||||
|
||||
// Verify that the operation `op` correctly generates the statement `st`. The operation
|
||||
// can reference any of the `prev_statements`.
|
||||
// TODO: Clean this up.
|
||||
let resolved_op_args = if prev_statements.len() == 0 {
|
||||
let resolved_op_args = if prev_statements.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
op.args
|
||||
|
|
@ -66,7 +66,7 @@ impl OperationVerifyGadget {
|
|||
// of the provided Merkle proofs (if any). These proofs have already
|
||||
// been verified, so we need only look up the claim.
|
||||
let resolved_merkle_claim =
|
||||
(merkle_claims.len() > 0).then(|| builder.vec_ref(merkle_claims, op.aux[0]));
|
||||
(!merkle_claims.is_empty()).then(|| builder.vec_ref(merkle_claims, op.aux[0]));
|
||||
|
||||
// The verification may require aux data which needs to be stored in the
|
||||
// `OperationVerifyTarget` so that we can set during witness generation.
|
||||
|
|
@ -76,13 +76,13 @@ impl OperationVerifyGadget {
|
|||
// as 'eval' restricted to the op of type X, where the
|
||||
// returned target is `false` if the input targets lie outside
|
||||
// of the domain.
|
||||
let op_checks = vec![
|
||||
let op_checks = [
|
||||
vec![
|
||||
self.eval_none(builder, st, op),
|
||||
self.eval_new_entry(builder, st, op, prev_statements),
|
||||
],
|
||||
// Skip these if there are no resolved op args
|
||||
if resolved_op_args.len() == 0 {
|
||||
if resolved_op_args.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
vec![
|
||||
|
|
@ -110,7 +110,7 @@ impl OperationVerifyGadget {
|
|||
|
||||
builder.connect(ok.target, _true.target);
|
||||
|
||||
Ok(OperationVerifyTarget {})
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn eval_not_contains_from_entries(
|
||||
|
|
@ -311,9 +311,8 @@ impl OperationVerifyGadget {
|
|||
|
||||
let dupe_check = {
|
||||
let individual_checks = prev_statements
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, ps)| {
|
||||
.iter()
|
||||
.map(|ps| {
|
||||
let same_predicate = builder.is_equal_slice(&st.predicate, &ps.predicate);
|
||||
let same_anchored_key =
|
||||
builder.is_equal_slice(&st.args[0].elements, &ps.args[0].elements);
|
||||
|
|
@ -344,21 +343,6 @@ impl OperationVerifyGadget {
|
|||
}
|
||||
}
|
||||
|
||||
struct OperationVerifyTarget {
|
||||
// TODO
|
||||
}
|
||||
|
||||
struct OperationVerifyInput {
|
||||
// TODO
|
||||
}
|
||||
|
||||
impl OperationVerifyTarget {
|
||||
fn set_targets(&self, pw: &mut PartialWitness<F>, input: &OperationVerifyInput) -> Result<()> {
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct MainPodVerifyGadget {
|
||||
params: Params,
|
||||
}
|
||||
|
|
@ -425,12 +409,11 @@ impl MainPodVerifyGadget {
|
|||
// 2. Calculate the Pod Id from the public statements
|
||||
let pub_statements_flattened = pub_statements
|
||||
.iter()
|
||||
.map(|s| {
|
||||
.flat_map(|s| {
|
||||
s.predicate
|
||||
.iter()
|
||||
.chain(s.args.iter().flat_map(|a| &a.elements))
|
||||
})
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect();
|
||||
let id = builder.hash_n_to_hash_no_pad::<PoseidonHash>(pub_statements_flattened);
|
||||
|
|
@ -451,14 +434,12 @@ impl MainPodVerifyGadget {
|
|||
// 3. check that all `input_statements` of type `ValueOf` with origin=SELF have unique keys
|
||||
// (no duplicates). We do this in the verification of NewEntry operation.
|
||||
// 5. Verify input statements
|
||||
let mut op_verifications = Vec::new();
|
||||
for (i, (st, op)) in input_statements.iter().zip(operations.iter()).enumerate() {
|
||||
let prev_statements = &statements[..input_statements_offset + i];
|
||||
let op_verification = OperationVerifyGadget {
|
||||
OperationVerifyGadget {
|
||||
params: params.clone(),
|
||||
}
|
||||
.eval(builder, st, op, prev_statements, &merkle_claims)?;
|
||||
op_verifications.push(op_verification);
|
||||
}
|
||||
|
||||
Ok(MainPodVerifyTarget {
|
||||
|
|
@ -468,7 +449,6 @@ impl MainPodVerifyGadget {
|
|||
statements: input_statements.to_vec(),
|
||||
operations,
|
||||
merkle_proofs,
|
||||
op_verifications,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -481,7 +461,6 @@ pub struct MainPodVerifyTarget {
|
|||
statements: Vec<StatementTarget>,
|
||||
operations: Vec<OperationTarget>,
|
||||
merkle_proofs: Vec<MerkleClaimAndProofTarget>,
|
||||
op_verifications: Vec<OperationVerifyTarget>,
|
||||
}
|
||||
|
||||
pub struct MainPodVerifyInput {
|
||||
|
|
@ -624,8 +603,6 @@ mod tests {
|
|||
merkle_proof.value,
|
||||
)?
|
||||
}
|
||||
let input = OperationVerifyInput {};
|
||||
operation_verify.set_targets(&mut pw, &input)?;
|
||||
|
||||
// generate & verify proof
|
||||
let data = builder.build::<C>();
|
||||
|
|
|
|||
|
|
@ -108,10 +108,7 @@ impl SignedPodVerifyTarget {
|
|||
.chain(iter::repeat_with(|| StatementArgTarget::none(builder)))
|
||||
.take(self.params.max_statement_args)
|
||||
.collect();
|
||||
let statement = StatementTarget {
|
||||
predicate: predicate.clone(),
|
||||
args,
|
||||
};
|
||||
let statement = StatementTarget { predicate, args };
|
||||
statements.push(statement);
|
||||
}
|
||||
statements
|
||||
|
|
@ -131,7 +128,7 @@ impl SignedPodVerifyTarget {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, k)| {
|
||||
let (v, proof) = pod.dict.prove(&k)?;
|
||||
let (v, proof) = pod.dict.prove(k)?;
|
||||
self.mt_proofs[i].set_targets(pw, true, pod.dict.commitment(), proof, *k, v)?;
|
||||
Ok(v)
|
||||
})
|
||||
|
|
@ -146,7 +143,7 @@ impl SignedPodVerifyTarget {
|
|||
continue;
|
||||
}
|
||||
|
||||
let (obtained_v, proof) = pod.dict.prove(&k)?;
|
||||
let (obtained_v, proof) = pod.dict.prove(k)?;
|
||||
assert_eq!(obtained_v, *v); // sanity check
|
||||
|
||||
self.mt_proofs[curr].set_targets(pw, true, pod.dict.commitment(), proof, *k, *v)?;
|
||||
|
|
@ -217,7 +214,7 @@ pub mod tests {
|
|||
pod.insert("idNumber", "4242424242");
|
||||
pod.insert("dateOfBirth", 1169909384);
|
||||
pod.insert("socialSecurityNumber", "G2121210");
|
||||
let sk = SecretKey::new();
|
||||
let sk = SecretKey::new_rand();
|
||||
let mut signer = Signer(sk);
|
||||
let pod = pod.sign(&mut signer).unwrap();
|
||||
let signed_pod = pod.pod.into_any().downcast::<SignedPod>().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue