|
1 | 1 | # -*- coding: utf8 -*-
|
2 | 2 | import bitcoin
|
3 | 3 | from rlp.utils import ascii_chr
|
4 |
| -from secp256k1 import PublicKey, ALL_FLAGS |
5 | 4 |
|
6 | 5 | from ethereum import utils, opcodes
|
7 | 6 | from ethereum.utils import safe_ord, decode_hex, encode_int32
|
@@ -29,28 +28,11 @@ def proc_ecrecover(ext, msg):
|
29 | 28 |
|
30 | 29 | if r >= bitcoin.N or s >= bitcoin.N or v < 27 or v > 28:
|
31 | 30 | return 1, msg.gas - opcodes.GECRECOVER, []
|
32 |
| - |
33 |
| - signature_bytes = [0] * 64 |
34 |
| - msg.data.extract_copy(signature_bytes, 0, 64, 32) |
35 |
| - msg.data.extract_copy(signature_bytes, 32, 96, 32) |
36 |
| - signature = b''.join(map(ascii_chr, signature_bytes)) |
37 |
| - |
38 |
| - pk = PublicKey(flags=ALL_FLAGS) |
39 | 31 | try:
|
40 |
| - pk.public_key = pk.ecdsa_recover( |
41 |
| - message_hash, |
42 |
| - pk.ecdsa_recoverable_deserialize( |
43 |
| - signature, |
44 |
| - v - 27 |
45 |
| - ), |
46 |
| - raw=True |
47 |
| - ) |
48 |
| - except Exception: |
49 |
| - # Recovery failed |
| 32 | + pub = utils.ecrecover_to_pub(message_hash, v, r, s) |
| 33 | + except: |
50 | 34 | return 1, msg.gas - gas_cost, []
|
51 |
| - |
52 |
| - pub = pk.serialize(compressed=False) |
53 |
| - o = [0] * 12 + [safe_ord(x) for x in utils.sha3(pub[1:])[-20:]] |
| 35 | + o = [0] * 12 + [safe_ord(x) for x in utils.sha3(pub)[-20:]] |
54 | 36 | return 1, msg.gas - gas_cost, o
|
55 | 37 |
|
56 | 38 |
|
|
0 commit comments