2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# 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>.
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib import btc, messages as proto
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2019-09-11 12:43:32 +00:00
|
|
|
from ..common import MNEMONIC12
|
2020-03-03 16:29:02 +00:00
|
|
|
from ..tx_cache import TxCache
|
2018-11-02 15:25:51 +00:00
|
|
|
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_d5f65e = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
|
|
|
)
|
2017-05-15 12:14:45 +00:00
|
|
|
|
|
|
|
|
2014-02-08 23:13:32 +00:00
|
|
|
# address_n = [177] < 68
|
|
|
|
# address_n = [16518] < 66
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestZerosig:
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_one_zero_signature(self, client):
|
2017-12-12 15:40:11 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2017-06-23 19:31:42 +00:00
|
|
|
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
|
|
# amount=390000,
|
|
|
|
prev_hash=TXHASH_d5f65e,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
2014-02-08 23:13:32 +00:00
|
|
|
|
|
|
|
# Following address_n has been mined by 'test_mine_zero_signature'
|
2017-12-12 15:40:11 +00:00
|
|
|
out1 = proto.TxOutputType(
|
2017-06-23 19:31:42 +00:00
|
|
|
address_n=[177],
|
|
|
|
amount=390000 - 10000,
|
2017-12-12 15:40:11 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2020-03-03 16:29:02 +00:00
|
|
|
client, "Bitcoin", [inp1], [out1], prev_txes=TxCache("Bitcoin")
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2017-12-18 21:26:26 +00:00
|
|
|
siglen = serialized_tx[44]
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2019-06-17 18:27:55 +00:00
|
|
|
# Trezor must strip leading zero from signature
|
2017-12-23 20:20:49 +00:00
|
|
|
assert siglen == 67
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_two_zero_signature(self, client):
|
2017-12-12 15:40:11 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2017-06-23 19:31:42 +00:00
|
|
|
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
|
|
# amount=390000,
|
|
|
|
prev_hash=TXHASH_d5f65e,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
2014-02-08 23:13:32 +00:00
|
|
|
|
|
|
|
# Following address_n has been mined by 'test_mine_zero_signature'
|
2017-12-12 15:40:11 +00:00
|
|
|
out1 = proto.TxOutputType(
|
2017-06-23 19:31:42 +00:00
|
|
|
address_n=[16518],
|
|
|
|
amount=390000 - 10000,
|
2017-12-12 15:40:11 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2020-03-03 16:29:02 +00:00
|
|
|
client, "Bitcoin", [inp1], [out1], prev_txes=TxCache("Bitcoin")
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2017-12-18 21:26:26 +00:00
|
|
|
siglen = serialized_tx[44]
|
2014-02-08 23:13:32 +00:00
|
|
|
|
2019-06-17 18:27:55 +00:00
|
|
|
# Trezor must strip leading zero from signature
|
2017-12-23 20:20:49 +00:00
|
|
|
assert siglen == 66
|