Skip to content

Commit

Permalink
use default little endian
Browse files Browse the repository at this point in the history
  • Loading branch information
CluEleSsUK committed Jan 30, 2025
1 parent dc725c0 commit dd50ae3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions shared/crypto/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crypto
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit dd50ae3

Please sign in to comment.