From 41ca8d42f944a8032aa89482552b49d5a6852941 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 10 Jul 2017 17:27:26 +0000 Subject: [PATCH 01/15] Added py-ecc (ethereum/py_pairing) to dev_requirements.txt for running tests --- dev_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev_requirements.txt b/dev_requirements.txt index 8bd463833..5d6a78a0d 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -3,4 +3,5 @@ coveralls pytest>=2.9.0 pytest-catchlog==1.2.2 pytest-timeout==1.0.0 +py-ecc https://github.com/ethereum/serpent/tarball/develop From cefa2afb989d6a176ca29d7f8c53204d44267aba Mon Sep 17 00:00:00 2001 From: NIC619 Date: Sat, 15 Jul 2017 11:38:30 -0400 Subject: [PATCH 02/15] fix byte/str type mismatch --- ethereum/pow/chain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/pow/chain.py b/ethereum/pow/chain.py index 3dedc8daf..a287b8104 100644 --- a/ethereum/pow/chain.py +++ b/ethereum/pow/chain.py @@ -365,7 +365,7 @@ def add_block(self, block): self.add_child(block) self.db.put('head_hash', self.head_hash) self.db.put(block.hash, rlp.encode(block)) - self.db.put(b'changed:'+block.hash, b''.join(list(changed.keys()))) + self.db.put(b'changed:'+block.hash, b''.join([k.encode() for k in list(changed.keys())])) print('Saved %d address change logs' % len(changed.keys())) self.db.put(b'deletes:'+block.hash, b''.join(deletes)) print('Saved %d trie node deletes for block %d (%s)' % (len(deletes), block.number, utils.encode_hex(block.hash))) From 8de4f8ba581ca3fe57c850840b58110f43fc1edc Mon Sep 17 00:00:00 2001 From: NIC619 Date: Sun, 16 Jul 2017 00:39:06 -0400 Subject: [PATCH 03/15] retain key if key is already in bytes format --- ethereum/pow/chain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/pow/chain.py b/ethereum/pow/chain.py index a287b8104..6500cfd35 100644 --- a/ethereum/pow/chain.py +++ b/ethereum/pow/chain.py @@ -365,7 +365,7 @@ def add_block(self, block): self.add_child(block) self.db.put('head_hash', self.head_hash) self.db.put(block.hash, rlp.encode(block)) - self.db.put(b'changed:'+block.hash, b''.join([k.encode() for k in list(changed.keys())])) + self.db.put(b'changed:'+block.hash, b''.join([k.encode() if isinstance(k, str) else k for k in list(changed.keys())])) print('Saved %d address change logs' % len(changed.keys())) self.db.put(b'deletes:'+block.hash, b''.join(deletes)) print('Saved %d trie node deletes for block %d (%s)' % (len(deletes), block.number, utils.encode_hex(block.hash))) From 6c34e6d235744c19afe45c8439772a1bf3aa7854 Mon Sep 17 00:00:00 2001 From: cdetrio Date: Tue, 8 Aug 2017 15:25:36 -0400 Subject: [PATCH 04/15] add pycryptodome to requirements.txt again --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5c22c1798..b111ddf27 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ scrypt py_ecc rlp>=0.4.7 https://github.com/ethereum/ethash/tarball/master +pycryptodome==3.4.6 From ac2403b106d6b56653c30e499c66a2790f4eb005 Mon Sep 17 00:00:00 2001 From: Alan Lu Date: Fri, 28 Apr 2017 13:57:14 -0500 Subject: [PATCH 05/15] Switched to coincurve --- ethereum/utils.py | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/ethereum/utils.py b/ethereum/utils.py index c54e4dd52..36b55d4fd 100644 --- a/ethereum/utils.py +++ b/ethereum/utils.py @@ -13,11 +13,11 @@ try: - import secp256k1 + import coincurve except ImportError: - import warnings - warnings.warn('could not import secp256k1', ImportWarning) - secp256k1 = None + import warning + warning.warn('could not import coincurve', ImportWarning) + coincurve = None big_endian_to_int = lambda x: big_endian_int.deserialize(str_to_bytes(x).lstrip(b'\x00')) int_to_big_endian = lambda x: big_endian_int.serialize(x) @@ -85,22 +85,15 @@ def bytes_to_int(value): def ecrecover_to_pub(rawhash, v, r, s): - if secp256k1 and hasattr(secp256k1, "PublicKey"): - # Legendre symbol check; the secp256k1 library does not seem to do this - pk = secp256k1.PublicKey(flags=secp256k1.ALL_FLAGS) - xc = r * r * r + 7 - assert pow(xc, (SECP256K1P - 1) // 2, SECP256K1P) == 1 + if coincurve and hasattr(coincurve, "PublicKey"): try: - pk.public_key = pk.ecdsa_recover( + pk = coincurve.PublicKey.from_signature_and_message( + zpad(utils.bytearray_to_bytestr(int_to_32bytearray(r)), 32) + zpad(utils.bytearray_to_bytestr(int_to_32bytearray(s)), 32) + + utils.ascii_chr(v - 27), rawhash, - pk.ecdsa_recoverable_deserialize( - zpad(bytearray_to_bytestr(int_to_32bytearray(r)), 32) + - zpad(bytearray_to_bytestr(int_to_32bytearray(s)), 32), - v - 27 - ), - raw=True + hasher=None, ) - pub = pk.serialize(compressed=False)[1:] + pub = pk.format(compressed=False)[1:] except: pub = b"\x00" * 64 else: @@ -111,12 +104,9 @@ def ecrecover_to_pub(rawhash, v, r, s): def ecsign(rawhash, key): - if secp256k1 and hasattr(secp256k1, 'PrivateKey'): - pk = secp256k1.PrivateKey(key, raw=True) - signature = pk.ecdsa_recoverable_serialize( - pk.ecdsa_sign_recoverable(rawhash, raw=True) - ) - signature = signature[0] + bytearray_to_bytestr([signature[1]]) + if coincurve and hasattr(coincurve, 'PrivateKey'): + pk = coincurve.PrivateKey(priv) + signature = pk.sign_recoverable(msghash, hasher=None) v = safe_ord(signature[64]) + 27 r = big_endian_to_int(signature[0:32]) s = big_endian_to_int(signature[32:64]) From e490fad48d1c16f9e920b51f3d4eef6ce1a1e8b5 Mon Sep 17 00:00:00 2001 From: Alan Lu Date: Tue, 15 Aug 2017 11:53:19 -0500 Subject: [PATCH 06/15] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5c22c1798..707691293 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ scrypt py_ecc rlp>=0.4.7 https://github.com/ethereum/ethash/tarball/master +coincurve>=5.0.1 From 9a9c2462b0065e407c1a641f6f2e604485c0a50c Mon Sep 17 00:00:00 2001 From: Alan Lu Date: Tue, 15 Aug 2017 11:57:49 -0500 Subject: [PATCH 07/15] Correct import for warnings --- ethereum/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/utils.py b/ethereum/utils.py index 36b55d4fd..d21998241 100644 --- a/ethereum/utils.py +++ b/ethereum/utils.py @@ -15,8 +15,8 @@ try: import coincurve except ImportError: - import warning - warning.warn('could not import coincurve', ImportWarning) + import warnings + warnings.warn('could not import coincurve', ImportWarning) coincurve = None big_endian_to_int = lambda x: big_endian_int.deserialize(str_to_bytes(x).lstrip(b'\x00')) From aecb73ad3bd494368459bcfb99c8c235c13f6ea3 Mon Sep 17 00:00:00 2001 From: Boris Kuznetsov Date: Tue, 15 Aug 2017 20:34:25 +0300 Subject: [PATCH 08/15] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 037bbe8a2..15091d989 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Contains the Transaction class, with the following methods and values: ### ethereum.tools.keys -Creates encrypted private key storaes +Creates encrypted private key storages * `decode_keystore_json(jsondata, password)` - returns the private key from an encrypted keystore object. NOTE: if you are loading from a file, the most convenient way to do this is `import json; key = decode_keystore_json(json.load(open('filename.json')), 'password')` * `make_keystore_json(key, pw, kdf='pbkdf2', cipher='aes-128-ctr')` - creates an encrypted keystore object for the key. Keeping `kdf` and `cipher` at their default values is recommended. From d3b8573929df6309aaa041e6d3cb4737a9d435ce Mon Sep 17 00:00:00 2001 From: mhchia Date: Wed, 16 Aug 2017 04:19:01 +0000 Subject: [PATCH 09/15] Add a check in tester.direct_tx To prevent from the error when `self.last_sender` is `None` already --- ethereum/tools/tester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/tools/tester.py b/ethereum/tools/tester.py index 98b89fca1..02791a43e 100644 --- a/ethereum/tools/tester.py +++ b/ethereum/tools/tester.py @@ -157,7 +157,7 @@ def __init__(self, alloc=base_alloc, env=None, genesis=None): def direct_tx(self, transaction): self.last_tx = transaction - if privtoaddr(self.last_sender) != transaction.sender: + if self.last_sender is not None and privtoaddr(self.last_sender) != transaction.sender: self.last_sender = None success, output = apply_transaction(self.head_state, transaction) self.block.transactions.append(transaction) From 486b1ac57a6871d3ed38482530e382c7007654e7 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Wed, 16 Aug 2017 12:15:08 -0400 Subject: [PATCH 10/15] upgrade pip in Travis too --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index df43175c3..c47988be8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_install: - if [ -n "$SOLC_VERSION" ]; then sudo apt-get install -y tree unzip; fi install: - if [ -n "$SOLC_VERSION" ]; then /.$TRAVIS_BUILD_DIR/.travis/install_solc.sh; fi - - travis_retry pip install setuptools --upgrade + - travis_retry pip install pip setuptools --upgrade - travis_retry pip install tox - travis_retry pip install coverage - travis_retry pip install flake8 From 3f5d7c39f8dd0acbc23d852f9b083768ae8c2361 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Wed, 16 Aug 2017 21:18:05 -0400 Subject: [PATCH 11/15] fix var name in utils.ecsign There was a an improper rebase in #777. This restores that fix. --- ethereum/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/utils.py b/ethereum/utils.py index d21998241..e82ab0c53 100644 --- a/ethereum/utils.py +++ b/ethereum/utils.py @@ -105,7 +105,7 @@ def ecrecover_to_pub(rawhash, v, r, s): def ecsign(rawhash, key): if coincurve and hasattr(coincurve, 'PrivateKey'): - pk = coincurve.PrivateKey(priv) + pk = coincurve.PrivateKey(key) signature = pk.sign_recoverable(msghash, hasher=None) v = safe_ord(signature[64]) + 27 r = big_endian_to_int(signature[0:32]) From d1bdcc744bd7f2437e46fb713ff2cd5aa585e31f Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 1 Jun 2017 14:40:59 +0200 Subject: [PATCH 12/15] solidity_names() recognizes interface Based directly on top of pyethereum v1.6.1 This is a hack. Solidity 0.4.11 introduces the interface keyword and breaks the solidity_names() function. This simply tweaks the function so that it also treats interfaces like contracts and does not break. I don't believe pyethereum should attempt to parse solidity files on its own as compatibility issues like this are almost certain to arise also in the future. For more long-term a different solution should be found where pyethereum queries solidity itself and does not parse anything on its own. --- ethereum/tools/_solidity.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ethereum/tools/_solidity.py b/ethereum/tools/_solidity.py index 8eb47f055..b1b1d979c 100644 --- a/ethereum/tools/_solidity.py +++ b/ethereum/tools/_solidity.py @@ -165,6 +165,13 @@ def solidity_names(code): # pylint: disable=too-many-branches if result: names.append(('contract', result.groups()[0])) + if char == 'i' and code[pos: pos + 9] == 'interface': + result = re.match('^interface[^_$a-zA-Z]+([_$a-zA-Z][_$a-zA-Z0-9]*)', code[pos:]) + + if result: + names.append(('contract', result.groups()[0])) + + if char == 'l' and code[pos: pos + 7] == 'library': result = re.match('^library[^_$a-zA-Z]+([_$a-zA-Z][_$a-zA-Z0-9]*)', code[pos:]) From 8d3c3f8fd035ac707eaf8fda3dc5c388c8716dca Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 17 Aug 2017 14:01:33 -0400 Subject: [PATCH 13/15] remove pbkdf2 dependency, use stdlib --- ethereum/tools/keys.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ethereum/tools/keys.py b/ethereum/tools/keys.py index d9b46232a..e9520c0f5 100644 --- a/ethereum/tools/keys.py +++ b/ethereum/tools/keys.py @@ -1,6 +1,6 @@ import os -import pbkdf2 import sys +from hashlib import pbkdf2_hmac from rlp.utils import decode_hex from ethereum.utils import encode_hex @@ -43,9 +43,8 @@ } PBKDF2_CONSTANTS = { - "prf": "hmac-sha256", "dklen": 32, - "c": 262144 + "rounds": 262144 } @@ -96,9 +95,8 @@ def mk_pbkdf2_params(): def pbkdf2_hash(val, params): - assert params["prf"] == "hmac-sha256" - return pbkdf2.PBKDF2(val, decode_hex(params["salt"]), params["c"], - SHA256).read(params["dklen"]) + return pbkdf2_hmac('sha256', val, decode_hex(params["salt"]), + params["rounds"], params["dklen"]) kdfs = { From 8e93253620a0447980da1d1496643ad0a741447a Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 17 Aug 2017 14:03:36 -0400 Subject: [PATCH 14/15] Update requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cb2c3d2af..539243791 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ pysha3>=1.0.1 PyYAML repoze.lru -pbkdf2 scrypt py_ecc rlp>=0.4.7 From 0fe8b15477c6b0981db13b5e6fbc018ef925eedc Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 17 Aug 2017 14:06:42 -0400 Subject: [PATCH 15/15] update supported versions --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c07d55a9..c2b1c6220 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ], )