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

Add PeerDAS KZG lib integration (construction & KZG verification) #6212

Merged
merged 12 commits into from
Aug 13, 2024

Conversation

jimmygchen
Copy link
Member

@jimmygchen jimmygchen commented Aug 1, 2024

Issue Addressed

Add PeerDAS KZG library and use it for data column construction and KZG verification.

Proposed Changes

Upstream PRs:

Thanks @kevaundray for the PRs!

Additional Info

I've also moved build_data_column_sidecars and reconstruct_data_columns functions from consensus/types to kzg_utils in the beacon_chain crates, where all other KZG related logic are located.

This PR doesn't include the following, in order to keep the PR size moderate and solely focused on KZG lib integration:

  • Constructing the data column sidecars when proposing a block
  • PeerDAS KZG spec tests

…ell kzg verification (sigp#5701, sigp#5941, sigp#6118, sigp#6179)

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
@jimmygchen jimmygchen added ready-for-review The code is ready for review das Data Availability Sampling das-unstable-merge labels Aug 1, 2024
@jimmygchen jimmygchen changed the title Add PeerDAS KZG library and use it for data column construction and KZG verification Add PeerDAS KZG lib integration (construction & KZG verification) Aug 1, 2024
Copy link
Collaborator

@dapplion dapplion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ok to move the code to kzg_utils

beacon_node/beacon_chain/src/metrics.rs Show resolved Hide resolved
@jimmygchen
Copy link
Member Author

I'm looking into the windows CI failure.

crypto/kzg/src/lib.rs Outdated Show resolved Hide resolved
crypto/kzg/src/lib.rs Outdated Show resolved Hide resolved
crypto/kzg/src/lib.rs Outdated Show resolved Hide resolved
//
// Note: One can also use `from_json` to initialize it from the consensus-specs
// json string.
let peerdas_trusted_setup = PeerDASTrustedSetup::default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an embedded trusted setup here, so we're loading the same setup twice right? so maybe we can at least add an equivalence check here if there's no way to consolidate the two yet

Copy link
Member Author

@jimmygchen jimmygchen Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's right. Yeah I think equivalence check is a good idea, or potentially cloning the values from existing trusted setup. There are a few more things I've done on another WIP branch, but I'm still thinking about whether it's a good idea:

  • Should we only load this if PeerDAS is scheduled (None otherwise), so we don't impact mainnet code path now (I have a branch here that does this)
  • Load PeerDAS setup from existing trusted_setup using clone (code), so we avoid reading file system and also avoid breaking --trusted-setup flag - although we don't really use this anymore

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to cherry-pick both changes into this branch.

With (2), I just did a bench on both approaches (loading from json / clone and encode existing trusted setup) - cloning is actually slightly faster than re-loading from json (-20ms), plus we get consistency, and we won't need to perform equivalent check.

Copy link
Member Author

@jimmygchen jimmygchen Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done #1, it actually involves touching a lot of files and I'm not sure if it's worth it, as loading the PeerDAS trusted setup only adds ~550ms on startup and ~100mb of memory for storing the precomputation. Existing Deneb code path still uses c-kzg so should be unaffected.

Once both libraries are feature complete and stable for deneb and PeerDAS, we could do this properly and only load one library with a cli flag.

What do you think @realbigsean ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced loading embedded trusted setup with cloning the existing trusted setup values.
11c53a8

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added conditionally load KZG on startup only if PeerDAS is enabled: 6881981

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once both libraries are feature complete and stable for deneb and PeerDAS, we could do this properly and only load one library with a cli flag.

That sounds good!

beacon_node/beacon_chain/src/kzg_utils.rs Outdated Show resolved Hide resolved
beacon_node/beacon_chain/src/kzg_utils.rs Outdated Show resolved Hide resolved
beacon_node/beacon_chain/src/kzg_utils.rs Show resolved Hide resolved
@jimmygchen jimmygchen added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Aug 6, 2024
jimmygchen and others added 2 commits August 7, 2024 22:14
…nnecessary `needless_lifetimes`.

Co-authored-by: realbigsean <sean@sigmaprime.io>
…y and maintain `--trusted-setup` functionality.
@jimmygchen jimmygchen added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Aug 7, 2024
/// A wrapper over a kzg library that holds the trusted setup parameters.
#[derive(Debug)]
pub struct Kzg {
trusted_setup: KzgSettings,
context: DASContext,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to conditionally load the DAS context for peerdas networks only? It's kindoff a bad penalty to force mainnet users to pay the extra 110MB in memory for an unused feature

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6881981

Copy link
Collaborator

@dapplion dapplion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@realbigsean realbigsean added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Aug 12, 2024
@jimmygchen
Copy link
Member Author

@mergify queue

Copy link

mergify bot commented Aug 12, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 6dc614f

mergify bot added a commit that referenced this pull request Aug 12, 2024
@mergify mergify bot merged commit 6dc614f into sigp:unstable Aug 13, 2024
28 checks passed
AgeManning pushed a commit to AgeManning/lighthouse that referenced this pull request Sep 3, 2024
…gp#6212)

* Add peerdas KZG library and use it for data column construction and cell kzg verification (sigp#5701, sigp#5941, sigp#6118, sigp#6179)

Co-authored-by: kevaundray <kevtheappdev@gmail.com>

* Update `rust_eth_kzg` crate to published version.

* Update kzg metrics buckets.

* Merge branch 'unstable' into peerdas-kzg

* Update KZG version to fix windows mem allocation.

* Refactor common logic from build sidecar and reconstruction. Remove unnecessary `needless_lifetimes`.

Co-authored-by: realbigsean <sean@sigmaprime.io>

* Copy existing trusted setup into `PeerDASTrustedSetup` for consistency and maintain `--trusted-setup` functionality.

* Merge branch 'unstable' into peerdas-kzg

* Merge branch 'peerdas-kzg' of github.com:jimmygchen/lighthouse into peerdas-kzg

* Merge branch 'unstable' into peerdas-kzg

* Merge branch 'unstable' into peerdas-kzg

* Load PeerDAS KZG only if PeerDAS is enabled.
chong-he pushed a commit to chong-he/lighthouse that referenced this pull request Nov 26, 2024
…gp#6212)

* Add peerdas KZG library and use it for data column construction and cell kzg verification (sigp#5701, sigp#5941, sigp#6118, sigp#6179)

Co-authored-by: kevaundray <kevtheappdev@gmail.com>

* Update `rust_eth_kzg` crate to published version.

* Update kzg metrics buckets.

* Merge branch 'unstable' into peerdas-kzg

* Update KZG version to fix windows mem allocation.

* Refactor common logic from build sidecar and reconstruction. Remove unnecessary `needless_lifetimes`.

Co-authored-by: realbigsean <sean@sigmaprime.io>

* Copy existing trusted setup into `PeerDASTrustedSetup` for consistency and maintain `--trusted-setup` functionality.

* Merge branch 'unstable' into peerdas-kzg

* Merge branch 'peerdas-kzg' of github.com:jimmygchen/lighthouse into peerdas-kzg

* Merge branch 'unstable' into peerdas-kzg

* Merge branch 'unstable' into peerdas-kzg

* Load PeerDAS KZG only if PeerDAS is enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
das Data Availability Sampling das-unstable-merge ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants