Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VidScheme allow disperse to reuse work done in commit_only #479

Closed
Tracked by #358
ggutoski opened this issue Feb 5, 2024 · 5 comments
Closed
Tracked by #358

VidScheme allow disperse to reuse work done in commit_only #479

ggutoski opened this issue Feb 5, 2024 · 5 comments
Assignees
Labels
cappuccino cappuccino-sprint1 optimize-vid https://www.notion.so/espressosys/9d835f79d4504926b8b3bb3d015abf06?v=b7028cdaea804b7aa918af95c0cd651 vid

Comments

@ggutoski
Copy link
Contributor

ggutoski commented Feb 5, 2024

A significant fraction of the work of commit_only is duplicated in disperse. ie. computing polynomial commitments (dominant cost!), bytes_to_field, and possibly other things.

commit_only should return additional data beyond the commitment. At a minimum, it should also return the polynomial commitments

disperse should take a (optional) argument for pre-computed polynomial commitments.

Need to update VidScheme trait with these API changes, then update ADVZ impl to conform.

VidScheme is supposed to be abstract, so we can't just add a poly_commits: Option<Vec<KzgCommit<E>>> arg to disperse. Instead we could add yet another assoc type to VidScheme called DisperseHelperData or whatever. The proposal is something like

trait VidScheme {
  // ...
  type DisperseHelperData: Clone + Debug + DeserializeOwned + Eq + PartialEq + Hash + Serialize + Sync;
  fn commit_only<B>(&self, payload: B) -> VidResult<(Self::Commit, Self::DisperseHelperData)>
  fn disperse<B>(&self, payload: B, helper_data: Option<Self::DisperseHelperData>) -> VidResult<VidDisperse<Self>>
  // ...
}

cc @elliedavidson for visibility.

@ggutoski ggutoski added vid cappuccino optimize-vid https://www.notion.so/espressosys/9d835f79d4504926b8b3bb3d015abf06?v=b7028cdaea804b7aa918af95c0cd651 cappuccino-sprint1 labels Feb 5, 2024
@ggutoski
Copy link
Contributor Author

ggutoski commented Feb 7, 2024

Discuss: If we change VidScheme trait then we also need to change everything downstream that depends on it. That will be a lot of work. 😕 An alternative is to make only additive changes to VidScheme. ie. new methods commit_only_with_helper_data and disperse_with_helper_data

@akonring If we do make breaking API changes then we should open PRs for everything downstream that will break. In order to do so we need to test everything locally via cargo patch directives.

EDIT: ...or maybe we can make a subtrait VidSchemeWithHelperData: VidScheme

@akonring
Copy link
Contributor

I don't have a strong opinion on this. I see that breaking changes to VidScheme trait will add more downstream complications but on the other hand adding new methods creates a less clean trait interface. Maybe there are other reasons to not introduce new methods?

@ggutoski
Copy link
Contributor Author

We already have an instance of the subtrait pattern with PayloadProver: VidScheme. I suggest we repeat that pattern for VidSchemeWithHelperData: VidScheme. (But please choose a better name!) We'll see how it looks in review and seek more opinions then.

@akonring
Copy link
Contributor

akonring commented Feb 13, 2024

Preliminary design of the subtrait below:

//! Trait for additional functionality in Verifiable Information Retrieval (VID)
//! for precomputation of specific data that allows for calling
//! methods using the data to save computation for the callee.

use core::fmt::Debug;

use super::{VidDisperse, VidResult, VidScheme};
use ark_std::hash::Hash;
use serde::{de::DeserializeOwned, Serialize};
/// Allow for precomputation of certain data for [`VidScheme`].
pub trait Precomputable: VidScheme {
    /// Precomputed data that can be (re-)used during disperse computation
    type PrecomputeData: Clone + Debug + Eq + PartialEq + Hash + Sync + Serialize + DeserializeOwned;

    /// Similar to [`VidScheme::commit_only`] but returns additional data that
    /// can be used as input to `disperse_precompute` for faster dispersal.
    fn commit_only_precompute<B>(
        &self,
        payload: B,
    ) -> VidResult<(Self::Commit, Self::PrecomputeData)>
    where
        B: AsRef<[u8]>;

    /// Similar to [`VidScheme::disperse`] but takes as input additional
    /// data for more efficient computation and faster disersal.
    fn disperse_precompute<B>(
        &self,
        payload: B,
        data: Self::PrecomputeData,
    ) -> VidResult<VidDisperse<Self>>
    where
        B: AsRef<[u8]>;
}

Currently, looking into the implementation: figure out the data we want to re-use and how to satisfy Serialize + DeserializeOwned for this data. Feedback is welcome.

@ggutoski
Copy link
Contributor Author

Looks pretty good. Notes:

  • data arg of disperse_precompute should probably be a reference type &Self::PrecomputeData
  • which data to re-use: For ADVZ this will be just a single field poly_commits: Vec<KzgCommit<E>>,, exactly like in the Common struct.
  • you can use Common as a model for how to satisfy serde traits. I suspect it'll look something like
#[derive(CanonicalSerialize, CanonicalDeserialize, Derivative, Deserialize, Serialize)]
#[derivative(
    Clone(bound = ""),
    Debug(bound = ""),
    Eq(bound = ""),
    Hash(bound = ""),
    PartialEq(bound = "")
)]
pub struct PrecomputeData<E>
where
    E: Pairing,
{
    #[serde(with = "canonical")]
    poly_commits: Vec<KzgCommit<E>>,
}

Because there's no H type param it might be possible to eliminate the derivative attribute with all the bound = "" fields and instead put all those trait bounds into the conventional derive attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cappuccino cappuccino-sprint1 optimize-vid https://www.notion.so/espressosys/9d835f79d4504926b8b3bb3d015abf06?v=b7028cdaea804b7aa918af95c0cd651 vid
Projects
None yet
Development

No branches or pull requests

3 participants