Skip to content

Commit

Permalink
feat: impl PartialEq and Eq for most of the types
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev committed Jul 3, 2024
1 parent 5a6bc5e commit a65e04c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
8 changes: 4 additions & 4 deletions portal-bridge/src/types/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ use serde::{Deserialize, Serialize};

use crate::types::witness::ExecutionWitness;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SignedBeaconBlock {
pub message: BeaconBlock,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BeaconBlock {
pub parent_root: B256,
pub state_root: B256,
pub body: BeaconBlockBody,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BeaconBlockBody {
pub execution_payload: ExecutionPayload,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExecutionPayload {
pub block_number: U64,
pub block_hash: B256,
Expand Down
4 changes: 2 additions & 2 deletions portal-bridge/src/types/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use verkle_core::{storage::AccountStorageLayout, Stem, TrieKey, TrieValue};

use super::witness::{StateDiff, StemStateDiff, SuffixStateDiff};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AccountAlloc {
pub balance: U256,
Expand All @@ -15,7 +15,7 @@ pub struct AccountAlloc {
pub storage: Option<HashMap<U256, TrieValue>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GenesisConfig {
pub alloc: HashMap<Address, AccountAlloc>,
}
Expand Down
2 changes: 1 addition & 1 deletion portal-bridge/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod genesis;
pub mod state_write;
pub mod witness;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct JsonResponseMessage {
pub data: SignedBeaconBlock,
}
Expand Down
4 changes: 2 additions & 2 deletions portal-bridge/src/types/state_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use verkle_core::{Stem, TrieValue};

use super::witness::{StateDiff, StemStateDiff, SuffixStateDiff};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SuffixStateWrites {
pub suffix: u8,
pub old_value: Option<TrieValue>,
Expand All @@ -30,7 +30,7 @@ impl SuffixStateWrites {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StemStateWrite {
pub stem: Stem,
pub suffix_writes: Vec<SuffixStateWrites>,
Expand Down
8 changes: 4 additions & 4 deletions portal-bridge/src/types/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use serde_nested_with::serde_nested;
use verkle_core::{proof::IpaProof, Point, Stem, TrieValue};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SuffixStateDiff {
pub suffix: U8,
Expand All @@ -13,7 +13,7 @@ pub struct SuffixStateDiff {
pub new_value: Option<TrieValue>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct StemStateDiff {
pub stem: Stem,
Expand All @@ -24,7 +24,7 @@ pub struct StemStateDiff {
pub type StateDiff = Vec<StemStateDiff>;

#[serde_nested]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct VerkleProof {
#[serde(alias = "otherStems")]
Expand All @@ -38,7 +38,7 @@ pub struct VerkleProof {
pub ipa_proof: IpaProof,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ExecutionWitness {
#[serde(alias = "stateDiff")]
Expand Down
2 changes: 1 addition & 1 deletion portal-verkle-trie/src/nodes/portal/ssz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod sparse_vector;

pub type TriePath = VariableList<u8, typenum::U30>;

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct TrieProof {
pub commitments_by_path: VariableList<Point, typenum::U32>,
pub multi_point_proof: MultiPointProof,
Expand Down
16 changes: 8 additions & 8 deletions portal-verkle-trie/src/nodes/portal/ssz/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,56 @@ use verkle_core::{constants::PORTAL_NETWORK_NODE_WIDTH, Point, Stem, TrieValue};

use super::{sparse_vector::SparseVector, BundleProof, TriePath, TrieProof};

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BranchBundleNode {
pub fragments: SparseVector<Point, PORTAL_NETWORK_NODE_WIDTH>,
pub proof: BundleProof,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BranchBundleNodeWithProof {
pub node: BranchBundleNode,
pub block_hash: B256,
pub path: TriePath,
pub proof: TrieProof,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BranchFragmentNode {
pub fragment_index: u8,
pub children: SparseVector<Point, PORTAL_NETWORK_NODE_WIDTH>,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BranchFragmentNodeWithProof {
pub node: BranchFragmentNode,
pub block_hash: B256,
pub path: TriePath,
pub proof: TrieProof,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct LeafBundleNode {
pub marker: u64,
pub stem: Stem,
pub fragments: SparseVector<Point, PORTAL_NETWORK_NODE_WIDTH>,
pub proof: BundleProof,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct LeafBundleNodeWithProof {
pub node: LeafBundleNode,
pub block_hash: B256,
pub proof: TrieProof,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct LeafFragmentNode {
pub fragment_index: u8,
pub children: SparseVector<TrieValue, PORTAL_NETWORK_NODE_WIDTH>,
}

#[derive(Debug, Clone, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct LeafFragmentNodeWithProof {
pub node: LeafFragmentNode,
pub block_hash: B256,
Expand Down
7 changes: 5 additions & 2 deletions verkle-core/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ssz_types::{typenum, FixedVector};
use crate::{Point, ScalarField};

/// The multi-point proof based on IPA.
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)]
#[serde(deny_unknown_fields)]
pub struct MultiPointProof {
#[serde(alias = "ipaProof")]
Expand All @@ -15,11 +15,14 @@ pub struct MultiPointProof {
}

/// The inner product argument proof.
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
#[serde(deny_unknown_fields)]
pub struct IpaProof {
pub cl: FixedVector<Point, typenum::U8>,
pub cr: FixedVector<Point, typenum::U8>,
#[serde(alias = "finalEvaluation")]
pub final_evaluation: ScalarField,
}

// TODO: Add this to Derive once ssz_types updates.
impl Eq for IpaProof {}

0 comments on commit a65e04c

Please sign in to comment.