Skip to content

Commit

Permalink
commentary around the little-endian situation
Browse files Browse the repository at this point in the history
  • Loading branch information
kasey committed May 22, 2024
1 parent b15c0ec commit 3c78b20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions consensus-types/blocks/get_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions consensus-types/primitives/wei.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3c78b20

Please sign in to comment.