Fixed size arrays in block interfaces and structs (#11375)

* Fixed size arrays in block fields

* test fix

* fmt

* fix fetcher test

* fix fuzz tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka
2022-09-06 16:30:16 +02:00
committed by GitHub
parent b98e9019ce
commit 4d90afe944
56 changed files with 432 additions and 383 deletions

View File

@@ -182,16 +182,21 @@ func BuildSignedBeaconBlockFromExecutionPayload(
if err != nil {
return nil, errors.Wrap(err, "could not get sync aggregate from block body")
}
parentRoot := b.ParentRoot()
stateRoot := b.StateRoot()
randaoReveal := b.Body().RandaoReveal()
graffiti := b.Body().Graffiti()
sig := blk.Signature()
bellatrixFullBlock := &eth.SignedBeaconBlockBellatrix{
Block: &eth.BeaconBlockBellatrix{
Slot: b.Slot(),
ProposerIndex: b.ProposerIndex(),
ParentRoot: b.ParentRoot(),
StateRoot: b.StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &eth.BeaconBlockBodyBellatrix{
RandaoReveal: b.Body().RandaoReveal(),
RandaoReveal: randaoReveal[:],
Eth1Data: b.Body().Eth1Data(),
Graffiti: b.Body().Graffiti(),
Graffiti: graffiti[:],
ProposerSlashings: b.Body().ProposerSlashings(),
AttesterSlashings: b.Body().AttesterSlashings(),
Attestations: b.Body().Attestations(),
@@ -201,7 +206,7 @@ func BuildSignedBeaconBlockFromExecutionPayload(
ExecutionPayload: payload,
},
},
Signature: blk.Signature(),
Signature: sig[:],
}
return NewSignedBeaconBlock(bellatrixFullBlock)
}

View File

@@ -201,31 +201,31 @@ func Test_NewBeaconBlockBody(t *testing.T) {
}
func Test_BuildSignedBeaconBlock(t *testing.T) {
sig := []byte("signature")
sig := bytesutil.ToBytes96([]byte("signature"))
t.Run("Phase0", func(t *testing.T) {
b := &BeaconBlock{version: version.Phase0, body: &BeaconBlockBody{version: version.Phase0}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Phase0, sb.Version())
})
t.Run("Altair", func(t *testing.T) {
b := &BeaconBlock{version: version.Altair, body: &BeaconBlockBody{version: version.Altair}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Altair, sb.Version())
})
t.Run("Bellatrix", func(t *testing.T) {
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Bellatrix, sb.Version())
})
t.Run("BellatrixBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix, isBlinded: true}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Bellatrix, sb.Version())

View File

@@ -3,6 +3,7 @@ package blocks
import (
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -21,7 +22,7 @@ func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error {
}
// Signature returns the respective block signature.
func (b *SignedBeaconBlock) Signature() []byte {
func (b *SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte {
return b.signature
}
@@ -166,12 +167,12 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot,
StateRoot: b.block.stateRoot,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.block.body.randaoReveal,
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashings,
Attestations: b.block.body.attestations,
@@ -181,7 +182,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
ExecutionPayloadHeader: header,
},
},
Signature: b.signature,
Signature: b.signature[:],
})
}
@@ -208,11 +209,11 @@ func (b *SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) {
Header: &eth.BeaconBlockHeader{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot,
StateRoot: b.block.stateRoot,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
BodyRoot: root[:],
},
Signature: b.signature,
Signature: b.signature[:],
}, nil
}
@@ -349,12 +350,12 @@ func (b *BeaconBlock) ProposerIndex() types.ValidatorIndex {
}
// ParentRoot returns the parent root of beacon block.
func (b *BeaconBlock) ParentRoot() []byte {
func (b *BeaconBlock) ParentRoot() [field_params.RootLength]byte {
return b.parentRoot
}
// StateRoot returns the state root of the beacon block.
func (b *BeaconBlock) StateRoot() []byte {
func (b *BeaconBlock) StateRoot() [field_params.RootLength]byte {
return b.stateRoot
}
@@ -379,10 +380,10 @@ func (b *BeaconBlock) Version() int {
}
// HashTreeRoot returns the ssz root of the block.
func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) {
func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
pb, err := b.Proto()
if err != nil {
return [32]byte{}, err
return [field_params.RootLength]byte{}, err
}
switch b.version {
case version.Phase0:
@@ -395,7 +396,7 @@ func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) {
}
return pb.(*eth.BeaconBlockBellatrix).HashTreeRoot()
default:
return [32]byte{}, errIncorrectBlockVersion
return [field_params.RootLength]byte{}, errIncorrectBlockVersion
}
}
@@ -570,7 +571,7 @@ func (b *BeaconBlockBody) IsNil() bool {
}
// RandaoReveal returns the randao reveal from the block body.
func (b *BeaconBlockBody) RandaoReveal() []byte {
func (b *BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte {
return b.randaoReveal
}
@@ -580,7 +581,7 @@ func (b *BeaconBlockBody) Eth1Data() *eth.Eth1Data {
}
// Graffiti returns the graffiti in the block.
func (b *BeaconBlockBody) Graffiti() []byte {
func (b *BeaconBlockBody) Graffiti() [field_params.RootLength]byte {
return b.graffiti
}
@@ -633,10 +634,10 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
}
// HashTreeRoot returns the ssz root of the block body.
func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) {
pb, err := b.Proto()
if err != nil {
return [32]byte{}, err
return [field_params.RootLength]byte{}, err
}
switch b.version {
case version.Phase0:
@@ -649,6 +650,6 @@ func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
}
return pb.(*eth.BeaconBlockBodyBellatrix).HashTreeRoot()
default:
return [32]byte{}, errIncorrectBodyVersion
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
}
}

