|
30 | 30 |
|
31 | 31 |
|
32 | 32 | class TestMsgEthereumSigntx(common.KeepKeyTest): |
| 33 | + def test_ethereum_unrenderable_amounts_are_rejected(self): |
| 34 | + """Neither a native nor ERC-20 amount may reach an approval blank.""" |
| 35 | + self.requires_firmware("7.14.2") |
| 36 | + self.requires_fullFeature() |
| 37 | + self.setup_mnemonic_nopin_nopassphrase() |
| 38 | + |
| 39 | + recipient = binascii.unhexlify( |
| 40 | + "1d1c328764a41bda0492b66baa30c4a339ff85ef" |
| 41 | + ) |
| 42 | + max_uint256 = (1 << 256) - 1 |
| 43 | + |
| 44 | + with self.client: |
| 45 | + self.client.set_expected_responses([ |
| 46 | + proto.Failure( |
| 47 | + code=proto_types.Failure_SyntaxError, |
| 48 | + message="Ethereum amount too large"), |
| 49 | + ]) |
| 50 | + with self.assertRaises(CallException): |
| 51 | + self.client.ethereum_sign_tx( |
| 52 | + n=[0, 0], nonce=0, gas_price=20, gas_limit=21000, |
| 53 | + to=recipient, value=max_uint256, chain_id=1, |
| 54 | + ) |
| 55 | + |
| 56 | + # Known mainnet ERC-20 transfer with the same unrenderable amount. |
| 57 | + erc20_data = ( |
| 58 | + binascii.unhexlify("a9059cbb" + "00" * 12) + |
| 59 | + recipient + int_to_big_endian(max_uint256).rjust(32, b"\x00") |
| 60 | + ) |
| 61 | + with self.client: |
| 62 | + self.client.set_expected_responses([ |
| 63 | + proto.Failure( |
| 64 | + code=proto_types.Failure_SyntaxError, |
| 65 | + message="Ethereum amount too large"), |
| 66 | + ]) |
| 67 | + with self.assertRaises(CallException): |
| 68 | + self.client.ethereum_sign_tx( |
| 69 | + n=[0, 0], nonce=0, gas_price=20, gas_limit=60000, |
| 70 | + to=binascii.unhexlify( |
| 71 | + "d0d6d6c5fe4a677d343cc433536bb717bae167dd" |
| 72 | + ), |
| 73 | + value=0, chain_id=1, data=erc20_data, |
| 74 | + ) |
| 75 | + |
33 | 76 | def test_ethereum_signtx_data(self): |
34 | 77 | self.requires_fullFeature() |
35 | 78 | self.setup_mnemonic_nopin_nopassphrase() |
|
0 commit comments