Skip to content

Commit

Permalink
truncate large balances (#521)
Browse files Browse the repository at this point in the history
* truncate large balances

Signed-off-by: Guillaume Ballet <[email protected]>

* add TODO in the code

* make linter happy

---------

Signed-off-by: Guillaume Ballet <[email protected]>
  • Loading branch information
gballet authored Oct 31, 2024
1 parent 8f53873 commit 054f953
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount,

binary.BigEndian.PutUint32(basicData[utils.BasicDataCodeSizeOffset-1:], uint32(codeLen))
binary.BigEndian.PutUint64(basicData[utils.BasicDataNonceOffset:], acc.Nonce)
// Because the balance is a max of 16 bytes, truncate
// the extra values. This happens in devmode, where
// 0xff**32 is allocated to the developer account.
balanceBytes := acc.Balance.Bytes()
// TODO: reduce the size of the allocation in devmode, then panic instead
// of truncating.
if len(balanceBytes) > 16 {
balanceBytes = balanceBytes[16:]
}
copy(basicData[32-len(balanceBytes):], balanceBytes[:])
values[utils.BasicDataLeafKey] = basicData[:]
values[utils.CodeHashLeafKey] = acc.CodeHash[:]
Expand Down

0 comments on commit 054f953

Please sign in to comment.