Skip to content

Commit 7da7019

Browse files
PeerDAS: Implement core. (#15192)
* Fulu: Implement params. * KZG tests: Re-implement `getRandBlob` to avoid tests cyclical dependencies. Not ideal, but any better idea welcome. * Fulu testing util: Implement `GenerateCellsAndProofs`. * Create `RODataColumn`. * Implement `MerkleProofKZGCommitments`. * Export `leavesFromCommitments`. * Implement peerDAS core. * Add changelog. * Update beacon-chain/core/peerdas/das_core.go Co-authored-by: terence <terence@prysmaticlabs.com> * Fix Terence's comment: Use `IsNil`. * Fix Terence's comment: Avoid useless `filteredIndices`. * Fix Terence's comment: Simplify odd/even cases. * Fix Terence's comment: Use `IsNil`. * Spectests: Add Fulu networking * Fix Terence's comment: `CustodyGroups`: Stick to the spec by returning a (sorted) slice. * Fix Terence's comment: `CustodyGroups`: Handle correctly the `maxUint256` case. * Update beacon-chain/core/peerdas/das_core.go Co-authored-by: terence <terence@prysmaticlabs.com> * Fix Terence's comment: `ComputeColumnsForCustodyGroup`: Add test if `custodyGroup == numberOfCustodyGroup` * `CustodyGroups`: Test if `custodyGroupCount > numberOfCustodyGroup`. * `CustodyGroups`: Add a shortcut if all custody groups are needed. * `ComputeCystodyGroupForColumn`: Move from `p2p_interface.go` to `das_core.go`. * Fix Terence's comment: Fix `ComputeCustodyGroupForColumn`. * Fix Terence's comment: Remove `constructCellsAndProofs` function. * Fix Terence's comment: `ValidatorsCustodyRequirement`: Use effective balance instead of balance. * `MerkleProofKZGCommitments`: Add tests * Remove peer sampling. * `DataColumnSidecars`: Add missing tests. * Fix Jame's comment. * Fix James' comment. * Fix James' comment. * Fix James' coment. * Fix James' comment. --------- Co-authored-by: terence <terence@prysmaticlabs.com>
1 parent 24cf930 commit 7da7019

39 files changed

+2517
-47
lines changed

beacon-chain/blockchain/kzg/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ go_test(
3030
deps = [
3131
"//consensus-types/blocks:go_default_library",
3232
"//testing/require:go_default_library",
33-
"//testing/util:go_default_library",
33+
"@com_github_consensys_gnark_crypto//ecc/bls12-381/fr:go_default_library",
3434
"@com_github_crate_crypto_go_kzg_4844//:go_default_library",
35+
"@com_github_sirupsen_logrus//:go_default_library",
3536
],
3637
)

beacon-chain/blockchain/kzg/validation_test.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package kzg
22

33
import (
4+
"bytes"
5+
"crypto/sha256"
6+
"encoding/binary"
47
"testing"
58

69
"github.com/OffchainLabs/prysm/v6/consensus-types/blocks"
710
"github.com/OffchainLabs/prysm/v6/testing/require"
8-
"github.com/OffchainLabs/prysm/v6/testing/util"
11+
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
912
GoKZG "github.com/crate-crypto/go-kzg-4844"
13+
"github.com/sirupsen/logrus"
1014
)
1115

1216
func GenerateCommitmentAndProof(blob GoKZG.Blob) (GoKZG.KZGCommitment, GoKZG.KZGProof, error) {
@@ -37,11 +41,44 @@ func TestBytesToAny(t *testing.T) {
3741
}
3842

3943
func TestGenerateCommitmentAndProof(t *testing.T) {
40-
blob := util.GetRandBlob(123)
44+
blob := getRandBlob(123)
4145
commitment, proof, err := GenerateCommitmentAndProof(blob)
4246
require.NoError(t, err)
4347
expectedCommitment := GoKZG.KZGCommitment{180, 218, 156, 194, 59, 20, 10, 189, 186, 254, 132, 93, 7, 127, 104, 172, 238, 240, 237, 70, 83, 89, 1, 152, 99, 0, 165, 65, 143, 62, 20, 215, 230, 14, 205, 95, 28, 245, 54, 25, 160, 16, 178, 31, 232, 207, 38, 85}
4448
expectedProof := GoKZG.KZGProof{128, 110, 116, 170, 56, 111, 126, 87, 229, 234, 211, 42, 110, 150, 129, 206, 73, 142, 167, 243, 90, 149, 240, 240, 236, 204, 143, 182, 229, 249, 81, 27, 153, 171, 83, 70, 144, 250, 42, 1, 188, 215, 71, 235, 30, 7, 175, 86}
4549
require.Equal(t, expectedCommitment, commitment)
4650
require.Equal(t, expectedProof, proof)
4751
}
52+
53+
func deterministicRandomness(seed int64) [32]byte {
54+
// Converts an int64 to a byte slice
55+
buf := new(bytes.Buffer)
56+
err := binary.Write(buf, binary.BigEndian, seed)
57+
if err != nil {
58+
logrus.WithError(err).Error("Failed to write int64 to bytes buffer")
59+
return [32]byte{}
60+
}
61+
bytes := buf.Bytes()
62+
63+
return sha256.Sum256(bytes)
64+
}
65+
66+
// Returns a serialized random field element in big-endian
67+
func getRandFieldElement(seed int64) [32]byte {
68+
bytes := deterministicRandomness(seed)
69+
var r fr.Element
70+
r.SetBytes(bytes[:])
71+
72+
return GoKZG.SerializeScalar(r)
73+
}
74+
75+
// Returns a random blob using the passed seed as entropy
76+
func getRandBlob(seed int64) GoKZG.Blob {
77+
var blob GoKZG.Blob
78+
bytesPerBlob := GoKZG.ScalarsPerBlob * GoKZG.SerializedScalarSize
79+
for i := 0; i < bytesPerBlob; i += GoKZG.SerializedScalarSize {
80+
fieldElementBytes := getRandFieldElement(seed + int64(i))
81+
copy(blob[i:i+GoKZG.SerializedScalarSize], fieldElementBytes[:])
82+
}
83+
return blob
84+
}

beacon-chain/core/peerdas/BUILD.bazel

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"das_core.go",
7+
"info.go",
8+
"metrics.go",
9+
"p2p_interface.go",
10+
"reconstruction.go",
11+
"util.go",
12+
"validator.go",
13+
],
14+
importpath = "github.com/OffchainLabs/prysm/v6/beacon-chain/core/peerdas",
15+
visibility = ["//visibility:public"],
16+
deps = [
17+
"//beacon-chain/blockchain/kzg:go_default_library",
18+
"//beacon-chain/state:go_default_library",
19+
"//cmd/beacon-chain/flags:go_default_library",
20+
"//config/fieldparams:go_default_library",
21+
"//config/params:go_default_library",
22+
"//consensus-types/blocks:go_default_library",
23+
"//consensus-types/interfaces:go_default_library",
24+
"//consensus-types/primitives:go_default_library",
25+
"//container/trie:go_default_library",
26+
"//crypto/hash:go_default_library",
27+
"//encoding/bytesutil:go_default_library",
28+
"//proto/prysm/v1alpha1:go_default_library",
29+
"//runtime/version:go_default_library",
30+
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
31+
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
32+
"@com_github_hashicorp_golang_lru//:go_default_library",
33+
"@com_github_holiman_uint256//:go_default_library",
34+
"@com_github_pkg_errors//:go_default_library",
35+
"@com_github_prometheus_client_golang//prometheus:go_default_library",
36+
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
37+
"@org_golang_x_sync//errgroup:go_default_library",
38+
],
39+
)
40+
41+
go_test(
42+
name = "go_default_test",
43+
srcs = [
44+
"das_core_test.go",
45+
"info_test.go",
46+
"p2p_interface_test.go",
47+
"reconstruction_test.go",
48+
"utils_test.go",
49+
"validator_test.go",
50+
],
51+
deps = [
52+
":go_default_library",
53+
"//beacon-chain/blockchain/kzg:go_default_library",
54+
"//beacon-chain/state/state-native:go_default_library",
55+
"//cmd/beacon-chain/flags:go_default_library",
56+
"//config/fieldparams:go_default_library",
57+
"//config/params:go_default_library",
58+
"//consensus-types/blocks:go_default_library",
59+
"//consensus-types/primitives:go_default_library",
60+
"//proto/engine/v1:go_default_library",
61+
"//proto/prysm/v1alpha1:go_default_library",
62+
"//testing/require:go_default_library",
63+
"//testing/util:go_default_library",
64+
"@com_github_consensys_gnark_crypto//ecc/bls12-381/fr:go_default_library",
65+
"@com_github_crate_crypto_go_kzg_4844//:go_default_library",
66+
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
67+
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
68+
"@com_github_pkg_errors//:go_default_library",
69+
"@com_github_sirupsen_logrus//:go_default_library",
70+
],
71+
)

0 commit comments

Comments
 (0)