-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Validate blobs feature #12574
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
Merged
Merged
Validate blobs feature #12574
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| load("@prysm//tools/go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = [ | ||
| "trusted_setup.go", | ||
| "validation.go", | ||
| ], | ||
| embedsrcs = ["trusted_setup.json"], | ||
| importpath = "github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain/kzg", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//proto/prysm/v1alpha1:go_default_library", | ||
| "@com_github_crate_crypto_go_kzg_4844//:go_default_library", | ||
| "@com_github_pkg_errors//:go_default_library", | ||
| ], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = [ | ||
| "trusted_setup_test.go", | ||
| "validation_test.go", | ||
| ], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "//proto/prysm/v1alpha1:go_default_library", | ||
| "//testing/require:go_default_library", | ||
| "@com_github_crate_crypto_go_kzg_4844//:go_default_library", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package kzg | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "encoding/json" | ||
|
|
||
| GoKZG "github.com/crate-crypto/go-kzg-4844" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| var ( | ||
| //go:embed trusted_setup.json | ||
| embeddedTrustedSetup []byte // 1.2Mb | ||
| kzgContext *GoKZG.Context | ||
| ) | ||
|
|
||
| func Start() error { | ||
| parsedSetup := GoKZG.JSONTrustedSetup{} | ||
| err := json.Unmarshal(embeddedTrustedSetup, &parsedSetup) | ||
| if err != nil { | ||
| return errors.Wrap(err, "could not parse trusted setup JSON") | ||
| } | ||
| kzgContext, err = GoKZG.NewContext4096(&parsedSetup) | ||
| if err != nil { | ||
| return errors.Wrap(err, "could not initialize go-kzg context") | ||
| } | ||
| return nil | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package kzg | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prysmaticlabs/prysm/v4/testing/require" | ||
| ) | ||
|
|
||
| func TestStart(t *testing.T) { | ||
| require.NoError(t, Start()) | ||
| require.NotNil(t, kzgContext) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package kzg | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| GoKZG "github.com/crate-crypto/go-kzg-4844" | ||
| ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" | ||
| ) | ||
|
|
||
| // IsDataAvailable checks that | ||
| // - all blobs in the block are available | ||
| // - Expected KZG commitments match the number of blobs in the block | ||
| // - That the number of proofs match the number of blobs | ||
| // - That the proofs are verified against the KZG commitments | ||
| func IsDataAvailable(commitments [][]byte, sidecars []*ethpb.BlobSidecar) error { | ||
| if len(commitments) != len(sidecars) { | ||
| return fmt.Errorf("could not check data availability, expected %d commitments, obtained %d", | ||
| len(commitments), len(sidecars)) | ||
| } | ||
| if len(commitments) == 0 { | ||
| return nil | ||
| } | ||
| blobs := make([]GoKZG.Blob, len(commitments)) | ||
| proofs := make([]GoKZG.KZGProof, len(commitments)) | ||
| cmts := make([]GoKZG.KZGCommitment, len(commitments)) | ||
| for i, sidecar := range sidecars { | ||
| blobs[i] = bytesToBlob(sidecar.Blob) | ||
| proofs[i] = bytesToKZGProof(sidecar.KzgProof) | ||
| cmts[i] = bytesToCommitment(commitments[i]) | ||
| } | ||
| return kzgContext.VerifyBlobKZGProofBatch(blobs, cmts, proofs) | ||
| } | ||
|
|
||
| func bytesToBlob(blob []byte) (ret GoKZG.Blob) { | ||
| copy(ret[:], blob) | ||
| return | ||
| } | ||
|
|
||
| func bytesToCommitment(commitment []byte) (ret GoKZG.KZGCommitment) { | ||
| copy(ret[:], commitment) | ||
| return | ||
| } | ||
|
|
||
| func bytesToKZGProof(proof []byte) (ret GoKZG.KZGProof) { | ||
| copy(ret[:], proof) | ||
| return | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package kzg | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| GoKZG "github.com/crate-crypto/go-kzg-4844" | ||
| ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" | ||
| "github.com/prysmaticlabs/prysm/v4/testing/require" | ||
| ) | ||
|
|
||
| func TestIsDataAvailable(t *testing.T) { | ||
| sidecars := make([]*ethpb.BlobSidecar, 0) | ||
| commitments := make([][]byte, 0) | ||
| require.NoError(t, IsDataAvailable(commitments, sidecars)) | ||
| } | ||
|
|
||
| func TestBytesToAny(t *testing.T) { | ||
| bytes := []byte{0x01, 0x02} | ||
| blob := GoKZG.Blob{0x01, 0x02} | ||
| commitment := GoKZG.KZGCommitment{0x01, 0x02} | ||
| proof := GoKZG.KZGProof{0x01, 0x02} | ||
| require.DeepEqual(t, blob, bytesToBlob(bytes)) | ||
| require.DeepEqual(t, commitment, bytesToCommitment(bytes)) | ||
| require.DeepEqual(t, proof, bytesToKZGProof(bytes)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| load("@prysm//tools/go:def.bzl", "go_test") | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| size = "small", | ||
| srcs = ["verify_blob_kzg_proof_batch_test.go"], | ||
| data = [ | ||
| "@consensus_spec_tests_general//:test_data", | ||
| ], | ||
| tags = ["spectest"], | ||
| deps = [ | ||
| "//beacon-chain/blockchain/kzg:go_default_library", | ||
| "//proto/prysm/v1alpha1:go_default_library", | ||
| "//testing/require:go_default_library", | ||
| "//testing/spectest/utils:go_default_library", | ||
| "//testing/util:go_default_library", | ||
| "@com_github_ghodss_yaml//:go_default_library", | ||
| ], | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the sidecars haven't arrived or one of them is missing at this point? What can information can I provide you from sync service or db service to get you to make the right move (wait)