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

Commit ae2498a

Browse files
committed
Move develop into 'fixed' state #373
1 parent 14d0ec6 commit ae2498a

File tree

15 files changed

+156
-388
lines changed

15 files changed

+156
-388
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ script:
2323
- tox -e $TOX_ENV -- --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
2424
- tox -e $TOX_ENV -- ethereum/tests/test_vm.py
2525
- tox -e $TOX_ENV -- ethereum/tests/test_state.py
26-
- cd .tox/$TOX_ENV && coverage report --show-missing
26+
- coverage report --show-missing
2727
after_success:
2828
- travis_retry pip install coveralls
2929
- cd .tox/$TOX_ENV && coveralls
3030
after_script:
31-
- cat .tox/$TOX_ENV/log/*.log
31+
- cat .tox/$TOX_ENV/log/*.log; true
3232
notifications:
3333
slack:
3434
secure: W/UAhQ/GgYwMWrl3aiVAVOWr4WGdWrxUOX/rTB3ZgwDwGqDYLzQO5UqbsQlo1JXPZ6JOWfIPMURhHu7DSfue9dBW6xQ+NL+bFHe9lSXG4nqFK3IjezYyTBzNRJRDbGUvSSqgj6D5cwhJ8BjfUIRPbJz3CxL64KmsNXezEaMY60w=

ethereum/abi.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ethereum import utils
1010
from ethereum.utils import encode_int, zpad, big_endian_to_int, is_numeric, is_string, ceil32
11-
from ethereum.utils import TT256, TT255
11+
from ethereum.utils import isnumeric, TT256, TT255
1212

1313

1414
def json_decode(data):
@@ -255,8 +255,8 @@ def decint(n, signed=False):
255255
n = utils.to_string(n)
256256

257257
if is_numeric(n):
258-
min, max = (-TT255,TT255-1) if signed else (0,TT256-1)
259-
if n > max or n < min:
258+
min_, max_ = (-TT255, TT255 - 1) if signed else (0, TT256 - 1)
259+
if n > max_ or n < min_:
260260
raise EncodingError("Number out of range: %r" % n)
261261
return n
262262
elif is_string(n):
@@ -274,6 +274,7 @@ def decint(n, signed=False):
274274
else:
275275
raise EncodingError("Cannot encode integer: %r" % n)
276276

277+
277278
# Encodes a base datum
278279
def encode_single(typ, arg):
279280
base, sub, _ = typ
@@ -282,7 +283,7 @@ def encode_single(typ, arg):
282283
sub = int(sub)
283284
i = decint(arg, False)
284285

285-
if not 0 <= i < 2**sub:
286+
if not 0 <= i < 2 ** sub:
286287
raise ValueOutOfBounds(repr(arg))
287288
return zpad(encode_int(i), 32)
288289
# bool: int<sz>
@@ -293,22 +294,22 @@ def encode_single(typ, arg):
293294
elif base == 'int':
294295
sub = int(sub)
295296
i = decint(arg, True)
296-
if not -2**(sub - 1) <= i < 2**(sub - 1):
297+
if not -2 ** (sub - 1) <= i < 2 ** (sub - 1):
297298
raise ValueOutOfBounds(repr(arg))
298-
return zpad(encode_int(i % 2**sub), 32)
299+
return zpad(encode_int(i % 2 ** sub), 32)
299300
# Unsigned reals: ureal<high>x<low>
300301
elif base == 'ureal':
301302
high, low = [int(x) for x in sub.split('x')]
302-
if not 0 <= arg < 2**high:
303+
if not 0 <= arg < 2 ** high:
303304
raise ValueOutOfBounds(repr(arg))
304-
return zpad(encode_int(int(arg * 2**low)), 32)
305+
return zpad(encode_int(int(arg * 2 ** low)), 32)
305306
# Signed reals: real<high>x<low>
306307
elif base == 'real':
307308
high, low = [int(x) for x in sub.split('x')]
308-
if not -2**(high - 1) <= arg < 2**(high - 1):
309+
if not -2 ** (high - 1) <= arg < 2 ** (high - 1):
309310
raise ValueOutOfBounds(repr(arg))
310-
i = int(arg * 2**low)
311-
return zpad(encode_int(i % 2**(high+low)), 32)
311+
i = int(arg * 2 ** low)
312+
return zpad(encode_int(i % 2 ** (high + low)), 32)
312313
# Strings
313314
elif base == 'string' or base == 'bytes':
314315
if not is_string(arg):
@@ -327,7 +328,7 @@ def encode_single(typ, arg):
327328
elif base == 'hash':
328329
if not (int(sub) and int(sub) <= 32):
329330
raise EncodingError("too long: %r" % arg)
330-
if is_numeric(arg):
331+
if isnumeric(arg):
331332
return zpad(encode_int(arg), 32)
332333
elif len(arg) == int(sub):
333334
return zpad(arg, 32)
@@ -338,7 +339,7 @@ def encode_single(typ, arg):
338339
# Addresses: address (== hash160)
339340
elif base == 'address':
340341
assert sub == ''
341-
if is_numeric(arg):
342+
if isnumeric(arg):
342343
return zpad(encode_int(arg), 32)
343344
elif len(arg) == 20:
344345
return zpad(arg, 32)
@@ -480,7 +481,7 @@ def decode_single(typ, data):
480481
if base == 'address':
481482
return encode_hex(data[12:])
482483
elif base == 'hash':
483-
return data[32-int(sub):]
484+
return data[32 - int(sub):]
484485
elif base == 'string' or base == 'bytes':
485486
if len(sub):
486487
return data[:int(sub)]
@@ -491,15 +492,15 @@ def decode_single(typ, data):
491492
return big_endian_to_int(data)
492493
elif base == 'int':
493494
o = big_endian_to_int(data)
494-
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
495+
return (o - 2 ** int(sub)) if o >= 2 ** (int(sub) - 1) else o
495496
elif base == 'ureal':
496497
high, low = [int(x) for x in sub.split('x')]
497-
return big_endian_to_int(data) * 1.0 // 2**low
498+
return big_endian_to_int(data) * 1.0 // 2 ** low
498499
elif base == 'real':
499500
high, low = [int(x) for x in sub.split('x')]
500501
o = big_endian_to_int(data)
501-
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
502-
return (i * 1.0 // 2**low)
502+
i = (o - 2 ** (high + low)) if o >= 2 ** (high + low - 1) else o
503+
return (i * 1.0 // 2 ** low)
503504
elif base == 'bool':
504505
return bool(int(encode_hex(data), 16))
505506

ethereum/blocks.py

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from ethereum.pruning_trie import Trie
1515
from ethereum.securetrie import SecureTrie
1616
from ethereum import utils
17-
from ethereum.utils import address, int256, trie_root, hash32, to_string
18-
from ethereum.utils import big_endian_to_int
17+
from ethereum.utils import address, int256, trie_root, hash32, to_string, big_endian_to_int
1918
from ethereum import processblock
2019
from ethereum.transactions import Transaction
2120
from ethereum import bloom
@@ -76,11 +75,11 @@ def calc_difficulty(parent, timestamp):
7675
o = int(max(parent.difficulty + offset * sign, min(parent.difficulty, config['MIN_DIFF'])))
7776
period_count = (parent.number + 1) // config['EXPDIFF_PERIOD']
7877
if period_count >= config['EXPDIFF_FREE_PERIODS']:
79-
o = max(o + 2**(period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
78+
o = max(o + 2 ** (period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
79+
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
8080
return o
8181

8282

83-
8483
class Account(rlp.Serializable):
8584

8685
"""An Ethereum account.
@@ -333,7 +332,7 @@ def __eq__(self, other):
333332
return isinstance(other, BlockHeader) and self.hash == other.hash
334333

335334
def __hash__(self):
336-
return utils.big_endian_to_int(self.hash)
335+
return big_endian_to_int(self.hash)
337336

338337
def __ne__(self, other):
339338
return not self.__eq__(other)
@@ -398,7 +397,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
398397
parent=None, making=False):
399398
assert isinstance(env, Env), "No Env object given"
400399
assert isinstance(env.db, BaseDB), "No database object given"
401-
self.env = env # don't re-set after init
400+
self.env = env # don't re-set after init
402401
self.db = env.db
403402
self.config = env.config
404403

@@ -444,9 +443,12 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
444443
raise ValueError("Gas used exceeds gas limit")
445444
if self.timestamp <= parent.header.timestamp:
446445
raise ValueError("Timestamp equal to or before parent")
447-
if self.timestamp >= 2**256:
446+
if self.timestamp >= 2 ** 256:
448447
raise ValueError("Timestamp waaaaaaaaaaayy too large")
449448

449+
if self.gas_limit > 2 ** 63 - 1:
450+
raise ValueError("Block's gaslimit went too high!")
451+
450452
for uncle in uncles:
451453
assert isinstance(uncle, BlockHeader)
452454

@@ -533,7 +535,7 @@ def must_le(what, a, b):
533535
if not self.check_fields():
534536
raise ValueError("Block is invalid")
535537
if len(to_string(self.header.extra_data)) > self.config['MAX_EXTRADATA_LENGTH']:
536-
raise ValueError("Extra data cannot exceed %d bytes" \
538+
raise ValueError("Extra data cannot exceed %d bytes"
537539
% default_config['MAX_EXTRADATA_LENGTH'])
538540
if self.header.coinbase == '':
539541
raise ValueError("Coinbase cannot be empty address")
@@ -697,7 +699,7 @@ def get_ancestor_list(self, n):
697699
if n == 0 or self.header.number == 0:
698700
return []
699701
p = self.get_parent()
700-
return [p] + p.get_ancestor_list(n-1)
702+
return [p] + p.get_ancestor_list(n - 1)
701703

702704
def get_ancestor_hash(self, n):
703705
assert n > 0
@@ -708,7 +710,7 @@ def get_ancestor_hash(self, n):
708710
self.ancestor_hashes.append(
709711
get_block(self.env,
710712
self.ancestor_hashes[-1]).get_parent().hash)
711-
return self.ancestor_hashes[n-1]
713+
return self.ancestor_hashes[n - 1]
712714

713715
# def get_ancestor(self, n):
714716
# return self.get_block(self.get_ancestor_hash(n))
@@ -787,7 +789,7 @@ def _delta_item(self, address, param, value):
787789
new_value = self._get_acct_item(address, param) + value
788790
if new_value < 0:
789791
return False
790-
self._set_acct_item(address, param, new_value % 2**256)
792+
self._set_acct_item(address, param, new_value % 2 ** 256)
791793
return True
792794

793795
def mk_transaction_receipt(self, tx):
@@ -965,7 +967,7 @@ def reset_storage(self, address):
965967
for k in self.caches[CACHE_KEY]:
966968
self.set_and_journal(CACHE_KEY, k, 0)
967969

968-
def get_storage_bytes(self, address, index):
970+
def get_storage_data(self, address, index):
969971
"""Get a specific item in the storage of an account.
970972
971973
:param address: the address of the account (binary or hex string)
@@ -981,16 +983,9 @@ def get_storage_bytes(self, address, index):
981983
key = utils.zpad(utils.coerce_to_bytes(index), 32)
982984
storage = self.get_storage(address).get(key)
983985
if storage:
984-
return rlp.decode(storage)
985-
else:
986-
return b''
987-
988-
def get_storage_data(self, address, index):
989-
bytez = self.get_storage_bytes(address, index)
990-
if len(bytez) >= 32:
991-
return big_endian_to_int(bytez[-32:])
986+
return rlp.decode(storage, big_endian_int)
992987
else:
993-
return big_endian_to_int(bytez)
988+
return 0
994989

995990
def set_storage_data(self, address, index, value):
996991
"""Set a specific item in the storage of an account.
@@ -1006,7 +1001,6 @@ def set_storage_data(self, address, index, value):
10061001
if CACHE_KEY not in self.caches:
10071002
self.caches[CACHE_KEY] = {}
10081003
self.set_and_journal('all', address, True)
1009-
assert isinstance(value, (str, bytes))
10101004
self.set_and_journal(CACHE_KEY, index, value)
10111005

10121006
def account_exists(self, address):
@@ -1108,12 +1102,12 @@ def account_to_dict(self, address, with_storage_root=False,
11081102
for kk in list(subcache.keys())]
11091103
for k in list(d.keys()) + subkeys:
11101104
v = d.get(k, None)
1111-
v2 = subcache.get(utils.big_endian_to_int(k), None)
1105+
v2 = subcache.get(big_endian_to_int(k), None)
11121106
hexkey = b'0x' + encode_hex(utils.zunpad(k))
11131107
if v2 is not None:
1114-
if v2 != b'':
1108+
if v2 != 0:
11151109
med_dict['storage'][hexkey] = \
1116-
b'0x' + encode_hex(v2)
1110+
b'0x' + encode_hex(utils.int_to_big_endian(v2))
11171111
elif v is not None:
11181112
med_dict['storage'][hexkey] = b'0x' + encode_hex(rlp.decode(v))
11191113

@@ -1177,14 +1171,6 @@ def revert(self, mysnapshot):
11771171
self.ether_delta = mysnapshot['ether_delta']
11781172

11791173
def initialize(self, parent):
1180-
# DAO fork
1181-
if self.number == self.config["DAO_FORK_BLKNUM"]:
1182-
dao_main_addr = utils.normalize_address(self.config["DAO_MAIN_ADDR"])
1183-
for acct in map(utils.normalize_address, self.config["DAO_ADDRESS_LIST"]):
1184-
self.delta_balance(dao_main_addr, self.get_balance(addr))
1185-
self.set_balance(addr, 0)
1186-
self.set_code(dao_main_addr, self.config["DAO_NEWCODE"])
1187-
# Likely metropolis changes
11881174
if self.number == self.config["METROPOLIS_FORK_BLKNUM"]:
11891175
self.set_code(utils.normalize_address(self.config["METROPOLIS_STATEROOT_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
11901176
self.set_code(utils.normalize_address(self.config["METROPOLIS_BLOCKHASH_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
@@ -1308,7 +1294,7 @@ def __eq__(self, other):
13081294
return isinstance(other, (Block, CachedBlock)) and self.hash == other.hash
13091295

13101296
def __hash__(self):
1311-
return utils.big_endian_to_int(self.hash)
1297+
return big_endian_to_int(self.hash)
13121298

13131299
def __ne__(self, other):
13141300
return not self.__eq__(other)
@@ -1366,7 +1352,7 @@ def commit_state(self):
13661352
pass
13671353

13681354
def __hash__(self):
1369-
return utils.big_endian_to_int(self.hash)
1355+
return big_endian_to_int(self.hash)
13701356

13711357
@property
13721358
def hash(self):
@@ -1454,9 +1440,8 @@ def genesis(env, **kwargs):
14541440
block.set_nonce(addr, utils.parse_int_or_hex(data['nonce']))
14551441
if 'storage' in data:
14561442
for k, v in data['storage'].items():
1457-
block.set_storage_data(addr,
1458-
utils.big_endian_to_int(decode_hex(k[2:])),
1459-
decode_hex(v[2:]))
1443+
block.set_storage_data(addr, big_endian_to_int(decode_hex(k[2:])),
1444+
big_endian_to_int(decode_hex(v[2:])))
14601445
block.commit_state()
14611446
block.state.db.commit()
14621447
# genesis block has predefined state root (so no additional finalization

ethereum/config.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,14 @@
4949
HOMESTEAD_FORK_BLKNUM=1150000,
5050
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
5151
# Metropolis fork
52-
METROPOLIS_FORK_BLKNUM=9999999,
53-
METROPOLIS_ENTRY_POINT=2**160 - 1,
52+
METROPOLIS_FORK_BLKNUM=2 ** 100,
53+
METROPOLIS_ENTRY_POINT=2 ** 160 - 1,
5454
METROPOLIS_STATEROOT_STORE=0x10,
5555
METROPOLIS_BLOCKHASH_STORE=0x20,
5656
METROPOLIS_WRAPAROUND=65536,
5757
METROPOLIS_GETTER_CODE=decode_hex('6000355460205260206020f3'),
5858
METROPOLIS_DIFF_ADJUSTMENT_CUTOFF=9,
59-
# DAO fork
60-
DAO_FORK_BLKNUM = 9999998,
61-
DAO_ADDRESS_LIST = [],
62-
DAO_MAIN_ADDR = '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
63-
DAO_NEWCODE = ''
59+
# Metropolis fork
6460
)
6561
assert default_config['NEPHEW_REWARD'] == \
6662
default_config['BLOCK_REWARD'] // 32

ethereum/ethpow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def mine(self, rounds=1000, start_nonce=0):
107107

108108

109109
def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):
110-
assert utils.is_numeric(start_nonce)
110+
assert utils.isnumeric(start_nonce)
111111
cache = get_cache(block_number)
112112
nonce = start_nonce
113113
target = utils.zpad(utils.int_to_big_endian(2**256 // (difficulty or 1)), 32)

ethereum/opcodes.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
0xa2: ['LOG2', 4, 0, 1125],
6262
0xa3: ['LOG3', 5, 0, 1500],
6363
0xa4: ['LOG4', 6, 0, 1875],
64-
0xe1: ['SLOADBYTES', 3, 0, 50],
65-
0xe2: ['SSTOREBYTES', 3, 0, 0],
66-
0xe3: ['SSIZE', 1, 1, 50],
6764
0xf0: ['CREATE', 3, 1, 32000],
6865
0xf1: ['CALL', 7, 1, 40],
6966
0xf2: ['CALLCODE', 7, 1, 40],
@@ -88,7 +85,10 @@
8885
GDEFAULT = 1
8986
GMEMORY = 3
9087
GQUADRATICMEMDENOM = 512 # 1 gas per 512 quadwords
91-
88+
GSTORAGEREFUND = 15000
89+
GSTORAGEKILL = 5000
90+
GSTORAGEMOD = 5000
91+
GSTORAGEADD = 20000
9292
GEXPONENTBYTE = 10 # cost of EXP exponent per byte
9393
GCOPY = 3 # cost to copy one 32 byte word
9494
GCONTRACTBYTE = 200 # one byte of code in contract creation
@@ -111,15 +111,3 @@
111111

112112
GCALLNEWACCOUNT = 25000
113113
GSUICIDEREFUND = 24000
114-
115-
GSTORAGEBASE = 2500
116-
GSTORAGEBYTESTORAGE = 250
117-
GSTORAGEBYTECHANGE = 40
118-
GSTORAGEMIN = 2500
119-
GSSIZE = 50
120-
GSLOADBYTES = 50
121-
122-
GSTORAGEREFUND = 15000
123-
GSTORAGEKILL = 5000
124-
GSTORAGEMOD = 5000
125-
GSTORAGEADD = 20000

0 commit comments

Comments
 (0)