Skip to content

Commit

Permalink
chore: VidScheme::Commit assoc type support TaggedBase64 conversion (#…
Browse files Browse the repository at this point in the history
…458)

* add TODO comment for #393

* add trait bounds to VidScheme::Commit, support it in advz impl
  • Loading branch information
ggutoski authored Jan 12, 2024
1 parent 7e906cf commit 8d071e2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions primitives/src/merkle_tree/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use digest::{
crypto_common::{generic_array::ArrayLength, Output},
Digest, OutputSizeUser,
};
use serde::{Deserialize, Serialize};
use tagged_base64::tagged;
use typenum::U3;

/// Merkle tree generic over [`Digest`] hasher `H`.
Expand Down Expand Up @@ -161,8 +161,7 @@ where
}

/// Newtype wrapper for hash output that impls [`NodeValue`](super::NodeValue).
#[derive(Derivative, Deserialize, Serialize)]
#[serde(bound = "Output<H>: Serialize + for<'a> Deserialize<'a>")]
#[derive(Derivative)]
#[derivative(
Clone(bound = ""),
Copy(bound = "<<H as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Copy"),
Expand All @@ -174,6 +173,7 @@ where
PartialEq(bound = ""),
PartialOrd(bound = "")
)]
#[tagged("HASH")]
pub struct HasherNode<H>(Output<H>)
where
H: Digest;
Expand Down
21 changes: 19 additions & 2 deletions primitives/src/vid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@

//! Trait and implementation for a Verifiable Information Retrieval (VID).
/// See <https://arxiv.org/abs/2111.12323> section 1.3--1.4 for intro to VID semantics.
use ark_std::{error::Error, fmt::Debug, hash::Hash, string::String, vec::Vec};
use ark_std::{
error::Error,
fmt::{Debug, Display},
hash::Hash,
string::String,
vec::Vec,
};
use displaydoc::Display;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tagged_base64::TaggedBase64;

/// VID: Verifiable Information Dispersal
pub trait VidScheme {
/// Payload commitment.
type Commit: Clone + Debug + DeserializeOwned + Eq + PartialEq + Hash + Serialize + Sync; // TODO https://github.com/EspressoSystems/jellyfish/issues/253
type Commit: Clone
+ Debug
+ Display
+ DeserializeOwned
+ Eq
+ PartialEq
+ Hash
+ Serialize
+ Sync
+ for<'a> TryFrom<&'a TaggedBase64>
+ Into<TaggedBase64>; // TODO https://github.com/EspressoSystems/jellyfish/issues/253

/// Share-specific data sent to a storage node.
type Share: Clone + Debug + DeserializeOwned + Eq + PartialEq + Hash + Serialize + Sync; // TODO https://github.com/EspressoSystems/jellyfish/issues/253
Expand Down
10 changes: 7 additions & 3 deletions primitives/src/vid/advz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{vid, VidDisperse, VidError, VidResult, VidScheme};
use crate::{
alloc::string::ToString,
merkle_tree::{
hasher::{HasherDigest, HasherMerkleTree},
hasher::{HasherDigest, HasherMerkleTree, HasherNode},
MerkleCommitment, MerkleTreeScheme,
},
pcs::{
Expand Down Expand Up @@ -100,6 +100,8 @@ where
num_storage_nodes: usize,
srs: impl Borrow<KzgSrs<E>>,
) -> VidResult<Self> {
// TODO support any degree, give multiple shares to nodes if needed
// https://github.com/EspressoSystems/jellyfish/issues/393
if num_storage_nodes < payload_chunk_size {
return Err(VidError::Argument(format!(
"payload_chunk_size {} exceeds num_storage_nodes {}",
Expand Down Expand Up @@ -196,7 +198,9 @@ where
E: Pairing,
H: HasherDigest,
{
type Commit = Output<H>;
// use HasherNode<H> instead of Output<H> to easily meet trait bounds
type Commit = HasherNode<H>;

type Share = Share<E, H>;
type Common = Common<E, H>;

Expand Down Expand Up @@ -550,7 +554,7 @@ where
.serialize_uncompressed(&mut hasher)
.map_err(vid)?;
}
Ok(hasher.finalize())
Ok(hasher.finalize().into())
}
}

Expand Down

0 comments on commit 8d071e2

Please sign in to comment.