Skip to content

Commit 944e1a0

Browse files
authored
beacon/types: auto-generate SyncCommittee marshaling methods (#27296)
1 parent 3223950 commit 944e1a0

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

beacon/types/committee.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -164,44 +164,21 @@ func (sc *SyncCommittee) VerifySignature(signingRoot common.Hash, signature *Syn
164164
return bls.FastAggregateVerify(keys, signingRoot[:], &sig)
165165
}
166166

167+
//go:generate go run github.com/fjl/gencodec -type SyncAggregate -field-override syncAggregateMarshaling -out gen_syncaggregate_json.go
168+
167169
// SyncAggregate represents an aggregated BLS signature with Signers referring
168170
// to a subset of the corresponding sync committee.
169171
//
170172
// See data structure definition here:
171173
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#syncaggregate
172174
type SyncAggregate struct {
173-
Signers [params.SyncCommitteeBitmaskSize]byte
174-
Signature [params.BLSSignatureSize]byte
175-
}
176-
177-
type jsonSyncAggregate struct {
178-
Signers hexutil.Bytes `json:"sync_committee_bits"`
179-
Signature hexutil.Bytes `json:"sync_committee_signature"`
175+
Signers [params.SyncCommitteeBitmaskSize]byte `gencodec:"required" json:"sync_committee_bits"`
176+
Signature [params.BLSSignatureSize]byte `gencodec:"required" json:"sync_committee_signature"`
180177
}
181178

182-
// MarshalJSON implements json.Marshaler.
183-
func (s *SyncAggregate) MarshalJSON() ([]byte, error) {
184-
return json.Marshal(&jsonSyncAggregate{
185-
Signers: s.Signers[:],
186-
Signature: s.Signature[:],
187-
})
188-
}
189-
190-
// UnmarshalJSON implements json.Marshaler.
191-
func (s *SyncAggregate) UnmarshalJSON(input []byte) error {
192-
var sc jsonSyncAggregate
193-
if err := json.Unmarshal(input, &sc); err != nil {
194-
return err
195-
}
196-
if len(sc.Signers) != params.SyncCommitteeBitmaskSize {
197-
return fmt.Errorf("invalid signature bitmask size %d", len(sc.Signers))
198-
}
199-
if len(sc.Signature) != params.BLSSignatureSize {
200-
return fmt.Errorf("invalid signature size %d", len(sc.Signature))
201-
}
202-
copy(s.Signers[:], sc.Signers)
203-
copy(s.Signature[:], sc.Signature)
204-
return nil
179+
type syncAggregateMarshaling struct {
180+
Signers hexutil.Bytes
181+
Signature hexutil.Bytes
205182
}
206183

207184
// SignerCount returns the number of signers in the aggregate signature.

beacon/types/gen_syncaggregate_json.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)