parent
cec1f39a90
commit
6f1005b155
@ -0,0 +1,67 @@
|
||||
{
|
||||
"setup": {
|
||||
"mnemonic": "all all all all all all all all all all all all",
|
||||
"passphrase": ""
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"parameters": {
|
||||
"path": "m/44'/60'/0'"
|
||||
},
|
||||
"result": {
|
||||
"address": "0xdA0b608bdb1a4A154325C854607c68950b4F1a34"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"path": "m/44'/60'/100'"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x93Fb0Ff84F5BB6E7b6a9835C7AA6dE7a76794266"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"path": "m/44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"path": "m/44'/60'/0'/0/100"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x1e6E3708a059aEa1241a81c7aAe84b6CDbC54d59"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ETC",
|
||||
"parameters": {
|
||||
"path": "m/44'/61'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0xF410e37E9C8BCf8CF319c84Ae9dCEbe057804a04"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "GoChain",
|
||||
"parameters": {
|
||||
"path": "m/44'/6060'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0xA26a450ef46a5f11a510eBA2119A3236fa0Aca92"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Wanchain",
|
||||
"parameters": {
|
||||
"path": "m/44'/5718350'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0xe432a7533D689ceed00B7EE91d9368b8A1693bD2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,160 @@
|
||||
{
|
||||
"setup": {
|
||||
"mnemonic": "all all all all all all all all all all all all",
|
||||
"passphrase": ""
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"name": "Ethereum",
|
||||
"parameters": {
|
||||
"chain_id": 1,
|
||||
"path": "44'/60'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 38,
|
||||
"sig_r": "6a6349bddb5749bb8b96ce2566a035ef87a09dbf89b5c7e3dfdf9ed725912f24",
|
||||
"sig_s": "4ae58ccd3bacee07cdc4a3e8540544fd009c4311af7048122da60f2054c07ee4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Ropsten",
|
||||
"parameters": {
|
||||
"chain_id": 3,
|
||||
"path": "44'/1'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 42,
|
||||
"sig_r": "9d49a5c234a134bc56d00a7cf0c208c97d746f002c1fd3609b643eb8ef99d07d",
|
||||
"sig_s": "3f064e133624cb59f8103fd5de76c089d8754e3da233a59d2ab2ca47fc306837"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Rinkeby",
|
||||
"parameters": {
|
||||
"chain_id": 4,
|
||||
"path": "44'/1'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 43,
|
||||
"sig_r": "79a9fd0391f027ed518f3d796a598bf33eef0fb30ef22568a140d674d6b0b76c",
|
||||
"sig_s": "408cd459abafcdb7f2e415b269c85a308aad4c53e63c01d3431d3db6ab6292dd"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ETC",
|
||||
"parameters": {
|
||||
"chain_id": 61,
|
||||
"path": "44'/61'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 158,
|
||||
"sig_r": "6f03621da2fe75877494697b0852c379ea3b2c4ec4f99ab9ce0c8753ebbaf3aa",
|
||||
"sig_s": "2b8c8def7534e7bc692ee2975a674a0e31c0dbd9137e53d27dee6b15e121c210"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Auxilium",
|
||||
"parameters": {
|
||||
"chain_id": 28945486,
|
||||
"path": "44'/344'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 57891008,
|
||||
"sig_r": "3298b58680045cfb373b9945f17c468a5c5725c9115c7c18915e8c585c67193f",
|
||||
"sig_s": "6bf1c719350150a520d59542815afd8263d7fe7087608051abe7df11dd7fcbec"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Pirl",
|
||||
"parameters": {
|
||||
"chain_id": 3125659152,
|
||||
"path": "44'/164'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 6251318340,
|
||||
"sig_r": "a876d3cf19f4f6b51fb980aac49e8bd378b88f11adbebc1be33d7b86eb84a054",
|
||||
"sig_s": "3bee0e5a07661e78c9c4af49c8a42f4735f80cbb82931607ac35fc78f8d5b113"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Unknown_chain_id_eth_path",
|
||||
"parameters": {
|
||||
"chain_id": 609112567,
|
||||
"path": "44'/60'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 1218225170,
|
||||
"sig_r": "0b0f20dc9202db0653a827b9dc924653bc83d67eec9e43d678e0fb6bb3eb6d9e",
|
||||
"sig_s": "5fdbae16da0ffc4d888e915ff210393e5c7655a3c48eaffbbe97d6db428fc277"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Unknown_chain_id_testnet_path",
|
||||
"parameters": {
|
||||
"chain_id": 609112567,
|
||||
"path": "44'/1'/0'/0/0",
|
||||
"nonce": 0,
|
||||
"gas_price": 20000000000,
|
||||
"gas_limit": 21000,
|
||||
"value": 10000000000,
|
||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
"tx_type": null,
|
||||
"data": ""
|
||||
},
|
||||
"result": {
|
||||
"sig_v": 1218225169,
|
||||
"sig_r": "f699de96e886995e460e760839d4f2c7b9f1c98f2d3c108d0add4e8663a679d8",
|
||||
"sig_s": "1447ba45be9fca42bcbf250389403245c8c1b0476e60b96dea320b0a596b5528"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,88 @@
|
||||
{
|
||||
"setup": {
|
||||
"mnemonic": "all all all all all all all all all all all all",
|
||||
"passphrase": ""
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This is an example of a signed message.",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "af4eac50f21acc6daeb0ab036f616f5d19fccade46e47100642b3dfc798c9b740d5873887bdc2f02502c90777a082d10dca113bd1ec29d08108396401421c8cc1b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "e9b3648fe10146a7c5c73ae1e42468273b945554b13769be19c3658e5b55c62d7036b56c1e094dc364060b798b120a528f31d91e815d0612c367bf7471519c761c"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs9",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "495b5b021517cd01cb05f02dfb6a1f79a8d9e4f82e8fb01d44ebf7d1218333f1528b67043ffc25c5b64b1e5a182f5d7d5707fcb639092af708969f90038155a91c"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs10",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "0c8eb57decbb95d2a783e69d444b3747c49ebcceb14f24287732ba77c39aa5cd2c66f7ec545b8108ef7ce078edac4588c70ab6249fc626114a95606783828f041b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs11!",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "5f1ab8940c2137baf69a2b94f55f0f7e53a022b9e363b564744616271eb89b66145055fc9923c6ead63dd784854c742f4f5651c8257d70cbce5a96ce2986dd311c"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 99!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "f2c3d9c81fe35a6bc68f0ace01bd7209baf11e455e7335903e7ad2879ce5d7bc2199bf8bafc1efe1ff2cfdf2963cd5767911a641c9445cca6f37dc6da72fd1611b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 100!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "a6d05d98180246cbd7084f191465d02c4242bc7f856632a2b5b43acd496c46c03a36cc60bfeca6ca98fd210748a3aa68aa7ebba71b39adcad7f88325fc34131a1b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 101!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"path": "44'/60'/0'/0/0"
|
||||
},
|
||||
"result": {
|
||||
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
|
||||
"sig": "fa9d60644436f27eb88956a50893e9a47f67c42fb1b57a44bde4c6e127ab777e0c23b234b6ec9327ffd0620daaa514243ebb5a3652a1bac2d720e0f5555b2e071c"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
{
|
||||
"setup": {
|
||||
"mnemonic": "all all all all all all all all all all all all",
|
||||
"passphrase": ""
|
||||
},
|
||||
"tests": [
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This is an example of a signed message.",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "9bacd833b51fde010bab53bafd9d832eadd3b175d2af2e629bb2944fcc987dce7ff68bb3571ed25a720c220f2f9538bc8d04f582bee002c9af086590a49805901c"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!VeryLongMessage!",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "752d283b3aea1eb44fd09203f4d5c430a6544e399b8500b02722b54325f6d8d457fd83460a31045cb0d6e8356240954ba072fdfe5cdb3f16d416e2acf1a180a51c"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs9",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "6570bd48d38a68ade78273fca18943ed36ec48cb2eb5b6792bc56f20588b1c75020f04b86740321e562eb2ec2022eec4ad673dc120c6895983856e5437cb95c91c"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs10",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "5f26de400e53a333479ce9518ef0724b81615b3e3842c3205754f48a9ff1a3fc0e383ccb7dabdfd8e284abe69c0065f15f033f37210f5efeccfc9a6b0813a2af1b"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "MsgLenIs11!",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "7d8c1deec29c01c1982f46a91e1d9d99e399374b8aac875703ca947583ec6d944e7579d3934ac10e910a2959daa9e89fa5f4c0fc62bacdc8ec788d09b22e2ad61c"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 99!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "ac255920b53788eb81f5debd3792554ee4666d38059c8c39f74abd4032483fce2365af2236b8edf83801ad6e57f1e126e55a7757f2a2ebc991efe495b48d16d01c"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 100!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "47a70be8e7161a2c597de2237ba3846218e86561e9b5115b7fe9604ab63c05f85456204ba309e11e3b242a8c09a166ce611fb34bf1c54598162bbcce749549ea1b"
|
||||
},
|
||||
"result": {}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"msg": "This message has length 101!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
|
||||
"address": "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b",
|
||||
"sig": "0f413d3eff519c52ba01333b8bd132d20c2e62e3a77483e6a803dc3b711e3c2e11548f21687764a7290347079c00fc9dd976e060600d774bf1ae2f99bd8803bf1c"
|
||||
},
|
||||
"result": {}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import parametrize_using_common_fixtures
|
||||
|
||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
||||
|
||||
|
||||
@parametrize_using_common_fixtures(
|
||||
"ethereum/getaddress.json",
|
||||
)
|
||||
def test_getaddress(client, parameters, result):
|
||||
address_n = parse_path(parameters["path"])
|
||||
assert ethereum.get_address(client, address_n) == result["address"]
|
@ -0,0 +1,92 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import parametrize_using_common_fixtures
|
||||
|
||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
||||
|
||||
|
||||
@parametrize_using_common_fixtures(
|
||||
"ethereum/signmessage.json",
|
||||
)
|
||||
def test_signmessage(client, parameters, result):
|
||||
res = ethereum.sign_message(
|
||||
client, parse_path(parameters["path"]), parameters["msg"]
|
||||
)
|
||||
assert res.address == result["address"]
|
||||
assert res.signature.hex() == result["sig"]
|
||||
|
||||
|
||||
@parametrize_using_common_fixtures(
|
||||
"ethereum/verifymessage.json",
|
||||
)
|
||||
def test_verify(client, parameters, result):
|
||||
res = ethereum.verify_message(
|
||||
client,
|
||||
parameters["address"],
|
||||
bytes.fromhex(parameters["sig"]),
|
||||
parameters["msg"],
|
||||
)
|
||||
assert res is True
|
||||
|
||||
|
||||
def test_verify_invalid(client):
|
||||
# First vector from the verifymessage JSON fixture
|
||||
msg = "This is an example of a signed message."
|
||||
address = "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b"
|
||||
sig = bytes.fromhex(
|
||||
"9bacd833b51fde010bab53bafd9d832eadd3b175d2af2e629bb2944fcc987dce7ff68bb3571ed25a720c220f2f9538bc8d04f582bee002c9af086590a49805901c"
|
||||
)
|
||||
|
||||
res = ethereum.verify_message(
|
||||
client,
|
||||
address,
|
||||
sig,
|
||||
msg,
|
||||
)
|
||||
assert res is True
|
||||
|
||||
# Changing the signature, expecting failure
|
||||
res = ethereum.verify_message(
|
||||
client,
|
||||
address,
|
||||
sig[:-1] + b"\x00",
|
||||
msg,
|
||||
)
|
||||
assert res is False
|
||||
|
||||
# Changing the message, expecting failure
|
||||
res = ethereum.verify_message(
|
||||
client,
|
||||
address,
|
||||
sig,
|
||||
msg + "abc",
|
||||
)
|
||||
assert res is False
|
||||
|
||||
# Changing the address, expecting failure
|
||||
res = ethereum.verify_message(
|
||||
client,
|
||||
address[:-1] + "a",
|
||||
sig,
|
||||
msg,
|
||||
)
|
||||
assert res is False
|
@ -0,0 +1,275 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum, messages
|
||||
from trezorlib.debuglink import message_filters
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ...common import parametrize_using_common_fixtures
|
||||
|
||||
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
||||
|
||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
||||
|
||||
|
||||
@parametrize_using_common_fixtures(
|
||||
"ethereum/sign_tx.json",
|
||||
"ethereum/sign_tx_eip155.json",
|
||||
)
|
||||
def test_signtx(client, parameters, result):
|
||||
with client:
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path(parameters["path"]),
|
||||
nonce=parameters["nonce"],
|
||||
gas_price=parameters["gas_price"],
|
||||
gas_limit=parameters["gas_limit"],
|
||||
to=parameters["to_address"],
|
||||
chain_id=parameters["chain_id"],
|
||||
value=parameters["value"],
|
||||
tx_type=parameters["tx_type"],
|
||||
data=bytes.fromhex(parameters["data"]),
|
||||
)
|
||||
|
||||
expected_v = 2 * parameters["chain_id"] + 35
|
||||
assert sig_v in (expected_v, expected_v + 1)
|
||||
assert sig_r.hex() == result["sig_r"]
|
||||
assert sig_s.hex() == result["sig_s"]
|
||||
assert sig_v == result["sig_v"]
|
||||
|
||||
|
||||
@parametrize_using_common_fixtures(
|
||||
"ethereum/sign_tx_eip1559.json",
|
||||
)
|
||||
@pytest.mark.skip_t1
|
||||
def test_signtx_eip1559(client, parameters, result):
|
||||
with client:
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path(parameters["path"]),
|
||||
nonce=parameters["nonce"],
|
||||
gas_limit=parameters["gas_limit"],
|
||||
max_gas_fee=parameters["max_gas_fee"],
|
||||
max_priority_fee=parameters["max_priority_fee"],
|
||||
to=parameters["to_address"],
|
||||
chain_id=parameters["chain_id"],
|
||||
value=parameters["value"],
|
||||
data=bytes.fromhex(parameters["data"]),
|
||||
)
|
||||
|
||||
assert sig_r.hex() == result["sig_r_hex"]
|
||||
assert sig_s.hex() == result["sig_s_hex"]
|
||||
assert sig_v == result["sig_v"]
|
||||
|
||||
|
||||
def test_sanity_checks(client):
|
||||
"""Is not vectorized because these are internal-only tests that do not
|
||||
need to be exposed to the public.
|
||||
"""
|
||||
# contract creation without data should fail.
|
||||
with pytest.raises(Exception):
|
||||
ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to="",
|
||||
value=12345678901234567890,
|
||||
)
|
||||
|
||||
# gas overflow
|
||||
with pytest.raises(TrezorFailure):
|
||||
ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
||||
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
||||
to=TO_ADDR,
|
||||
value=12345678901234567890,
|
||||
)
|
||||
|
||||
# no gas price
|
||||
with pytest.raises(TrezorFailure):
|
||||
client.call(
|
||||
messages.EthereumSignTx(
|
||||
address_n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=b"AAA",
|
||||
gas_limit=ethereum.int_to_big_endian(10000),
|
||||
to=TO_ADDR,
|
||||
value=ethereum.int_to_big_endian(12345678901234567890),
|
||||
)
|
||||
)
|
||||
|
||||
# no gas limit
|
||||
with pytest.raises(TrezorFailure):
|
||||
client.call(
|
||||
messages.EthereumSignTx(
|
||||
address_n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=b"AAA",
|
||||
gas_price=ethereum.int_to_big_endian(10000),
|
||||
to=TO_ADDR,
|
||||
value=ethereum.int_to_big_endian(12345678901234567890),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_data_streaming(client):
|
||||
"""Only verifying the expected responses, the signatures are
|
||||
checked in vectorized function above.
|
||||
"""
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
message_filters.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
message_filters.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
message_filters.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
message_filters.EthereumTxRequest(
|
||||
data_length=3,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
message_filters.EthereumTxRequest(data_length=None),
|
||||
]
|
||||
)
|
||||
|
||||
ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to=TO_ADDR,
|
||||
value=0,
|
||||
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_signtx_eip1559_access_list(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
|
||||
chain_id=1,
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
access_list=[
|
||||
messages.EthereumAccessList(
|
||||
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000003"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "9f8763f3ff8d4d409f6b96bc3f1d84dd504e2c667b162778508478645401f121"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "51e30b68b9091cf8138c07380c4378c2711779b68b2e5264d141479f13a12f57"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_signtx_eip1559_access_list_larger(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
|
||||
chain_id=1,
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
access_list=[
|
||||
messages.EthereumAccessList(
|
||||
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000003"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
],
|
||||
),
|
||||
messages.EthereumAccessList(
|
||||
address="0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000006"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000009"
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "718a3a30827c979975c846d2f60495310c4959ee3adce2d89e0211785725465c"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "7d0ea2a28ef5702ca763c1f340427c0020292ffcbb4553dd1c8ea8e2b9126dbc"
|
||||
)
|
@ -1,41 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
VECTORS = ( # path, address
|
||||
("m/44'/60'/0'", "0xdA0b608bdb1a4A154325C854607c68950b4F1a34"),
|
||||
("m/44'/60'/100'", "0x93Fb0Ff84F5BB6E7b6a9835C7AA6dE7a76794266"),
|
||||
("m/44'/60'/0'/0/0", "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8"),
|
||||
("m/44'/60'/0'/0/100", "0x1e6E3708a059aEa1241a81c7aAe84b6CDbC54d59"),
|
||||
# ETC
|
||||
("m/44'/61'/0'/0/0", "0xF410e37E9C8BCf8CF319c84Ae9dCEbe057804a04"),
|
||||
# GoChain
|
||||
("m/44'/6060'/0'/0/0", "0xA26a450ef46a5f11a510eBA2119A3236fa0Aca92"),
|
||||
# Wanchain
|
||||
("m/44'/5718350'/0'/0/0", "0xe432a7533D689ceed00B7EE91d9368b8A1693bD2"),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
@pytest.mark.parametrize("path, address", VECTORS)
|
||||
def test_ethereum_getaddress(client, path, address):
|
||||
address_n = parse_path(path)
|
||||
assert ethereum.get_address(client, address_n) == address
|
@ -1,66 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
PATH = parse_path("m/44h/60h/0h/0/0")
|
||||
ADDRESS = "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8"
|
||||
VECTORS = ( # message, signature
|
||||
(
|
||||
"This is an example of a signed message.",
|
||||
"af4eac50f21acc6daeb0ab036f616f5d19fccade46e47100642b3dfc798c9b740d5873887bdc2f02502c90777a082d10dca113bd1ec29d08108396401421c8cc1b",
|
||||
),
|
||||
(
|
||||
"VeryLongMessage!" * 64,
|
||||
"e9b3648fe10146a7c5c73ae1e42468273b945554b13769be19c3658e5b55c62d7036b56c1e094dc364060b798b120a528f31d91e815d0612c367bf7471519c761c",
|
||||
),
|
||||
(
|
||||
"MsgLenIs9",
|
||||
"495b5b021517cd01cb05f02dfb6a1f79a8d9e4f82e8fb01d44ebf7d1218333f1528b67043ffc25c5b64b1e5a182f5d7d5707fcb639092af708969f90038155a91c",
|
||||
),
|
||||
(
|
||||
"MsgLenIs10",
|
||||
"0c8eb57decbb95d2a783e69d444b3747c49ebcceb14f24287732ba77c39aa5cd2c66f7ec545b8108ef7ce078edac4588c70ab6249fc626114a95606783828f041b",
|
||||
),
|
||||
(
|
||||
"MsgLenIs11!",
|
||||
"5f1ab8940c2137baf69a2b94f55f0f7e53a022b9e363b564744616271eb89b66145055fc9923c6ead63dd784854c742f4f5651c8257d70cbce5a96ce2986dd311c",
|
||||
),
|
||||
(
|
||||
"This message has length 99" + 73 * "!",
|
||||
"f2c3d9c81fe35a6bc68f0ace01bd7209baf11e455e7335903e7ad2879ce5d7bc2199bf8bafc1efe1ff2cfdf2963cd5767911a641c9445cca6f37dc6da72fd1611b",
|
||||
),
|
||||
(
|
||||
"This message has length 100" + 73 * "!",
|
||||
"a6d05d98180246cbd7084f191465d02c4242bc7f856632a2b5b43acd496c46c03a36cc60bfeca6ca98fd210748a3aa68aa7ebba71b39adcad7f88325fc34131a1b",
|
||||
),
|
||||
(
|
||||
"This message has length 101" + 74 * "!",
|
||||
"fa9d60644436f27eb88956a50893e9a47f67c42fb1b57a44bde4c6e127ab777e0c23b234b6ec9327ffd0620daaa514243ebb5a3652a1bac2d720e0f5555b2e071c",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
@pytest.mark.parametrize("message, signature", VECTORS)
|
||||
def test_sign(client, message, signature):
|
||||
res = ethereum.sign_message(client, PATH, message)
|
||||
assert res.address == ADDRESS
|
||||
assert res.signature.hex() == signature
|
@ -1,446 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum, messages
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
from ..common import MNEMONIC12
|
||||
|
||||
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
class TestMsgEthereumSigntx:
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_known_erc20_token(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(data_length=None),
|
||||
]
|
||||
)
|
||||
|
||||
data = bytearray()
|
||||
# method id signalizing `transfer(address _to, uint256 _value)` function
|
||||
data.extend(bytes.fromhex("a9059cbb"))
|
||||
# 1st function argument (to - the receiver)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b"
|
||||
)
|
||||
)
|
||||
# 2nd function argument (value - amount to be transferred)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000000000000000000000000000000000000bebc200"
|
||||
)
|
||||
)
|
||||
# 200 000 000 in dec, decimals of ADT = 9, trezor1 displays 0.2 ADT, Trezor T 200 000 000 Wei ADT
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20,
|
||||
gas_limit=20,
|
||||
# ADT token address
|
||||
to="0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
|
||||
chain_id=1,
|
||||
# value needs to be 0, token value is set in the contract (data)
|
||||
value=0,
|
||||
data=data,
|
||||
)
|
||||
|
||||
# taken from T1 might not be 100% correct but still better than nothing
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "ec1df922115d256745410fbc2070296756583c8786e4d402a88d4e29ec513fa9"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "7001bfe3ba357e4a9f9e0d3a3f8a8962257615a4cf215db93e48b98999fc51b7"
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_wanchain(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(data_length=None),
|
||||
]
|
||||
)
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/5718350'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20,
|
||||
gas_limit=20,
|
||||
# ADT token address
|
||||
to="0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
|
||||
chain_id=1,
|
||||
tx_type=1,
|
||||
# value needs to be 0, token value is set in the contract (data)
|
||||
value=100,
|
||||
)
|
||||
|
||||
# ad-hoc generated signature. might not be valid.
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "d6e197029031ec90b53ed14e8233aa78b592400513ac0386d2d55cdedc3d796f"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "326e0d600dd1b7ee606eb531b998a6a3b3293d4995fb8cfe0677962e8a43cff6"
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_unknown_erc20_token(self, client):
|
||||
with client:
|
||||
expected_responses = [
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
]
|
||||
# TT asks for contract address confirmation
|
||||
if client.features.model == "T":
|
||||
expected_responses.append(
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx)
|
||||
)
|
||||
|
||||
expected_responses.append(messages.EthereumTxRequest(data_length=None))
|
||||
client.set_expected_responses(expected_responses)
|
||||
|
||||
data = bytearray()
|
||||
# method id signalizing `transfer(address _to, uint256 _value)` function
|
||||
data.extend(bytes.fromhex("a9059cbb"))
|
||||
# 1st function argument (to - the receiver)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b"
|
||||
)
|
||||
)
|
||||
# 2nd function argument (value - amount to be transferred)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000123"
|
||||
)
|
||||
)
|
||||
# since this token is unknown trezor should display "unknown token value"
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/1"),
|
||||
nonce=0,
|
||||
gas_price=20,
|
||||
gas_limit=20,
|
||||
# unknown token address (Grzegorz Brzęczyszczykiewicz Token)
|
||||
to="0xfc6b5d6af8a13258f7cbd0d39e11b35e01a32f93",
|
||||
chain_id=1,
|
||||
# value needs to be 0, token value is set in the contract (data)
|
||||
value=0,
|
||||
data=data,
|
||||
)
|
||||
|
||||
# taken from T1 might not be 100% correct but still better than nothing
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "2559bbf1bcb80992b6eaa96f0074b19606d8ea7bf4219e1c9ac64a12855c0cce"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "633a74429eb6d3aeec4ed797542236a85daab3cab15e37736b87a45697541d7a"
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_nodata(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(data_length=None), # v,r,s checked later
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_price=20,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
value=10,
|
||||
)
|
||||
|
||||
assert sig_v == 27
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "2f548f63ddb4cf19b6b9f922da58ff71833b967d590f3b4dcc2a70810338a982"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "428d35f0dca963b5196b63e7aa5e0405d8bff77d6aee1202183f1f68dacb4483"
|
||||
)
|
||||
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(data_length=None),
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=123456,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to=TO_ADDR,
|
||||
value=12345678901234567890,
|
||||
)
|
||||
assert sig_v == 27
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "3bf0470cd7f5ad8d82613199f73deadc55c3c9f32f91b1a21b5ef644144ebd58"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "48b3ef1b2502febdf35e9ff4df0ba1fda62f042fad639eb4852a297fc9872ebd"
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_data(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(data_length=None),
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
value=10,
|
||||
data=b"abcdefghijklmnop" * 16,
|
||||
)
|
||||
assert sig_v == 27
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "e90f9e3dbfb34861d40d67570cb369049e675c6eebfdda6b08413a2283421b85"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "763912b8801f76cbea7792d98123a245514beeab2f3afebb4bab637888e8393a"
|
||||
)
|
||||
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=3),
|
||||
messages.EthereumTxRequest(),
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to=TO_ADDR,
|
||||
value=12345678901234567890,
|
||||
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
||||
)
|
||||
assert sig_v == 27
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "dd96d82d791118a55601dfcede237760d2e9734b76c373ede5362a447c42ac48"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "60a77558f28d483d476f9507cd8a6a4bb47b86611aaff95fd5499b9ee9ebe7ee"
|
||||
)
|
||||
|
||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
||||
def test_ethereum_signtx_message(self, client):
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=3),
|
||||
messages.EthereumTxRequest(),
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to=TO_ADDR,
|
||||
value=0,
|
||||
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
||||
)
|
||||
assert sig_v == 27
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "81af16020d3c6ad820cab2e2b0834fa37f4a9b0c2443f151a4e2f12fe1081b09"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "7b34b5d8a43771d493cd9fa0c7b27a9563e2a31799fb9f0c2809539a848b9f47"
|
||||
)
|
||||
|
||||
def test_ethereum_signtx_newcontract(self, client):
|
||||
# contract creation without data should fail.
|
||||
with pytest.raises(Exception):
|
||||
ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to="",
|
||||
value=12345678901234567890,
|
||||
)
|
||||
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||
messages.EthereumTxRequest(
|
||||
data_length=1024,
|
||||
signature_r=None,
|
||||
signature_s=None,
|
||||
signature_v=None,
|
||||
),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=1024),
|
||||
messages.EthereumTxRequest(data_length=3),
|
||||
messages.EthereumTxRequest(),
|
||||
]
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20000,
|
||||
gas_limit=20000,
|
||||
to="",
|
||||
value=12345678901234567890,
|
||||
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
||||
)
|
||||
assert sig_v == 28
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "c86bda9de238b1c602648996561e7270a3be208da96bbf23474cb8e4014b9f93"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "18742403f75a05e7fa9868c30b36f1e55628de02d01c03084c1ff6775a13137c"
|
||||
)
|
||||
|
||||
def test_ethereum_sanity_checks(self, client):
|
||||
# gas overflow
|
||||
with pytest.raises(TrezorFailure):
|
||||
ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
||||
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
||||
to=TO_ADDR,
|
||||
value=12345678901234567890,
|
||||
)
|
||||
|
||||
# no gas price
|
||||
with pytest.raises(TrezorFailure):
|
||||
client.call(
|
||||
messages.EthereumSignTx(
|
||||
address_n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=b"AAA",
|
||||
gas_limit=ethereum.int_to_big_endian(10000),
|
||||
to=TO_ADDR,
|
||||
value=ethereum.int_to_big_endian(12345678901234567890),
|
||||
)
|
||||
)
|
||||
|
||||
# no gas limit
|
||||
with pytest.raises(TrezorFailure):
|
||||
client.call(
|
||||
messages.EthereumSignTx(
|
||||
address_n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=b"AAA",
|
||||
gas_price=ethereum.int_to_big_endian(10000),
|
||||
to=TO_ADDR,
|
||||
value=ethereum.int_to_big_endian(12345678901234567890),
|
||||
)
|
||||
)
|
||||
|
||||
# no nonce
|
||||
# TODO this was supposed to expect a failure if nonce is not provided.
|
||||
# Trezor does not raise such failure however.
|
||||
# with pytest.raises(TrezorFailure):
|
||||
# client.call(
|
||||
# messages.EthereumSignTx(
|
||||
# address_n=parse_path("44'/60'/0'/0/0"),
|
||||
# gas_price=ethereum.int_to_big_endian(10000),
|
||||
# gas_limit=ethereum.int_to_big_endian(10000),
|
||||
# to=TO_ADDR,
|
||||
# value=ethereum.int_to_big_endian(12345678901234567890),
|
||||
# )
|
||||
# )
|
@ -1,148 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
VECTORS_CHAIN_IDS = ( # chain_id, slip44, sig_v, sig_r, sig_s
|
||||
# Ethereum
|
||||
(
|
||||
1,
|
||||
60,
|
||||
(
|
||||
38,
|
||||
"6a6349bddb5749bb8b96ce2566a035ef87a09dbf89b5c7e3dfdf9ed725912f24",
|
||||
"4ae58ccd3bacee07cdc4a3e8540544fd009c4311af7048122da60f2054c07ee4",
|
||||
),
|
||||
),
|
||||
# Ropsten
|
||||
(
|
||||
3,
|
||||
1,
|
||||
(
|
||||
42,
|
||||
"9d49a5c234a134bc56d00a7cf0c208c97d746f002c1fd3609b643eb8ef99d07d",
|
||||
"3f064e133624cb59f8103fd5de76c089d8754e3da233a59d2ab2ca47fc306837",
|
||||
),
|
||||
),
|
||||
# Rinkeby
|
||||
(
|
||||
4,
|
||||
1,
|
||||
(
|
||||
43,
|
||||
"79a9fd0391f027ed518f3d796a598bf33eef0fb30ef22568a140d674d6b0b76c",
|
||||
"408cd459abafcdb7f2e415b269c85a308aad4c53e63c01d3431d3db6ab6292dd",
|
||||
),
|
||||
),
|
||||
# ETC
|
||||
(
|
||||
61,
|
||||
61,
|
||||
(
|
||||
158,
|
||||
"6f03621da2fe75877494697b0852c379ea3b2c4ec4f99ab9ce0c8753ebbaf3aa",
|
||||
"2b8c8def7534e7bc692ee2975a674a0e31c0dbd9137e53d27dee6b15e121c210",
|
||||
),
|
||||
),
|
||||
# Auxilium
|
||||
(
|
||||
28945486,
|
||||
344,
|
||||
(
|
||||
57891008,
|
||||
"3298b58680045cfb373b9945f17c468a5c5725c9115c7c18915e8c585c67193f",
|
||||
"6bf1c719350150a520d59542815afd8263d7fe7087608051abe7df11dd7fcbec",
|
||||
),
|
||||
),
|
||||
# Pirl
|
||||
(
|
||||
3125659152,
|
||||
164,
|
||||
(
|
||||
6251318340,
|
||||
"a876d3cf19f4f6b51fb980aac49e8bd378b88f11adbebc1be33d7b86eb84a054",
|
||||
"3bee0e5a07661e78c9c4af49c8a42f4735f80cbb82931607ac35fc78f8d5b113",
|
||||
),
|
||||
),
|
||||
# Unknown chain id with Ethereum path
|
||||
(
|
||||
609112567,
|
||||
60,
|
||||
(
|
||||
1218225170,
|
||||
"0b0f20dc9202db0653a827b9dc924653bc83d67eec9e43d678e0fb6bb3eb6d9e",
|
||||
"5fdbae16da0ffc4d888e915ff210393e5c7655a3c48eaffbbe97d6db428fc277",
|
||||
),
|
||||
),
|
||||
# Unknown chain id with testnet path
|
||||
(
|
||||
609112567,
|
||||
1,
|
||||
(
|
||||
1218225169,
|
||||
"f699de96e886995e460e760839d4f2c7b9f1c98f2d3c108d0add4e8663a679d8",
|
||||
"1447ba45be9fca42bcbf250389403245c8c1b0476e60b96dea320b0a596b5528",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
@pytest.mark.parametrize("chain_id, slip44, sig", VECTORS_CHAIN_IDS)
|
||||
def test_chain_ids(client, chain_id, slip44, sig):
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path(f"m/44h/{slip44}h/0h/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20000000000,
|
||||
gas_limit=21000,
|
||||
to="0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
value=10000000000,
|
||||
chain_id=chain_id,
|
||||
)
|
||||
expected_v = 2 * chain_id + 35
|
||||
assert sig_v in (expected_v, expected_v + 1)
|
||||
assert (sig_v, sig_r.hex(), sig_s.hex()) == sig
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
def test_with_data(client):
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||
client,
|
||||
n=parse_path("m/44h/60h/0h/0/0"),
|
||||
nonce=0,
|
||||
gas_price=20000000000,
|
||||
gas_limit=21000,
|
||||
to="0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||
value=10000000000,
|
||||
chain_id=1,
|
||||
data=b"ABCDEFGHIJKLM",
|
||||
)
|
||||
assert sig_v == 37
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "c57556e308f49c84adc614042bf443381676fd2797f9512a85dc529f7acb7fa8"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "60a82338641fd4a924a6ec31da4aadc0a43ac77d3a021307ec07bb6982ccbe8d"
|
||||
)
|
@ -1,308 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum, messages
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
||||
|
||||
|
||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum, pytest.mark.skip_t1]
|
||||
|
||||
|
||||
def test_ethereum_signtx_nodata(client):
|
||||
with client:
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
chain_id=1,
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "2ceeaabc994fbce2fbd66551f9d48fc711c8db2a12e93779eeddede11e41f636"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "2db4a9ecc73da91206f84397ae9287a399076fdc01ed7f3c6554b1c57c39bf8c"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_data(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
chain_id=1,
|
||||
to=TO_ADDR,
|
||||
value=10,
|
||||
data=b"abcdefghijklmnop" * 16,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
)
|
||||
assert sig_v == 0
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "8e4361e40e76a7cab17e0a982724bbeaf5079cd02d50c20d431ba7dde2404ea4"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "411930f091bb508e593e22a9ee45bd4d9eeb504ac398123aec889d5951bdebc3"
|
||||
)
|
||||
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=123456,
|
||||
gas_limit=20000,
|
||||
to=TO_ADDR,
|
||||
chain_id=1,
|
||||
value=12345678901234567890,
|
||||
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
)
|
||||
assert sig_v == 0
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "2e4f4c0e7c4e51270b891480060712e9d3bcab01e8ad0fadf2dfddd71504ca94"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "2599beb32757a144dedc82b79153c21269c9939a9245342bcf35764115b62bc1"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_access_list(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
chain_id=1,
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
access_list=[
|
||||
messages.EthereumAccessList(
|
||||
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000003"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "9f8763f3ff8d4d409f6b96bc3f1d84dd504e2c667b162778508478645401f121"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "51e30b68b9091cf8138c07380c4378c2711779b68b2e5264d141479f13a12f57"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_access_list_larger(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
chain_id=1,
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
access_list=[
|
||||
messages.EthereumAccessList(
|
||||
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000003"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
],
|
||||
),
|
||||
messages.EthereumAccessList(
|
||||
address="0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
|
||||
storage_keys=[
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000006"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000007"
|
||||
),
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000009"
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "718a3a30827c979975c846d2f60495310c4959ee3adce2d89e0211785725465c"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "7d0ea2a28ef5702ca763c1f340427c0020292ffcbb4553dd1c8ea8e2b9126dbc"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_known_erc20_token(client):
|
||||
with client:
|
||||
|
||||
data = bytearray()
|
||||
# method id signalizing `transfer(address _to, uint256 _value)` function
|
||||
data.extend(bytes.fromhex("a9059cbb"))
|
||||
# 1st function argument (to - the receiver)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b"
|
||||
)
|
||||
)
|
||||
# 2nd function argument (value - amount to be transferred)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000000000000000000000000000000000000bebc200"
|
||||
)
|
||||
)
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/0"),
|
||||
nonce=0,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
gas_limit=20,
|
||||
# ADT token address
|
||||
to="0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
|
||||
chain_id=1,
|
||||
# value needs to be 0, token value is set in the contract (data)
|
||||
value=0,
|
||||
data=data,
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "94d67bacb7966f881339d91103f5d738d9c491fff4c01a6513c554ab15e86cc0"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "405bd19a7bf4ae62d41fcb7844e36c786b106b456185c3d0877a7ce7eab6c751"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_unknown_erc20_token(client):
|
||||
with client:
|
||||
data = bytearray()
|
||||
# method id signalizing `transfer(address _to, uint256 _value)` function
|
||||
data.extend(bytes.fromhex("a9059cbb"))
|
||||
# 1st function argument (to - the receiver)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"000000000000000000000000574bbb36871ba6b78e27f4b4dcfb76ea0091880b"
|
||||
)
|
||||
)
|
||||
# 2nd function argument (value - amount to be transferred)
|
||||
data.extend(
|
||||
bytes.fromhex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000123"
|
||||
)
|
||||
)
|
||||
# since this token is unknown trezor should display "unknown token value"
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/1"),
|
||||
nonce=0,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
gas_limit=20,
|
||||
# unknown token address (Grzegorz Brzęczyszczykiewicz Token)
|
||||
to="0xfc6b5d6af8a13258f7cbd0d39e11b35e01a32f93",
|
||||
chain_id=1,
|
||||
# value needs to be 0, token value is set in the contract (data)
|
||||
value=0,
|
||||
data=data,
|
||||
)
|
||||
|
||||
assert sig_v == 1
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "e631b56bcc596844cb8686b2046e36cf33634aa396e7e1ea94a97aac02c18bda"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "399bff8752539176c4b2f1d5d2a8f6029f79841d28802149ab339a033ffe4c1f"
|
||||
)
|
||||
|
||||
|
||||
def test_ethereum_signtx_large_chainid(client):
|
||||
with client:
|
||||
|
||||
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
||||
client,
|
||||
n=parse_path("44'/60'/0'/0/100"),
|
||||
nonce=0,
|
||||
gas_limit=20,
|
||||
to=TO_ADDR,
|
||||
chain_id=3125659152, # Pirl chain id, doesn't support EIP1559 at this time, but chosen for large chain id
|
||||
value=10,
|
||||
max_gas_fee=20,
|
||||
max_priority_fee=1,
|
||||
)
|
||||
|
||||
assert sig_v == 0
|
||||
assert (
|
||||
sig_r.hex()
|
||||
== "07f8c967227c5a190cb90525c3387691a426fe61f8e0503274280724060ea95c"
|
||||
)
|
||||
assert (
|
||||
sig_s.hex()
|
||||
== "0bf83eaf74e24aa9146b23e06f9edec6e25acb81d3830e8d146b9e7b6923ad1e"
|
||||
)
|
@ -1,72 +0,0 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 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>.
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import ethereum
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
@pytest.mark.ethereum
|
||||
class TestMsgEthereumVerifymessage:
|
||||
|
||||
ADDRESS = "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b"
|
||||
VECTORS = [
|
||||
(
|
||||
"This is an example of a signed message.",
|
||||
"9bacd833b51fde010bab53bafd9d832eadd3b175d2af2e629bb2944fcc987dce7ff68bb3571ed25a720c220f2f9538bc8d04f582bee002c9af086590a49805901c",
|
||||
),
|
||||
(
|
||||
"VeryLongMessage!" * 64,
|
||||
"752d283b3aea1eb44fd09203f4d5c430a6544e399b8500b02722b54325f6d8d457fd83460a31045cb0d6e8356240954ba072fdfe5cdb3f16d416e2acf1a180a51c",
|
||||
),
|
||||
(
|
||||
"MsgLenIs9",
|
||||
"6570bd48d38a68ade78273fca18943ed36ec48cb2eb5b6792bc56f20588b1c75020f04b86740321e562eb2ec2022eec4ad673dc120c6895983856e5437cb95c91c",
|
||||
),
|
||||
(
|
||||
"MsgLenIs10",
|
||||
"5f26de400e53a333479ce9518ef0724b81615b3e3842c3205754f48a9ff1a3fc0e383ccb7dabdfd8e284abe69c0065f15f033f37210f5efeccfc9a6b0813a2af1b",
|
||||
),
|
||||
(
|
||||
"MsgLenIs11!",
|
||||
"7d8c1deec29c01c1982f46a91e1d9d99e399374b8aac875703ca947583ec6d944e7579d3934ac10e910a2959daa9e89fa5f4c0fc62bacdc8ec788d09b22e2ad61c",
|
||||
),
|
||||
(
|
||||
"This message has length 99" + 73 * "!",
|
||||
"ac255920b53788eb81f5debd3792554ee4666d38059c8c39f74abd4032483fce2365af2236b8edf83801ad6e57f1e126e55a7757f2a2ebc991efe495b48d16d01c",
|
||||
),
|
||||
(
|
||||
"This message has length 100" + 73 * "!",
|
||||
"47a70be8e7161a2c597de2237ba3846218e86561e9b5115b7fe9604ab63c05f85456204ba309e11e3b242a8c09a166ce611fb34bf1c54598162bbcce749549ea1b",
|
||||
),
|
||||
(
|
||||
"This message has length 101" + 74 * "!",
|
||||
"0f413d3eff519c52ba01333b8bd132d20c2e62e3a77483e6a803dc3b711e3c2e11548f21687764a7290347079c00fc9dd976e060600d774bf1ae2f99bd8803bf1c",
|
||||
),
|
||||
]
|
||||
|
||||
def test_verify(self, client):
|
||||
for msg, sig in self.VECTORS:
|
||||
res = ethereum.verify_message(client, self.ADDRESS, bytes.fromhex(sig), msg)
|
||||
assert res is True
|
||||
|
||||
def test_verify_invalid(self, client):
|
||||
signature = bytes.fromhex(self.VECTORS[0][1])
|
||||
res = ethereum.verify_message(
|
||||
client, self.ADDRESS, signature, "another message"
|
||||
)
|
||||
assert res is False
|
Loading…
Reference in new issue