From 3c78b202007573339f8bf00cde7734a53f60c44d Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Tue, 21 May 2024 21:08:17 -0500 Subject: [PATCH] commentary around the little-endian situation --- consensus-types/blocks/get_payload.go | 4 ++++ consensus-types/primitives/wei.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/consensus-types/blocks/get_payload.go b/consensus-types/blocks/get_payload.go index 3618c30674fb..81bfda64b0da 100644 --- a/consensus-types/blocks/get_payload.go +++ b/consensus-types/blocks/get_payload.go @@ -41,6 +41,10 @@ func NewGetPayloadResponse(msg proto.Message) (*GetPayloadResponse, error) { bidValueGetter, hasBid := msg.(bidValueGetter) wei := primitives.ZeroWei if hasBid { + // The protobuf types that engine api responses unmarshal into store their values in little endian form. + // This is done for consistency with other uint256 values stored in protobufs for SSZ values. + // Long term we should move away from protobuf types for these values and just keep the bid as a big.Int as soon + // as we unmarshal it from the engine api response. wei = primitives.LittleEndianBytesToWei(bidValueGetter.GetValue()) } r.Bid = wei diff --git a/consensus-types/primitives/wei.go b/consensus-types/primitives/wei.go index 8d687d69b4a1..01aa288894c5 100644 --- a/consensus-types/primitives/wei.go +++ b/consensus-types/primitives/wei.go @@ -72,6 +72,9 @@ func Uint64ToWei(v uint64) Wei { } // LittleEndianBytesToWei returns a Wei value given a little-endian binary representation. +// The only places we use this representation are in protobuf types that hold either the +// local execution payload bid or the builder bid. Going forward we should avoid that representation +// so this function being used in new places should be considered a code smell. func LittleEndianBytesToWei(value []byte) Wei { if len(value) == 0 { return big.NewInt(0)