From dd50ae38cab60e8854943db7ad49a8e1aba62f32 Mon Sep 17 00:00:00 2001 From: Patrick McClurg Date: Thu, 30 Jan 2025 14:29:43 +0100 Subject: [PATCH] use default little endian --- shared/crypto/ethereum.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/shared/crypto/ethereum.go b/shared/crypto/ethereum.go index 2c45ba6..ca15a1c 100644 --- a/shared/crypto/ethereum.go +++ b/shared/crypto/ethereum.go @@ -3,6 +3,7 @@ package crypto import ( "bytes" "crypto/sha256" + "encoding/binary" "encoding/hex" "errors" "fmt" @@ -43,20 +44,14 @@ func DepositMessageRoot(data DepositMessage) ([]byte, error) { b := bytes.Buffer{} b.Write(data.PublicKey) b.Write(data.WithdrawalCredentials) - b.Write(encodeUint64(data.Amount)) - + err := binary.Write(&b, binary.LittleEndian, data.Amount) + if err != nil { + return nil, err + } hashedRoot := sha256.Sum256(b.Bytes()) return hashedRoot[:], nil } -func encodeUint64(i uint64) []byte { - b := make([]byte, 8) - for j := uint(0); j < 8; j++ { - b[j] = byte(i >> (8 * j)) - } - return b -} - type DepositData struct { WithdrawalCredentials []byte Amount uint64 @@ -85,7 +80,10 @@ func DepositDataRoot(data DepositData) ([]byte, error) { b := bytes.Buffer{} b.Write(data.PublicKey) b.Write(data.WithdrawalCredentials) - b.Write(encodeUint64(data.Amount)) + err := binary.Write(&b, binary.LittleEndian, data.Amount) + if err != nil { + return nil, err + } b.Write(data.Signature) hash := sha256.Sum256(b.Bytes())