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

Commit 8f5eea7

Browse files
committed
Merge pull request #301 from hackaugusto/develop
Fixed naming differences between the c_secp256k1 and bitcoin libraries
2 parents c19a90f + a5df437 commit 8f5eea7

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

ethereum/specials.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
# -*- coding: utf8 -*-
12
import bitcoin
23
from ethereum import utils, opcodes
34
from ethereum.utils import safe_ord, decode_hex
45
from rlp.utils import ascii_chr
56

7+
try:
8+
from c_secp256k1 import ecdsa_recover_raw
9+
except ImportError:
10+
import warnings
11+
warnings.warn('missing c_secp256k1 falling back to pybitcointools')
12+
13+
from bitcoin import ecdsa_raw_recover as ecdsa_recover_raw
14+
15+
616
ZERO_PRIVKEY_ADDR = decode_hex('3f17f1962b36e491b30a40b2405849e597ba5fb5')
717

818

@@ -20,7 +30,7 @@ def proc_ecrecover(ext, msg):
2030
s = msg.data.extract32(96)
2131
if r >= bitcoin.N or s >= bitcoin.N or v < 27 or v > 28:
2232
return 1, msg.gas - opcodes.GECRECOVER, []
23-
recovered_addr = bitcoin.ecdsa_raw_recover(h, (v, r, s))
33+
recovered_addr = ecdsa_recover_raw(h, (v, r, s))
2434
if recovered_addr in (False, (0, 0)):
2535
return 1, msg.gas - gas_cost, []
2636
pub = bitcoin.encode_pubkey(recovered_addr, 'bin')

ethereum/tests/test_contracts.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import bitcoin
1+
# -*- coding: utf8 -*-
22
import os
3+
4+
import bitcoin
35
import pytest
4-
from ethereum import tester, utils, abi
56
import serpent
67
from rlp.utils import decode_hex, encode_hex
7-
from ethereum.utils import safe_ord
8+
9+
from ethereum import tester, utils, abi
810
from ethereum.slogging import set_level
11+
from ethereum.utils import safe_ord
12+
13+
try:
14+
from c_secp256k1 import ecdsa_sign_raw
15+
except ImportError:
16+
import warnings
17+
warnings.warn('missing c_secp256k1 falling back to pybitcointools')
18+
19+
from bitcoin import ecdsa_raw_sign as ecdsa_sign_raw
920

1021
# customize VM log output to your needs
1122
# hint: use 'py.test' with the '-s' option to dump logs to the console
@@ -1207,7 +1218,7 @@ def test_ecrecover():
12071218
pub = bitcoin.privtopub(priv)
12081219

12091220
msghash = encode_hex(utils.sha3('the quick brown fox jumps over the lazy dog'))
1210-
V, R, S = bitcoin.ecdsa_raw_sign(msghash, priv)
1221+
V, R, S = ecdsa_sign_raw(msghash, priv)
12111222
assert bitcoin.ecdsa_raw_verify(msghash, (V, R, S), pub)
12121223

12131224
addr = utils.big_endian_to_int(utils.sha3(bitcoin.encode_pubkey(pub, 'bin')[1:])[12:])
@@ -1660,7 +1671,7 @@ def test_prefix_types_in_functions():
16601671
s = tester.state()
16611672
c = s.abi_contract(prefix_types_in_functions_code)
16621673
assert c.sqrdiv(25, 2) == 156
1663-
1674+
16641675

16651676

16661677
# test_evm = None

ethereum/transactions.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
from bitcoin import encode_pubkey, N, P
2-
try:
3-
from c_secp256k1 import ecdsa_raw_sign, ecdsa_raw_recover
4-
except ImportError:
5-
from bitcoin import ecdsa_raw_sign, ecdsa_raw_recover
1+
# -*- coding: utf8 -*-
62
import rlp
3+
from bitcoin import encode_pubkey, N, P
74
from rlp.sedes import big_endian_int, binary
85
from rlp.utils import decode_hex, encode_hex, str_to_bytes, ascii_chr
6+
7+
from ethereum.exceptions import InvalidTransaction
98
from ethereum import bloom
9+
from ethereum import opcodes
1010
from ethereum import utils
11-
from ethereum.utils import TT256, mk_contract_address
12-
from ethereum.exceptions import InvalidTransaction
1311
from ethereum.slogging import get_logger
14-
from ethereum import opcodes
12+
from ethereum.utils import TT256, mk_contract_address
13+
14+
try:
15+
from c_secp256k1 import ecdsa_sign_raw, ecdsa_recover_raw
16+
except ImportError:
17+
import warnings
18+
warnings.warn('missing c_secp256k1 falling back to pybitcointools')
19+
20+
from bitcoin import ecdsa_raw_sign as ecdsa_sign_raw, ecdsa_raw_recover as ecdsa_recover_raw
21+
1522
log = get_logger('eth.chain.tx')
1623

1724
# in the yellow paper it is specified that s should be smaller than secpk1n (eq.205)
@@ -78,7 +85,7 @@ def sender(self):
7885
log.debug('recovering sender')
7986
rlpdata = rlp.encode(self, UnsignedTransaction)
8087
rawhash = utils.sha3(rlpdata)
81-
pub = ecdsa_raw_recover(rawhash, (self.v, self.r, self.s))
88+
pub = ecdsa_recover_raw(rawhash, (self.v, self.r, self.s))
8289
if pub is False:
8390
raise InvalidTransaction("Invalid signature values (x^3+7 is non-residue)")
8491
if pub == (0, 0):
@@ -102,7 +109,7 @@ def sign(self, key):
102109
if key in (0, '', '\x00' * 32):
103110
raise InvalidTransaction("Zero privkey cannot sign")
104111
rawhash = utils.sha3(rlp.encode(self, UnsignedTransaction))
105-
self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
112+
self.v, self.r, self.s = ecdsa_sign_raw(rawhash, key)
106113
self.sender = utils.privtoaddr(key)
107114
return self
108115

0 commit comments

Comments
 (0)