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:
Eduard S. 2025-04-08 11:52:02 -07:00 committed by GitHub
parent 24ff82dd3d
commit 0759d6e165
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 217 additions and 339 deletions

View file

@ -23,15 +23,12 @@ use plonky2::{
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
backends::counter,
middleware::{
serialization::{
deserialize_hash_tuple, deserialize_value_tuple, serialize_hash_tuple,
serialize_value_tuple,
},
Params, ToFields,
use crate::middleware::{
serialization::{
deserialize_hash_tuple, deserialize_value_tuple, serialize_hash_tuple,
serialize_value_tuple,
},
Params, ToFields,
};
/// F is the native field we use everywhere. Currently it's Goldilocks from plonky2
@ -83,10 +80,10 @@ impl Ord for Value {
fn cmp(&self, other: &Self) -> Ordering {
for (lhs, rhs) in self.0.iter().zip(other.0.iter()).rev() {
let (lhs, rhs) = (lhs.to_canonical_u64(), rhs.to_canonical_u64());
if lhs < rhs {
return Ordering::Less;
} else if lhs > rhs {
return Ordering::Greater;
match lhs.cmp(&rhs) {
Ordering::Less => return Ordering::Less,
Ordering::Greater => return Ordering::Greater,
_ => {}
}
}
Ordering::Equal
@ -159,10 +156,7 @@ pub fn hash_value(input: &Value) -> Hash {
}
pub fn hash_fields(input: &[F]) -> Hash {
// Note: the counter counts when this method is called, but different input
// sizes will have different costs in-circuit.
counter::count_hash();
Hash(PoseidonHash::hash_no_pad(&input).elements)
Hash(PoseidonHash::hash_no_pad(input).elements)
}
impl From<Value> for Hash {

View file

@ -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));

View file

@ -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>();

View file

@ -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();

View file

@ -39,14 +39,15 @@ impl PodProver for Prover {
.signed_pods
.iter()
.map(|p| {
let p: Box<dyn middleware::Pod> = (*p).clone();
*p.into_any()
.downcast::<SignedPod>()
.expect("type SignedPod")
let p = p
.as_any()
.downcast_ref::<SignedPod>()
.expect("type SignedPod");
p.clone()
})
.collect_vec();
let merkle_proofs = MockMainPod::extract_merkle_proofs(params, &inputs.operations)?;
let merkle_proofs = MockMainPod::extract_merkle_proofs(params, inputs.operations)?;
// TODO: Move these methods from the mock main pod to a common place
let statements = MockMainPod::layout_statements(params, &inputs);
@ -151,6 +152,9 @@ impl Pod for MainPod {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
fn as_any(&self) -> &dyn Any {
self
}
fn serialized_proof(&self) -> String {
todo!()

View file

@ -2,7 +2,6 @@ use std::{any::Any, fmt};
use anyhow::{anyhow, Result};
use base64::prelude::*;
use itertools::Itertools;
use plonky2::{hash::poseidon::PoseidonHash, plonk::config::Hasher};
use serde::{Deserialize, Serialize};
@ -92,7 +91,7 @@ fn fmt_statement_index(
op: Option<&Operation>,
index: usize,
) -> fmt::Result {
if !(!f.alternate() && st.is_none()) {
if f.alternate() || !st.is_none() {
write!(f, " {:03}. ", index)?;
if f.alternate() {
write!(f, "{:#}", &st)?;
@ -127,9 +126,6 @@ pub fn fill_pad<T: Clone>(v: &mut Vec<T>, pad_value: T, len: usize) {
/// - private Statements
/// - public Statements
impl MockMainPod {
fn offset_input_signed_pods(&self) -> usize {
0
}
fn offset_input_main_pods(&self) -> usize {
self.params.max_input_signed_pods * self.params.max_signed_pod_values
}
@ -143,9 +139,6 @@ impl MockMainPod {
fn pad_statement(params: &Params, s: &mut Statement) {
fill_pad(&mut s.1, StatementArg::None, params.max_statement_args)
}
fn pad_operation(params: &Params, op: &mut Operation) {
fill_pad(&mut op.1, OperationArg::None, params.max_operation_args)
}
/// Returns the statements from the given MainPodInputs, padding to the
/// respective max lengths defined at the given Params.
@ -153,10 +146,11 @@ impl MockMainPod {
let mut statements = Vec::new();
// Input signed pods region
let none_sig_pod: Box<dyn Pod> = Box::new(NonePod {});
let none_sig_pod_box: Box<dyn Pod> = Box::new(NonePod {});
let none_sig_pod = none_sig_pod_box.as_ref();
assert!(inputs.signed_pods.len() <= params.max_input_signed_pods);
for i in 0..params.max_input_signed_pods {
let pod = inputs.signed_pods.get(i).copied().unwrap_or(&none_sig_pod);
let pod = inputs.signed_pods.get(i).unwrap_or(&none_sig_pod);
let sts = pod.pub_statements();
assert!(sts.len() <= params.max_signed_pod_values);
for j in 0..params.max_signed_pod_values {
@ -171,10 +165,11 @@ impl MockMainPod {
}
// Input main pods region
let none_main_pod: Box<dyn Pod> = Box::new(NonePod {});
let none_main_pod_box: Box<dyn Pod> = Box::new(NonePod {});
let none_main_pod = none_main_pod_box.as_ref();
assert!(inputs.main_pods.len() <= params.max_input_main_pods);
for i in 0..params.max_input_main_pods {
let pod = inputs.main_pods.get(i).copied().unwrap_or(&none_main_pod);
let pod = inputs.main_pods.get(i).copied().unwrap_or(none_main_pod);
let sts = pod.pub_statements();
assert!(sts.len() <= params.max_public_statements);
for j in 0..params.max_public_statements {
@ -256,11 +251,11 @@ impl MockMainPod {
})
.collect::<Result<Vec<_>>>()?;
if merkle_proofs.len() > params.max_merkle_proofs {
return Err(anyhow!(
Err(anyhow!(
"The number of required Merkle proofs ({}) exceeds the maximum number ({}).",
merkle_proofs.len(),
params.max_merkle_proofs
));
))
} else {
fill_pad(
&mut merkle_proofs,
@ -388,7 +383,7 @@ impl MockMainPod {
// value=PodType::MockMainPod`
let statements = Self::layout_statements(params, &inputs);
// Extract Merkle proofs and pad.
let merkle_proofs = Self::extract_merkle_proofs(params, &inputs.operations)?;
let merkle_proofs = Self::extract_merkle_proofs(params, inputs.operations)?;
let operations = Self::process_private_statements_operations(
params,
@ -399,22 +394,6 @@ impl MockMainPod {
let operations =
Self::process_public_statements_operations(params, &statements, operations)?;
let input_signed_pods = inputs
.signed_pods
.iter()
.map(|p| (*p).clone())
.collect_vec();
let input_main_pods = inputs.main_pods.iter().map(|p| (*p).clone()).collect_vec();
let input_statements = inputs
.statements
.iter()
.cloned()
.map(|s| {
let mut s = s.into();
Self::pad_statement(params, &mut s);
s
})
.collect_vec();
let public_statements =
statements[statements.len() - params.max_public_statements..].to_vec();
@ -434,26 +413,6 @@ impl MockMainPod {
})
}
fn statement_none(params: &Params) -> Statement {
let mut args = Vec::with_capacity(params.max_statement_args);
Self::pad_statement_args(params, &mut args);
Statement(Predicate::Native(NativePredicate::None), args)
}
fn operation_none(params: &Params) -> Operation {
let mut op = Operation(
OperationType::Native(NativeOperation::None),
vec![],
OperationAux::None,
);
fill_pad(&mut op.1, OperationArg::None, params.max_operation_args);
op
}
fn pad_statement_args(params: &Params, args: &mut Vec<StatementArg>) {
fill_pad(args, StatementArg::None, params.max_statement_args)
}
fn pad_operation_args(params: &Params, args: &mut Vec<OperationArg>) {
fill_pad(args, OperationArg::None, params.max_operation_args)
}
@ -487,19 +446,15 @@ impl Pod for MockMainPod {
let ids_match = self.id == PodId(hash_statements(&self.public_statements, &self.params));
// find a ValueOf statement from the public statements with key=KEY_TYPE and check that the
// value is PodType::MockMainPod
let has_type_statement = self
.public_statements
.iter()
.find(|s| {
s.0 == Predicate::Native(NativePredicate::ValueOf)
&& !s.1.is_empty()
&& if let StatementArg::Key(AnchoredKey(pod_id, key_hash)) = s.1[0] {
pod_id == SELF && key_hash == hash_str(KEY_TYPE)
} else {
false
}
})
.is_some();
let has_type_statement = self.public_statements.iter().any(|s| {
s.0 == Predicate::Native(NativePredicate::ValueOf)
&& !s.1.is_empty()
&& if let StatementArg::Key(AnchoredKey(pod_id, key_hash)) = s.1[0] {
pod_id == SELF && key_hash == hash_str(KEY_TYPE)
} else {
false
}
});
// 3. check that all `input_statements` of type `ValueOf` with origin=SELF have unique keys
// (no duplicates)
// TODO: Instead of doing this, do a uniqueness check when verifying the output of a
@ -597,6 +552,9 @@ impl Pod for MockMainPod {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
fn as_any(&self) -> &dyn Any {
self
}
fn serialized_proof(&self) -> String {
BASE64_STANDARD.encode(serde_json::to_string(self).unwrap())

View file

@ -94,8 +94,8 @@ impl MerkleClaimAndProof {
let (other_key, other_value) = mid_mp.other_leaf.unwrap_or((EMPTY_VALUE, EMPTY_VALUE));
Ok(Self {
enabled: true,
root: root.clone().into(),
key: key.clone(),
root: (*root).into(),
key: *key,
value: value.cloned().unwrap_or(EMPTY_VALUE),
existence: mid_mp.existence,
siblings: mid_mp
@ -197,7 +197,7 @@ impl fmt::Display for Operation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} ", self.0)?;
for (i, arg) in self.1.iter().enumerate() {
if !(!f.alternate() && arg.is_none()) {
if f.alternate() || !arg.is_none() {
if i != 0 {
write!(f, " ")?;
}

View file

@ -118,7 +118,7 @@ impl fmt::Display for Statement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} ", self.0)?;
for (i, arg) in self.1.iter().enumerate() {
if !(!f.alternate() && arg.is_none()) {
if f.alternate() || !arg.is_none() {
if i != 0 {
write!(f, " ")?;
}

View file

@ -123,6 +123,9 @@ impl Pod for MockSignedPod {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
fn as_any(&self) -> &dyn Any {
self
}
fn serialized_proof(&self) -> String {
self.signature.to_string()

View file

@ -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);

View file

@ -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()

View file

@ -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);

View file

@ -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)?;

View file

@ -103,6 +103,9 @@ impl Pod for SignedPod {
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
fn as_any(&self) -> &dyn Any {
self
}
fn serialized_proof(&self) -> String {
let mut buffer = Vec::new();
@ -134,7 +137,7 @@ pub mod tests {
pod.insert("socialSecurityNumber", "G2121210");
// TODO: Use a deterministic secret key to get deterministic tests
let sk = SecretKey::new();
let sk = SecretKey::new_rand();
let mut signer = Signer(sk);
let pod = pod.sign(&mut signer).unwrap();
let pod = pod.pod.into_any().downcast::<SignedPod>().unwrap();