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

Deneb container changes beacon-chain #7420

Merged
merged 13 commits into from
May 6, 2023
1 change: 1 addition & 0 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ type BeaconChainConfig struct {
DomainApplicationMask [4]byte `yaml:"DOMAIN_APPLICATION_MASK" spec:"true"` // DomainApplicationMask defines the BLS signature domain for application mask.
DomainApplicationBuilder [4]byte // DomainApplicationBuilder defines the BLS signature domain for application builder.
DomainBLSToExecutionChange [4]byte // DomainBLSToExecutionChange defines the BLS signature domain to change withdrawal addresses to ETH1 prefix
DomainBlobSideCar [4]byte `yaml:"DOMAIN_BLOB_SIDECAR" spec:"true"` // DomainBlobSideCar defines the BLS signature domain for blob sidecar verification

// Prysm constants.
GweiPerEth uint64 // GweiPerEth is the amount of gwei corresponding to 1 eth.
Expand Down
5 changes: 4 additions & 1 deletion cl/clparams/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const (
Phase0Version StateVersion = 0
AltairVersion StateVersion = 1
BellatrixVersion StateVersion = 2
CapellaVersion StateVersion = 3 // Unimplemented!
CapellaVersion StateVersion = 3
DenebVersion StateVersion = 4
)

// stringToClVersion converts the string to the current state version.
Expand All @@ -20,6 +21,8 @@ func StringToClVersion(s string) StateVersion {
return BellatrixVersion
case "capella":
return CapellaVersion
case "deneb":
return DenebVersion
default:
panic("unsupported fork version: " + s)
}
Expand Down
8 changes: 4 additions & 4 deletions cl/cltypes/attestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (a *Attestation) DecodeSSZ(buf []byte, version int) error {
var err error
size := uint64(len(buf))
if size < 228 {
return ssz.ErrLowBufferSize
return fmt.Errorf("[Attestation] err: %s", ssz.ErrLowBufferSize)
}

tail := buf
Expand Down Expand Up @@ -385,7 +385,7 @@ func (i *IndexedAttestation) DecodeSSZ(buf []byte, version int) error {
var err error
size := uint64(len(buf))
if size < 228 {
return ssz.ErrLowBufferSize
return fmt.Errorf("[IndexedAttestation] err: %s", ssz.ErrLowBufferSize)
}

i.Data = new(AttestationData)
Expand Down Expand Up @@ -468,7 +468,7 @@ func (a *AttestationData) DecodeSSZ(buf []byte, version int) error {
var err error
size := uint64(len(buf))
if size != uint64(a.EncodingSizeSSZ()) {
return ssz.ErrLowBufferSize
return fmt.Errorf("[AttestationData] err: %s", ssz.ErrLowBufferSize)
}

a.Slot = ssz.UnmarshalUint64SSZ(buf)
Expand Down Expand Up @@ -542,7 +542,7 @@ func (a *PendingAttestation) EncodeSSZ(buf []byte) (dst []byte, err error) {
func (a *PendingAttestation) DecodeSSZ(buf []byte, version int) error {
var err error
if len(buf) < a.EncodingSizeSSZ() {
return ssz.ErrLowBufferSize
return fmt.Errorf("[PendingAttestation] err: %s", ssz.ErrLowBufferSize)
}

tail := buf
Expand Down
56 changes: 42 additions & 14 deletions cl/cltypes/beacon_blob_side_car.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BlobSideCar struct {
Slot Slot
BlockParentRoot libcommon.Hash
ProposerIndex uint64 // validator index
Blob Blob
Blob *Blob
KZGCommitment KZGCommitment
KZGProof KZGProof
}
Expand Down Expand Up @@ -46,7 +46,7 @@ func (b *BlobSideCar) EncodeSSZ(buf []byte) ([]byte, error) {
return buf, nil
}

func (b *BlobSideCar) DecodeSSZ(buf []byte) error {
func (b *BlobSideCar) DecodeSSZ(buf []byte, version int) error {
pos := 0 // current position at the buffer

copy(b.BlockRoot[:], buf[pos:32])
Expand Down Expand Up @@ -79,14 +79,14 @@ func (b *BlobSideCar) EncodingSizeSSZ() int {
return 131_256
}

func (b *BlobSideCar) HashSSZ() (libcommon.Hash, error) {
func (b *BlobSideCar) HashSSZ() ([32]byte, error) {
KZGCommitmentLeave, err := merkle_tree.PublicKeyRoot(b.KZGCommitment)
if err != nil {
return libcommon.Hash{}, err
return [32]byte{}, err
}
KZGProofLeave, err := merkle_tree.PublicKeyRoot(b.KZGProof)
if err != nil {
return libcommon.Hash{}, err
return [32]byte{}, err
}

blobLeave := [][32]byte{}
Expand All @@ -98,7 +98,7 @@ func (b *BlobSideCar) HashSSZ() (libcommon.Hash, error) {

blobRoot, err := merkle_tree.ArraysRoot(blobLeave, 4096)
if err != nil {
return libcommon.Hash{}, err
return [32]byte{}, err
}

return merkle_tree.ArraysRoot([][32]byte{
Expand All @@ -114,7 +114,7 @@ func (b *BlobSideCar) HashSSZ() (libcommon.Hash, error) {
}

type SignedBlobSideCar struct {
Message BlobSideCar
Message *BlobSideCar
Signature [96]byte
}

Expand All @@ -132,9 +132,9 @@ func (b *SignedBlobSideCar) EncodeSSZ(buf []byte) ([]byte, error) {
return buf, nil
}

func (b *SignedBlobSideCar) DecodeSSZ(buf []byte) error {
func (b *SignedBlobSideCar) DecodeSSZ(buf []byte, version int) error {
pos := b.Message.EncodingSizeSSZ()
err := b.Message.DecodeSSZ(buf[:pos])
err := b.Message.DecodeSSZ(buf[:pos], version)
if err != nil {
return err
}
Expand All @@ -147,15 +147,15 @@ func (b *SignedBlobSideCar) EncodingSizeSSZ() int {
return b.Message.EncodingSizeSSZ() + 96
}

func (b *SignedBlobSideCar) HashSSZ() (libcommon.Hash, error) {
func (b *SignedBlobSideCar) HashSSZ() ([32]byte, error) {
messageLeave, err := b.Message.HashSSZ()
if err != nil {
return libcommon.Hash{}, err
return [32]byte{}, err
}

signatureLeave, err := merkle_tree.SignatureRoot(b.Signature)
if err != nil {
return libcommon.Hash{}, err
return [32]byte{}, err
}

return merkle_tree.ArraysRoot([][32]byte{
Expand All @@ -181,7 +181,7 @@ func (b *BlobIdentifier) EncodeSSZ(buf []byte) ([]byte, error) {
return buf, nil
}

func (b *BlobIdentifier) DecodeSSZ(buf []byte) error {
func (b *BlobIdentifier) DecodeSSZ(buf []byte, version int) error {
copy(b.BlockRoot[:], buf[:32])
b.Index = ssz.UnmarshalUint64SSZ(buf[32:])
return nil
Expand All @@ -191,9 +191,37 @@ func (b *BlobIdentifier) EncodingSizeSSZ() int {
return 40
}

func (b *BlobIdentifier) HashSSZ() (libcommon.Hash, error) {
func (b *BlobIdentifier) HashSSZ() ([32]byte, error) {
return merkle_tree.ArraysRoot([][32]byte{
b.BlockRoot,
merkle_tree.Uint64Root(b.Index),
}, 2)
}

type BlobKZGCommitment struct {
Commitment KZGCommitment
}

func (b *BlobKZGCommitment) Copy() *BlobKZGCommitment {
copy := *b
return &copy
}

func (b *BlobKZGCommitment) EncodeSSZ(buf []byte) ([]byte, error) {
buf = append(buf, b.Commitment[:]...)
return buf, nil
}

func (b *BlobKZGCommitment) DecodeSSZ(buf []byte, version int) error {
copy(b.Commitment[:], buf[:])

return nil
}

func (b *BlobKZGCommitment) EncodingSizeSSZ() int {
return 48
}

func (b *BlobKZGCommitment) HashSSZ() ([32]byte, error) {
return merkle_tree.PublicKeyRoot(b.Commitment)
}
17 changes: 9 additions & 8 deletions cl/cltypes/beacon_blob_side_car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/stretchr/testify/assert"
)
Expand All @@ -15,7 +16,7 @@ func TestBlobSideCar_EncodeDecodeSSZ(t *testing.T) {
slot := cltypes.Slot(456)
blockParentRoot := libcommon.Hash{4, 5, 6}
proposerIndex := uint64(789)
blob := cltypes.Blob{}
blob := &cltypes.Blob{1, 2, 3, 4, 5, 6, 7, 8}
kzgCommitment := cltypes.KZGCommitment{7, 8, 9}
kzgProof := cltypes.KZGProof{10, 11, 12}

Expand All @@ -35,8 +36,8 @@ func TestBlobSideCar_EncodeDecodeSSZ(t *testing.T) {
t.Fatal(err)
}

decoded := &cltypes.BlobSideCar{}
err = decoded.DecodeSSZ(encoded)
decoded := &cltypes.BlobSideCar{Blob: &cltypes.Blob{}}
err = decoded.DecodeSSZ(encoded, int(clparams.DenebVersion))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -70,13 +71,13 @@ func TestBlobSideCar_EncodeDecodeSSZ(t *testing.T) {
func TestSignedBlobSideCar(t *testing.T) {
// Create a BlobSideCar to use as the message for SignedBlobSideCar
blob := cltypes.Blob{1, 2, 3, 4, 5, 6, 7, 8}
blobSideCar := cltypes.BlobSideCar{
blobSideCar := &cltypes.BlobSideCar{
BlockRoot: libcommon.Hash{1},
Index: 2,
Slot: 3,
BlockParentRoot: libcommon.Hash{4},
ProposerIndex: 5,
Blob: blob,
Blob: &blob,
KZGCommitment: cltypes.KZGCommitment{6},
KZGProof: cltypes.KZGProof{7},
}
Expand All @@ -93,8 +94,8 @@ func TestSignedBlobSideCar(t *testing.T) {
assert.NoError(t, err)

// Decode the encoded SignedBlobSideCar
decoded := cltypes.SignedBlobSideCar{}
err = decoded.DecodeSSZ(encoded)
decoded := cltypes.SignedBlobSideCar{Message: &cltypes.BlobSideCar{Blob: &cltypes.Blob{}}}
err = decoded.DecodeSSZ(encoded, int(clparams.DenebVersion))
assert.NoError(t, err)

// Assert that the decoded SignedBlobSideCar is equal to the original SignedBlobSideCar
Expand Down Expand Up @@ -126,7 +127,7 @@ func TestBlobIdentifier_EncodeDecodeSSZ(t *testing.T) {

// decode from SSZ
decoded := &cltypes.BlobIdentifier{}
if err := decoded.DecodeSSZ(encoded); err != nil {
if err := decoded.DecodeSSZ(encoded, int(clparams.DenebVersion)); err != nil {
t.Fatalf("DecodeSSZ failed: %v", err)
}

Expand Down
Loading