2022-10-28 14:25:48 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-11-01 17:15:11 +00:00
|
|
|
use serde_big_array::BigArray;
|
2022-11-02 14:30:41 +00:00
|
|
|
use ssz_derive::{Decode, Encode};
|
2022-10-04 01:48:02 +00:00
|
|
|
use std::fmt;
|
2022-10-03 14:06:04 +00:00
|
|
|
use tree_hash::{PackedEncoding, TreeHash};
|
2022-09-17 07:49:12 +00:00
|
|
|
|
|
|
|
const KZG_PROOF_BYTES_LEN: usize = 48;
|
|
|
|
|
2022-11-02 14:30:41 +00:00
|
|
|
#[derive(Debug, PartialEq, Hash, Clone, Copy, Encode, Decode, Serialize, Deserialize)]
|
2022-09-17 07:49:12 +00:00
|
|
|
#[serde(transparent)]
|
2022-11-02 14:30:41 +00:00
|
|
|
#[ssz(struct_behaviour = "transparent")]
|
2022-10-28 14:18:04 +00:00
|
|
|
pub struct KzgProof(#[serde(with = "BigArray")] pub [u8; KZG_PROOF_BYTES_LEN]);
|
2022-09-17 07:49:12 +00:00
|
|
|
|
|
|
|
impl fmt::Display for KzgProof {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2022-11-14 19:14:31 +00:00
|
|
|
write!(f, "{}", eth2_serde_utils::hex::encode(self.0))
|
2022-09-17 07:49:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 09:26:18 +00:00
|
|
|
impl Default for KzgProof {
|
|
|
|
fn default() -> Self {
|
|
|
|
KzgProof([0; 48])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 07:49:12 +00:00
|
|
|
impl From<[u8; KZG_PROOF_BYTES_LEN]> for KzgProof {
|
|
|
|
fn from(bytes: [u8; KZG_PROOF_BYTES_LEN]) -> Self {
|
|
|
|
Self(bytes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<[u8; KZG_PROOF_BYTES_LEN]> for KzgProof {
|
|
|
|
fn into(self) -> [u8; KZG_PROOF_BYTES_LEN] {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TreeHash for KzgProof {
|
|
|
|
fn tree_hash_type() -> tree_hash::TreeHashType {
|
|
|
|
<[u8; KZG_PROOF_BYTES_LEN]>::tree_hash_type()
|
|
|
|
}
|
|
|
|
|
2022-10-03 14:06:04 +00:00
|
|
|
fn tree_hash_packed_encoding(&self) -> PackedEncoding {
|
2022-09-17 07:49:12 +00:00
|
|
|
self.0.tree_hash_packed_encoding()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tree_hash_packing_factor() -> usize {
|
|
|
|
<[u8; KZG_PROOF_BYTES_LEN]>::tree_hash_packing_factor()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tree_hash_root(&self) -> tree_hash::Hash256 {
|
|
|
|
self.0.tree_hash_root()
|
|
|
|
}
|
|
|
|
}
|