Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cl/cltypes/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ type SignedAggregateAndProof struct {
}

func (a *SignedAggregateAndProof) EncodeSSZ(dst []byte) ([]byte, error) {
return ssz2.MarshalSSZ(dst, a.Message, a.Signature[:])
return encodeSigned(dst, a.Message, a.Signature[:])
}

func (a *SignedAggregateAndProof) DecodeSSZ(buf []byte, version int) error {
a.Message = new(AggregateAndProof)
return ssz2.UnmarshalSSZ(buf, version, a.Message, a.Signature[:])
return decodeSigned(buf, version, a.Message, a.Signature[:])
}

func (a *SignedAggregateAndProof) EncodingSizeSSZ() int {
return 100 + a.Message.EncodingSizeSSZ()
return sizeSigned(a.Message)
}

func (a *SignedAggregateAndProof) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(a.Message, a.Signature[:])
return hashSigned(a.Message, a.Signature[:])
}

// Default mainnet sync committee bits size in bytes (512 / 8).
Expand Down
9 changes: 4 additions & 5 deletions cl/cltypes/beacon_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ func (b *SignedBeaconBlockHeader) Static() bool {
}

func (b *SignedBeaconBlockHeader) EncodeSSZ(dst []byte) ([]byte, error) {
return ssz2.MarshalSSZ(dst, b.Header, b.Signature[:])
return encodeSigned(dst, b.Header, b.Signature[:])
}

func (b *SignedBeaconBlockHeader) DecodeSSZ(buf []byte, version int) error {
b.Header = new(BeaconBlockHeader)
return ssz2.UnmarshalSSZ(buf, version, b.Header, b.Signature[:])

return decodeSigned(buf, version, b.Header, b.Signature[:])
}

func (b *SignedBeaconBlockHeader) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(b.Header, b.Signature[:])
return hashSigned(b.Header, b.Signature[:])
}

func (b *SignedBeaconBlockHeader) EncodingSizeSSZ() int {
return b.Header.EncodingSizeSSZ() + 96
return sizeSigned(b.Header)
}
8 changes: 4 additions & 4 deletions cl/cltypes/bls_to_execution_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ type SignedBLSToExecutionChange struct {
}

func (s *SignedBLSToExecutionChange) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, s.Message, s.Signature[:])
return encodeSigned(buf, s.Message, s.Signature[:])
}

func (s *SignedBLSToExecutionChange) DecodeSSZ(buf []byte, version int) error {
s.Message = new(BLSToExecutionChange)
return ssz2.UnmarshalSSZ(buf, version, s.Message, s.Signature[:])
return decodeSigned(buf, version, s.Message, s.Signature[:])
}

func (s *SignedBLSToExecutionChange) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(s.Message, s.Signature[:])
return hashSigned(s.Message, s.Signature[:])
}

func (s *SignedBLSToExecutionChange) EncodingSizeSSZ() int {
return 96 + s.Message.EncodingSizeSSZ()
return sizeSigned(s.Message)
}
9 changes: 4 additions & 5 deletions cl/cltypes/contribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type SignedContributionAndProof struct {
}

func (a *SignedContributionAndProof) EncodeSSZ(dst []byte) ([]byte, error) {
return ssz2.MarshalSSZ(dst, a.Message, a.Signature[:])
return encodeSigned(dst, a.Message, a.Signature[:])
}

func (a *SignedContributionAndProof) DecodeSSZ(buf []byte, version int) error {
Expand All @@ -77,16 +77,15 @@ func (a *SignedContributionAndProof) DecodeSSZ(buf []byte, version int) error {
if a.Message.Contribution == nil {
a.Message.Contribution = new(Contribution)
}
return ssz2.UnmarshalSSZ(buf, version, a.Message, a.Signature[:])
return decodeSigned(buf, version, a.Message, a.Signature[:])
}

func (a *SignedContributionAndProof) EncodingSizeSSZ() int {
return length.Bytes96 + a.Message.EncodingSizeSSZ()
// return 100 + a.Message.EncodingSizeSSZ()
return sizeSigned(a.Message)
}

func (a *SignedContributionAndProof) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(a.Message, a.Signature[:])
return hashSigned(a.Message, a.Signature[:])
}

