add eq & partial_eq for RecursivePod, Pod traits and VDSet struct (for usage from introduction-pods) (#309)

* add eq & partial_eq for VDSet (for usage from introduction-pods)

* add eq & partial_eq impls for Pod & RecursivePod traits
This commit is contained in:
arnaucube 2025-06-24 17:41:46 +02:00 committed by GitHub
parent 256d76ae34
commit e1775d8578
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 121 additions and 9 deletions

View file

@ -77,6 +77,15 @@ pub struct VDSet {
vds_hashes: Vec<Hash>,
}
impl PartialEq for VDSet {
fn eq(&self, other: &Self) -> bool {
self.root == other.root
&& self.tree_depth == other.tree_depth
&& self.vds_hashes == other.vds_hashes
}
}
impl Eq for VDSet {}
impl VDSet {
fn new_from_vds_hashes(tree_depth: usize, mut vds_hashes: Vec<Hash>) -> Result<Self> {
// before using the hash values, sort them, so that each set of

View file

@ -1,4 +1,5 @@
use std::{
any::Any,
collections::HashMap,
sync::{LazyLock, Mutex},
};
@ -73,7 +74,7 @@ impl EmptyPodVerifyTarget {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EmptyPod {
params: Params,
id: PodId,
@ -192,6 +193,17 @@ impl Pod for EmptyPod {
})
.expect("serialization to json")
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<EmptyPod>() {
self == other
} else {
false
}
}
}
impl RecursivePod for EmptyPod {

View file

@ -561,7 +561,7 @@ impl PodProver for Prover {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MainPod {
params: Params,
id: PodId,
@ -676,6 +676,17 @@ impl Pod for MainPod {
})
.expect("serialization to json")
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<MainPod>() {
self == other
} else {
false
}
}
}
impl RecursivePod for MainPod {

View file

@ -10,6 +10,8 @@ use crate::{
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Statement(pub Predicate, pub Vec<StatementArg>);
impl Eq for Statement {}
impl Statement {
pub fn is_none(&self) -> bool {
self.0 == Predicate::Native(NativePredicate::None)

View file

@ -1,3 +1,5 @@
use std::any::Any;
use itertools::Itertools;
use crate::{
@ -12,7 +14,7 @@ use crate::{
},
};
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MockEmptyPod {
params: Params,
id: PodId,
@ -67,6 +69,17 @@ impl Pod for MockEmptyPod {
fn serialize_data(&self) -> serde_json::Value {
serde_json::Value::Null
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<MockEmptyPod>() {
self == other
} else {
false
}
}
}
impl RecursivePod for MockEmptyPod {

View file

@ -2,7 +2,7 @@
// MainPod
//
use std::{fmt, iter};
use std::{any::Any, fmt, iter};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
@ -56,6 +56,21 @@ pub struct MockMainPod {
merkle_proofs_containers: Vec<MerkleClaimAndProof>,
}
impl PartialEq for MockMainPod {
fn eq(&self, other: &Self) -> bool {
self.params == other.params
&& self.id == other.id
&& self.vd_set == other.vd_set
&& self.input_signed_pods == other.input_signed_pods
&& self.input_recursive_pods == other.input_recursive_pods
&& self.statements == other.statements
&& self.operations == other.operations
&& self.public_statements == other.public_statements
&& self.merkle_proofs_containers == other.merkle_proofs_containers
}
}
impl Eq for MockMainPod {}
impl fmt::Display for MockMainPod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "MockMainPod ({}):", self.id)?;
@ -365,6 +380,17 @@ impl Pod for MockMainPod {
})
.expect("serialization to json")
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<MockMainPod>() {
self == other
} else {
false
}
}
}
impl RecursivePod for MockMainPod {

View file

@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{any::Any, collections::HashMap};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
@ -45,7 +45,7 @@ impl PodSigner for MockSigner {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MockSignedPod {
id: PodId,
signature: String,
@ -158,6 +158,17 @@ impl Pod for MockSignedPod {
})
.expect("serialization to json")
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<MockSignedPod>() {
self == other
} else {
false
}
}
}
#[cfg(test)]

View file

@ -35,7 +35,7 @@ use crate::{
};
/// Schnorr signature over ecGFp5.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Signature {
pub s: BigUint,
pub e: BigUint,

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::LazyLock};
use std::{any::Any, collections::HashMap, sync::LazyLock};
use itertools::Itertools;
use num_bigint::{BigUint, RandBigInt};
@ -67,7 +67,7 @@ impl PodSigner for Signer {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SignedPod {
pub id: PodId,
pub signature: Signature,
@ -204,6 +204,17 @@ impl Pod for SignedPod {
})
.expect("serialization to json")
}
fn as_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn Pod) -> bool {
if let Some(other) = other.as_any().downcast_ref::<SignedPod>() {
self == other
} else {
false
}
}
}
#[cfg(test)]