1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-10-13 19:39:05 +00:00
trezor-firmware/trezorlib/tests/device_tests/test_zerosig.py
matejcik 54f1599a5a regenerate license headers
This clarifies the intent: the project is licenced under terms
of LGPL version 3 only, but the standard headers cover only "3 or later",
so we had to rewrite them.

In the same step, we removed author information from individual files
in favor of "SatoshiLabs and contributors", and include an AUTHORS
file that lists the contributors.

Apologies to those whose names are missing; please contact us if you wish
to add your info to the AUTHORS file.
2018-06-21 16:49:13 +02:00

106 lines
3.5 KiB
Python

# This file is part of the Trezor project.
#
# Copyright (C) 2012-2018 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# 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 License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from binascii import unhexlify
from .common import TrezorTest
from trezorlib import messages as proto
TXHASH_d5f65e = unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
# address_n = [177] < 68
# address_n = [16518] < 66
class TestZerosig(TrezorTest):
'''
def test_mine_zero_signature(self):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
msg = self.client._prepare_sign_tx('Bitcoin', [inp1, ], [])
for n in range(3500, 200000):
out1 = proto.TxOutputType(address_n=[n],
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
msg.ClearField('outputs')
msg.outputs.extend([out1, ])
tx = self.client.call(msg)
siglen = tx.serialized_tx[44]
print(siglen)
if siglen < 67:
print("!!!!", n)
print(hexlify(tx.serialized_tx))
return
'''
def test_one_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto.TxOutputType(
address_n=[177],
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = serialized_tx[44]
# TREZOR must strip leading zero from signature
assert siglen == 67
def test_two_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto.TxOutputType(
address_n=[16518],
amount=390000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])
siglen = serialized_tx[44]
# TREZOR must strip leading zero from signature
assert siglen == 66