From 2829ec3aab60e31f10923171a85a4d153084d298 Mon Sep 17 00:00:00 2001 From: Giulio Rebuffo Date: Sat, 11 Mar 2023 22:30:52 +0100 Subject: [PATCH] yo --- cl/clparams/config.go | 4 +- cl/cltypes/aggregate.go | 10 +- cl/cltypes/attestations.go | 76 +++++++-------- cl/cltypes/beacon_block.go | 68 +++++++------- cl/cltypes/beacon_header.go | 10 +- cl/cltypes/block_requests.go | 4 +- cl/cltypes/bls_to_execution_change.go | 10 +- cl/cltypes/checkpoint.go | 8 +- cl/cltypes/eth1_block.go | 32 +++---- cl/cltypes/eth1_data.go | 8 +- cl/cltypes/eth1_header.go | 26 ++--- cl/cltypes/fork.go | 8 +- cl/cltypes/historical_summary.go | 4 +- cl/cltypes/lightclient.go | 36 +++---- cl/cltypes/network.go | 44 ++++----- cl/cltypes/network_test.go | 6 +- cl/cltypes/slashings.go | 8 +- cl/cltypes/{ssz_utils => ssz}/errors.go | 2 +- cl/cltypes/{ssz_utils => ssz}/ssz.go | 2 +- cl/cltypes/validator.go | 38 ++++---- cl/fork/fork.go | 4 +- cl/merkle_tree/list.go | 4 +- cl/rpc/rpc.go | 4 +- cl/utils/bytes.go | 8 +- cmd/ef-tests-cl/consensus_tests/utils.go | 4 +- cmd/erigon-cl/core/state/ssz.go | 94 +++++++++---------- cmd/erigon-cl/network/beacon_downloader.go | 4 +- cmd/erigon-cl/network/gossip_manager.go | 6 +- cmd/sentinel/main.go | 4 +- .../communication/ssz_snappy/encoding.go | 10 +- core/types/withdrawal.go | 16 ++-- 31 files changed, 278 insertions(+), 284 deletions(-) rename cl/cltypes/{ssz_utils => ssz}/errors.go (95%) rename cl/cltypes/{ssz_utils => ssz}/ssz.go (99%) diff --git a/cl/clparams/config.go b/cl/clparams/config.go index f760eb05004..fd3ce772e5b 100644 --- a/cl/clparams/config.go +++ b/cl/clparams/config.go @@ -24,7 +24,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "gopkg.in/yaml.v2" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/params/networkname" ) @@ -753,7 +753,7 @@ func ParseGenesisSSZToGenesisConfig(genesisFile string) (GenesisConfig, error) { return GenesisConfig{}, nil } // Read first 2 fields of SSZ - cfg.GenesisTime = ssz_utils.UnmarshalUint64SSZ(b) + cfg.GenesisTime = ssz.UnmarshalUint64SSZ(b) copy(cfg.GenesisValidatorRoot[:], b[8:]) return cfg, nil } diff --git a/cl/cltypes/aggregate.go b/cl/cltypes/aggregate.go index 4680c256f3c..7e2bb188e42 100644 --- a/cl/cltypes/aggregate.go +++ b/cl/cltypes/aggregate.go @@ -1,7 +1,7 @@ package cltypes import ( - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/cl/utils" ) @@ -20,8 +20,8 @@ func (a *AggregateAndProof) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst var err error - buf = append(buf, ssz_utils.Uint64SSZ(a.AggregatorIndex)...) - buf = append(buf, ssz_utils.OffsetSSZ(108)...) + buf = append(buf, ssz.Uint64SSZ(a.AggregatorIndex)...) + buf = append(buf, ssz.OffsetSSZ(108)...) buf = append(buf, a.SelectionProof[:]...) buf, err = a.Aggregate.EncodeSSZ(buf) if err != nil { @@ -31,7 +31,7 @@ func (a *AggregateAndProof) EncodeSSZ(dst []byte) ([]byte, error) { } func (a *AggregateAndProof) DecodeSSZ(buf []byte) error { - a.AggregatorIndex = ssz_utils.UnmarshalUint64SSZ(buf) + a.AggregatorIndex = ssz.UnmarshalUint64SSZ(buf) if a.Aggregate == nil { a.Aggregate = new(Attestation) } @@ -55,7 +55,7 @@ type SignedAggregateAndProof struct { func (a *SignedAggregateAndProof) EncodedSSZ(dst []byte) ([]byte, error) { buf := dst var err error - buf = append(buf, ssz_utils.OffsetSSZ(100)...) + buf = append(buf, ssz.OffsetSSZ(100)...) buf = append(buf, a.Signature[:]...) buf, err = a.Message.EncodeSSZ(buf) diff --git a/cl/cltypes/attestations.go b/cl/cltypes/attestations.go index e86e0d5bb31..c3bd2e4bfc6 100644 --- a/cl/cltypes/attestations.go +++ b/cl/cltypes/attestations.go @@ -7,9 +7,8 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" - ssz "github.com/prysmaticlabs/fastssz" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/common" ) @@ -271,7 +270,7 @@ func rebuildAggregationBits(buf []byte) (n int, ret []byte) { // MarshalSSZTo ssz marshals the Attestation object to a target array func (a *Attestation) EncodeSSZ(buf []byte) (dst []byte, err error) { dst = buf - dst = append(dst, ssz_utils.OffsetSSZ(228)...) + dst = append(dst, ssz.OffsetSSZ(228)...) if dst, err = a.Data.EncodeSSZ(dst); err != nil { return @@ -291,7 +290,7 @@ func (a *Attestation) DecodeSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size < 228 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } tail := buf @@ -308,16 +307,14 @@ func (a *Attestation) DecodeSSZ(buf []byte) error { copy(a.Signature[:], buf[132:228]) // Field (0) 'AggregationBits' - { - buf = tail[228:] - if err = ssz.ValidateBitlist(buf, 2048); err != nil { - return err - } - if cap(a.AggregationBits) == 0 { - a.AggregationBits = make([]byte, 0, len(buf)) - } - a.AggregationBits = append(a.AggregationBits, buf...) + + buf = tail[228:] + + if cap(a.AggregationBits) == 0 { + a.AggregationBits = make([]byte, 0, len(buf)) } + a.AggregationBits = append(a.AggregationBits, buf...) + return err } @@ -367,7 +364,7 @@ type IndexedAttestation struct { func (i *IndexedAttestation) EncodeSSZ(buf []byte) (dst []byte, err error) { dst = buf // Write indicies offset. - dst = append(dst, ssz_utils.OffsetSSZ(228)...) + dst = append(dst, ssz.OffsetSSZ(228)...) // Process data field. if dst, err = i.Data.EncodeSSZ(dst); err != nil { @@ -381,7 +378,7 @@ func (i *IndexedAttestation) EncodeSSZ(buf []byte) (dst []byte, err error) { return nil, errors.New("too bing attesting indices") } for _, index := range i.AttestingIndices { - dst = append(dst, ssz_utils.Uint64SSZ(index)...) + dst = append(dst, ssz.Uint64SSZ(index)...) } return @@ -392,7 +389,7 @@ func (i *IndexedAttestation) DecodeSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size < 228 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } i.Data = new(AttestationData) @@ -404,15 +401,15 @@ func (i *IndexedAttestation) DecodeSSZ(buf []byte) error { bitsBuf := buf[228:] num := len(bitsBuf) / 8 if len(bitsBuf)%8 != 0 { - return ssz_utils.ErrBufferNotRounded + return ssz.ErrBufferNotRounded } if num > 2048 { - return ssz_utils.ErrBadDynamicLength + return ssz.ErrBadDynamicLength } i.AttestingIndices = make([]uint64, num) for index := 0; index < num; index++ { - i.AttestingIndices[index] = ssz_utils.UnmarshalUint64SSZ(bitsBuf[index*8:]) + i.AttestingIndices[index] = ssz.UnmarshalUint64SSZ(bitsBuf[index*8:]) } return nil } @@ -426,7 +423,7 @@ func (i *IndexedAttestation) EncodingSizeSSZ() int { func (i *IndexedAttestation) HashSSZ() ([32]byte, error) { leaves := make([][32]byte, 3) var err error - leaves[0], err = merkle_tree.Uint64ListRootWithLimit(i.AttestingIndices, ssz_utils.CalculateIndiciesLimit(2048, uint64(len(i.AttestingIndices)), 8)) + leaves[0], err = merkle_tree.Uint64ListRootWithLimit(i.AttestingIndices, ssz.CalculateIndiciesLimit(2048, uint64(len(i.AttestingIndices)), 8)) if err != nil { return [32]byte{}, err } @@ -461,8 +458,8 @@ func (a *AttestationData) Equal(other *AttestationData) bool { func (a *AttestationData) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst var err error - buf = append(buf, ssz_utils.Uint64SSZ(a.Slot)...) - buf = append(buf, ssz_utils.Uint64SSZ(a.Index)...) + buf = append(buf, ssz.Uint64SSZ(a.Slot)...) + buf = append(buf, ssz.Uint64SSZ(a.Index)...) buf = append(buf, a.BeaconBlockHash[:]...) if buf, err = a.Source.EncodeSSZ(buf); err != nil { return nil, err @@ -475,11 +472,11 @@ func (a *AttestationData) DecodeSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size != uint64(a.EncodingSizeSSZ()) { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - a.Slot = ssz_utils.UnmarshalUint64SSZ(buf) - a.Index = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + a.Slot = ssz.UnmarshalUint64SSZ(buf) + a.Index = ssz.UnmarshalUint64SSZ(buf[8:]) copy(a.BeaconBlockHash[:], buf[16:48]) a.Source = new(Checkpoint) @@ -530,13 +527,13 @@ type PendingAttestation struct { // MarshalSSZTo ssz marshals the Attestation object to a target array func (a *PendingAttestation) EncodeSSZ(buf []byte) (dst []byte, err error) { dst = buf - dst = append(dst, ssz_utils.OffsetSSZ(148)...) + dst = append(dst, ssz.OffsetSSZ(148)...) if dst, err = a.Data.EncodeSSZ(dst); err != nil { return } fmt.Println(dst) - dst = append(dst, ssz_utils.Uint64SSZ(a.InclusionDelay)...) - dst = append(dst, ssz_utils.Uint64SSZ(a.ProposerIndex)...) + dst = append(dst, ssz.Uint64SSZ(a.InclusionDelay)...) + dst = append(dst, ssz.Uint64SSZ(a.ProposerIndex)...) if len(a.AggregationBits) > 2048 { return nil, fmt.Errorf("too many aggregation bits in attestation") @@ -550,7 +547,7 @@ func (a *PendingAttestation) EncodeSSZ(buf []byte) (dst []byte, err error) { func (a *PendingAttestation) DecodeSSZ(buf []byte) error { var err error if len(buf) < a.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } tail := buf @@ -563,19 +560,16 @@ func (a *PendingAttestation) DecodeSSZ(buf []byte) error { return err } - a.InclusionDelay = ssz_utils.UnmarshalUint64SSZ(buf[132:]) - a.ProposerIndex = ssz_utils.UnmarshalUint64SSZ(buf[140:]) - // Field (0) 'AggregationBits' - { - buf = tail[148:] - if err = ssz.ValidateBitlist(buf, 2048); err != nil { - return err - } - if cap(a.AggregationBits) == 0 { - a.AggregationBits = make([]byte, 0, len(buf)) - } - a.AggregationBits = append(a.AggregationBits, buf...) + a.InclusionDelay = ssz.UnmarshalUint64SSZ(buf[132:]) + a.ProposerIndex = ssz.UnmarshalUint64SSZ(buf[140:]) + + buf = tail[148:] + + if cap(a.AggregationBits) == 0 { + a.AggregationBits = make([]byte, 0, len(buf)) } + a.AggregationBits = append(a.AggregationBits, buf...) + return err } diff --git a/cl/cltypes/beacon_block.go b/cl/cltypes/beacon_block.go index ede35063f4a..1370ae830a8 100644 --- a/cl/cltypes/beacon_block.go +++ b/cl/cltypes/beacon_block.go @@ -7,7 +7,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/ethdb/cbor" @@ -133,34 +133,34 @@ func (b *BeaconBody) EncodeSSZ(dst []byte) ([]byte, error) { } buf = append(buf, b.Graffiti...) // Write offsets for proposer slashings - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.ProposerSlashings)) * 416 // Attester slashings offset - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) for _, slashing := range b.AttesterSlashings { offset += uint32(slashing.EncodingSizeSSZ()) + 4 } // Attestation offset - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) for _, attestation := range b.Attestations { offset += uint32(attestation.EncodingSizeSSZ()) + 4 } // Deposits offset - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.Deposits)) * 1240 // Voluntary Exit offset - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.VoluntaryExits)) * 112 // Encode Sync Aggregate if b.Version >= clparams.AltairVersion { buf = b.SyncAggregate.EncodeSSZ(buf) } if b.Version >= clparams.BellatrixVersion { - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) offset += uint32(b.ExecutionPayload.EncodingSizeSSZ()) } if b.Version >= clparams.CapellaVersion { - buf = append(buf, ssz_utils.OffsetSSZ(offset)...) + buf = append(buf, ssz.OffsetSSZ(offset)...) } // Now start encoding the rest of the fields. if len(b.AttesterSlashings) > MaxAttesterSlashings { @@ -188,10 +188,10 @@ func (b *BeaconBody) EncodeSSZ(dst []byte) ([]byte, error) { } } // Write attester slashings as a dynamic list. - if buf, err = ssz_utils.EncodeDynamicList(buf, b.AttesterSlashings); err != nil { + if buf, err = ssz.EncodeDynamicList(buf, b.AttesterSlashings); err != nil { return nil, err } - if buf, err = ssz_utils.EncodeDynamicList(buf, b.Attestations); err != nil { + if buf, err = ssz.EncodeDynamicList(buf, b.Attestations); err != nil { return nil, err } @@ -258,7 +258,7 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { var err error if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } // Start wildly decoding this thing @@ -272,15 +272,15 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { b.Graffiti = libcommon.Copy(buf[168:200]) // Decode offsets - offSetProposerSlashings := ssz_utils.DecodeOffset(buf[200:]) - offsetAttesterSlashings := ssz_utils.DecodeOffset(buf[204:]) - offsetAttestations := ssz_utils.DecodeOffset(buf[208:]) - offsetDeposits := ssz_utils.DecodeOffset(buf[212:]) - offsetExits := ssz_utils.DecodeOffset(buf[216:]) + offSetProposerSlashings := ssz.DecodeOffset(buf[200:]) + offsetAttesterSlashings := ssz.DecodeOffset(buf[204:]) + offsetAttestations := ssz.DecodeOffset(buf[208:]) + offsetDeposits := ssz.DecodeOffset(buf[212:]) + offsetExits := ssz.DecodeOffset(buf[216:]) // Decode sync aggregate if we are past altair. if b.Version >= clparams.AltairVersion { if len(buf) < 380 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } b.SyncAggregate = new(SyncAggregate) if err := b.SyncAggregate.DecodeSSZ(buf[220:380]); err != nil { @@ -291,32 +291,32 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { // Execution Payload offset if past bellatrix. var offsetExecution uint32 if b.Version >= clparams.BellatrixVersion { - offsetExecution = ssz_utils.DecodeOffset(buf[380:]) + offsetExecution = ssz.DecodeOffset(buf[380:]) } // Execution to BLS changes var blsChangesOffset uint32 if b.Version >= clparams.CapellaVersion { - blsChangesOffset = ssz_utils.DecodeOffset(buf[384:]) + blsChangesOffset = ssz.DecodeOffset(buf[384:]) } // Decode Proposer slashings proposerSlashingLength := 416 - b.ProposerSlashings, err = ssz_utils.DecodeStaticList[*ProposerSlashing](buf, offSetProposerSlashings, offsetAttesterSlashings, uint32(proposerSlashingLength), MaxProposerSlashings) + b.ProposerSlashings, err = ssz.DecodeStaticList[*ProposerSlashing](buf, offSetProposerSlashings, offsetAttesterSlashings, uint32(proposerSlashingLength), MaxProposerSlashings) if err != nil { return err } // Decode attester slashings - b.AttesterSlashings, err = ssz_utils.DecodeDynamicList[*AttesterSlashing](buf, offsetAttesterSlashings, offsetAttestations, MaxAttesterSlashings) + b.AttesterSlashings, err = ssz.DecodeDynamicList[*AttesterSlashing](buf, offsetAttesterSlashings, offsetAttestations, MaxAttesterSlashings) if err != nil { return err } // Decode attestations - b.Attestations, err = ssz_utils.DecodeDynamicList[*Attestation](buf, offsetAttestations, offsetDeposits, MaxAttestations) + b.Attestations, err = ssz.DecodeDynamicList[*Attestation](buf, offsetAttestations, offsetDeposits, MaxAttestations) if err != nil { return err } // Decode deposits depositsLength := 1240 - b.Deposits, err = ssz_utils.DecodeStaticList[*Deposit](buf, offsetDeposits, offsetExits, uint32(depositsLength), MaxDeposits) + b.Deposits, err = ssz.DecodeStaticList[*Deposit](buf, offsetDeposits, offsetExits, uint32(depositsLength), MaxDeposits) if err != nil { return err } @@ -326,7 +326,7 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { if b.Version >= clparams.BellatrixVersion { endOffset = int(offsetExecution) } - b.VoluntaryExits, err = ssz_utils.DecodeStaticList[*SignedVoluntaryExit](buf, offsetExits, uint32(endOffset), uint32(exitLength), MaxVoluntaryExits) + b.VoluntaryExits, err = ssz.DecodeStaticList[*SignedVoluntaryExit](buf, offsetExits, uint32(endOffset), uint32(exitLength), MaxVoluntaryExits) if err != nil { return err } @@ -338,7 +338,7 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { if b.Version >= clparams.BellatrixVersion { b.ExecutionPayload = new(Eth1Block) if offsetExecution > uint32(endOffset) || len(buf) < endOffset { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } if err := b.ExecutionPayload.DecodeSSZWithVersion(buf[offsetExecution:endOffset], int(b.Version)); err != nil { return err @@ -346,7 +346,7 @@ func (b *BeaconBody) DecodeSSZWithVersion(buf []byte, version int) error { } if b.Version >= clparams.CapellaVersion { - if b.ExecutionChanges, err = ssz_utils.DecodeStaticList[*SignedBLSToExecutionChange](buf, blsChangesOffset, uint32(len(buf)), 172, MaxExecutionChanges); err != nil { + if b.ExecutionChanges, err = ssz.DecodeStaticList[*SignedBLSToExecutionChange](buf, blsChangesOffset, uint32(len(buf)), 172, MaxExecutionChanges); err != nil { return err } @@ -433,12 +433,12 @@ func (b *BeaconBody) HashSSZ() ([32]byte, error) { func (b *BeaconBlock) EncodeSSZ(buf []byte) (dst []byte, err error) { dst = buf // Encode base params - dst = append(dst, ssz_utils.Uint64SSZ(b.Slot)...) - dst = append(dst, ssz_utils.Uint64SSZ(b.ProposerIndex)...) + dst = append(dst, ssz.Uint64SSZ(b.Slot)...) + dst = append(dst, ssz.Uint64SSZ(b.ProposerIndex)...) dst = append(dst, b.ParentRoot[:]...) dst = append(dst, b.StateRoot[:]...) // Encode body - dst = append(dst, ssz_utils.OffsetSSZ(84)...) + dst = append(dst, ssz.OffsetSSZ(84)...) if dst, err = b.Body.EncodeSSZ(dst); err != nil { return } @@ -455,10 +455,10 @@ func (b *BeaconBlock) EncodingSizeSSZ() int { func (b *BeaconBlock) DecodeSSZWithVersion(buf []byte, version int) error { if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - b.Slot = ssz_utils.UnmarshalUint64SSZ(buf) - b.ProposerIndex = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + b.Slot = ssz.UnmarshalUint64SSZ(buf) + b.ProposerIndex = ssz.UnmarshalUint64SSZ(buf[8:]) copy(b.ParentRoot[:], buf[16:]) copy(b.StateRoot[:], buf[48:]) b.Body = new(BeaconBody) @@ -485,7 +485,7 @@ func (*BeaconBlock) DecodeSSZ(buf []byte) error { func (b *SignedBeaconBlock) EncodeSSZ(buf []byte) ([]byte, error) { dst := buf var err error - dst = append(dst, ssz_utils.OffsetSSZ(100)...) + dst = append(dst, ssz.OffsetSSZ(100)...) dst = append(dst, b.Signature[:]...) dst, err = b.Block.EncodeSSZ(dst) if err != nil { @@ -507,7 +507,7 @@ func (b *SignedBeaconBlock) DecodeSSZ(buf []byte) error { func (b *SignedBeaconBlock) DecodeSSZWithVersion(buf []byte, s int) error { if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } copy(b.Signature[:], buf[4:100]) return b.Block.DecodeSSZWithVersion(buf[100:], s) diff --git a/cl/cltypes/beacon_header.go b/cl/cltypes/beacon_header.go index 67e92b41a8e..704f039362f 100644 --- a/cl/cltypes/beacon_header.go +++ b/cl/cltypes/beacon_header.go @@ -4,7 +4,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -22,8 +22,8 @@ type BeaconBlockHeader struct { func (b *BeaconBlockHeader) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst - buf = append(buf, ssz_utils.Uint64SSZ(b.Slot)...) - buf = append(buf, ssz_utils.Uint64SSZ(b.ProposerIndex)...) + buf = append(buf, ssz.Uint64SSZ(b.Slot)...) + buf = append(buf, ssz.Uint64SSZ(b.ProposerIndex)...) buf = append(buf, b.ParentRoot[:]...) buf = append(buf, b.Root[:]...) buf = append(buf, b.BodyRoot[:]...) @@ -31,8 +31,8 @@ func (b *BeaconBlockHeader) EncodeSSZ(dst []byte) ([]byte, error) { } func (b *BeaconBlockHeader) DecodeSSZ(buf []byte) error { - b.Slot = ssz_utils.UnmarshalUint64SSZ(buf) - b.ProposerIndex = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + b.Slot = ssz.UnmarshalUint64SSZ(buf) + b.ProposerIndex = ssz.UnmarshalUint64SSZ(buf[8:]) copy(b.ParentRoot[:], buf[16:]) copy(b.Root[:], buf[48:]) copy(b.BodyRoot[:], buf[80:]) diff --git a/cl/cltypes/block_requests.go b/cl/cltypes/block_requests.go index 7f762f5fe8e..df4aa4fcffd 100644 --- a/cl/cltypes/block_requests.go +++ b/cl/cltypes/block_requests.go @@ -3,7 +3,7 @@ package cltypes import ( "fmt" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" ) const ( @@ -54,7 +54,7 @@ func (r *BeaconBlocksByRootRequest) DecodeSSZ(buf []byte) error { return fmt.Errorf("expected buffer with length of upto %d but received length %d", maxLength, bufLen) } if bufLen%rootLength != 0 { - return ssz_utils.ErrBufferNotRounded + return ssz.ErrBufferNotRounded } numOfRoots := bufLen / rootLength roots := make([][rootLength]byte, 0, numOfRoots) diff --git a/cl/cltypes/bls_to_execution_change.go b/cl/cltypes/bls_to_execution_change.go index 3256b8045c7..ce9b563ee5d 100644 --- a/cl/cltypes/bls_to_execution_change.go +++ b/cl/cltypes/bls_to_execution_change.go @@ -2,7 +2,7 @@ package cltypes import ( libcommon "github.com/ledgerwatch/erigon-lib/common" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -15,7 +15,7 @@ type BLSToExecutionChange struct { func (b *BLSToExecutionChange) EncodeSSZ(buf []byte) ([]byte, error) { dst := buf - dst = append(dst, ssz_utils.Uint64SSZ(b.ValidatorIndex)...) + dst = append(dst, ssz.Uint64SSZ(b.ValidatorIndex)...) dst = append(dst, b.From[:]...) dst = append(dst, b.To[:]...) return dst, nil @@ -35,9 +35,9 @@ func (b *BLSToExecutionChange) HashSSZ() ([32]byte, error) { func (b *BLSToExecutionChange) DecodeSSZ(buf []byte) error { if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - b.ValidatorIndex = ssz_utils.UnmarshalUint64SSZ(buf) + b.ValidatorIndex = ssz.UnmarshalUint64SSZ(buf) copy(b.From[:], buf[8:]) copy(b.To[:], buf[56:]) return nil @@ -64,7 +64,7 @@ func (s *SignedBLSToExecutionChange) EncodeSSZ(buf []byte) ([]byte, error) { func (s *SignedBLSToExecutionChange) DecodeSSZ(buf []byte) error { if len(buf) < s.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } s.Message = new(BLSToExecutionChange) if err := s.Message.DecodeSSZ(buf); err != nil { diff --git a/cl/cltypes/checkpoint.go b/cl/cltypes/checkpoint.go index f5dcde87e51..8c4510f5888 100644 --- a/cl/cltypes/checkpoint.go +++ b/cl/cltypes/checkpoint.go @@ -4,7 +4,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -18,16 +18,16 @@ func (c *Checkpoint) Equal(other *Checkpoint) bool { } func (c *Checkpoint) EncodeSSZ(buf []byte) ([]byte, error) { - return append(buf, append(ssz_utils.Uint64SSZ(c.Epoch), c.Root[:]...)...), nil + return append(buf, append(ssz.Uint64SSZ(c.Epoch), c.Root[:]...)...), nil } func (c *Checkpoint) DecodeSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size < uint64(c.EncodingSizeSSZ()) { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - c.Epoch = ssz_utils.UnmarshalUint64SSZ(buf[0:8]) + c.Epoch = ssz.UnmarshalUint64SSZ(buf[0:8]) copy(c.Root[:], buf[8:40]) return err diff --git a/cl/cltypes/eth1_block.go b/cl/cltypes/eth1_block.go index 2a19fe6fda5..fcb3cc29a7c 100644 --- a/cl/cltypes/eth1_block.go +++ b/cl/cltypes/eth1_block.go @@ -7,7 +7,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/consensus/serenity" @@ -136,7 +136,7 @@ func (b *Eth1Block) DecodeSSZ(buf []byte) error { func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { b.version = clparams.StateVersion(version) if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } // We can reuse code from eth1-header for partial decoding payloadHeader := Eth1Header{} @@ -155,12 +155,12 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { b.Time = payloadHeader.Time b.BaseFeePerGas = payloadHeader.BaseFeePerGas // Decode the rest - transactionsOffset := ssz_utils.DecodeOffset(buf[pos:]) + transactionsOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 var withdrawalOffset *uint32 if version >= int(clparams.CapellaVersion) { withdrawalOffset = new(uint32) - *withdrawalOffset = ssz_utils.DecodeOffset(buf[pos:]) + *withdrawalOffset = ssz.DecodeOffset(buf[pos:]) } // Compute extra data. b.Extra = common.CopyBytes(buf[extraDataOffset:transactionsOffset]) @@ -171,12 +171,12 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { var transactionsBuffer []byte if withdrawalOffset == nil { if len(transactionsBuffer) > len(buf) { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } transactionsBuffer = buf[transactionsOffset:] } else { if len(transactionsBuffer) > int(*withdrawalOffset) || int(*withdrawalOffset) > len(buf) { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } transactionsBuffer = buf[transactionsOffset:*withdrawalOffset] } @@ -188,13 +188,13 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { length = 0 } else { if len(transactionsBuffer) < 4 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - txOffset = ssz_utils.DecodeOffset(transactionsBuffer) + txOffset = ssz.DecodeOffset(transactionsBuffer) length = txOffset / 4 // Retrieve tx length if txOffset%4 != 0 { - return ssz_utils.ErrBadDynamicLength + return ssz.ErrBadDynamicLength } } @@ -206,11 +206,11 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { if length == 1 { txEndOffset = uint32(len(transactionsBuffer)) } else { - txEndOffset = ssz_utils.DecodeOffset(transactionsBuffer[transactionsPosition:]) + txEndOffset = ssz.DecodeOffset(transactionsBuffer[transactionsPosition:]) } transactionsPosition += 4 if txOffset > txEndOffset { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } b.Transactions[txIdx] = transactionsBuffer[txOffset:txEndOffset] // Decode RLP and put it in the tx list. @@ -222,7 +222,7 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { // If withdrawals are enabled, process them. if withdrawalOffset != nil { var err error - b.Withdrawals, err = ssz_utils.DecodeStaticList[*types.Withdrawal](buf, *withdrawalOffset, uint32(len(buf)), 44, 16) + b.Withdrawals, err = ssz.DecodeStaticList[*types.Withdrawal](buf, *withdrawalOffset, uint32(len(buf)), 44, 16) if err != nil { return err } @@ -234,7 +234,7 @@ func (b *Eth1Block) DecodeSSZWithVersion(buf []byte, version int) error { func (b *Eth1Block) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst var err error - currentOffset := ssz_utils.BaseExtraDataSSZOffsetBlock + currentOffset := ssz.BaseExtraDataSSZOffsetBlock if b.version >= clparams.CapellaVersion { currentOffset += 4 @@ -249,14 +249,14 @@ func (b *Eth1Block) EncodeSSZ(dst []byte) ([]byte, error) { } currentOffset += len(b.Extra) // Write transaction offset - buf = append(buf, ssz_utils.OffsetSSZ(uint32(currentOffset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(currentOffset))...) for _, tx := range b.Transactions { currentOffset += len(tx) + 4 } // Write withdrawals offset if exist if b.version >= clparams.CapellaVersion { - buf = append(buf, ssz_utils.OffsetSSZ(uint32(currentOffset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(currentOffset))...) } // Sanity check for extra data then write it. if len(b.Extra) > 32 { @@ -266,7 +266,7 @@ func (b *Eth1Block) EncodeSSZ(dst []byte) ([]byte, error) { // Write all tx offsets txOffset := len(b.Transactions) * 4 for _, tx := range b.Transactions { - buf = append(buf, ssz_utils.OffsetSSZ(uint32(txOffset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(txOffset))...) txOffset += len(tx) } // Write all transactions diff --git a/cl/cltypes/eth1_data.go b/cl/cltypes/eth1_data.go index b60a1352fcc..c951d4445ca 100644 --- a/cl/cltypes/eth1_data.go +++ b/cl/cltypes/eth1_data.go @@ -3,7 +3,7 @@ package cltypes import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/common" ) @@ -22,7 +22,7 @@ func (e *Eth1Data) Equal(b *Eth1Data) bool { func (e *Eth1Data) EncodeSSZ(buf []byte) (dst []byte, err error) { dst = buf dst = append(dst, e.Root[:]...) - dst = append(dst, ssz_utils.Uint64SSZ(e.DepositCount)...) + dst = append(dst, ssz.Uint64SSZ(e.DepositCount)...) dst = append(dst, e.BlockHash[:]...) return } @@ -32,11 +32,11 @@ func (e *Eth1Data) DecodeSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size < 72 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } copy(e.Root[:], buf[0:32]) - e.DepositCount = ssz_utils.UnmarshalUint64SSZ(buf[32:40]) + e.DepositCount = ssz.UnmarshalUint64SSZ(buf[32:40]) copy(e.BlockHash[:], buf[40:72]) return err diff --git a/cl/cltypes/eth1_header.go b/cl/cltypes/eth1_header.go index d132ceafd3d..1e17f66b0ee 100644 --- a/cl/cltypes/eth1_header.go +++ b/cl/cltypes/eth1_header.go @@ -3,7 +3,7 @@ package cltypes import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/core/types" @@ -45,11 +45,11 @@ func (h *Eth1Header) encodeHeaderMetadataForSSZ(dst []byte, extraDataOffset int) buf = append(buf, h.ReceiptsRoot[:]...) buf = append(buf, h.LogsBloom[:]...) buf = append(buf, h.PrevRandao[:]...) - buf = append(buf, ssz_utils.Uint64SSZ(h.BlockNumber)...) - buf = append(buf, ssz_utils.Uint64SSZ(h.GasLimit)...) - buf = append(buf, ssz_utils.Uint64SSZ(h.GasUsed)...) - buf = append(buf, ssz_utils.Uint64SSZ(h.Time)...) - buf = append(buf, ssz_utils.OffsetSSZ(uint32(extraDataOffset))...) + buf = append(buf, ssz.Uint64SSZ(h.BlockNumber)...) + buf = append(buf, ssz.Uint64SSZ(h.GasLimit)...) + buf = append(buf, ssz.Uint64SSZ(h.GasUsed)...) + buf = append(buf, ssz.Uint64SSZ(h.Time)...) + buf = append(buf, ssz.OffsetSSZ(uint32(extraDataOffset))...) // Add Base Fee buf = append(buf, h.BaseFeePerGas[:]...) @@ -60,7 +60,7 @@ func (h *Eth1Header) encodeHeaderMetadataForSSZ(dst []byte, extraDataOffset int) // EncodeSSZ encodes the header in SSZ format. func (h *Eth1Header) EncodeSSZ(dst []byte) (buf []byte, err error) { buf = dst - offset := ssz_utils.BaseExtraDataSSZOffsetHeader + offset := ssz.BaseExtraDataSSZOffsetHeader if h.version >= clparams.CapellaVersion { offset += 32 @@ -100,12 +100,12 @@ func (h *Eth1Header) decodeHeaderMetadataForSSZ(buf []byte) (pos int, extraDataO copy(h.PrevRandao[:], buf[pos:]) pos += len(h.PrevRandao) - h.BlockNumber = ssz_utils.UnmarshalUint64SSZ(buf[pos:]) - h.GasLimit = ssz_utils.UnmarshalUint64SSZ(buf[pos+8:]) - h.GasUsed = ssz_utils.UnmarshalUint64SSZ(buf[pos+16:]) - h.Time = ssz_utils.UnmarshalUint64SSZ(buf[pos+24:]) + h.BlockNumber = ssz.UnmarshalUint64SSZ(buf[pos:]) + h.GasLimit = ssz.UnmarshalUint64SSZ(buf[pos+8:]) + h.GasUsed = ssz.UnmarshalUint64SSZ(buf[pos+16:]) + h.Time = ssz.UnmarshalUint64SSZ(buf[pos+24:]) pos += 32 - extraDataOffset = int(ssz_utils.DecodeOffset(buf[pos:])) + extraDataOffset = int(ssz.DecodeOffset(buf[pos:])) pos += 4 // Add Base Fee copy(h.BaseFeePerGas[:], buf[pos:]) @@ -119,7 +119,7 @@ func (h *Eth1Header) decodeHeaderMetadataForSSZ(buf []byte) (pos int, extraDataO func (h *Eth1Header) DecodeSSZWithVersion(buf []byte, version int) error { h.version = clparams.StateVersion(version) if len(buf) < h.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } pos, _ := h.decodeHeaderMetadataForSSZ(buf) copy(h.TransactionsRoot[:], buf[pos:]) diff --git a/cl/cltypes/fork.go b/cl/cltypes/fork.go index af0fb2920c6..d9016c1376f 100644 --- a/cl/cltypes/fork.go +++ b/cl/cltypes/fork.go @@ -2,7 +2,7 @@ package cltypes import ( "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -17,17 +17,17 @@ func (f *Fork) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst buf = append(buf, f.PreviousVersion[:]...) buf = append(buf, f.CurrentVersion[:]...) - buf = append(buf, ssz_utils.Uint64SSZ(f.Epoch)...) + buf = append(buf, ssz.Uint64SSZ(f.Epoch)...) return buf, nil } func (f *Fork) DecodeSSZ(buf []byte) error { if len(buf) < f.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } copy(f.PreviousVersion[:], buf) copy(f.CurrentVersion[:], buf[clparams.VersionLength:]) - f.Epoch = ssz_utils.UnmarshalUint64SSZ(buf[clparams.VersionLength*2:]) + f.Epoch = ssz.UnmarshalUint64SSZ(buf[clparams.VersionLength*2:]) return nil } diff --git a/cl/cltypes/historical_summary.go b/cl/cltypes/historical_summary.go index 47f5e5fee93..2e6866ad1b1 100644 --- a/cl/cltypes/historical_summary.go +++ b/cl/cltypes/historical_summary.go @@ -3,7 +3,7 @@ package cltypes import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -18,7 +18,7 @@ func (h *HistoricalSummary) EncodeSSZ(buf []byte) ([]byte, error) { func (h *HistoricalSummary) DecodeSSZ(buf []byte) error { if len(buf) < h.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } copy(h.BlockSummaryRoot[:], buf) copy(h.StateSummaryRoot[:], buf[length.Hash:]) diff --git a/cl/cltypes/lightclient.go b/cl/cltypes/lightclient.go index 6a83e6bef69..c771b1374fe 100644 --- a/cl/cltypes/lightclient.go +++ b/cl/cltypes/lightclient.go @@ -6,7 +6,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/length" "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/utils" ) @@ -67,7 +67,7 @@ func (l *LightClientHeader) EncodeSSZ(buf []byte) ([]byte, error) { } // Post-Capella offset := uint32(l.HeaderEth2.EncodingSizeSSZ() + len(l.ExecutionBranch)*length.Hash + 4) - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) for _, root := range l.ExecutionBranch { dst = append(dst, root[:]...) } @@ -116,7 +116,7 @@ func (l *LightClientBootstrap) EncodeSSZ(dst []byte) ([]byte, error) { return nil, err } } else { - buf = append(buf, ssz_utils.OffsetSSZ(uint32(offset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(offset))...) } if buf, err = l.CurrentSyncCommittee.EncodeSSZ(buf); err != nil { @@ -142,7 +142,7 @@ func (l *LightClientBootstrap) DecodeSSZWithVersion(buf []byte, version int) err l.version = clparams.StateVersion(version) if len(buf) < l.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } l.Header = new(LightClientHeader) l.CurrentSyncCommittee = new(SyncCommittee) @@ -244,7 +244,7 @@ func (l *LightClientUpdate) EncodeSSZ(buf []byte) ([]byte, error) { len(l.FinalityBranch)*length.Hash + l.SyncAggregate.EncodingSizeSSZ() + 8 if l.version >= clparams.CapellaVersion { - dst = append(dst, ssz_utils.OffsetSSZ(uint32(offset))...) + dst = append(dst, ssz.OffsetSSZ(uint32(offset))...) offset += l.AttestedHeader.EncodingSizeSSZ() } else { // Generic Update Specific @@ -285,7 +285,7 @@ func encodeFinalityUpdateSpecificField(buf []byte, finalizedHeader *LightClientH dst := buf var err error if finalizedHeader.version >= clparams.CapellaVersion { - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) } else { if dst, err = finalizedHeader.EncodeSSZ(dst); err != nil { return nil, err @@ -304,7 +304,7 @@ func encodeFinalityUpdateSpecificField(buf []byte, finalizedHeader *LightClientH func encodeUpdateFooter(buf []byte, aggregate *SyncAggregate, signatureSlot uint64) []byte { dst := buf dst = aggregate.EncodeSSZ(dst) - return append(dst, ssz_utils.Uint64SSZ(signatureSlot)...) + return append(dst, ssz.Uint64SSZ(signatureSlot)...) } func decodeFinalityUpdateSpecificField(buf []byte, version clparams.StateVersion) (*LightClientHeader, []libcommon.Hash, uint32, int, error) { @@ -317,7 +317,7 @@ func decodeFinalityUpdateSpecificField(buf []byte, version clparams.StateVersion } pos += header.EncodingSizeSSZ() } else { - offset = ssz_utils.DecodeOffset(buf) + offset = ssz.DecodeOffset(buf) pos += 4 } @@ -334,7 +334,7 @@ func decodeUpdateFooter(buf []byte) (*SyncAggregate, uint64, error) { if err := aggregate.DecodeSSZ(buf); err != nil { return nil, 0, err } - return aggregate, ssz_utils.UnmarshalUint64SSZ(buf[aggregate.EncodingSizeSSZ():]), nil + return aggregate, ssz.UnmarshalUint64SSZ(buf[aggregate.EncodingSizeSSZ():]), nil } // LightClientFinalityUpdate is used to update the sync aggreggate every 6 minutes. @@ -362,7 +362,7 @@ func (l *LightClientUpdate) DecodeSSZWithVersion(buf []byte, version int) error var err error l.version = clparams.StateVersion(version) if len(buf) < l.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } l.AttestedHeader = new(LightClientHeader) @@ -378,7 +378,7 @@ func (l *LightClientUpdate) DecodeSSZWithVersion(buf []byte, version int) error ) if l.version >= clparams.CapellaVersion { - offsetAttested = ssz_utils.DecodeOffset(buf) + offsetAttested = ssz.DecodeOffset(buf) pos += 4 } else { if err = l.AttestedHeader.DecodeSSZWithVersion(buf, version); err != nil { @@ -406,7 +406,7 @@ func (l *LightClientUpdate) DecodeSSZWithVersion(buf []byte, version int) error l.SyncAggregate, l.SignatureSlot, err = decodeUpdateFooter(buf[pos:]) if l.version >= clparams.CapellaVersion { if offsetAttested > offsetFinalized || offsetFinalized > uint32(len(buf)) { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } if err = l.AttestedHeader.DecodeSSZWithVersion(buf[offsetAttested:offsetFinalized], version); err != nil { return err @@ -452,7 +452,7 @@ func (l *LightClientFinalityUpdate) EncodeSSZ(buf []byte) ([]byte, error) { var err error offset := 8 + len(l.FinalityBranch)*length.Hash + l.SyncAggregate.EncodingSizeSSZ() + 8 if l.version >= clparams.CapellaVersion { - dst = append(dst, ssz_utils.OffsetSSZ(uint32(offset))...) + dst = append(dst, ssz.OffsetSSZ(uint32(offset))...) offset += l.AttestedHeader.EncodingSizeSSZ() } else { // Generic Update Specific @@ -482,7 +482,7 @@ func (l *LightClientFinalityUpdate) DecodeSSZWithVersion(buf []byte, version int var err error l.version = clparams.StateVersion(version) if len(buf) < l.EncodingSizeSSZ() { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } pos := 0 @@ -495,7 +495,7 @@ func (l *LightClientFinalityUpdate) DecodeSSZWithVersion(buf []byte, version int } pos += l.AttestedHeader.EncodingSizeSSZ() } else { - offsetAttested = ssz_utils.DecodeOffset(buf) + offsetAttested = ssz.DecodeOffset(buf) pos += 4 } @@ -512,7 +512,7 @@ func (l *LightClientFinalityUpdate) DecodeSSZWithVersion(buf []byte, version int } if l.version >= clparams.CapellaVersion { if offsetAttested > offsetFinalized || offsetFinalized > uint32(len(buf)) { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } if err = l.AttestedHeader.DecodeSSZWithVersion(buf[offsetAttested:offsetFinalized], version); err != nil { return err @@ -564,7 +564,7 @@ func (l *LightClientOptimisticUpdate) EncodeSSZ(buf []byte) ([]byte, error) { dst := buf var err error if l.version >= clparams.CapellaVersion { - dst = append(dst, ssz_utils.OffsetSSZ(uint32(8+l.SyncAggregate.EncodingSizeSSZ()+4))...) + dst = append(dst, ssz.OffsetSSZ(uint32(8+l.SyncAggregate.EncodingSizeSSZ()+4))...) } else { if dst, err = l.AttestedHeader.EncodeSSZ(dst); err != nil { return nil, err @@ -583,7 +583,7 @@ func (l *LightClientOptimisticUpdate) DecodeSSZWithVersion(buf []byte, version i var err error l.version = clparams.StateVersion(version) if len(buf) < l.EncodingSizeSSZ() { - return ssz_utils.ErrBadOffset + return ssz.ErrBadOffset } pos := 0 diff --git a/cl/cltypes/network.go b/cl/cltypes/network.go index 74e0468c852..1b96dc110b1 100644 --- a/cl/cltypes/network.go +++ b/cl/cltypes/network.go @@ -3,7 +3,7 @@ package cltypes import ( "github.com/ledgerwatch/erigon-lib/common/length" "github.com/ledgerwatch/erigon/cl/cltypes/clonable" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/common" ) @@ -15,24 +15,24 @@ type Metadata struct { func (m *Metadata) EncodeSSZ(buf []byte) ([]byte, error) { ret := buf - ret = append(ret, ssz_utils.Uint64SSZ(m.SeqNumber)...) - ret = append(ret, ssz_utils.Uint64SSZ(m.Attnets)...) + ret = append(ret, ssz.Uint64SSZ(m.SeqNumber)...) + ret = append(ret, ssz.Uint64SSZ(m.Attnets)...) if m.Syncnets == nil { return ret, nil } - ret = append(ret, ssz_utils.Uint64SSZ(*m.Syncnets)...) + ret = append(ret, ssz.Uint64SSZ(*m.Syncnets)...) return ret, nil } func (m *Metadata) DecodeSSZ(buf []byte) error { - m.SeqNumber = ssz_utils.UnmarshalUint64SSZ(buf) - m.Attnets = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + m.SeqNumber = ssz.UnmarshalUint64SSZ(buf) + m.Attnets = ssz.UnmarshalUint64SSZ(buf[8:]) if len(buf) < 24 { return nil } m.Syncnets = new(uint64) - *m.Syncnets = ssz_utils.UnmarshalUint64SSZ(buf[16:]) + *m.Syncnets = ssz.UnmarshalUint64SSZ(buf[16:]) return nil } @@ -54,11 +54,11 @@ type Ping struct { } func (p *Ping) EncodeSSZ(buf []byte) ([]byte, error) { - return append(buf, ssz_utils.Uint64SSZ(p.Id)...), nil + return append(buf, ssz.Uint64SSZ(p.Id)...), nil } func (p *Ping) DecodeSSZ(buf []byte) error { - p.Id = ssz_utils.UnmarshalUint64SSZ(buf) + p.Id = ssz.UnmarshalUint64SSZ(buf) return nil } @@ -114,12 +114,12 @@ func (l *LightClientUpdatesByRangeRequest) DecodeSSZWithVersion(buf []byte, _ in } func (l *LightClientUpdatesByRangeRequest) EncodeSSZ(buf []byte) ([]byte, error) { - return append(buf, append(ssz_utils.Uint64SSZ(l.Period), ssz_utils.Uint64SSZ(l.Count)...)...), nil + return append(buf, append(ssz.Uint64SSZ(l.Period), ssz.Uint64SSZ(l.Count)...)...), nil } func (l *LightClientUpdatesByRangeRequest) DecodeSSZ(buf []byte) error { - l.Period = ssz_utils.UnmarshalUint64SSZ(buf) - l.Count = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + l.Period = ssz.UnmarshalUint64SSZ(buf) + l.Count = ssz.UnmarshalUint64SSZ(buf[8:]) return nil } @@ -138,16 +138,16 @@ type BeaconBlocksByRangeRequest struct { func (b *BeaconBlocksByRangeRequest) EncodeSSZ(buf []byte) ([]byte, error) { dst := buf - dst = append(dst, ssz_utils.Uint64SSZ(b.StartSlot)...) - dst = append(dst, ssz_utils.Uint64SSZ(b.Count)...) - dst = append(dst, ssz_utils.Uint64SSZ(b.Step)...) + dst = append(dst, ssz.Uint64SSZ(b.StartSlot)...) + dst = append(dst, ssz.Uint64SSZ(b.Count)...) + dst = append(dst, ssz.Uint64SSZ(b.Step)...) return dst, nil } func (b *BeaconBlocksByRangeRequest) DecodeSSZ(buf []byte) error { - b.StartSlot = ssz_utils.UnmarshalUint64SSZ(buf) - b.Count = ssz_utils.UnmarshalUint64SSZ(buf[8:]) - b.Step = ssz_utils.UnmarshalUint64SSZ(buf[16:]) + b.StartSlot = ssz.UnmarshalUint64SSZ(buf) + b.Count = ssz.UnmarshalUint64SSZ(buf[8:]) + b.Step = ssz.UnmarshalUint64SSZ(buf[16:]) return nil } @@ -179,18 +179,18 @@ func (s *Status) EncodeSSZ(buf []byte) ([]byte, error) { dst := buf dst = append(dst, s.ForkDigest[:]...) dst = append(dst, s.FinalizedRoot[:]...) - dst = append(dst, ssz_utils.Uint64SSZ(s.FinalizedEpoch)...) + dst = append(dst, ssz.Uint64SSZ(s.FinalizedEpoch)...) dst = append(dst, s.HeadRoot[:]...) - dst = append(dst, ssz_utils.Uint64SSZ(s.HeadSlot)...) + dst = append(dst, ssz.Uint64SSZ(s.HeadSlot)...) return dst, nil } func (s *Status) DecodeSSZ(buf []byte) error { copy(s.ForkDigest[:], buf) copy(s.FinalizedRoot[:], buf[4:]) - s.FinalizedEpoch = ssz_utils.UnmarshalUint64SSZ(buf[36:]) + s.FinalizedEpoch = ssz.UnmarshalUint64SSZ(buf[36:]) copy(s.HeadRoot[:], buf[44:]) - s.HeadSlot = ssz_utils.UnmarshalUint64SSZ(buf[76:]) + s.HeadSlot = ssz.UnmarshalUint64SSZ(buf[76:]) return nil } diff --git a/cl/cltypes/network_test.go b/cl/cltypes/network_test.go index bb2faf0a821..0af1cbdd523 100644 --- a/cl/cltypes/network_test.go +++ b/cl/cltypes/network_test.go @@ -8,7 +8,7 @@ import ( "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" ) var testMetadata = &cltypes.Metadata{ @@ -89,7 +89,7 @@ var testLcBootstrap = (&cltypes.LightClientBootstrap{ }).WithVersion(clparams.CapellaVersion) func TestMarshalNetworkTypes(t *testing.T) { - cases := []ssz_utils.EncodableSSZ{ + cases := []ssz.EncodableSSZ{ testMetadata, testPing, testSingleRoot, @@ -102,7 +102,7 @@ func TestMarshalNetworkTypes(t *testing.T) { testLcBootstrap, } - unmarshalDestinations := []ssz_utils.EncodableSSZ{ + unmarshalDestinations := []ssz.EncodableSSZ{ &cltypes.Metadata{}, &cltypes.Ping{}, &cltypes.SingleRoot{}, diff --git a/cl/cltypes/slashings.go b/cl/cltypes/slashings.go index 89f1da86a29..254929d10a3 100644 --- a/cl/cltypes/slashings.go +++ b/cl/cltypes/slashings.go @@ -1,7 +1,7 @@ package cltypes import ( - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) @@ -59,9 +59,9 @@ func (a *AttesterSlashing) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst offset := 8 // Write offsets - buf = append(buf, ssz_utils.OffsetSSZ(uint32(offset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(offset))...) offset += a.Attestation_1.EncodingSizeSSZ() - buf = append(buf, ssz_utils.OffsetSSZ(uint32(offset))...) + buf = append(buf, ssz.OffsetSSZ(uint32(offset))...) // Write the attestations var err error buf, err = a.Attestation_1.EncodeSSZ(buf) @@ -78,7 +78,7 @@ func (a *AttesterSlashing) EncodeSSZ(dst []byte) ([]byte, error) { func (a *AttesterSlashing) DecodeSSZ(buf []byte) error { a.Attestation_1 = new(IndexedAttestation) a.Attestation_2 = new(IndexedAttestation) - attestation2Offset := ssz_utils.DecodeOffset(buf[4:]) + attestation2Offset := ssz.DecodeOffset(buf[4:]) if err := a.Attestation_1.DecodeSSZ(buf[8:attestation2Offset]); err != nil { return err } diff --git a/cl/cltypes/ssz_utils/errors.go b/cl/cltypes/ssz/errors.go similarity index 95% rename from cl/cltypes/ssz_utils/errors.go rename to cl/cltypes/ssz/errors.go index ea4c3d3a8fa..257d142d31f 100644 --- a/cl/cltypes/ssz_utils/errors.go +++ b/cl/cltypes/ssz/errors.go @@ -1,4 +1,4 @@ -package ssz_utils +package ssz import "errors" diff --git a/cl/cltypes/ssz_utils/ssz.go b/cl/cltypes/ssz/ssz.go similarity index 99% rename from cl/cltypes/ssz_utils/ssz.go rename to cl/cltypes/ssz/ssz.go index 4c1940da24c..fefe4b7391b 100644 --- a/cl/cltypes/ssz_utils/ssz.go +++ b/cl/cltypes/ssz/ssz.go @@ -1,4 +1,4 @@ -package ssz_utils +package ssz import ( "encoding/binary" diff --git a/cl/cltypes/validator.go b/cl/cltypes/validator.go index 83c45e396cd..45192d332ff 100644 --- a/cl/cltypes/validator.go +++ b/cl/cltypes/validator.go @@ -6,7 +6,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/cl/utils" ) @@ -28,7 +28,7 @@ func (d *DepositData) EncodeSSZ(dst []byte) []byte { buf := dst buf = append(buf, d.PubKey[:]...) buf = append(buf, d.WithdrawalCredentials[:]...) - buf = append(buf, ssz_utils.Uint64SSZ(d.Amount)...) + buf = append(buf, ssz.Uint64SSZ(d.Amount)...) buf = append(buf, d.Signature[:]...) return buf } @@ -36,7 +36,7 @@ func (d *DepositData) EncodeSSZ(dst []byte) []byte { func (d *DepositData) DecodeSSZ(buf []byte) error { copy(d.PubKey[:], buf) copy(d.WithdrawalCredentials[:], buf[48:]) - d.Amount = ssz_utils.UnmarshalUint64SSZ(buf[80:]) + d.Amount = ssz.UnmarshalUint64SSZ(buf[80:]) copy(d.Signature[:], buf[88:]) return nil } @@ -138,12 +138,12 @@ type VoluntaryExit struct { } func (e *VoluntaryExit) EncodeSSZ(buf []byte) []byte { - return append(buf, append(ssz_utils.Uint64SSZ(e.Epoch), ssz_utils.Uint64SSZ(e.ValidatorIndex)...)...) + return append(buf, append(ssz.Uint64SSZ(e.Epoch), ssz.Uint64SSZ(e.ValidatorIndex)...)...) } func (e *VoluntaryExit) DecodeSSZ(buf []byte) error { - e.Epoch = ssz_utils.UnmarshalUint64SSZ(buf) - e.ValidatorIndex = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + e.Epoch = ssz.UnmarshalUint64SSZ(buf) + e.ValidatorIndex = ssz.UnmarshalUint64SSZ(buf[8:]) return nil } @@ -225,7 +225,7 @@ func (s *SyncCommittee) EncodeSSZ(buf []byte) ([]byte, error) { // DecodeSSZ ssz unmarshals the SyncCommittee object func (s *SyncCommittee) DecodeSSZ(buf []byte) error { if len(buf) < 24624 { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } s.PubKeys = make([][48]byte, SyncCommitteeSize) @@ -334,12 +334,12 @@ func (v *Validator) EncodeSSZ(dst []byte) ([]byte, error) { buf := dst buf = append(buf, v.PublicKey[:]...) buf = append(buf, v.WithdrawalCredentials[:]...) - buf = append(buf, ssz_utils.Uint64SSZ(v.EffectiveBalance)...) - buf = append(buf, ssz_utils.BoolSSZ(v.Slashed)) - buf = append(buf, ssz_utils.Uint64SSZ(v.ActivationEligibilityEpoch)...) - buf = append(buf, ssz_utils.Uint64SSZ(v.ActivationEpoch)...) - buf = append(buf, ssz_utils.Uint64SSZ(v.ExitEpoch)...) - buf = append(buf, ssz_utils.Uint64SSZ(v.WithdrawableEpoch)...) + buf = append(buf, ssz.Uint64SSZ(v.EffectiveBalance)...) + buf = append(buf, ssz.BoolSSZ(v.Slashed)) + buf = append(buf, ssz.Uint64SSZ(v.ActivationEligibilityEpoch)...) + buf = append(buf, ssz.Uint64SSZ(v.ActivationEpoch)...) + buf = append(buf, ssz.Uint64SSZ(v.ExitEpoch)...) + buf = append(buf, ssz.Uint64SSZ(v.WithdrawableEpoch)...) return buf, nil } @@ -349,16 +349,16 @@ func (v *Validator) DecodeSSZWithVersion(buf []byte, _ int) error { func (v *Validator) DecodeSSZ(buf []byte) error { if len(buf) < v.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } copy(v.PublicKey[:], buf) copy(v.WithdrawalCredentials[:], buf[48:]) - v.EffectiveBalance = ssz_utils.UnmarshalUint64SSZ(buf[80:]) + v.EffectiveBalance = ssz.UnmarshalUint64SSZ(buf[80:]) v.Slashed = buf[88] == 1 - v.ActivationEligibilityEpoch = ssz_utils.UnmarshalUint64SSZ(buf[89:]) - v.ActivationEpoch = ssz_utils.UnmarshalUint64SSZ(buf[97:]) - v.ExitEpoch = ssz_utils.UnmarshalUint64SSZ(buf[105:]) - v.WithdrawableEpoch = ssz_utils.UnmarshalUint64SSZ(buf[113:]) + v.ActivationEligibilityEpoch = ssz.UnmarshalUint64SSZ(buf[89:]) + v.ActivationEpoch = ssz.UnmarshalUint64SSZ(buf[97:]) + v.ExitEpoch = ssz.UnmarshalUint64SSZ(buf[105:]) + v.WithdrawableEpoch = ssz.UnmarshalUint64SSZ(buf[113:]) return nil } diff --git a/cl/fork/fork.go b/cl/fork/fork.go index 44c2a4aa932..6ecc6d4b3f7 100644 --- a/cl/fork/fork.go +++ b/cl/fork/fork.go @@ -25,7 +25,7 @@ import ( "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/utils" ) @@ -190,7 +190,7 @@ func ComputeDomain( } func ComputeSigningRoot( - obj ssz_utils.HashableSSZ, + obj ssz.HashableSSZ, domain []byte, ) ([32]byte, error) { objRoot, err := obj.HashSSZ() diff --git a/cl/merkle_tree/list.go b/cl/merkle_tree/list.go index db788367b67..a2bb4845fd6 100644 --- a/cl/merkle_tree/list.go +++ b/cl/merkle_tree/list.go @@ -6,7 +6,7 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/prysmaticlabs/gohashtree" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/utils" ) @@ -206,7 +206,7 @@ func TransactionsListRoot(transactions [][]byte) (libcommon.Hash, error) { return utils.Keccak256(transactionsBaseRoot[:], countRoot[:]), nil } -func ListObjectSSZRoot[T ssz_utils.HashableSSZ](list []T, limit uint64) ([32]byte, error) { +func ListObjectSSZRoot[T ssz.HashableSSZ](list []T, limit uint64) ([32]byte, error) { subLeaves := make([][32]byte, 0, len(list)) for _, element := range list { subLeaf, err := element.HashSSZ() diff --git a/cl/rpc/rpc.go b/cl/rpc/rpc.go index 86f93ddaa40..da61b993965 100644 --- a/cl/rpc/rpc.go +++ b/cl/rpc/rpc.go @@ -17,7 +17,7 @@ import ( "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/fork" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication" @@ -132,7 +132,7 @@ func (b *BeaconRpcP2P) SendLightClientUpdatesReqV1(period uint64) (*cltypes.Ligh return nil, err } - responsePacket := []ssz_utils.EncodableSSZ{&cltypes.LightClientUpdate{}} + responsePacket := []ssz.EncodableSSZ{&cltypes.LightClientUpdate{}} data := common.CopyBytes(buffer.Bytes()) message, err := b.sentinel.SendRequest(b.ctx, &sentinel.RequestData{ diff --git a/cl/utils/bytes.go b/cl/utils/bytes.go index 66d9aa65a1c..aad96a3889b 100644 --- a/cl/utils/bytes.go +++ b/cl/utils/bytes.go @@ -18,7 +18,7 @@ import ( "math/bits" "github.com/golang/snappy" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" ) func Uint32ToBytes4(n uint32) (ret [4]byte) { @@ -56,7 +56,7 @@ func CompressSnappy(data []byte) []byte { return snappy.Encode(nil, data) } -func EncodeSSZSnappy(data ssz_utils.Marshaler) ([]byte, error) { +func EncodeSSZSnappy(data ssz.Marshaler) ([]byte, error) { var ( enc = make([]byte, 0, data.EncodingSizeSSZ()) err error @@ -69,7 +69,7 @@ func EncodeSSZSnappy(data ssz_utils.Marshaler) ([]byte, error) { return snappy.Encode(nil, enc), nil } -func DecodeSSZSnappy(dst ssz_utils.Unmarshaler, src []byte) error { +func DecodeSSZSnappy(dst ssz.Unmarshaler, src []byte) error { dec, err := snappy.Decode(nil, src) if err != nil { return err @@ -83,7 +83,7 @@ func DecodeSSZSnappy(dst ssz_utils.Unmarshaler, src []byte) error { return nil } -func DecodeSSZSnappyWithVersion(dst ssz_utils.Unmarshaler, src []byte, version int) error { +func DecodeSSZSnappyWithVersion(dst ssz.Unmarshaler, src []byte, version int) error { dec, err := snappy.Decode(nil, src) if err != nil { return err diff --git a/cmd/ef-tests-cl/consensus_tests/utils.go b/cmd/ef-tests-cl/consensus_tests/utils.go index f1c17a4fe17..747d408d496 100644 --- a/cmd/ef-tests-cl/consensus_tests/utils.go +++ b/cmd/ef-tests-cl/consensus_tests/utils.go @@ -6,7 +6,7 @@ import ( "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/utils" "github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state" ) @@ -23,7 +23,7 @@ func decodeStateFromFile(context testContext, filepath string) (*state.BeaconSta return testState, nil } -func decodeSSZObjectFromFile(obj ssz_utils.Unmarshaler, version clparams.StateVersion, filepath string) error { +func decodeSSZObjectFromFile(obj ssz.Unmarshaler, version clparams.StateVersion, filepath string) error { sszSnappy, err := os.ReadFile(filepath) if err != nil { return err diff --git a/cmd/erigon-cl/core/state/ssz.go b/cmd/erigon-cl/core/state/ssz.go index 726b4a2325e..fa5b2ea4a4d 100644 --- a/cmd/erigon-cl/core/state/ssz.go +++ b/cmd/erigon-cl/core/state/ssz.go @@ -7,7 +7,7 @@ import ( "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/cltypes/clonable" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding" ) @@ -68,9 +68,9 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { // Start encoding offset := b.baseOffsetSSZ() - dst = append(dst, ssz_utils.Uint64SSZ(b.genesisTime)...) + dst = append(dst, ssz.Uint64SSZ(b.genesisTime)...) dst = append(dst, b.genesisValidatorsRoot[:]...) - dst = append(dst, ssz_utils.Uint64SSZ(b.slot)...) + dst = append(dst, ssz.Uint64SSZ(b.slot)...) if dst, err = b.fork.EncodeSSZ(dst); err != nil { return nil, err @@ -88,7 +88,7 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { } // Historical roots offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.historicalRoots) * 32) if dst, err = b.eth1Data.EncodeSSZ(dst); err != nil { @@ -96,17 +96,17 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { } // votes offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.eth1DataVotes)) * 72 - dst = append(dst, ssz_utils.Uint64SSZ(b.eth1DepositIndex)...) + dst = append(dst, ssz.Uint64SSZ(b.eth1DepositIndex)...) // validators offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.validators)) * 121 // balances offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.balances)) * 8 for _, mix := range &b.randaoMixes { @@ -114,11 +114,11 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { } for _, slashing := range &b.slashings { - dst = append(dst, ssz_utils.Uint64SSZ(slashing)...) + dst = append(dst, ssz.Uint64SSZ(slashing)...) } // prev participation offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) // Gotta account for phase0 format (we used to store the attestations). if b.version == clparams.Phase0Version { for _, attestation := range b.previousEpochAttestations { @@ -128,7 +128,7 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { offset += uint32(len(b.previousEpochParticipation)) } // current participation offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) // Gotta account for phase0 format (we used to store the attestations). if b.version == clparams.Phase0Version { for _, attestation := range b.currentEpochAttestations { @@ -154,7 +154,7 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { if b.version >= clparams.AltairVersion { // Inactivity scores offset - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) offset += uint32(len(b.inactivityScores)) * 8 // Sync commitees @@ -166,16 +166,16 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { } // Offset (24) 'LatestExecutionPayloadHeader' - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) if b.version >= clparams.BellatrixVersion { offset += uint32(b.latestExecutionPayloadHeader.EncodingSizeSSZ()) } } if b.version >= clparams.CapellaVersion { - dst = append(dst, ssz_utils.Uint64SSZ(b.nextWithdrawalIndex)...) - dst = append(dst, ssz_utils.Uint64SSZ(b.nextWithdrawalValidatorIndex)...) - dst = append(dst, ssz_utils.OffsetSSZ(offset)...) + dst = append(dst, ssz.Uint64SSZ(b.nextWithdrawalIndex)...) + dst = append(dst, ssz.Uint64SSZ(b.nextWithdrawalValidatorIndex)...) + dst = append(dst, ssz.OffsetSSZ(offset)...) } // Write historical roots (offset 1) for _, root := range b.historicalRoots { @@ -195,15 +195,15 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { } // Write balances (offset 4) for _, balance := range b.balances { - dst = append(dst, ssz_utils.Uint64SSZ(balance)...) + dst = append(dst, ssz.Uint64SSZ(balance)...) } // Write participations (offset 4 & 5) if b.version == clparams.Phase0Version { - if dst, err = ssz_utils.EncodeDynamicList(dst, b.previousEpochAttestations); err != nil { + if dst, err = ssz.EncodeDynamicList(dst, b.previousEpochAttestations); err != nil { return nil, err } - if dst, err = ssz_utils.EncodeDynamicList(dst, b.currentEpochAttestations); err != nil { + if dst, err = ssz.EncodeDynamicList(dst, b.currentEpochAttestations); err != nil { return nil, err } } else { @@ -213,7 +213,7 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { if b.version >= clparams.AltairVersion { // write inactivity scores (offset 6) for _, score := range b.inactivityScores { - dst = append(dst, ssz_utils.Uint64SSZ(score)...) + dst = append(dst, ssz.Uint64SSZ(score)...) } } @@ -239,12 +239,12 @@ func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) { func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { b.version = clparams.StateVersion(version) if len(buf) < b.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } // Direct unmarshalling for first 3 fields - b.genesisTime = ssz_utils.UnmarshalUint64SSZ(buf) + b.genesisTime = ssz.UnmarshalUint64SSZ(buf) copy(b.genesisValidatorsRoot[:], buf[8:]) - b.slot = ssz_utils.UnmarshalUint64SSZ(buf[40:]) + b.slot = ssz.UnmarshalUint64SSZ(buf[40:]) // Fork data b.fork = new(cltypes.Fork) if err := b.fork.DecodeSSZ(buf[48:]); err != nil { @@ -268,7 +268,7 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { pos += 32 } // Read historical roots offset - historicalRootsOffset := ssz_utils.DecodeOffset(buf[pos:]) + historicalRootsOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 // Decode eth1 data b.eth1Data = new(cltypes.Eth1Data) @@ -277,16 +277,16 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { } pos += b.eth1Data.EncodingSizeSSZ() // Read votes offset - votesOffset := ssz_utils.DecodeOffset(buf[pos:]) + votesOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 // Decode deposit index - b.eth1DepositIndex = ssz_utils.UnmarshalUint64SSZ(buf[pos:]) + b.eth1DepositIndex = ssz.UnmarshalUint64SSZ(buf[pos:]) pos += 8 // Read validators offset - validatorsOffset := ssz_utils.DecodeOffset(buf[pos:]) + validatorsOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 // Read balances offset - balancesOffset := ssz_utils.DecodeOffset(buf[pos:]) + balancesOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 // Decode randao mixes for i := range b.randaoMixes { @@ -295,13 +295,13 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { } // Decode slashings for i := range b.slashings { - b.slashings[i] = ssz_utils.UnmarshalUint64SSZ(buf[pos:]) + b.slashings[i] = ssz.UnmarshalUint64SSZ(buf[pos:]) pos += 8 } // partecipation offsets - previousEpochParticipationOffset := ssz_utils.DecodeOffset(buf[pos:]) + previousEpochParticipationOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 - currentEpochParticipationOffset := ssz_utils.DecodeOffset(buf[pos:]) + currentEpochParticipationOffset := ssz.DecodeOffset(buf[pos:]) pos += 4 // just take that one smol byte @@ -327,7 +327,7 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { var inactivityScoresOffset uint32 // Decode sync committees if b.version >= clparams.AltairVersion { - inactivityScoresOffset = ssz_utils.DecodeOffset(buf[pos:]) + inactivityScoresOffset = ssz.DecodeOffset(buf[pos:]) pos += 4 b.currentSyncCommittee = new(cltypes.SyncCommittee) b.nextSyncCommittee = new(cltypes.SyncCommittee) @@ -344,47 +344,47 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { var executionPayloadOffset uint32 // Execution Payload header offset if b.version >= clparams.BellatrixVersion { - executionPayloadOffset = ssz_utils.DecodeOffset(buf[pos:]) + executionPayloadOffset = ssz.DecodeOffset(buf[pos:]) pos += 4 } var historicalSummariesOffset uint32 if b.version >= clparams.CapellaVersion { - b.nextWithdrawalIndex = ssz_utils.UnmarshalUint64SSZ(buf[pos:]) + b.nextWithdrawalIndex = ssz.UnmarshalUint64SSZ(buf[pos:]) pos += 8 - b.nextWithdrawalValidatorIndex = ssz_utils.UnmarshalUint64SSZ(buf[pos:]) + b.nextWithdrawalValidatorIndex = ssz.UnmarshalUint64SSZ(buf[pos:]) pos += 8 - historicalSummariesOffset = ssz_utils.DecodeOffset(buf[pos:]) + historicalSummariesOffset = ssz.DecodeOffset(buf[pos:]) // pos += 4 } // Now decode all the lists. var err error - if b.historicalRoots, err = ssz_utils.DecodeHashList(buf, historicalRootsOffset, votesOffset, state_encoding.HistoricalRootsLength); err != nil { + if b.historicalRoots, err = ssz.DecodeHashList(buf, historicalRootsOffset, votesOffset, state_encoding.HistoricalRootsLength); err != nil { return err } - if b.eth1DataVotes, err = ssz_utils.DecodeStaticList[*cltypes.Eth1Data](buf, votesOffset, validatorsOffset, 72, maxEth1Votes); err != nil { + if b.eth1DataVotes, err = ssz.DecodeStaticList[*cltypes.Eth1Data](buf, votesOffset, validatorsOffset, 72, maxEth1Votes); err != nil { return err } - if b.validators, err = ssz_utils.DecodeStaticList[*cltypes.Validator](buf, validatorsOffset, balancesOffset, 121, state_encoding.ValidatorRegistryLimit); err != nil { + if b.validators, err = ssz.DecodeStaticList[*cltypes.Validator](buf, validatorsOffset, balancesOffset, 121, state_encoding.ValidatorRegistryLimit); err != nil { return err } - if b.balances, err = ssz_utils.DecodeNumbersList(buf, balancesOffset, previousEpochParticipationOffset, state_encoding.ValidatorRegistryLimit); err != nil { + if b.balances, err = ssz.DecodeNumbersList(buf, balancesOffset, previousEpochParticipationOffset, state_encoding.ValidatorRegistryLimit); err != nil { return err } if b.version == clparams.Phase0Version { maxAttestations := b.beaconConfig.SlotsPerEpoch * b.beaconConfig.MaxAttestations - if b.previousEpochAttestations, err = ssz_utils.DecodeDynamicList[*cltypes.PendingAttestation](buf, previousEpochParticipationOffset, currentEpochParticipationOffset, maxAttestations); err != nil { + if b.previousEpochAttestations, err = ssz.DecodeDynamicList[*cltypes.PendingAttestation](buf, previousEpochParticipationOffset, currentEpochParticipationOffset, maxAttestations); err != nil { return err } - if b.currentEpochAttestations, err = ssz_utils.DecodeDynamicList[*cltypes.PendingAttestation](buf, currentEpochParticipationOffset, uint32(len(buf)), maxAttestations); err != nil { + if b.currentEpochAttestations, err = ssz.DecodeDynamicList[*cltypes.PendingAttestation](buf, currentEpochParticipationOffset, uint32(len(buf)), maxAttestations); err != nil { return err } return b.initBeaconState() } else { var previousEpochParticipation, currentEpochParticipation []byte - if previousEpochParticipation, err = ssz_utils.DecodeString(buf, uint64(previousEpochParticipationOffset), uint64(currentEpochParticipationOffset), state_encoding.ValidatorRegistryLimit); err != nil { + if previousEpochParticipation, err = ssz.DecodeString(buf, uint64(previousEpochParticipationOffset), uint64(currentEpochParticipationOffset), state_encoding.ValidatorRegistryLimit); err != nil { return err } - if currentEpochParticipation, err = ssz_utils.DecodeString(buf, uint64(currentEpochParticipationOffset), uint64(inactivityScoresOffset), state_encoding.ValidatorRegistryLimit); err != nil { + if currentEpochParticipation, err = ssz.DecodeString(buf, uint64(currentEpochParticipationOffset), uint64(inactivityScoresOffset), state_encoding.ValidatorRegistryLimit); err != nil { return err } b.previousEpochParticipation, b.currentEpochParticipation = cltypes.ParticipationFlagsListFromBytes(previousEpochParticipation), cltypes.ParticipationFlagsListFromBytes(currentEpochParticipation) @@ -395,7 +395,7 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { if executionPayloadOffset != 0 { endOffset = executionPayloadOffset } - if b.inactivityScores, err = ssz_utils.DecodeNumbersList(buf, inactivityScoresOffset, endOffset, state_encoding.ValidatorRegistryLimit); err != nil { + if b.inactivityScores, err = ssz.DecodeNumbersList(buf, inactivityScoresOffset, endOffset, state_encoding.ValidatorRegistryLimit); err != nil { return err } if b.version == clparams.AltairVersion { @@ -407,7 +407,7 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { } if len(buf) < int(endOffset) || executionPayloadOffset > endOffset { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } b.latestExecutionPayloadHeader = new(cltypes.Eth1Header) if err := b.latestExecutionPayloadHeader.DecodeSSZWithVersion(buf[executionPayloadOffset:endOffset], int(b.version)); err != nil { @@ -416,7 +416,7 @@ func (b *BeaconState) DecodeSSZWithVersion(buf []byte, version int) error { if b.version == clparams.BellatrixVersion { return b.initBeaconState() } - if b.historicalSummaries, err = ssz_utils.DecodeStaticList[*cltypes.HistoricalSummary](buf, historicalSummariesOffset, uint32(len(buf)), 64, state_encoding.HistoricalRootsLength); err != nil { + if b.historicalSummaries, err = ssz.DecodeStaticList[*cltypes.HistoricalSummary](buf, historicalSummariesOffset, uint32(len(buf)), 64, state_encoding.HistoricalRootsLength); err != nil { return err } // Capella diff --git a/cmd/erigon-cl/network/beacon_downloader.go b/cmd/erigon-cl/network/beacon_downloader.go index d5633d58fb4..94c7a1be73a 100644 --- a/cmd/erigon-cl/network/beacon_downloader.go +++ b/cmd/erigon-cl/network/beacon_downloader.go @@ -7,7 +7,7 @@ import ( "golang.org/x/net/context" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/rpc" ) @@ -45,7 +45,7 @@ func NewForwardBeaconDownloader(ctx context.Context, rpc *rpc.BeaconRpcP2P) *For } // Start begins the gossip listening process. -func (f *ForwardBeaconDownloader) ReceiveGossip(obj ssz_utils.Unmarshaler) { +func (f *ForwardBeaconDownloader) ReceiveGossip(obj ssz.Unmarshaler) { signedBlock := obj.(*cltypes.SignedBeaconBlock) if signedBlock.Block.ParentRoot == f.highestBlockRootProcessed { f.addSegment(signedBlock) diff --git a/cmd/erigon-cl/network/gossip_manager.go b/cmd/erigon-cl/network/gossip_manager.go index aadab8daac1..c4685afd5e2 100644 --- a/cmd/erigon-cl/network/gossip_manager.go +++ b/cmd/erigon-cl/network/gossip_manager.go @@ -6,13 +6,13 @@ import ( "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/log/v3" ) type GossipReceiver interface { - ReceiveGossip(ssz_utils.Unmarshaler) + ReceiveGossip(ssz.Unmarshaler) } type GossipManager struct { @@ -54,7 +54,7 @@ func (g *GossipManager) Loop() { //If the deserialization fails, an error is logged and the loop continues to the next iteration. //If the deserialization is successful, the object is set to the deserialized value and the loop continues to the next iteration. receivers := g.receivers[data.Type] - var object ssz_utils.Unmarshaler + var object ssz.Unmarshaler switch data.Type { case sentinel.GossipType_BeaconBlockGossipType: object = &cltypes.SignedBeaconBlock{} diff --git a/cmd/sentinel/main.go b/cmd/sentinel/main.go index 601a00be2bd..5b2238bab7e 100644 --- a/cmd/sentinel/main.go +++ b/cmd/sentinel/main.go @@ -26,7 +26,7 @@ import ( sentinelrpc "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel" "github.com/ledgerwatch/erigon/cl/cltypes" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/fork" lcCli "github.com/ledgerwatch/erigon/cmd/sentinel/cli" "github.com/ledgerwatch/erigon/cmd/sentinel/cli/flags" @@ -61,7 +61,7 @@ func constructBodyFreeRequest(t string) *sentinelrpc.RequestData { } } -func constructRequest(t string, reqBody ssz_utils.EncodableSSZ) (*sentinelrpc.RequestData, error) { +func constructRequest(t string, reqBody ssz.EncodableSSZ) (*sentinelrpc.RequestData, error) { var buffer buffer.Buffer if err := ssz_snappy.EncodeAndWrite(&buffer, reqBody); err != nil { return nil, fmt.Errorf("unable to encode request body: %v", err) diff --git a/cmd/sentinel/sentinel/communication/ssz_snappy/encoding.go b/cmd/sentinel/sentinel/communication/ssz_snappy/encoding.go index 84b07a79f11..4b363fa78aa 100644 --- a/cmd/sentinel/sentinel/communication/ssz_snappy/encoding.go +++ b/cmd/sentinel/sentinel/communication/ssz_snappy/encoding.go @@ -24,11 +24,11 @@ import ( "github.com/golang/snappy" libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon/cl/clparams" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/fork" ) -func EncodeAndWrite(w io.Writer, val ssz_utils.Marshaler, prefix ...byte) error { +func EncodeAndWrite(w io.Writer, val ssz.Marshaler, prefix ...byte) error { // create prefix for length of packet lengthBuf := make([]byte, 10) vin := binary.PutUvarint(lengthBuf, uint64(val.EncodingSizeSSZ())) @@ -52,7 +52,7 @@ func EncodeAndWrite(w io.Writer, val ssz_utils.Marshaler, prefix ...byte) error return err } -func DecodeAndRead(r io.Reader, val ssz_utils.EncodableSSZ, b *clparams.BeaconChainConfig, genesisValidatorRoot libcommon.Hash) error { +func DecodeAndRead(r io.Reader, val ssz.EncodableSSZ, b *clparams.BeaconChainConfig, genesisValidatorRoot libcommon.Hash) error { var forkDigest [4]byte // TODO(issues/5884): assert the fork digest matches the expectation for // a specific configuration. @@ -66,7 +66,7 @@ func DecodeAndRead(r io.Reader, val ssz_utils.EncodableSSZ, b *clparams.BeaconCh return DecodeAndReadNoForkDigest(r, val, version) } -func DecodeAndReadNoForkDigest(r io.Reader, val ssz_utils.EncodableSSZ, version clparams.StateVersion) error { +func DecodeAndReadNoForkDigest(r io.Reader, val ssz.EncodableSSZ, version clparams.StateVersion) error { // Read varint for length of message. encodedLn, _, err := ReadUvarint(r) if err != nil { @@ -108,7 +108,7 @@ func ReadUvarint(r io.Reader) (x, n uint64, err error) { return 0, n, nil } -func DecodeListSSZ(data []byte, count uint64, list []ssz_utils.EncodableSSZ, b *clparams.BeaconChainConfig, genesisValidatorRoot libcommon.Hash) error { +func DecodeListSSZ(data []byte, count uint64, list []ssz.EncodableSSZ, b *clparams.BeaconChainConfig, genesisValidatorRoot libcommon.Hash) error { objSize := list[0].EncodingSizeSSZ() r := bytes.NewReader(data) diff --git a/core/types/withdrawal.go b/core/types/withdrawal.go index d775fd1d69b..b8a3dea5679 100644 --- a/core/types/withdrawal.go +++ b/core/types/withdrawal.go @@ -25,7 +25,7 @@ import ( "github.com/ledgerwatch/erigon-lib/common/length" "github.com/ledgerwatch/erigon/cl/cltypes/clonable" - "github.com/ledgerwatch/erigon/cl/cltypes/ssz_utils" + "github.com/ledgerwatch/erigon/cl/cltypes/ssz" "github.com/ledgerwatch/erigon/cl/merkle_tree" "github.com/ledgerwatch/erigon/common/hexutil" "github.com/ledgerwatch/erigon/rlp" @@ -86,10 +86,10 @@ func (obj *Withdrawal) EncodeRLP(w io.Writer) error { func (obj *Withdrawal) EncodeSSZ() []byte { buf := make([]byte, obj.EncodingSizeSSZ()) - ssz_utils.MarshalUint64SSZ(buf, obj.Index) - ssz_utils.MarshalUint64SSZ(buf[8:], obj.Validator) + ssz.MarshalUint64SSZ(buf, obj.Index) + ssz.MarshalUint64SSZ(buf[8:], obj.Validator) copy(buf[16:], obj.Address[:]) - ssz_utils.MarshalUint64SSZ(buf[36:], obj.Amount) + ssz.MarshalUint64SSZ(buf[36:], obj.Amount) return buf } @@ -99,12 +99,12 @@ func (obj *Withdrawal) DecodeSSZWithVersion(buf []byte, _ int) error { func (obj *Withdrawal) DecodeSSZ(buf []byte) error { if len(buf) < obj.EncodingSizeSSZ() { - return ssz_utils.ErrLowBufferSize + return ssz.ErrLowBufferSize } - obj.Index = ssz_utils.UnmarshalUint64SSZ(buf) - obj.Validator = ssz_utils.UnmarshalUint64SSZ(buf[8:]) + obj.Index = ssz.UnmarshalUint64SSZ(buf) + obj.Validator = ssz.UnmarshalUint64SSZ(buf[8:]) copy(obj.Address[:], buf[16:]) - obj.Amount = ssz_utils.UnmarshalUint64SSZ(buf[36:]) + obj.Amount = ssz.UnmarshalUint64SSZ(buf[36:]) return nil }