-
Notifications
You must be signed in to change notification settings - Fork 962
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc9f63f
commit 3dd915b
Showing
15 changed files
with
315 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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.