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

Commit 4b2f106

Browse files
vubvub
authored andcommitted
A few py3 compatibility and test network changes
1 parent 99110e9 commit 4b2f106

File tree

10 files changed

+38
-14
lines changed

10 files changed

+38
-14
lines changed

ethereum/abi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def encode_abi(types, args):
478478
def decode_single(typ, data):
479479
base, sub, _ = typ
480480
if base == 'address':
481-
return encode_hex(data[12:])
481+
return '0x' + encode_hex(data[12:])
482482
elif base == 'hash':
483483
return data[32-int(sub):]
484484
elif base == 'string' or base == 'bytes':
@@ -553,7 +553,7 @@ def dec(typ, arg):
553553
# Dynamic-sized strings are encoded as <len(str)> + <str>
554554
if base in ('string', 'bytes') and not sub:
555555
L = big_endian_to_int(arg[:32])
556-
assert len(arg[32:]) == ceil32(L), "Wrong data size for string/bytes object"
556+
assert len(arg[32:]) == ceil32(L), "Wrong data size for string/bytes object: expected %d actual %d" % (ceil32(L), len(arg[32:]))
557557
return arg[32:][:L]
558558
# Dynamic-sized arrays
559559
elif sz is None:

ethereum/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
DAO_WITHDRAWER = utils.normalize_address('0xbf4ed7b27f1d666546e30d74d50d173d20bca754'),
6464
# Anti-DoS fork
6565
ANTI_DOS_FORK_BLKNUM = 2463000,
66-
CLEARING_FORK_BLKNUM = 3500000,
66+
CLEARING_FORK_BLKNUM = 2675000,
6767
# Default consensus strategy: ethash, poa, casper, pbft
6868
CONSENSUS_STRATEGY = 'ethash',
6969
# Serenity fork

ethereum/state.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,19 @@ def revert(self, snapshot):
315315
if not premod:
316316
del self.modified[addr]
317317

318+
# Prints the state for a single account
319+
def account_to_dict(self, address):
320+
address = normalize_address(address)
321+
acct = self._get_account_unsafe(address)
322+
acct_trie = SecureTrie(Trie(self.db))
323+
acct_trie.root_hash = acct.storage
324+
odict = acct_trie.to_dict()
325+
if address in self.cache:
326+
for k, v in self.cache[address].items():
327+
if k not in ACCOUNT_SPECIAL_PARAMS:
328+
odict[k] = v
329+
return {'0x'+encode_hex(key): '0x'+encode_hex(val) for key, val in odict.items()}
330+
318331
# Converts the state tree to a dictionary
319332
def to_dict(self):
320333
state_dump = {}
@@ -324,7 +337,7 @@ def to_dict(self):
324337
acct_trie = SecureTrie(Trie(self.db))
325338
acct_trie.root_hash = acct.storage
326339
for key, v in acct_trie.to_dict().items():
327-
storage_dump[encode_hex(key.lstrip('\x00') or '\x00')] = encode_hex(rlp.decode(v))
340+
storage_dump['0x'+encode_hex(key.lstrip('\x00') or '\x00')] = '0x'+encode_hex(rlp.decode(v))
328341
acct_dump = {"storage": storage_dump}
329342
for c in ACCOUNT_OUTPUTTABLE_PARAMS:
330343
acct_dump[c] = snapshot_form(getattr(acct, c))
@@ -341,7 +354,7 @@ def to_dict(self):
341354
acct_dump[key] = snapshot_form(val)
342355
else:
343356
if val:
344-
acct_dump["storage"][encode_hex(key)] = encode_hex(val)
357+
acct_dump["storage"]['0x'+encode_hex(key)] = '0x'+encode_hex(val)
345358
elif encode_hex(key) in acct_dump["storage"]:
346359
del acct_dump["storage"][val]
347360
return state_dump

ethereum/state_transition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def __init__(self, state, tx):
409409
self.get_storage_data = state.get_storage_data
410410
self.get_storage_bytes = state.get_storage_bytes
411411
self.set_storage_bytes = state.set_storage_bytes
412-
self.log_storage = lambda x: 'storage logging stub'
412+
self.log_storage = lambda x: state.account_to_dict(x)
413413
self.add_suicide = lambda x: state.add_to_list('suicides', x)
414414
self.add_refund = lambda x: \
415415
state.set_param('refunds', state.refunds + x)

