python-trezor/trezorlib/tests/device_tests/test_zerosig.py

112 lines
3.7 KiB
Python
Raw Normal View History

2017-01-03 10:40:05 -08:00
# This file is part of the TREZOR project.
#
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
2016-05-20 13:27:20 -07:00
from __future__ import print_function
2014-02-08 15:13:32 -08:00
import unittest
import binascii
import sys
2017-12-19 01:19:38 -08:00
from . import common
2014-02-08 15:13:32 -08:00
from trezorlib import messages as proto
2014-02-08 15:13:32 -08:00
2017-05-15 05:14:45 -07:00
TXHASH_d5f65e = binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
2017-05-15 05:14:45 -07:00
2014-02-08 15:13:32 -08: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.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
2014-02-08 15:13:32 -08:00
# amount=390000,
2017-05-15 05:14:45 -07:00
prev_hash=TXHASH_d5f65e,
2014-02-08 15:13:32 -08:00
prev_index=0,
)
msg = self.client._prepare_sign_tx('Bitcoin', [inp1, ], [])
2014-02-08 15:13:32 -08:00
for n in range(3500, 200000):
out1 = proto.TxOutputType(address_n=[n],
2014-02-08 15:13:32 -08:00
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
2014-02-08 15:13:32 -08:00
)
msg.ClearField('outputs')
msg.outputs.extend([out1, ])
tx = self.client.call(msg)
2014-02-16 16:54:54 -08:00
siglen = tx.serialized_tx[44]
2016-05-20 04:36:17 -07:00
print(siglen)
2014-02-08 15:13:32 -08:00
if siglen < 67:
2016-05-20 04:36:17 -07:00
print("!!!!", n)
print(binascii.hexlify(tx.serialized_tx))
2014-02-08 15:13:32 -08:00
return
'''
def test_one_zero_signature(self):
2014-02-16 16:54:54 -08:00
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType(
2017-06-23 12:31:42 -07:00
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
2014-02-08 15:13:32 -08:00
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto.TxOutputType(
2017-06-23 12:31:42 -07:00
address_n=[177],
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
2017-06-23 12:31:42 -07:00
)
2014-02-08 15:13:32 -08:00
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = serialized_tx[44]
2014-02-08 15:13:32 -08:00
2016-02-10 07:46:58 -08:00
# TREZOR must strip leading zero from signature
2014-02-08 15:13:32 -08:00
self.assertEqual(siglen, 67)
def test_two_zero_signature(self):
2014-02-16 16:54:54 -08:00
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType(
2017-06-23 12:31:42 -07:00
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
2014-02-08 15:13:32 -08:00
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto.TxOutputType(
2017-06-23 12:31:42 -07:00
address_n=[16518],
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
2017-06-23 12:31:42 -07:00
)
2014-02-08 15:13:32 -08:00
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = serialized_tx[44]
2014-02-08 15:13:32 -08:00
2016-02-10 07:46:58 -08:00
# TREZOR must strip leading zero from signature
2014-02-08 15:13:32 -08:00
self.assertEqual(siglen, 66)