diff --git a/api/v1/deneb/generate.go b/api/v1/deneb/generate.go index 2546891f..d5e1a9f7 100644 --- a/api/v1/deneb/generate.go +++ b/api/v1/deneb/generate.go @@ -14,6 +14,6 @@ package deneb // Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work. -//go:generate rm -f blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blindedblobsidecar_ssz.go blindedblockcontents_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblindedblockcontents_ssz.go signedblockcontents_ssz.go -//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella,../../../spec/deneb -path . --suffix ssz -objs BlindedBeaconBlock,BlindedBeaconBlockBody,BlindedBlobSidecar,BlindedBlockContents,BlockContents,SignedBlindedBeaconBlock,SignedBlindedBlockContents,SignedBlockContents -//go:generate goimports -w blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blindedblobsidecar_ssz.go blindedblockcontents_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblindedblockcontents_ssz.go,signedblockcontents_ssz.go +//go:generate rm -f blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblockcontents_ssz.go +//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella,../../../spec/deneb -path . --suffix ssz -objs BlindedBeaconBlock,BlindedBeaconBlockBody,BlockContents,SignedBlindedBeaconBlock,SignedBlockContents +//go:generate goimports -w blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblockcontents_ssz.go diff --git a/spec/phase0/attestation.go b/spec/phase0/attestation.go index e87cdf38..e9c5715c 100644 --- a/spec/phase0/attestation.go +++ b/spec/phase0/attestation.go @@ -72,7 +72,7 @@ func (a *Attestation) unpack(attestationJSON *attestationJSON) error { return errors.New("aggregation bits missing") } if a.AggregationBits, err = hex.DecodeString(strings.TrimPrefix(attestationJSON.AggregationBits, "0x")); err != nil { - return errors.Wrap(err, "invalid value for beacon block root") + return errors.Wrap(err, "invalid value for aggregation bits") } a.Data = attestationJSON.Data if a.Data == nil { diff --git a/spec/phase0/attestation_test.go b/spec/phase0/attestation_test.go index cdfd6926..162c2bde 100644 --- a/spec/phase0/attestation_test.go +++ b/spec/phase0/attestation_test.go @@ -52,7 +52,7 @@ func TestAttestationJSON(t *testing.T) { { name: "AggregationBitsInvalid", input: []byte(`{"aggregation_bits":"invalid","data":{"slot":"100","index":"1","beacon_block_root":"0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f","source":{"epoch":"1","root":"0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"},"target":{"epoch":"2","root":"0x404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f"}},"signature":"0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf"}`), - err: "invalid value for beacon block root: encoding/hex: invalid byte: U+0069 'i'", + err: "invalid value for aggregation bits: encoding/hex: invalid byte: U+0069 'i'", }, { name: "DataMissing", diff --git a/spec/phase0/types.go b/spec/phase0/types.go index 1b7d6d57..74954a66 100644 --- a/spec/phase0/types.go +++ b/spec/phase0/types.go @@ -29,6 +29,9 @@ func (e *Epoch) UnmarshalJSON(input []byte) error { if len(input) == 0 { return errors.New("input missing") } + if len(input) < 3 { + return errors.New("input malformed") + } if !bytes.HasPrefix(input, []byte{'"'}) { return errors.New("invalid prefix") @@ -47,7 +50,7 @@ func (e *Epoch) UnmarshalJSON(input []byte) error { } // MarshalJSON implements json.Marshaler. -func (e *Epoch) MarshalJSON() ([]byte, error) { +func (e Epoch) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`"%d"`, e)), nil }