Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit cfd86bf

Browse files
committed
Restrict account balances and block.value_transfer < TT256
1 parent 344132b commit cfd86bf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ethereum/blocks.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515
from ethereum.pruning_trie import Trie
1616
from ethereum.securetrie import SecureTrie
1717
from ethereum import utils
18-
from ethereum.utils import address, int256, trie_root, hash32, to_string, big_endian_to_int
18+
from ethereum.utils import (
19+
address,
20+
int256,
21+
trie_root,
22+
hash32,
23+
to_string,
24+
big_endian_to_int,
25+
TT256,
26+
)
1927
from ethereum import processblock
2028
from ethereum.transactions import Transaction
2129
from ethereum import bloom
@@ -30,7 +38,6 @@
3038
else:
3139
from functools import lru_cache
3240

33-
3441
log = get_logger('eth.block')
3542
log_state = get_logger('eth.msg.state')
3643
Log = processblock.Log
@@ -920,7 +927,10 @@ def get_balance(self, address):
920927
921928
:param address: the address of the account (binary or hex string)
922929
"""
923-
return self._get_acct_item(address, 'balance')
930+
balance = self._get_acct_item(address, 'balance')
931+
if balance >= TT256:
932+
raise ValueError("balance too high")
933+
return balance
924934

925935
def set_balance(self, address, value):
926936
"""Set the balance of an account.
@@ -929,6 +939,8 @@ def set_balance(self, address, value):
929939
:param value: the new balance
930940
:returns: `True` if successful, otherwise `False`
931941
"""
942+
if value >= TT256:
943+
raise ValueError("value too high")
932944
self._set_acct_item(address, 'balance', value)
933945

934946
def delta_balance(self, address, value):
@@ -950,7 +962,7 @@ def transfer_value(self, from_addr, to_addr, value):
950962
:param value: the (positive) value to send
951963
:returns: `True` if successful, otherwise `False`
952964
"""
953-
assert value >= 0
965+
assert value >= 0 and value < TT256
954966
if self.delta_balance(from_addr, -value):
955967
return self.delta_balance(to_addr, value)
956968
return False

ethereum/tests/test_chain.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ def test_transfer(db, balance):
142142
assert blk.get_balance(v2) == b_v2 + value
143143

144144

145+
def test_alloc_too_big(db):
146+
k, v, k2, v2 = accounts()
147+
blk = None
148+
with pytest.raises(ValueError):
149+
blk = blocks.genesis(env(db), start_alloc={v: {"balance": 2 ** 256}})
150+
assert blk is None
151+
152+
145153
def test_failing_transfer(db):
146154
k, v, k2, v2 = accounts()
147155
blk = blocks.genesis(env(db), start_alloc={v: {"balance": denoms.ether * 1}})

0 commit comments

Comments
 (0)