From 69438583e538569cdc8eb9b130849600629424ac Mon Sep 17 00:00:00 2001 From: terencechain Date: Wed, 15 Jun 2022 21:29:32 -0700 Subject: [PATCH] Pad `Uint256`'s `SSZBytes` to length 32 (#10889) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- api/client/builder/types.go | 2 +- api/client/builder/types_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/client/builder/types.go b/api/client/builder/types.go index a54b797ec..61ee0ed44 100644 --- a/api/client/builder/types.go +++ b/api/client/builder/types.go @@ -63,7 +63,7 @@ func sszBytesToUint256(b []byte) Uint256 { // SSZBytes creates an ssz-style (little-endian byte slice) representation of the Uint256 func (s Uint256) SSZBytes() []byte { - return bytesutil.ReverseByteOrder(s.Int.Bytes()) + return bytesutil.PadTo(bytesutil.ReverseByteOrder(s.Int.Bytes()), 32) } var errUnmarshalUint256Failed = errors.New("unable to UnmarshalText into a Uint256 value") diff --git a/api/client/builder/types_test.go b/api/client/builder/types_test.go index a75f5e5c5..60a0e4007 100644 --- a/api/client/builder/types_test.go +++ b/api/client/builder/types_test.go @@ -694,9 +694,10 @@ func TestMarshalBlindedBeaconBlockBodyBellatrix(t *testing.T) { } func TestRoundTripUint256(t *testing.T) { - vs := "452312848583266388373324160190187140051835877600158453279131187530910662656" + vs := "4523128485832663883733241601901871400518358776001584532791311875309106626" u := stringToUint256(vs) sb := u.SSZBytes() + require.Equal(t, 32, len(sb)) uu := sszBytesToUint256(sb) require.Equal(t, true, bytes.Equal(u.SSZBytes(), uu.SSZBytes())) require.Equal(t, vs, uu.String())