Skip to content

Commit

Permalink
force the 32-byte alignment of nonce and balance (#71)
Browse files Browse the repository at this point in the history
* force the 32-byte alignment of nonce and balance

* review feedback: fix endianness in output
  • Loading branch information
gballet committed Feb 9, 2022
1 parent 2554974 commit 291a947
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ func (t *VerkleTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
}
var nonce [32]byte
binary.BigEndian.PutUint64(nonce[:], acc.Nonce)
binary.LittleEndian.PutUint64(nonce[24:], acc.Nonce)
if err = t.TryUpdate(utils.GetTreeKeyNonce(key), nonce[:]); err != nil {
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
}
if err = t.TryUpdate(utils.GetTreeKeyBalance(key), acc.Balance.Bytes()); err != nil {
var balance [32]byte
for i, b := range acc.Balance.Bytes() {
balance[31-i] = b
}
if err = t.TryUpdate(utils.GetTreeKeyBalance(key), balance[:]); err != nil {
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
}
if err = t.TryUpdate(utils.GetTreeKeyCodeKeccak(key), acc.CodeHash); err != nil {
Expand Down

0 comments on commit 291a947

Please sign in to comment.