-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable E2E And Add Fixes * Register Same Topic For Data Columns * Initialize Capacity Of Slice * Fix Initialization of Data Column Receiver * Remove Mix In From Merkle Proof * E2E: Subscribe to all subnets. * Remove Index Check * Remaining Bug Fixes to Get It Working * Change Evaluator to Allow Test to Finish * Fix Build * Add Data Column Verification * Fix LoopVar Bug * Do Not Allocate Memory * Update beacon-chain/blockchain/process_block.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update beacon-chain/core/peerdas/helpers.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update beacon-chain/core/peerdas/helpers.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Gofmt * Fix It Again * Fix Test Setup * Fix Build * Fix Trusted Setup panic * Fix Trusted Setup panic * Use New Test --------- Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com>
- Loading branch information
Showing
22 changed files
with
297 additions
and
45 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
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,91 @@ | ||
package peerdas_test | ||
|
||
import ( | ||
"bytes" | ||
"crypto/sha256" | ||
"encoding/binary" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr" | ||
GoKZG "github.com/crate-crypto/go-kzg-4844" | ||
ckzg4844 "github.com/ethereum/c-kzg-4844/bindings/go" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/kzg" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func deterministicRandomness(seed int64) [32]byte { | ||
// Converts an int64 to a byte slice | ||
buf := new(bytes.Buffer) | ||
err := binary.Write(buf, binary.BigEndian, seed) | ||
if err != nil { | ||
logrus.WithError(err).Error("Failed to write int64 to bytes buffer") | ||
return [32]byte{} | ||
} | ||
bytes := buf.Bytes() | ||
|
||
return sha256.Sum256(bytes) | ||
} | ||
|
||
// Returns a serialized random field element in big-endian | ||
func GetRandFieldElement(seed int64) [32]byte { | ||
bytes := deterministicRandomness(seed) | ||
var r fr.Element | ||
r.SetBytes(bytes[:]) | ||
|
||
return GoKZG.SerializeScalar(r) | ||
} | ||
|
||
// Returns a random blob using the passed seed as entropy | ||
func GetRandBlob(seed int64) ckzg4844.Blob { | ||
var blob ckzg4844.Blob | ||
bytesPerBlob := GoKZG.ScalarsPerBlob * GoKZG.SerializedScalarSize | ||
for i := 0; i < bytesPerBlob; i += GoKZG.SerializedScalarSize { | ||
fieldElementBytes := GetRandFieldElement(seed + int64(i)) | ||
copy(blob[i:i+GoKZG.SerializedScalarSize], fieldElementBytes[:]) | ||
} | ||
return blob | ||
} | ||
|
||
func GenerateCommitmentAndProof(blob ckzg4844.Blob) (ckzg4844.KZGCommitment, ckzg4844.KZGProof, error) { | ||
commitment, err := ckzg4844.BlobToKZGCommitment(&blob) | ||
if err != nil { | ||
return ckzg4844.KZGCommitment{}, ckzg4844.KZGProof{}, err | ||
} | ||
proof, err := ckzg4844.ComputeBlobKZGProof(&blob, ckzg4844.Bytes48(commitment)) | ||
if err != nil { | ||
return ckzg4844.KZGCommitment{}, ckzg4844.KZGProof{}, err | ||
} | ||
return commitment, proof, err | ||
} | ||
|
||
func TestVerifyDataColumnSidecarKZGProofs(t *testing.T) { | ||
dbBlock := util.NewBeaconBlockDeneb() | ||
require.NoError(t, kzg.Start()) | ||
|
||
comms := [][]byte{} | ||
blobs := []ckzg4844.Blob{} | ||
for i := int64(0); i < 6; i++ { | ||
blob := GetRandBlob(i) | ||
commitment, _, err := GenerateCommitmentAndProof(blob) | ||
require.NoError(t, err) | ||
comms = append(comms, commitment[:]) | ||
blobs = append(blobs, blob) | ||
} | ||
|
||
dbBlock.Block.Body.BlobKzgCommitments = comms | ||
sBlock, err := blocks.NewSignedBeaconBlock(dbBlock) | ||
require.NoError(t, err) | ||
sCars, err := peerdas.DataColumnSidecars(sBlock, blobs) | ||
require.NoError(t, err) | ||
|
||
for i, sidecar := range sCars { | ||
verified, err := peerdas.VerifyDataColumnSidecarKZGProofs(sidecar) | ||
require.NoError(t, err) | ||
require.Equal(t, true, verified, fmt.Sprintf("sidecar %d failed", i)) | ||
} | ||
} |
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
Oops, something went wrong.