Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signed Ethereum network and token definitions from host #2410

Merged
merged 19 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4994ae3
refactor(core): delegate EthereumGetPublicKey to bitcoin GetPublicKey
matejcik Feb 3, 2023
ab6cf72
docs(common): how to add new protobuf message
Feb 3, 2023
ee72762
feat(common): protobuf messages for Ethereum definitions
Feb 3, 2023
2d1d4f4
docs: document Ethereum definition binary format
Feb 3, 2023
d09e0ad
feat(common): switch to external Ethereum definitions, add generators
Jun 15, 2022
40e3283
fix(common): deal with duplicity code leftovers
matejcik Feb 8, 2023
7028552
feat(core): external Ethereum definitions
Feb 3, 2023
4571c2e
feat(legacy): support external Ethereum definitions
Feb 3, 2023
202cf0c
feat(python): support external Ethereum definitions
Feb 3, 2023
0ae454b
feat(core): implement CoSi module and CoSi verification
matejcik Mar 15, 2023
e35b005
feat(core): update Ethereum definitions to verify using CoSi
matejcik Mar 15, 2023
105bace
feat(legacy): implement CoSi verification
matejcik Mar 16, 2023
9ea9cb5
feat(legacy): update Ethereum definitions to verify using CoSi
matejcik Mar 16, 2023
2d0c4e8
tests: update device_tests for external definitions
matejcik Mar 16, 2023
8c77bd4
fix(python/trezorctl): fix colliding option shortcut in ethereum sign-tx
matejcik Mar 17, 2023
7fc4cf5
fix(legacy): display very large amounts
matejcik Mar 17, 2023
b05115c
fix(tests): only override left clicks in index custom script
matejcik Mar 20, 2023
ccd4bf6
fix(legacy): limit EthereumGetPublicKey allowable paths
matejcik Mar 22, 2023
5300790
fix(core): remove `shutdown()`
matejcik Mar 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
[submodule "vendor/secp256k1-zkp"]
path = vendor/secp256k1-zkp
url = https://github.com/bitcoin-core/secp256k1.git
[submodule "common/defs/ethereum/tokens"]
path = common/defs/ethereum/tokens
url = https://github.com/ethereum-lists/tokens.git
[submodule "crypto/tests/wycheproof"]
path = crypto/tests/wycheproof
url = https://github.com/google/wycheproof
Expand All @@ -24,6 +21,3 @@
[submodule "vendor/fido2-tests"]
path = vendor/fido2-tests
url = https://github.com/trezor/fido2-tests.git
[submodule "common/defs/ethereum/chains"]
path = common/defs/ethereum/chains
url = https://github.com/ethereum-lists/chains
93 changes: 23 additions & 70 deletions common/defs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ Testnet is considered a separate coin, so it must have its own JSON and icon.

We will not support coins that have `address_type` 0, i.e., same as Bitcoin.

#### `eth`
#### `eth` and `erc20`

The file [`ethereum/networks.json`](ethereum/networks.json) has a list of descriptions
of Ethereum networks. Each network must also have a PNG icon in `ethereum/<chain>.png`
file.
Definitions for Ethereum chains (networks) and tokens (erc20) are split in two parts:

