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

Commit df3446b

Browse files
committed
Fix rawhash in EIP155 signing #417
1 parent 8c69e25 commit df3446b

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

ethereum/transactions.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import rlp
33
from bitcoin import encode_pubkey, N, encode_privkey
44
from rlp.sedes import big_endian_int, binary
5-
from rlp.utils import encode_hex, str_to_bytes, ascii_chr
5+
from rlp.utils import encode_hex, str_to_bytes, ascii_chr, int_to_big_endian
66
from secp256k1 import PublicKey, ALL_FLAGS, PrivateKey
77

88
from ethereum.exceptions import InvalidTransaction
@@ -108,15 +108,6 @@ def sender(self):
108108
self._sender = 0
109109
return self._sender
110110

111-
@property
112-
def normalized_v(self):
113-
"""EIP155
114-
"""
115-
if self.v in (27, 28):
116-
return self.v - 27
117-
else:
118-
return self.v - (self.__class__._chain_id * 2 + 1)
119-
120111
@sender.setter
121112
def sender(self, value):
122113
self._sender = value
@@ -131,7 +122,19 @@ def sign(self, key, backwards_compatible=True):
131122
"""
132123
if key in (0, '', b'\x00' * 32, '0' * 64):
133124
raise InvalidTransaction("Zero privkey cannot sign")
134-
rawhash = utils.sha3(rlp.encode(self, UnsignedTransaction))
125+
if backwards_compatible:
126+
rawhash = utils.sha3(rlp.encode(self, UnsignedTransaction))
127+
else:
128+
rawhash = utils.sha3(rlp.encode(Transaction(
129+
self.nonce,
130+
self.gasprice,
131+
self.startgas,
132+
self.to,
133+
self.value,
134+
self.data,
135+
18,
136+
0,
137+
0), Transaction))
135138

136139
if len(key) == 64:
137140
# we need a binary key
@@ -156,6 +159,15 @@ def sign(self, key, backwards_compatible=True):
156159
def hash(self):
157160
return utils.sha3(rlp.encode(self))
158161

162+
@property
163+
def normalized_v(self):
164+
"""EIP155
165+
"""
166+
if self.v in (27, 28):
167+
return self.v - 27
168+
else:
169+
return self.v - (self.__class__._chain_id * 2 + 1)
170+
159171
def log_bloom(self):
160172
"returns int"
161173
bloomables = [x.bloomables() for x in self.logs]
@@ -225,7 +237,7 @@ def __init__(self, *args, **kwargs):
225237
super(EIP155Transaction, self).__init__(*args, **kwargs)
226238

227239
def sign(self, key, backwards_compatible=False):
228-
return super(self).sign(key, backwards_compatible)
240+
return super(self.__class__, self).sign(key, backwards_compatible)
229241

230242

231243
UnsignedTransaction = Transaction.exclude(['v', 'r', 's'])

0 commit comments

Comments
 (0)