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

Commit

Permalink
Move develop into 'fixed' state #373
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkonrad committed Jul 8, 2016
1 parent 14d0ec6 commit ae2498a
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 388 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ script:
- tox -e $TOX_ENV -- --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
- tox -e $TOX_ENV -- ethereum/tests/test_vm.py
- tox -e $TOX_ENV -- ethereum/tests/test_state.py
- cd .tox/$TOX_ENV && coverage report --show-missing
- coverage report --show-missing
after_success:
- travis_retry pip install coveralls
- cd .tox/$TOX_ENV && coveralls
after_script:
- cat .tox/$TOX_ENV/log/*.log
- cat .tox/$TOX_ENV/log/*.log; true
notifications:
slack:
secure: W/UAhQ/GgYwMWrl3aiVAVOWr4WGdWrxUOX/rTB3ZgwDwGqDYLzQO5UqbsQlo1JXPZ6JOWfIPMURhHu7DSfue9dBW6xQ+NL+bFHe9lSXG4nqFK3IjezYyTBzNRJRDbGUvSSqgj6D5cwhJ8BjfUIRPbJz3CxL64KmsNXezEaMY60w=
Expand Down
37 changes: 19 additions & 18 deletions ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ethereum import utils
from ethereum.utils import encode_int, zpad, big_endian_to_int, is_numeric, is_string, ceil32
from ethereum.utils import TT256, TT255
from ethereum.utils import isnumeric, TT256, TT255


def json_decode(data):
Expand Down Expand Up @@ -255,8 +255,8 @@ def decint(n, signed=False):
n = utils.to_string(n)

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


# Encodes a base datum
def encode_single(typ, arg):
base, sub, _ = typ
Expand All @@ -282,7 +283,7 @@ def encode_single(typ, arg):
sub = int(sub)
i = decint(arg, False)

if not 0 <= i < 2**sub:
if not 0 <= i < 2 ** sub:
raise ValueOutOfBounds(repr(arg))
return zpad(encode_int(i), 32)
# bool: int<sz>
Expand All @@ -293,22 +294,22 @@ def encode_single(typ, arg):
elif base == 'int':
sub = int(sub)
i = decint(arg, True)
if not -2**(sub - 1) <= i < 2**(sub - 1):
if not -2 ** (sub - 1) <= i < 2 ** (sub - 1):
raise ValueOutOfBounds(repr(arg))
return zpad(encode_int(i % 2**sub), 32)
return zpad(encode_int(i % 2 ** sub), 32)
# Unsigned reals: ureal<high>x<low>
elif base == 'ureal':
high, low = [int(x) for x in sub.split('x')]
if not 0 <= arg < 2**high:
if not 0 <= arg < 2 ** high:
raise ValueOutOfBounds(repr(arg))
return zpad(encode_int(int(arg * 2**low)), 32)
return zpad(encode_int(int(arg * 2 ** low)), 32)
# Signed reals: real<high>x<low>
elif base == 'real':
high, low = [int(x) for x in sub.split('x')]
if not -2**(high - 1) <= arg < 2**(high - 1):
if not -2 ** (high - 1) <= arg < 2 ** (high - 1):
raise ValueOutOfBounds(repr(arg))
i = int(arg * 2**low)
return zpad(encode_int(i % 2**(high+low)), 32)
i = int(arg * 2 ** low)
return zpad(encode_int(i % 2 ** (high + low)), 32)
# Strings
elif base == 'string' or base == 'bytes':
if not is_string(arg):
Expand All @@ -327,7 +328,7 @@ def encode_single(typ, arg):
elif base == 'hash':
if not (int(sub) and int(sub) <= 32):
raise EncodingError("too long: %r" % arg)
if is_numeric(arg):
if isnumeric(arg):
return zpad(encode_int(arg), 32)
elif len(arg) == int(sub):
return zpad(arg, 32)
Expand All @@ -338,7 +339,7 @@ def encode_single(typ, arg):
# Addresses: address (== hash160)
elif base == 'address':
assert sub == ''
if is_numeric(arg):
if isnumeric(arg):
return zpad(encode_int(arg), 32)
elif len(arg) == 20:
return zpad(arg, 32)
Expand Down Expand Up @@ -480,7 +481,7 @@ def decode_single(typ, data):
if base == 'address':
return encode_hex(data[12:])
elif base == 'hash':
return data[32-int(sub):]
return data[32 - int(sub):]
elif base == 'string' or base == 'bytes':
if len(sub):
return data[:int(sub)]
Expand All @@ -491,15 +492,15 @@ def decode_single(typ, data):
return big_endian_to_int(data)
elif base == 'int':
o = big_endian_to_int(data)
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
return (o - 2 ** int(sub)) if o >= 2 ** (int(sub) - 1) else o
elif base == 'ureal':
high, low = [int(x) for x in sub.split('x')]
return big_endian_to_int(data) * 1.0 // 2**low
return big_endian_to_int(data) * 1.0 // 2 ** low
elif base == 'real':
high, low = [int(x) for x in sub.split('x')]
o = big_endian_to_int(data)
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
return (i * 1.0 // 2**low)
i = (o - 2 ** (high + low)) if o >= 2 ** (high + low - 1) else o
return (i * 1.0 // 2 ** low)
elif base == 'bool':
return bool(int(encode_hex(data), 16))

Expand Down
61 changes: 23 additions & 38 deletions ethereum/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from ethereum.pruning_trie import Trie
from ethereum.securetrie import SecureTrie
from ethereum import utils
from ethereum.utils import address, int256, trie_root, hash32, to_string
from ethereum.utils import big_endian_to_int
from ethereum.utils import address, int256, trie_root, hash32, to_string, big_endian_to_int
from ethereum import processblock
from ethereum.transactions import Transaction
from ethereum import bloom
Expand Down Expand Up @@ -76,11 +75,11 @@ def calc_difficulty(parent, timestamp):
o = int(max(parent.difficulty + offset * sign, min(parent.difficulty, config['MIN_DIFF'])))
period_count = (parent.number + 1) // config['EXPDIFF_PERIOD']
if period_count >= config['EXPDIFF_FREE_PERIODS']:
o = max(o + 2**(period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
o = max(o + 2 ** (period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
return o



class Account(rlp.Serializable):

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

def __hash__(self):
return utils.big_endian_to_int(self.hash)
return big_endian_to_int(self.hash)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down Expand Up @@ -398,7 +397,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
parent=None, making=False):
assert isinstance(env, Env), "No Env object given"
assert isinstance(env.db, BaseDB), "No database object given"
self.env = env # don't re-set after init
self.env = env # don't re-set after init
self.db = env.db
self.config = env.config

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

if self.gas_limit > 2 ** 63 - 1:
raise ValueError("Block's gaslimit went too high!")

for uncle in uncles:
assert isinstance(uncle, BlockHeader)

Expand Down Expand Up @@ -533,7 +535,7 @@ def must_le(what, a, b):
if not self.check_fields():
raise ValueError("Block is invalid")
if len(to_string(self.header.extra_data)) > self.config['MAX_EXTRADATA_LENGTH']:
raise ValueError("Extra data cannot exceed %d bytes" \
raise ValueError("Extra data cannot exceed %d bytes"
% default_config['MAX_EXTRADATA_LENGTH'])
if self.header.coinbase == '':
raise ValueError("Coinbase cannot be empty address")
Expand Down Expand Up @@ -697,7 +699,7 @@ def get_ancestor_list(self, n):
if n == 0 or self.header.number == 0:
return []
p = self.get_parent()
return [p] + p.get_ancestor_list(n-1)
return [p] + p.get_ancestor_list(n - 1)

def get_ancestor_hash(self, n):
assert n > 0
Expand All @@ -708,7 +710,7 @@ def get_ancestor_hash(self, n):
self.ancestor_hashes.append(
get_block(self.env,
self.ancestor_hashes[-1]).get_parent().hash)
return self.ancestor_hashes[n-1]
return self.ancestor_hashes[n - 1]

# def get_ancestor(self, n):
# return self.get_block(self.get_ancestor_hash(n))
Expand Down Expand Up @@ -787,7 +789,7 @@ def _delta_item(self, address, param, value):
new_value = self._get_acct_item(address, param) + value
if new_value < 0:
return False
self._set_acct_item(address, param, new_value % 2**256)
self._set_acct_item(address, param, new_value % 2 ** 256)
return True

def mk_transaction_receipt(self, tx):
Expand Down Expand Up @@ -965,7 +967,7 @@ def reset_storage(self, address):
for k in self.caches[CACHE_KEY]:
self.set_and_journal(CACHE_KEY, k, 0)

def get_storage_bytes(self, address, index):
def get_storage_data(self, address, index):
"""Get a specific item in the storage of an account.
:param address: the address of the account (binary or hex string)
Expand All @@ -981,16 +983,9 @@ def get_storage_bytes(self, address, index):
key = utils.zpad(utils.coerce_to_bytes(index), 32)
storage = self.get_storage(address).get(key)
if storage:
return rlp.decode(storage)
else:
return b''

def get_storage_data(self, address, index):
bytez = self.get_storage_bytes(address, index)
if len(bytez) >= 32:
return big_endian_to_int(bytez[-32:])
return rlp.decode(storage, big_endian_int)
else:
return big_endian_to_int(bytez)
return 0

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

def account_exists(self, address):
Expand Down Expand Up @@ -1108,12 +1102,12 @@ def account_to_dict(self, address, with_storage_root=False,
for kk in list(subcache.keys())]
for k in list(d.keys()) + subkeys:
v = d.get(k, None)
v2 = subcache.get(utils.big_endian_to_int(k), None)
v2 = subcache.get(big_endian_to_int(k), None)
hexkey = b'0x' + encode_hex(utils.zunpad(k))
if v2 is not None:
if v2 != b'':
if v2 != 0:
med_dict['storage'][hexkey] = \
b'0x' + encode_hex(v2)
b'0x' + encode_hex(utils.int_to_big_endian(v2))
elif v is not None:
med_dict['storage'][hexkey] = b'0x' + encode_hex(rlp.decode(v))

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

def initialize(self, parent):
# DAO fork
if self.number == self.config["DAO_FORK_BLKNUM"]:
dao_main_addr = utils.normalize_address(self.config["DAO_MAIN_ADDR"])
for acct in map(utils.normalize_address, self.config["DAO_ADDRESS_LIST"]):
self.delta_balance(dao_main_addr, self.get_balance(addr))
self.set_balance(addr, 0)
self.set_code(dao_main_addr, self.config["DAO_NEWCODE"])
# Likely metropolis changes
if self.number == self.config["METROPOLIS_FORK_BLKNUM"]:
self.set_code(utils.normalize_address(self.config["METROPOLIS_STATEROOT_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
self.set_code(utils.normalize_address(self.config["METROPOLIS_BLOCKHASH_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
Expand Down Expand Up @@ -1308,7 +1294,7 @@ def __eq__(self, other):
return isinstance(other, (Block, CachedBlock)) and self.hash == other.hash

def __hash__(self):
return utils.big_endian_to_int(self.hash)
return big_endian_to_int(self.hash)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down Expand Up @@ -1366,7 +1352,7 @@ def commit_state(self):
pass

def __hash__(self):
return utils.big_endian_to_int(self.hash)
return big_endian_to_int(self.hash)

@property
def hash(self):
Expand Down Expand Up @@ -1454,9 +1440,8 @@ def genesis(env, **kwargs):
block.set_nonce(addr, utils.parse_int_or_hex(data['nonce']))
if 'storage' in data:
for k, v in data['storage'].items():
block.set_storage_data(addr,
utils.big_endian_to_int(decode_hex(k[2:])),
decode_hex(v[2:]))
block.set_storage_data(addr, big_endian_to_int(decode_hex(k[2:])),
big_endian_to_int(decode_hex(v[2:])))
block.commit_state()
block.state.db.commit()
# genesis block has predefined state root (so no additional finalization
Expand Down
10 changes: 3 additions & 7 deletions ethereum/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@
HOMESTEAD_FORK_BLKNUM=1150000,
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
# Metropolis fork
METROPOLIS_FORK_BLKNUM=9999999,
METROPOLIS_ENTRY_POINT=2**160 - 1,
METROPOLIS_FORK_BLKNUM=2 ** 100,
METROPOLIS_ENTRY_POINT=2 ** 160 - 1,
METROPOLIS_STATEROOT_STORE=0x10,
METROPOLIS_BLOCKHASH_STORE=0x20,
METROPOLIS_WRAPAROUND=65536,
METROPOLIS_GETTER_CODE=decode_hex('6000355460205260206020f3'),
METROPOLIS_DIFF_ADJUSTMENT_CUTOFF=9,
# DAO fork
DAO_FORK_BLKNUM = 9999998,
DAO_ADDRESS_LIST = [],
DAO_MAIN_ADDR = '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
DAO_NEWCODE = ''
# Metropolis fork
)
assert default_config['NEPHEW_REWARD'] == \
default_config['BLOCK_REWARD'] // 32
Expand Down
2 changes: 1 addition & 1 deletion ethereum/ethpow.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def mine(self, rounds=1000, start_nonce=0):


def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):
assert utils.is_numeric(start_nonce)
assert utils.isnumeric(start_nonce)
cache = get_cache(block_number)
nonce = start_nonce
target = utils.zpad(utils.int_to_big_endian(2**256 // (difficulty or 1)), 32)
Expand Down
20 changes: 4 additions & 16 deletions ethereum/opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
0xa2: ['LOG2', 4, 0, 1125],
0xa3: ['LOG3', 5, 0, 1500],
0xa4: ['LOG4', 6, 0, 1875],
0xe1: ['SLOADBYTES', 3, 0, 50],
0xe2: ['SSTOREBYTES', 3, 0, 0],
0xe3: ['SSIZE', 1, 1, 50],
0xf0: ['CREATE', 3, 1, 32000],
0xf1: ['CALL', 7, 1, 40],
0xf2: ['CALLCODE', 7, 1, 40],
Expand All @@ -88,7 +85,10 @@
GDEFAULT = 1
GMEMORY = 3
GQUADRATICMEMDENOM = 512 # 1 gas per 512 quadwords

GSTORAGEREFUND = 15000
GSTORAGEKILL = 5000
GSTORAGEMOD = 5000
GSTORAGEADD = 20000
GEXPONENTBYTE = 10 # cost of EXP exponent per byte
GCOPY = 3 # cost to copy one 32 byte word
GCONTRACTBYTE = 200 # one byte of code in contract creation
Expand All @@ -111,15 +111,3 @@

GCALLNEWACCOUNT = 25000
GSUICIDEREFUND = 24000

GSTORAGEBASE = 2500
GSTORAGEBYTESTORAGE = 250
GSTORAGEBYTECHANGE = 40
GSTORAGEMIN = 2500
GSSIZE = 50
GSLOADBYTES = 50

GSTORAGEREFUND = 15000
GSTORAGEKILL = 5000
GSTORAGEMOD = 5000
GSTORAGEADD = 20000
Loading

0 comments on commit ae2498a

Please sign in to comment.