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

Implement PeerDAS #14129

Draft
wants to merge 83 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
5e55834
Add in column sidecars protos (#13862)
nalepae Jul 17, 2024
aef68db
add it (#13865)
nisdas Apr 11, 2024
ac905f6
add in networking params (#13866)
nisdas Apr 11, 2024
dee92e5
Add Support For Discovery Of Column Subnets (#13883)
nisdas Apr 17, 2024
ab917ba
Add Data Column Gossip Handlers (#13894)
nisdas Apr 22, 2024
ee2d0f4
Add Request And Response RPC Methods For Data Columns (#13909)
nisdas Apr 24, 2024
bb70e1a
Peer das core (#13877)
nalepae Apr 24, 2024
325a5b0
Implement `custody_subnet_count` ENR field. (#13915)
nalepae Apr 24, 2024
b891d58
Update .bazelrc (#13931)
nisdas Apr 29, 2024
a574b87
Implement peer DAS proposer RPC (#13922)
nalepae Apr 30, 2024
4b2d7bb
Add DA Check For Data Columns (#13938)
nisdas May 2, 2024
004f913
Spectests (#13940)
nalepae May 2, 2024
a50d7aa
`SendDataColumnSidecarByRoot`: Return `RODataColumn` instead of `ROBl…
nalepae May 7, 2024
9802e50
[PeerDAS] Upgrade c-kzg-4844 package (#13967)
jtraglia May 9, 2024
b622e22
Enable E2E For PeerDAS (#13945)
nisdas May 13, 2024
8bf9481
Implement Data Columns By Range Request And Response Methods (#13972)
nisdas May 14, 2024
cf42d6c
Sample from peers some data columns. (#13980)
nalepae May 15, 2024
f5acce7
Set Custody Count Correctly (#14004)
nisdas May 16, 2024
5072f2d
Fix beacon chain config. (#14017)
nalepae May 17, 2024
3ddcbe6
Fix `CustodyColumns` to comply with alpha-2 spectests. (#14008)
nalepae May 17, 2024
6fd443a
Request Data Columns When Fetching Pending Blocks (#14007)
nisdas May 17, 2024
904b782
Disable Evaluators For E2E (#14019)
nisdas May 17, 2024
4f80111
Fix Custody Columns (#14021)
nisdas May 17, 2024
5615f09
PeerDAS: Implement reconstruction. (#14036)
nalepae May 29, 2024
e7f4807
PeerDAS: Implement / use data column feed from database. (#14062)
nalepae Jun 4, 2024
d72ce70
PeerDAS: Withhold data on purpose. (#14076)
nalepae Jun 4, 2024
b431acd
`recoverBlobs`: Cover the `0 < blobsCount < fieldparams.MaxBlobsPerBl…
nalepae Jun 4, 2024
87152c0
PeerDAS: Only saved custodied columns even after reconstruction. (#14…
nalepae Jun 6, 2024
96f57c3
PeerDAS: Gossip the reconstructed columns (#14079)
nalepae Jun 6, 2024
5ae7885
PeerDAS: Stop generating new P2P private key at start. (#14099)
nalepae Jun 12, 2024
bae92a7
[PeerDAS] rework ENR custody_subnet_count and add tests (#14077)
0x00101010 Jun 12, 2024
68e25dd
[PeerDAS] fixes and tests for gossiping out data columns (#14102)
0x00101010 Jun 13, 2024
cf90fae
[PeerDAS] implement DataColumnSidecarsByRootReq and fix related bugs …
0x00101010 Jun 14, 2024
9cf8cfc
Fix columns sampling (#14118)
nalepae Jun 18, 2024
b5c798b
[PeerDAS] rework ENR custody_subnet_count and add tests (#14077)
0x00101010 Jun 20, 2024
bbf8abe
PeerDAS: add data column batch config (#14122)
0x00101010 Jun 21, 2024
66a37a6
PeerDAS: Implement IncrementalDAS (#14109)
nalepae Jun 21, 2024
eb5c5e0
chore: Encapsulate all kzg functionality for PeerDAS into the kzg pac…
kevaundray Jul 3, 2024
6b18fb8
chore!: Refactor `RecoverBlob` to `RecoverCellsAndProofs` (#14160)
kevaundray Jul 3, 2024
d20e441
Activate PeerDAS with the EIP7594 Fork Epoch (#14184)
nisdas Jul 8, 2024
9100fe7
Move log from error to debug. (#14194)
nalepae Jul 8, 2024
1cd0555
chore!: Make Cell be a flat sequence of bytes (#14159)
kevaundray Jul 9, 2024
8a218d7
PeerDAS: Add KZG verification when sampling (#14187)
nalepae Jul 9, 2024
a11636a
Trigger PeerDAS At Deneb For E2E (#14193)
nisdas Jul 9, 2024
2ef0725
chore!: Use `RecoverCellsAndKZGProofs` instead of `RecoverAllCells ` …
kevaundray Jul 9, 2024
1d83f33
[PeerDAS] Parallelize data column sampling (#14105)
0x00101010 Jul 16, 2024
e59d059
Implement and use `filterPeerForDataColumnsSubnet`. (#14230)
nalepae Jul 17, 2024
f58c309
Add Current Changes (#14231)
nisdas Jul 17, 2024
18c1f8f
Update ckzg4844 to latest version of das branch (#14223)
jtraglia Jul 17, 2024
aa658e0
PeerDAS: Run reconstruction in parallel. (#14236)
nalepae Jul 18, 2024
bf0342a
Make deepsource happy (#14237)
nalepae Jul 19, 2024
68721e8
PeerDAS: Fix initial sync (#14208)
nalepae Jul 25, 2024
9ae8492
Fix data columns sampling (#14263)
nalepae Jul 29, 2024
8c5dac1
PeerDAS: Add `MetadataV3` with `custody_subnet_count` (#14274)
nalepae Aug 5, 2024
75f06f4
Add Data Column Verification (#14287)
nisdas Aug 12, 2024
afc69af
Implement `/eth/v1/beacon/blob_sidecars/{block_id}` for peerDAS. (#14…
nalepae Aug 14, 2024
1304eb8
Fix CI in PeerDAS (#14347)
nisdas Aug 15, 2024
edae704
Update Config To Latest Value (#14352)
nisdas Aug 22, 2024
b14e269
Use Data Column Validation Across Prysm (#14377)
nisdas Aug 26, 2024
b242f40
Change Custody Count to Uint8 (#14386)
nisdas Aug 27, 2024
a7ee0e7
Fix Bugs in PeerDAS Testing (#14396)
nisdas Aug 29, 2024
155ac62
PeerDAS: Improve logging and reduce the number of needed goroutines f…
nalepae Aug 29, 2024
bbac508
Set Precompute at 8 (#14399)
nisdas Aug 30, 2024
f1d49a9
Add Data Column Computation Metrics (#14400)
nisdas Aug 30, 2024
d4b3a65
Fix Initial Sync with 128 data columns subnets (#14403)
nalepae Sep 3, 2024
db424df
Revert "Change Custody Count to Uint8 (#14386)" (#14415)
nisdas Sep 4, 2024
4bf2c27
Fix CPU usage in small devnets (#14446)
nalepae Sep 13, 2024
6b1b04e
Peerdas: Full subnet sampling and `sendBatchRootRequest` fix. (#14452)
nalepae Sep 18, 2024
5ca87d5
Peerdas: Several updates (#14459)
nalepae Sep 19, 2024
4675f9e
Update c-kzg-4844 to v2.0.1 (#14421)
jtraglia Sep 20, 2024
d9a1f96
PeerDAS: Multiple improvements (#14467)
nalepae Sep 23, 2024
4d3e389
PeerDAS: Re-enable full node joining the main fork (#14475)
nalepae Sep 24, 2024
a62d616
PeerDAS: Misc improvements (#14482)
nalepae Sep 26, 2024
1d9c41f
Stop disconnecting peers for bad response / excessive colocation. (#1…
nalepae Sep 26, 2024
679737b
Put Subscriber in Goroutine (#14486)
nisdas Sep 27, 2024
190a27a
PeerDAS: Fix initial sync (#14494)
nalepae Oct 1, 2024
f61938c
PeerDAS: Fix initial sync with super nodes (#14495)
nalepae Oct 1, 2024
6535ace
PeerDAS: Improve initial sync logs (#14496)
nalepae Oct 2, 2024
9ecf085
Fix Commitments Check (#14493)
nisdas Oct 4, 2024
9c67a71
Data columns initial sync: Rework. (#14522)
nalepae Oct 15, 2024
dfdb265
PeerDAS: Fix major bug in `dataColumnSidecarsByRangeRPCHandler` and a…
nalepae Oct 16, 2024
083f59b
`streamDataColumnBatch`: Sort columns by index. (#14542)
nalepae Oct 16, 2024
2ab8c3b
PeerDAS: Batch columns verifications (#14559)
nalepae Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ coverage --define=coverage_enabled=1
build --workspace_status_command=./hack/workspace_status.sh

build --define blst_disabled=false
build --compilation_mode=opt
run --define blst_disabled=false

build:blst_disabled --define blst_disabled=true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Golangci-lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.55.2
version: v1.56.1
args: --config=.golangci.yml --out-${NO_FUTURE}format colored-line-number

build:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ linters:
- promlinter
- protogetter
- revive
- spancheck
- staticcheck
- stylecheck
- tagalign
Expand Down
3 changes: 3 additions & 0 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go_library(
"receive_attestation.go",
"receive_blob.go",
"receive_block.go",
"receive_data_column.go",
"service.go",
"tracked_proposer.go",
"weak_subjectivity_checks.go",
Expand All @@ -48,6 +49,7 @@ go_library(
"//beacon-chain/core/feed/state:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/light-client:go_default_library",
"//beacon-chain/core/peerdas:go_default_library",
"//beacon-chain/core/signing:go_default_library",
"//beacon-chain/core/time:go_default_library",
"//beacon-chain/core/transition:go_default_library",
Expand Down Expand Up @@ -157,6 +159,7 @@ go_test(
"//beacon-chain/operations/slashings:go_default_library",
"//beacon-chain/operations/voluntaryexits:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/startup:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/blockchain/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
)

var errMaxBlobsExceeded = errors.New("Expected commitments in block exceeds MAX_BLOBS_PER_BLOCK")
var errMaxDataColumnsExceeded = errors.New("Expected data columns for node exceeds NUMBER_OF_COLUMNS")

// An invalid block is the block that fails state transition based on the core protocol rules.
// The beacon node shall not be accepting nor building blocks that branch off from an invalid block.
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/blockchain/kzg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"kzg.go",
"trusted_setup.go",
"validation.go",
],
Expand All @@ -12,6 +13,9 @@ go_library(
deps = [
"//consensus-types/blocks:go_default_library",
"@com_github_crate_crypto_go_kzg_4844//:go_default_library",
"@com_github_ethereum_c_kzg_4844//bindings/go:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_ethereum_go_ethereum//crypto/kzg4844:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
Expand Down
109 changes: 109 additions & 0 deletions beacon-chain/blockchain/kzg/kzg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package kzg

import (
"errors"

ckzg4844 "github.com/ethereum/c-kzg-4844/v2/bindings/go"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
)

// BytesPerBlob is the number of bytes in a single blob.
const BytesPerBlob = ckzg4844.BytesPerBlob

// Blob represents a serialized chunk of data.
type Blob [BytesPerBlob]byte

// BytesPerCell is the number of bytes in a single cell.
const BytesPerCell = ckzg4844.BytesPerCell

// Cell represents a chunk of an encoded Blob.
type Cell [BytesPerCell]byte

// Commitment represent a KZG commitment to a Blob.
type Commitment [48]byte

// Proof represents a KZG proof that attests to the validity of a Blob or parts of it.
type Proof [48]byte

// Bytes48 is a 48-byte array.
type Bytes48 = ckzg4844.Bytes48

// Bytes32 is a 32-byte array.
type Bytes32 = ckzg4844.Bytes32

// CellsAndProofs represents the Cells and Proofs corresponding to
// a single blob.
type CellsAndProofs struct {
Cells []Cell
Proofs []Proof
}

func BlobToKZGCommitment(blob *Blob) (Commitment, error) {
comm, err := kzg4844.BlobToCommitment(kzg4844.Blob(*blob))
if err != nil {
return Commitment{}, err
}
return Commitment(comm), nil
}

func ComputeBlobKZGProof(blob *Blob, commitment Commitment) (Proof, error) {
proof, err := kzg4844.ComputeBlobProof(kzg4844.Blob(*blob), kzg4844.Commitment(commitment))
if err != nil {
return [48]byte{}, err
}
return Proof(proof), nil
}

func ComputeCellsAndKZGProofs(blob *Blob) (CellsAndProofs, error) {
ckzgBlob := (*ckzg4844.Blob)(blob)
ckzgCells, ckzgProofs, err := ckzg4844.ComputeCellsAndKZGProofs(ckzgBlob)
if err != nil {
return CellsAndProofs{}, err
}

return makeCellsAndProofs(ckzgCells[:], ckzgProofs[:])
}

func VerifyCellKZGProofBatch(commitmentsBytes []Bytes48, cellIndices []uint64, cells []Cell, proofsBytes []Bytes48) (bool, error) {
// Convert `Cell` type to `ckzg4844.Cell`
ckzgCells := make([]ckzg4844.Cell, len(cells))
for i := range cells {
ckzgCells[i] = ckzg4844.Cell(cells[i])
}

return ckzg4844.VerifyCellKZGProofBatch(commitmentsBytes, cellIndices, ckzgCells, proofsBytes)
}

func RecoverCellsAndKZGProofs(cellIndices []uint64, partialCells []Cell) (CellsAndProofs, error) {
// Convert `Cell` type to `ckzg4844.Cell`
ckzgPartialCells := make([]ckzg4844.Cell, len(partialCells))
for i := range partialCells {
ckzgPartialCells[i] = ckzg4844.Cell(partialCells[i])
}

ckzgCells, ckzgProofs, err := ckzg4844.RecoverCellsAndKZGProofs(cellIndices, ckzgPartialCells)
if err != nil {
return CellsAndProofs{}, err
}

return makeCellsAndProofs(ckzgCells[:], ckzgProofs[:])
}

// Convert cells/proofs to the CellsAndProofs type defined in this package.
func makeCellsAndProofs(ckzgCells []ckzg4844.Cell, ckzgProofs []ckzg4844.KZGProof) (CellsAndProofs, error) {
if len(ckzgCells) != len(ckzgProofs) {
return CellsAndProofs{}, errors.New("different number of cells/proofs")
}

var cells []Cell
var proofs []Proof
for i := range ckzgCells {
cells = append(cells, Cell(ckzgCells[i]))
proofs = append(proofs, Proof(ckzgProofs[i]))
}

return CellsAndProofs{
Cells: cells,
Proofs: proofs,
}, nil
}
44 changes: 41 additions & 3 deletions beacon-chain/blockchain/kzg/trusted_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,62 @@ import (
"encoding/json"

GoKZG "github.com/crate-crypto/go-kzg-4844"
CKZG "github.com/ethereum/c-kzg-4844/v2/bindings/go"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
)

var (
//go:embed trusted_setup.json
embeddedTrustedSetup []byte // 1.2Mb
kzgContext *GoKZG.Context
kzgLoaded bool
)

type TrustedSetup struct {
G1Monomial [GoKZG.ScalarsPerBlob]GoKZG.G1CompressedHexStr `json:"g1_monomial"`
G1Lagrange [GoKZG.ScalarsPerBlob]GoKZG.G1CompressedHexStr `json:"g1_lagrange"`
G2Monomial [65]GoKZG.G2CompressedHexStr `json:"g2_monomial"`
}

func Start() error {
parsedSetup := GoKZG.JSONTrustedSetup{}
err := json.Unmarshal(embeddedTrustedSetup, &parsedSetup)
trustedSetup := &TrustedSetup{}
err := json.Unmarshal(embeddedTrustedSetup, trustedSetup)
if err != nil {
return errors.Wrap(err, "could not parse trusted setup JSON")
}
kzgContext, err = GoKZG.NewContext4096(&parsedSetup)
kzgContext, err = GoKZG.NewContext4096(&GoKZG.JSONTrustedSetup{
SetupG2: trustedSetup.G2Monomial[:],
SetupG1Lagrange: trustedSetup.G1Lagrange})
if err != nil {
return errors.Wrap(err, "could not initialize go-kzg context")
}

// Length of a G1 point, converted from hex to binary.
g1MonomialBytes := make([]byte, len(trustedSetup.G1Monomial)*(len(trustedSetup.G1Monomial[0])-2)/2)
for i, g1 := range &trustedSetup.G1Monomial {
copy(g1MonomialBytes[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
}
// Length of a G1 point, converted from hex to binary.
g1LagrangeBytes := make([]byte, len(trustedSetup.G1Lagrange)*(len(trustedSetup.G1Lagrange[0])-2)/2)
for i, g1 := range &trustedSetup.G1Lagrange {
copy(g1LagrangeBytes[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
}
// Length of a G2 point, converted from hex to binary.
g2MonomialBytes := make([]byte, len(trustedSetup.G2Monomial)*(len(trustedSetup.G2Monomial[0])-2)/2)
for i, g2 := range &trustedSetup.G2Monomial {
copy(g2MonomialBytes[i*(len(g2)-2)/2:], hexutil.MustDecode(g2))
}
if !kzgLoaded {
// TODO: Provide a configuration option for this.
var precompute uint = 8

// Free the current trusted setup before running this method. CKZG
// panics if the same setup is run multiple times.
if err = CKZG.LoadTrustedSetup(g1MonomialBytes, g1LagrangeBytes, g2MonomialBytes, precompute); err != nil {
panic(err)
}
}
kzgLoaded = true
return nil
}
Loading
Loading