Skip to content

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

Merged
mergify[bot] merged 12 commits into
sigp:unstablefrom
jimmygchen:peerdas-kzg
Aug 13, 2024
Merged

Add PeerDAS KZG lib integration (construction & KZG verification)#6212
mergify[bot] merged 12 commits into
sigp:unstablefrom
jimmygchen:peerdas-kzg

Conversation

@jimmygchen

@jimmygchen jimmygchen commented Aug 1, 2024

Copy link
Copy Markdown
Member

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

@dapplion dapplion left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread beacon_node/beacon_chain/src/metrics.rs
@jimmygchen

Copy link
Copy Markdown
Member Author

I'm looking into the windows CI failure.

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

Copy link
Copy Markdown
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

@jimmygchen jimmygchen Aug 6, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

@jimmygchen jimmygchen Aug 7, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread beacon_node/beacon_chain/src/kzg_utils.rs Outdated
Comment thread beacon_node/beacon_chain/src/kzg_utils.rs Outdated
Comment thread beacon_node/beacon_chain/src/kzg_utils.rs
@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 requested a review from realbigsean August 7, 2024 12:56
@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
Comment thread crypto/kzg/src/lib.rs Outdated
#[derive(Debug)]
pub struct Kzg {
trusted_setup: KzgSettings,
context: DASContext,

Copy link
Copy Markdown
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
Copy Markdown
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

@dapplion dapplion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@dapplion dapplion requested a review from pawanjay176 August 12, 2024 13:47
@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
Copy Markdown
Member Author

@mergify queue

@mergify

mergify Bot commented Aug 12, 2024

Copy link
Copy Markdown

queue

✅ The pull request has been merged automatically

Details

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
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