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

Commit e404f0b

Browse files
authored
Merge branch 'develop' into dep-pycryptodome
2 parents 6c34e6d + 315bc3f commit e404f0b

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ before_install:
2323
- if [ -n "$SOLC_VERSION" ]; then sudo apt-get install -y tree unzip; fi
2424
install:
2525
- if [ -n "$SOLC_VERSION" ]; then /.$TRAVIS_BUILD_DIR/.travis/install_solc.sh; fi
26-
- travis_retry pip install setuptools --upgrade
26+
- travis_retry pip install pip setuptools --upgrade
2727
- travis_retry pip install tox
2828
- travis_retry pip install coverage
2929
- travis_retry pip install flake8

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Contains the Transaction class, with the following methods and values:
160160

161161
### ethereum.tools.keys
162162

163-
Creates encrypted private key storaes
163+
Creates encrypted private key storages
164164

165165
* `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')`
166166
* `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.

ethereum/tools/tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, alloc=base_alloc, env=None, genesis=None):
157157

158158
def direct_tx(self, transaction):
159159
self.last_tx = transaction
160-
if privtoaddr(self.last_sender) != transaction.sender:
160+
if self.last_sender is not None and privtoaddr(self.last_sender) != transaction.sender:
161161
self.last_sender = None
162162
success, output = apply_transaction(self.head_state, transaction)
163163
self.block.transactions.append(transaction)

ethereum/utils.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414

1515
try:
16-
import secp256k1
16+
import coincurve
1717
except ImportError:
1818
import warnings
19-
warnings.warn('could not import secp256k1', ImportWarning)
20-
secp256k1 = None
19+
warnings.warn('could not import coincurve', ImportWarning)
20+
coincurve = None
2121

2222
big_endian_to_int = lambda x: big_endian_int.deserialize(str_to_bytes(x).lstrip(b'\x00'))
2323
int_to_big_endian = lambda x: big_endian_int.serialize(x)
@@ -85,22 +85,15 @@ def bytes_to_int(value):
8585

8686

8787
def ecrecover_to_pub(rawhash, v, r, s):
88-
if secp256k1 and hasattr(secp256k1, "PublicKey"):
89-
# Legendre symbol check; the secp256k1 library does not seem to do this
90-
pk = secp256k1.PublicKey(flags=secp256k1.ALL_FLAGS)
91-
xc = r * r * r + 7
92-
assert pow(xc, (SECP256K1P - 1) // 2, SECP256K1P) == 1
88+
if coincurve and hasattr(coincurve, "PublicKey"):
9389
try:
94-
pk.public_key = pk.ecdsa_recover(
90+
pk = coincurve.PublicKey.from_signature_and_message(
91+
zpad(utils.bytearray_to_bytestr(int_to_32bytearray(r)), 32) + zpad(utils.bytearray_to_bytestr(int_to_32bytearray(s)), 32) +
92+
utils.ascii_chr(v - 27),
9593
rawhash,
96-
pk.ecdsa_recoverable_deserialize(
97-
zpad(bytearray_to_bytestr(int_to_32bytearray(r)), 32) +
98-
zpad(bytearray_to_bytestr(int_to_32bytearray(s)), 32),
99-
v - 27
100-
),
101-
raw=True
94+
hasher=None,
10295
)
103-
pub = pk.serialize(compressed=False)[1:]
96+
pub = pk.format(compressed=False)[1:]
10497
except:
10598
pub = b"\x00" * 64
10699
else:
@@ -111,12 +104,9 @@ def ecrecover_to_pub(rawhash, v, r, s):
111104

112105

113106
def ecsign(rawhash, key):
114-
if secp256k1 and hasattr(secp256k1, 'PrivateKey'):
115-
pk = secp256k1.PrivateKey(key, raw=True)
116-
signature = pk.ecdsa_recoverable_serialize(
117-
pk.ecdsa_sign_recoverable(rawhash, raw=True)
118-
)
119-
signature = signature[0] + bytearray_to_bytestr([signature[1]])
107+
if coincurve and hasattr(coincurve, 'PrivateKey'):
108+
pk = coincurve.PrivateKey(priv)
109+
signature = pk.sign_recoverable(msghash, hasher=None)
120110
v = safe_ord(signature[64]) + 27
121111
r = big_endian_to_int(signature[0:32])
122112
s = big_endian_to_int(signature[32:64])

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ py_ecc
77
rlp>=0.4.7
88
https://github.com/ethereum/ethash/tarball/master
99
pycryptodome==3.4.6
10+
coincurve>=5.0.1

0 commit comments

Comments
 (0)