Skip to content

Commit c014a53

Browse files
committed
Fix errors
1 parent 9f189b7 commit c014a53

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

beacon-chain/blockchain/kzg/BUILD.bazel

+2-1
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

+39-2
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

9+
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
610
GoKZG "github.com/crate-crypto/go-kzg-4844"
711
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
812
"github.com/prysmaticlabs/prysm/v5/testing/require"
9-
"github.com/prysmaticlabs/prysm/v5/testing/util"
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/db/filesystem/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ go_library(
2626
"//consensus-types/primitives:go_default_library",
2727
"//encoding/bytesutil:go_default_library",
2828
"//io/file:go_default_library",
29+
"//proto/prysm/v1alpha1:go_default_library",
2930
"//runtime/logging:go_default_library",
3031
"//time/slots:go_default_library",
3132
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
@@ -49,10 +50,12 @@ go_test(
4950
],
5051
embed = [":go_default_library"],
5152
deps = [
53+
"//beacon-chain/blockchain/kzg:go_default_library",
5254
"//beacon-chain/db:go_default_library",
5355
"//beacon-chain/verification:go_default_library",
5456
"//config/fieldparams:go_default_library",
5557
"//config/params:go_default_library",
58+
"//consensus-types/blocks:go_default_library",
5659
"//consensus-types/primitives:go_default_library",
5760
"//encoding/bytesutil:go_default_library",
5861
"//proto/prysm/v1alpha1:go_default_library",

testing/util/BUILD.bazel

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ go_library(
1919
"electra.go",
2020
"electra_block.go",
2121
"electra_state.go",
22+
"fulu.go",
2223
"helpers.go",
2324
"lightclient.go",
2425
"logging.go",
@@ -31,9 +32,11 @@ go_library(
3132
importpath = "github.com/prysmaticlabs/prysm/v5/testing/util",
3233
visibility = ["//visibility:public"],
3334
deps = [
35+
"//beacon-chain/blockchain/kzg:go_default_library",
3436
"//beacon-chain/core/altair:go_default_library",
3537
"//beacon-chain/core/blocks:go_default_library",
3638
"//beacon-chain/core/helpers:go_default_library",
39+
"//beacon-chain/core/peerdas:go_default_library",
3740
"//beacon-chain/core/signing:go_default_library",
3841
"//beacon-chain/core/time:go_default_library",
3942
"//beacon-chain/core/transition:go_default_library",
@@ -85,12 +88,14 @@ go_test(
8588
"capella_block_test.go",
8689
"deneb_test.go",
8790
"deposits_test.go",
91+
"fulu_test.go",
8892
"helpers_test.go",
8993
"logging_test.go",
9094
"state_test.go",
9195
],
9296
embed = [":go_default_library"],
9397
deps = [
98+
"//beacon-chain/blockchain/kzg:go_default_library",
9499
"//beacon-chain/core/blocks:go_default_library",
95100
"//beacon-chain/core/helpers:go_default_library",
96101
"//beacon-chain/core/signing:go_default_library",

0 commit comments

Comments
 (0)