// DefaultSyncCommitteeAggregationBitsSize is the mainnet default: 512/4/8 = 16 bytes.
Expand Down
16 changes: 8 additions & 8 deletions cl/cltypes/epbs_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,24 +373,24 @@ type SignedExecutionPayloadBid struct {
}

func (s *SignedExecutionPayloadBid) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(s.Message, s.Signature[:])
return hashSigned(s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadBid) EncodingSizeSSZ() int {
return 4 + s.Message.EncodingSizeSSZ() + length.Bytes96 // 4 is the offset for Message (variable-length field)
return sizeSigned(s.Message)
}

func (s *SignedExecutionPayloadBid) Static() bool {
return false
}

func (s *SignedExecutionPayloadBid) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, s.Message, s.Signature[:])
return encodeSigned(buf, s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadBid) DecodeSSZ(buf []byte, version int) error {
s.Message = new(ExecutionPayloadBid)
return ssz2.UnmarshalSSZ(buf, version, s.Message, s.Signature[:])
return decodeSigned(buf, version, s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadBid) Clone() clonable.Clonable {
Expand Down Expand Up @@ -494,26 +494,26 @@ type SignedExecutionPayloadEnvelope struct {
}

func (s *SignedExecutionPayloadEnvelope) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(s.Message, s.Signature[:])
return hashSigned(s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadEnvelope) Static() bool {
return false
}

func (s *SignedExecutionPayloadEnvelope) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, s.Message, s.Signature[:])
return encodeSigned(buf, s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadEnvelope) DecodeSSZ(buf []byte, version int) error {
if s.Message == nil {
s.Message = NewExecutionPayloadEnvelope(s.beaconCfg)
}
return ssz2.UnmarshalSSZ(buf, version, s.Message, s.Signature[:])
return decodeSigned(buf, version, s.Message, s.Signature[:])
}

func (s *SignedExecutionPayloadEnvelope) EncodingSizeSSZ() int {
return 4 + s.Message.EncodingSizeSSZ() + length.Bytes96 // 4 is the offset for Message (variable-length)
return sizeSigned(s.Message)
}

func (s *SignedExecutionPayloadEnvelope) Clone() clonable.Clonable {
Expand Down
8 changes: 4 additions & 4 deletions cl/cltypes/epbs_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,24 @@ func (s *SignedProposerPreferences) EncodingSizeSSZ() int {
if s.Message == nil {
return length.Bytes96
}
return s.Message.EncodingSizeSSZ() + length.Bytes96
return sizeSigned(s.Message)
}

func (s *SignedProposerPreferences) Static() bool {
return true
}

func (s *SignedProposerPreferences) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, s.Message, s.Signature[:])
return encodeSigned(buf, s.Message, s.Signature[:])
}

func (s *SignedProposerPreferences) DecodeSSZ(buf []byte, version int) error {
s.Message = new(ProposerPreferences)
return ssz2.UnmarshalSSZ(buf, version, s.Message, s.Signature[:])
return decodeSigned(buf, version, s.Message, s.Signature[:])
}

func (s *SignedProposerPreferences) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(s.Message, s.Signature[:])
return hashSigned(s.Message, s.Signature[:])
}

func (s *SignedProposerPreferences) Clone() clonable.Clonable {
Expand Down
46 changes: 46 additions & 0 deletions cl/cltypes/signed_ssz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2026 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.

package cltypes

import (
"github.com/erigontech/erigon/cl/merkle_tree"
ssz2 "github.com/erigontech/erigon/cl/ssz"
"github.com/erigontech/erigon/common/length"
"github.com/erigontech/erigon/common/ssz"
)

// SSZ quartet shared by the signed container types ({Message, Signature} pairs).

func encodeSigned(buf []byte, msg ssz2.SizedObjectSSZ, sig []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, msg, sig)
}

func decodeSigned(buf []byte, version int, msg ssz2.SizedObjectSSZ, sig []byte) error {
return ssz2.UnmarshalSSZ(buf, version, msg, sig)
}

func sizeSigned(msg ssz2.SizedObjectSSZ) int {
size := length.Bytes96 + msg.EncodingSizeSSZ()
if !msg.Static() {
size += 4
}
return size
}

func hashSigned(msg ssz.HashableSSZ, sig []byte) ([32]byte, error) {
return merkle_tree.HashTreeRoot(msg, sig)
}
Loading
Loading