python-trezor/tests/test_zerosig.py

96 lines
3.5 KiB
Python
Raw Normal View History

2016-05-20 20:27:20 +00:00
from __future__ import print_function
2014-02-08 23:13:32 +00:00
import unittest
import common
import binascii
import sys
2014-02-08 23:13:32 +00:00
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
if sys.version_info < (3,):
def byteindex(data, index):
return ord(data[index])
else:
byteindex = lambda data, index: data[index]
2014-02-08 23:13:32 +00:00
# address_n = [177] < 68
# address_n = [16518] < 66
class TestZeroSig(common.TrezorTest):
'''
def test_mine_zero_signature(self):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0,
)
msg = self.client._prepare_sign_tx('Bitcoin', [inp1, ], [])
2014-02-08 23:13:32 +00:00
for n in range(3500, 200000):
out1 = proto_types.TxOutputType(address_n=[n],
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
msg.ClearField('outputs')
msg.outputs.extend([out1, ])
tx = self.client.call(msg)
2014-02-17 00:54:54 +00:00
siglen = byteindex(tx.serialized_tx, 44)
2016-05-20 11:36:17 +00:00
print(siglen)
2014-02-08 23:13:32 +00:00
if siglen < 67:
2016-05-20 11:36:17 +00:00
print("!!!!", n)
print(binascii.hexlify(tx.serialized_tx))
2014-02-08 23:13:32 +00:00
return
'''
def test_one_zero_signature(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
2014-02-08 23:13:32 +00:00
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto_types.TxOutputType(address_n=[177],
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = byteindex(serialized_tx, 44)
2014-02-08 23:13:32 +00:00
2016-02-10 15:46:58 +00:00
# TREZOR must strip leading zero from signature
2014-02-08 23:13:32 +00:00
self.assertEqual(siglen, 67)
def test_two_zero_signature(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
2014-02-08 23:13:32 +00:00
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto_types.TxOutputType(address_n=[16518],
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = byteindex(serialized_tx, 44)
2014-02-08 23:13:32 +00:00
2016-02-10 15:46:58 +00:00
# TREZOR must strip leading zero from signature
2014-02-08 23:13:32 +00:00
self.assertEqual(siglen, 66)
2014-02-17 00:54:54 +00:00
2014-02-08 23:13:32 +00:00
if __name__ == '__main__':
unittest.main()