#### `erc20`
1. built-in definitions - some of the chain and token definitions are built into the firmware
image. List of built-in chains is stored in [`ethereum/networks.json`](ethereum/networks.json)
and tokens in [`ethereum/tokens.json`](ethereum/tokens.json).
2. external definitions - dynamically generated from multiple sources. Whole process is
described in separate
[document](https://docs.trezor.io/trezor-firmware/common/ethereum-definitions.html).

`ethereum/tokens` is a submodule linking to [Ethereum Lists](https://github.com/ethereum-lists/tokens)
project with descriptions of ERC20 tokens. If you want to add or update a token
definition in Trezor, you need to get your change to the `tokens` repository first.

Trezor will only support tokens that have a unique symbol.
We generally do not accept updates to the built-in definitions. Instead, make sure your
network or token is included in the external definitions. A good place to start is the
[`ethereum-lists` GitHub organization](https://gitub.com/ethereum-lists): add your token
to the [tokens](https://github.com/ethereum-lists/tokens) repository, or your EVM chain to the
[chains](https://github.com/ethereum-lists/chains) repository.

#### `nem`

Expand All @@ -57,82 +60,32 @@ Supported coins that are not derived from Bitcoin, Ethereum or NEM are currently
and listed in separate file [`misc/misc.json`](misc/misc.json). Each coin must also have
an icon in `misc/<short>.png`, where `short` is lowercased `shortcut` field from the JSON.

## Keys
### Keys

Throughout the system, coins are identified by a _key_ - a colon-separated string
generated from the coin's type and shortcut:

* for Bitcoin-likes, key is `bitcoin:XYZ`
* for Ethereum networks, key is `eth:XYZ`
* for ERC20 tokens, key is `erc20:<chain>:XYZ`
* for NEM mosaic, key is `nem:XYZ`
* for others, key is `misc:XYZ`
* for Bitcoin-likes, key is `bitcoin:<shortcut>`
* for Ethereum networks, key is `eth:<shortcut>:<chain_id>`
* for ERC20 tokens, key is `erc20:<chain_symbol>:<token_shortcut>`
* for NEM mosaic, key is `nem:<shortcut>`
* for others, key is `misc:<shortcut>`

If a token shortcut has a suffix, such as `CAT (BlockCat)`, the whole thing is part
of the key (so the key is `erc20:eth:CAT (BlockCat)`).

Sometimes coins end up with duplicate symbols, which in case of ERC20 tokens leads to
key collisions. We do not allow duplicate symbols in the data, so this doesn't affect
everyday use (see below). However, for validation purposes, it is sometimes useful
to work with unfiltered data that includes the duplicates. In such cases, keys are
deduplicated by adding a counter at end, e.g.: `erc20:eth:SMT:0`, `erc20:eth:SMT:1`.
Note that the suffix _is not stable_, so these coins can't be reliably uniquely identified.

## Duplicate Detection

**Duplicate symbols are not allowed** in our data. Tokens that have symbol collisions
are removed from the data set before processing. The duplicate status is mentioned
in `support.json` (see below), but it is impossible to override from there.

Duplicate detection works as follows:

1. a _symbol_ is split off from the shortcut string. E.g., for `CAT (BlockCat)`, symbol
is just `CAT`. It is compared, case-insensitive, with other coins (so `WIC` and `WiC`
are considered the same symbol), and identical symbols are put into a _bucket_.
2. if _all_ coins in the bucket also have a suffix (`CAT (BlockCat)` and `CAT (BitClave)`),
they are _not_ considered duplicate.
3. if _any_ coin in the bucket does _not_ have a suffix (`MIT` and `MIT (Mychatcoin)`),
all coins in the bucket are considered duplicate.
4. Duplicate tokens (coins from the `erc20` group) are automatically removed from data.
Duplicate non-tokens are marked but not removed. For instance, `bitcoin:FTC` (Feathercoin)
and `erc20:eth:FTC` (FTC) are duplicate, and `erc20:eth:FTC` is removed.
5. If two non-tokens collide with each other, it is an error that fails the CI build.

The file [`duplicity_overrides.json`](duplicity_overrides.json) can override detection
results: keys set to `true` are considered duplicate (in a separate bucket), keys set
to `false` are considered non-duplicate even if auto-detected. This is useful for
whitelisting a supported token explicitly, or blacklisting things that the detection
can't match (for instance "Battle" and "Bitlle" have suffixes, but they are too similar).

External contributors should not make changes to `duplicity_overrides.json`, unless
asked to.
Duplicate keys are not allowed and coins that would result in duplicate keys cannot be
added to the dataset.

You can use `./tools/cointool.py check -d all` to inspect duplicate detection in detail.


# Coins Details

The file [`coins_details.json`](coins_details.json) is a list of all known coins
with support status, market cap information and relevant links. This is the source
file for https://trezor.io/coins.

You should never make changes to `coins_details.json` directly. Use `./tools/coins_details.py`
to regenerate it from known data.

If you need to change information in this file, modify the source information instead -
one of the JSON files in the groups listed above, support info in `support.json`, or
make a pull request to the tokens repository.
## Wallet URLs

If you want to add a **wallet link**, modify the file [`wallets.json`](wallets.json).

If this is not viable for some reason, or if there is no source information ,
you can also edit [`coins_details.override.json`](coins_details.override.json).
External contributors should not touch this file unless asked to.


# Support Information

We keep track of support status of each coin over our devices. That is
We keep track of support status of each built-in coin over our devices. That is
`trezor1` for Trezor One, `trezor2` for Trezor T, `connect` for [Connect](https://github.com/trezor/connect)
and `suite` for [Trezor Suite](https://suite.trezor.io/). In further description, the word "device"
applies to Connect and Suite as well.
Expand Down
45 changes: 0 additions & 45 deletions common/defs/coins_details.override.json

This file was deleted.

43 changes: 8 additions & 35 deletions common/defs/duplicity_overrides.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
{
"erc20:eth:BTL (Battle)": true,
"erc20:eth:BTL (Bitlle)": true,
"erc20:eth:LINK Platform": true,
"erc20:eth:NXX": false,
"erc20:eth:SNX:c011": false,
"erc20:eth:TUSD": false,
"erc20:eth:Hdp": true,
"erc20:eth:Hdp.ф": true,
"erc20:eth:HEX:2b59": false,
"erc20:eth:JOB:dfbc": false,
"misc:BNB": false,
"eth:BNB": false,
"eth:ONE:1666600000": false,
"eth:ONE:1666600001": false,
"eth:ONE:1666600002": false,
"eth:ONE:1666600003": false,
"eth:tGOR:5": false,
"eth:tGOR:420": false,
"eth:tCELO:44787": false,
"eth:tCELO:62320": false,
"eth:QKC:100000": false,
"eth:QKC:100001": false,
"eth:QKC:100002": false,
"eth:QKC:100003": false,
"eth:QKC:100004": false,
"eth:QKC:100005": false,
"eth:QKC:100006": false,
"eth:QKC:100007": false,
"eth:QKC:100008": false,
"eth:xDAI:100": false,
"eth:xDAI:200": false,
"eth:CPAY:3000": false,
"eth:CPAY:3001": false,
"eth:CPAY:21337": false,
"erc20:eth:MATIC": false,
"erc20:eth:USDT": false,
"erc20:avax:USDT": false
"eth:BNB:56": false,
"eth:MATIC:137": false,
"eth:tETH:3": false,
"eth:tETH:4": false,
"eth:tETH:5": false,
"misc:BNB": false,
"misc:USDT": false
}
1 change: 0 additions & 1 deletion common/defs/ethereum/chains
Submodule chains deleted from 805ae4
62 changes: 62 additions & 0 deletions common/defs/ethereum/networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"chain": "eth",
"chain_id": 1,
"coingecko_id": "ethereum",
"is_testnet": false,
"name": "Ethereum",
"shortcut": "ETH",
"slip44": 60
},
{
"chain": "rop",
"chain_id": 3,
"is_testnet": true,
"name": "Ropsten",
"shortcut": "tETH",
"slip44": 1
},
{
"chain": "rin",
"chain_id": 4,
"is_testnet": true,
"name": "Rinkeby",
"shortcut": "tETH",
"slip44": 1
},
{
"chain": "gor",
"chain_id": 5,
"is_testnet": true,
"name": "Görli",
"shortcut": "tETH",
"slip44": 1
},
{
"chain": "bnb",
"chain_id": 56,
"coingecko_id": "binance-smart-chain",
"is_testnet": false,
"name": "Binance Smart Chain",
"shortcut": "BNB",
"slip44": 714
},
{
"chain": "etc",
"chain_id": 61,
"coingecko_id": "ethereum-classic",
"is_testnet": false,
"name": "Ethereum Classic",
"shortcut": "ETC",
"slip44": 61
},
{
"chain": "MATIC",
"chain_id": 137,
"coingecko_id": "polygon-pos",
"is_testnet": false,
"name": "Polygon",
"shortcut": "MATIC",
"slip44": 966
}
]
1 change: 1 addition & 0 deletions common/defs/ethereum/released-definitions-timestamp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1669892465
1 change: 0 additions & 1 deletion common/defs/ethereum/tokens
Submodule tokens deleted from 0eeaf9
Loading