View File

@@ -7,6 +7,7 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
@@ -40,8 +41,8 @@ func Test_BeaconBlockIsNil(t *testing.T) {
}
func Test_SignedBeaconBlock_Signature(t *testing.T) {
sb := &SignedBeaconBlock{signature: []byte("signature")}
assert.DeepEqual(t, []byte("signature"), sb.Signature())
sb := &SignedBeaconBlock{signature: bytesutil.ToBytes96([]byte("signature"))}
assert.DeepEqual(t, bytesutil.ToBytes96([]byte("signature")), sb.Signature())
}
func Test_SignedBeaconBlock_Block(t *testing.T) {
@@ -88,12 +89,12 @@ func Test_SignedBeaconBlock_Version(t *testing.T) {
func Test_SignedBeaconBlock_Header(t *testing.T) {
bb := &BeaconBlockBody{
version: version.Phase0,
randaoReveal: make([]byte, 96),
randaoReveal: [96]byte{},
eth1Data: &eth.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
graffiti: make([]byte, 32),
graffiti: [32]byte{},
}
sb := &SignedBeaconBlock{
version: version.Phase0,
@@ -101,19 +102,19 @@ func Test_SignedBeaconBlock_Header(t *testing.T) {
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: []byte("parentroot"),
stateRoot: []byte("stateroot"),
parentRoot: bytesutil.ToBytes32([]byte("parentroot")),
stateRoot: bytesutil.ToBytes32([]byte("stateroot")),
body: bb,
},
signature: []byte("signature"),
signature: bytesutil.ToBytes96([]byte("signature")),
}
h, err := sb.Header()
require.NoError(t, err)
assert.DeepEqual(t, sb.signature, h.Signature)
assert.DeepEqual(t, sb.signature[:], h.Signature)
assert.Equal(t, sb.block.slot, h.Header.Slot)
assert.Equal(t, sb.block.proposerIndex, h.Header.ProposerIndex)
assert.DeepEqual(t, sb.block.parentRoot, h.Header.ParentRoot)
assert.DeepEqual(t, sb.block.stateRoot, h.Header.StateRoot)
assert.DeepEqual(t, sb.block.parentRoot[:], h.Header.ParentRoot)
assert.DeepEqual(t, sb.block.stateRoot[:], h.Header.StateRoot)
expectedHTR, err := bb.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR[:], h.Header.BodyRoot)
@@ -147,13 +148,13 @@ func Test_BeaconBlock_ProposerIndex(t *testing.T) {
}
func Test_BeaconBlock_ParentRoot(t *testing.T) {
b := &BeaconBlock{parentRoot: []byte("parentroot")}
assert.DeepEqual(t, []byte("parentroot"), b.ParentRoot())
b := &BeaconBlock{parentRoot: bytesutil.ToBytes32([]byte("parentroot"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("parentroot")), b.ParentRoot())
}
func Test_BeaconBlock_StateRoot(t *testing.T) {
b := &BeaconBlock{stateRoot: []byte("stateroot")}
assert.DeepEqual(t, []byte("stateroot"), b.StateRoot())
b := &BeaconBlock{stateRoot: bytesutil.ToBytes32([]byte("stateroot"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("stateroot")), b.StateRoot())
}
func Test_BeaconBlock_Body(t *testing.T) {
@@ -255,8 +256,8 @@ func Test_BeaconBlockBody_IsNil(t *testing.T) {
}
func Test_BeaconBlockBody_RandaoReveal(t *testing.T) {
bb := &BeaconBlockBody{randaoReveal: []byte("randaoreveal")}
assert.DeepEqual(t, []byte("randaoreveal"), bb.RandaoReveal())
bb := &BeaconBlockBody{randaoReveal: bytesutil.ToBytes96([]byte("randaoreveal"))}
assert.DeepEqual(t, bytesutil.ToBytes96([]byte("randaoreveal")), bb.RandaoReveal())
}
func Test_BeaconBlockBody_Eth1Data(t *testing.T) {
@@ -266,8 +267,8 @@ func Test_BeaconBlockBody_Eth1Data(t *testing.T) {
}
func Test_BeaconBlockBody_Graffiti(t *testing.T) {
bb := &BeaconBlockBody{graffiti: []byte("graffiti")}
assert.DeepEqual(t, []byte("graffiti"), bb.Graffiti())
bb := &BeaconBlockBody{graffiti: bytesutil.ToBytes32([]byte("graffiti"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("graffiti")), bb.Graffiti())
}
func Test_BeaconBlockBody_ProposerSlashings(t *testing.T) {

View File

@@ -2,6 +2,7 @@ package blocks
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"google.golang.org/protobuf/proto"
@@ -30,7 +31,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlock{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
case version.Altair:
var block *eth.BeaconBlockAltair
@@ -43,7 +44,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlockAltair{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
case version.Bellatrix:
if b.IsBlinded() {
@@ -57,7 +58,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBlindedBeaconBlockBellatrix{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
}
var block *eth.BeaconBlockBellatrix
@@ -70,7 +71,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlockBellatrix{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
default:
return nil, errors.New("unsupported signed beacon block version")
@@ -101,8 +102,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlock{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
case version.Altair:
@@ -117,8 +118,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlockAltair{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
case version.Bellatrix:
@@ -134,8 +135,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BlindedBeaconBlockBellatrix{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
}
@@ -150,8 +151,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlockBellatrix{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
default:
@@ -168,9 +169,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
switch b.version {
case version.Phase0:
return &eth.BeaconBlockBody{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -179,9 +180,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
}, nil
case version.Altair:
return &eth.BeaconBlockBodyAltair{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -192,9 +193,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
case version.Bellatrix:
if b.isBlinded {
return &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -205,9 +206,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
}, nil
}
return &eth.BeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -233,7 +234,7 @@ func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlo
b := &SignedBeaconBlock{
version: version.Phase0,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -250,7 +251,7 @@ func initSignedBlockFromProtoAltair(pb *eth.SignedBeaconBlockAltair) (*SignedBea
b := &SignedBeaconBlock{
version: version.Altair,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -267,7 +268,7 @@ func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*Sig
b := &SignedBeaconBlock{
version: version.Bellatrix,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -284,7 +285,7 @@ func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBe
b := &SignedBeaconBlock{
version: version.Bellatrix,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -302,8 +303,8 @@ func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) {
version: version.Phase0,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -322,8 +323,8 @@ func initBlockFromProtoAltair(pb *eth.BeaconBlockAltair) (*BeaconBlock, error) {
version: version.Altair,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -342,8 +343,8 @@ func initBlockFromProtoBellatrix(pb *eth.BeaconBlockBellatrix) (*BeaconBlock, er
version: version.Bellatrix,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -362,8 +363,8 @@ func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*B
version: version.Bellatrix,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -377,9 +378,9 @@ func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, er
b := &BeaconBlockBody{
version: version.Phase0,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -397,9 +398,9 @@ func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBo
b := &BeaconBlockBody{
version: version.Altair,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -418,9 +419,9 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -440,9 +441,9 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,

View File

@@ -12,11 +12,8 @@ import (
)
type fields struct {
b20 []byte
b32 []byte
b48 []byte
b96 []byte
b256 []byte
root [32]byte
sig [96]byte
deposits []*eth.Deposit
atts []*eth.Attestation
proposerSlashings []*eth.ProposerSlashing
@@ -35,11 +32,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Phase0,
@@ -47,11 +44,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyPhase0(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -69,11 +66,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Altair,
@@ -81,11 +78,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Altair,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyAltair(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -103,11 +100,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Bellatrix,
@@ -115,11 +112,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -137,11 +134,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Bellatrix,
@@ -149,11 +146,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -175,16 +172,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
}
block := &BeaconBlock{
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyPhase0(),
}
@@ -202,16 +199,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
}
block := &BeaconBlock{
version: version.Altair,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyAltair(),
}
@@ -229,16 +226,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
}
block := &BeaconBlock{
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
}
@@ -256,16 +253,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
}
block := &BeaconBlock{
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
}
@@ -343,11 +340,11 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) {
Block: &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoPhase0(expectedBlock)
require.NoError(t, err)
@@ -356,7 +353,7 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initSignedBlockFromProtoAltair(t *testing.T) {
@@ -365,11 +362,11 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) {
Block: &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoAltair(expectedBlock)
require.NoError(t, err)
@@ -378,7 +375,7 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
@@ -387,11 +384,11 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
Block: &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoBellatrix(expectedBlock)
require.NoError(t, err)
@@ -400,7 +397,7 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
@@ -409,11 +406,11 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initBlindedSignedBlockFromProtoBellatrix(expectedBlock)
require.NoError(t, err)
@@ -422,7 +419,7 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlockFromProtoPhase0(t *testing.T) {
@@ -430,8 +427,8 @@ func Test_initBlockFromProtoPhase0(t *testing.T) {
expectedBlock := &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
}
resultBlock, err := initBlockFromProtoPhase0(expectedBlock)
@@ -448,8 +445,8 @@ func Test_initBlockFromProtoAltair(t *testing.T) {
expectedBlock := &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
}
resultBlock, err := initBlockFromProtoAltair(expectedBlock)
@@ -466,8 +463,8 @@ func Test_initBlockFromProtoBellatrix(t *testing.T) {
expectedBlock := &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
}
resultBlock, err := initBlockFromProtoBellatrix(expectedBlock)
@@ -484,8 +481,8 @@ func Test_initBlockFromProtoBlindedBellatrix(t *testing.T) {
expectedBlock := &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
}
resultBlock, err := initBlindedBlockFromProtoBellatrix(expectedBlock)
@@ -544,13 +541,13 @@ func Test_initBlockBodyFromProtoBlindedBellatrix(t *testing.T) {
func bodyPbPhase0() *eth.BeaconBlockBody {
f := getFields()
return &eth.BeaconBlockBody{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -562,13 +559,13 @@ func bodyPbPhase0() *eth.BeaconBlockBody {
func bodyPbAltair() *eth.BeaconBlockBodyAltair {
f := getFields()
return &eth.BeaconBlockBodyAltair{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -581,13 +578,13 @@ func bodyPbAltair() *eth.BeaconBlockBodyAltair {
func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix {
f := getFields()
return &eth.BeaconBlockBodyBellatrix{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -601,13 +598,13 @@ func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix {
func bodyPbBlindedBellatrix() *eth.BlindedBeaconBlockBodyBellatrix {
f := getFields()
return &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -622,13 +619,13 @@ func bodyPhase0() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Phase0,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -641,13 +638,13 @@ func bodyAltair() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Altair,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -661,13 +658,13 @@ func bodyBellatrix() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Bellatrix,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -683,13 +680,13 @@ func bodyBlindedBellatrix() *BeaconBlockBody {
return &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -702,45 +699,45 @@ func bodyBlindedBellatrix() *BeaconBlockBody {
func getFields() fields {
b20 := make([]byte, 20)
b32 := make([]byte, 32)
b48 := make([]byte, 48)
b96 := make([]byte, 96)
b256 := make([]byte, 256)
var root [32]byte
var sig [96]byte
b20[0], b20[5], b20[10] = 'q', 'u', 'x'
b32[0], b32[5], b32[10] = 'f', 'o', 'o'
b48[0], b48[5], b48[10] = 'b', 'a', 'r'
b96[0], b96[5], b96[10] = 'b', 'a', 'z'
b256[0], b256[5], b256[10] = 'x', 'y', 'z'
root[0], root[5], root[10] = 'a', 'b', 'c'
sig[0], sig[5], sig[10] = 'd', 'e', 'f'
deposits := make([]*eth.Deposit, 16)
for i := range deposits {
deposits[i] = &eth.Deposit{}
deposits[i].Proof = make([][]byte, 33)
for j := range deposits[i].Proof {
deposits[i].Proof[j] = b32
deposits[i].Proof[j] = root[:]
}
deposits[i].Data = &eth.Deposit_Data{
PublicKey: b48,
WithdrawalCredentials: b32,
WithdrawalCredentials: root[:],
Amount: 128,
Signature: b96,
Signature: sig[:],
}
}
atts := make([]*eth.Attestation, 128)
for i := range atts {
atts[i] = &eth.Attestation{}
atts[i].Signature = b96
atts[i].Signature = sig[:]
atts[i].AggregationBits = bitfield.NewBitlist(1)
atts[i].Data = &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
}
}
@@ -749,21 +746,21 @@ func getFields() fields {
Header: &eth.BeaconBlockHeader{
Slot: 128,
ProposerIndex: 128,
ParentRoot: b32,
StateRoot: b32,
BodyRoot: b32,
ParentRoot: root[:],
StateRoot: root[:],
BodyRoot: root[:],
},
Signature: b96,
Signature: sig[:],
},
Header_2: &eth.SignedBeaconBlockHeader{
Header: &eth.BeaconBlockHeader{
Slot: 128,
ProposerIndex: 128,
ParentRoot: b32,
StateRoot: b32,
BodyRoot: b32,
ParentRoot: root[:],
StateRoot: root[:],
BodyRoot: root[:],
},
Signature: b96,
Signature: sig[:],
},
}
attesterSlashing := &eth.AttesterSlashing{
@@ -772,34 +769,34 @@ func getFields() fields {
Data: &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
},
Signature: b96,
Signature: sig[:],
},
Attestation_2: &eth.IndexedAttestation{
AttestingIndices: []uint64{1, 2, 8},
Data: &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
},
Signature: b96,
Signature: sig[:],
},
}
voluntaryExit := &eth.SignedVoluntaryExit{
@@ -807,7 +804,7 @@ func getFields() fields {
Epoch: 128,
ValidatorIndex: 128,
},
Signature: b96,
Signature: sig[:],
}
syncCommitteeBits := bitfield.NewBitvector512()
syncCommitteeBits.SetBitAt(1, true)
@@ -815,22 +812,22 @@ func getFields() fields {
syncCommitteeBits.SetBitAt(8, true)
syncAggregate := &eth.SyncAggregate{
SyncCommitteeBits: syncCommitteeBits,
SyncCommitteeSignature: b96,
SyncCommitteeSignature: sig[:],
}
execPayload := &enginev1.ExecutionPayload{
ParentHash: b32,
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: b32,
ReceiptsRoot: b32,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: b32,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: b32,
BaseFeePerGas: b32,
BlockHash: b32,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
Transactions: [][]byte{
[]byte("transaction1"),
[]byte("transaction2"),
@@ -838,28 +835,25 @@ func getFields() fields {
},
}
execPayloadHeader := &enginev1.ExecutionPayloadHeader{
ParentHash: b32,
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: b32,
ReceiptsRoot: b32,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: b32,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: b32,
BaseFeePerGas: b32,
BlockHash: b32,
TransactionsRoot: b32,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
TransactionsRoot: root[:],
}
return fields{
b20: b20,
b32: b32,
b48: b48,
b96: b96,
b256: b256,
root: root,
sig: sig,
deposits: deposits,
atts: atts,
proposerSlashings: []*eth.ProposerSlashing{proposerSlashing},

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/pkg/errors"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
engine "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
@@ -39,9 +40,9 @@ var (
type BeaconBlockBody struct {
version int
isBlinded bool
randaoReveal []byte
randaoReveal [field_params.BLSSignatureLength]byte
eth1Data *eth.Eth1Data
graffiti []byte
graffiti [field_params.RootLength]byte
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
attestations []*eth.Attestation
@@ -57,8 +58,8 @@ type BeaconBlock struct {
version int
slot types.Slot
proposerIndex types.ValidatorIndex
parentRoot []byte
stateRoot []byte
parentRoot [field_params.RootLength]byte
stateRoot [field_params.RootLength]byte
body *BeaconBlockBody
}
@@ -66,7 +67,7 @@ type BeaconBlock struct {
type SignedBeaconBlock struct {
version int
block *BeaconBlock
signature []byte
signature [field_params.BLSSignatureLength]byte
}
func errNotSupported(funcName string, ver int) error {

View File

@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",

View File

@@ -2,6 +2,7 @@ package interfaces
import (
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
@@ -12,7 +13,7 @@ import (
// a signed beacon block.
type SignedBeaconBlock interface {
Block() BeaconBlock
Signature() []byte
Signature() [field_params.BLSSignatureLength]byte
IsNil() bool
Copy() (SignedBeaconBlock, error)
Proto() (proto.Message, error)
@@ -34,12 +35,12 @@ type SignedBeaconBlock interface {
type BeaconBlock interface {
Slot() types.Slot
ProposerIndex() types.ValidatorIndex
ParentRoot() []byte
StateRoot() []byte
ParentRoot() [field_params.RootLength]byte
StateRoot() [field_params.RootLength]byte
Body() BeaconBlockBody
IsNil() bool
IsBlinded() bool
HashTreeRoot() ([32]byte, error)
HashTreeRoot() ([field_params.RootLength]byte, error)
Proto() (proto.Message, error)
ssz.Marshaler
ssz.Unmarshaler
@@ -51,9 +52,9 @@ type BeaconBlock interface {
// BeaconBlockBody describes the method set employed by an object
// that is a beacon block body.
type BeaconBlockBody interface {
RandaoReveal() []byte
RandaoReveal() [field_params.BLSSignatureLength]byte
Eth1Data() *ethpb.Eth1Data
Graffiti() []byte
Graffiti() [field_params.RootLength]byte
ProposerSlashings() []*ethpb.ProposerSlashing
AttesterSlashings() []*ethpb.AttesterSlashing
Attestations() []*ethpb.Attestation
@@ -61,7 +62,7 @@ type BeaconBlockBody interface {
VoluntaryExits() []*ethpb.SignedVoluntaryExit
SyncAggregate() (*ethpb.SyncAggregate, error)
IsNil() bool
HashTreeRoot() ([32]byte, error)
HashTreeRoot() ([field_params.RootLength]byte, error)
Proto() (proto.Message, error)
Execution() (ExecutionData, error)
}

View File

@@ -38,9 +38,10 @@ func SignedBeaconBlockHeaderFromBlockInterface(sb SignedBeaconBlock) (*ethpb.Sig
if err != nil {
return nil, errors.Wrap(err, "failed to get block header of block")
}
sig := sb.Signature()
return &ethpb.SignedBeaconBlockHeader{
Header: h,
Signature: sb.Signature(),
Signature: sig[:],
}, nil
}
@@ -73,11 +74,13 @@ func BeaconBlockHeaderFromBlockInterface(block BeaconBlock) (*ethpb.BeaconBlockH
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
parentRoot := block.ParentRoot()
stateRoot := block.StateRoot()
return &ethpb.BeaconBlockHeader{
Slot: block.Slot(),
ProposerIndex: block.ProposerIndex(),
ParentRoot: block.ParentRoot(),
StateRoot: block.StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
BodyRoot: bodyRoot[:],
}, nil
}

View File

@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/mock",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -2,6 +2,7 @@ package mock
import (
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -21,7 +22,7 @@ func (m SignedBeaconBlock) Block() interfaces.BeaconBlock {
return m.BeaconBlock
}
func (SignedBeaconBlock) Signature() []byte {
func (SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte {
panic("implement me")
}
@@ -86,7 +87,7 @@ func (SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) {
}
type BeaconBlock struct {
Htr [32]byte
Htr [field_params.RootLength]byte
HtrErr error
BeaconBlockBody interfaces.BeaconBlockBody
BlockSlot types.Slot
@@ -96,7 +97,7 @@ func (BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, error)
panic("implement me")
}
func (m BeaconBlock) HashTreeRoot() ([32]byte, error) {
func (m BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
return m.Htr, m.HtrErr
}
@@ -108,11 +109,11 @@ func (BeaconBlock) ProposerIndex() types.ValidatorIndex {
panic("implement me")
}
func (BeaconBlock) ParentRoot() []byte {
func (BeaconBlock) ParentRoot() [field_params.RootLength]byte {
panic("implement me")
}
func (BeaconBlock) StateRoot() []byte {
func (BeaconBlock) StateRoot() [field_params.RootLength]byte {
panic("implement me")
}
@@ -158,7 +159,7 @@ func (BeaconBlock) Version() int {
type BeaconBlockBody struct{}
func (BeaconBlockBody) RandaoReveal() []byte {
func (BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte {
panic("implement me")
}
@@ -166,7 +167,7 @@ func (BeaconBlockBody) Eth1Data() *eth.Eth1Data {
panic("implement me")
}
func (BeaconBlockBody) Graffiti() []byte {
func (BeaconBlockBody) Graffiti() [field_params.RootLength]byte {
panic("implement me")
}
@@ -198,7 +199,7 @@ func (BeaconBlockBody) IsNil() bool {
return false
}
func (BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
func (BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) {
panic("implement me")
}