ethereum/transactions.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def sender(self):
7474
if not self._sender:
7575
# Determine sender
7676
if self.v:
77-
if self.r >= N or self.s >= N or self.v not in (27, 28, 37, 38) \
77+
if self.r >= N or self.s >= N or self.v not in (27, 28, 37, 38, 41, 42) \
7878
or self.r == 0 or self.s == 0:
7979
raise InvalidTransaction("Invalid signature values!")
8080
log.debug('reco< 27 or self.v > 28 \vering sender')
@@ -86,6 +86,10 @@ def sender(self):
8686
rlpdata = rlp.encode(rlp.infer_sedes(self).serialize(self)[:-3] + ['\x01', '', ''])
8787
rawhash = utils.sha3(rlpdata)
8888
v = self.v - 10
89+
elif self.v in (41, 42):
90+
rlpdata = rlp.encode(rlp.infer_sedes(self).serialize(self)[:-3] + ['\x03', '', ''])
91+
rawhash = utils.sha3(rlpdata)
92+
v = self.v - 14
8993
pub = ecrecover_to_pub(rawhash, v, self.r, self.s)
9094
if pub == b"\x00" * 64:
9195
raise InvalidTransaction("Invalid signature (zero privkey cannot sign)")
@@ -99,20 +103,27 @@ def sender(self):
99103
def sender(self, value):
100104
self._sender = value
101105

102-
def sign(self, key):
106+
def sign(self, key, network_id=None):
103107
"""Sign this transaction with a private key.
104108
105109
A potentially already existing signature would be overridden.
106110
"""
107111
if key in (0, '', b'\x00' * 32, '0' * 64):
108112
raise InvalidTransaction("Zero privkey cannot sign")
109-
rawhash = utils.sha3(rlp.encode(self, UnsignedTransaction))
113+
if network_id is None:
114+
rawhash = utils.sha3(rlp.encode(self, UnsignedTransaction))
115+
else:
116+
assert 1 <= network_id < 2**63 - 18
117+
rlpdata = rlp.encode(rlp.infer_sedes(self).serialize(self)[:-3] + [big_endian_to_int(network_id), '', ''])
118+
rawhash = utils.sha3(rlpdata)
110119

111120
if len(key) == 64:
112121
# we need a binary key
113122
key = encode_privkey(key, 'bin')
114123

115124
self.v, self.r, self.s = ecsign(rawhash, key)
125+
if network_id is not None:
126+
self.v += 8 + network_id * 2
116127

117128
self.sender = utils.privtoaddr(key)
118129
return self

ethereum/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def ecrecover_to_pub(rawhash, v, r, s):
7676
# Legendre symbol check; the secp256k1 library does not seem to do this
7777
pk = secp256k1.PublicKey(flags=secp256k1.ALL_FLAGS)
7878
xc = r * r * r + 7
79-
assert pow(xc, (SECP256K1P - 1) / 2, SECP256K1P) == 1
79+
assert pow(xc, (SECP256K1P - 1) // 2, SECP256K1P) == 1
8080
try:
8181
pk.public_key = pk.ecdsa_recover(
8282
rawhash,

ethereum/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def vm_execute(ext, msg, code):
231231
in compustate.memory])
232232
else:
233233
trace_data['sha3memory'] = \
234-
encode_hex(utils.sha3(''.join([ascii_chr(x) for
234+
encode_hex(utils.sha3(b''.join([ascii_chr(x) for
235235
x in compustate.memory])))
236236
if _prevop in ('SSTORE', 'SLOAD') or steps == 0:
237237
trace_data['storage'] = ext.log_storage(msg.to)

fixtures

Submodule fixtures updated 33 files

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.3.6
2+
current_version = 1.3.7
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility.
2323
# see: https://github.com/ethereum/pyethapp/wiki/Development:-Versions-and-Releases
24-
version = '1.3.6'
24+
version = '1.3.7'
2525

2626
setup(
2727
name="ethereum",

0 commit comments

Comments
 (0)