1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-31 21:28:46 +00:00

fix(core): don't confirm known Solana tokens' details

This commit is contained in:
Roman Zeyde 2025-05-25 10:13:24 +03:00
parent 256d6d8ee7
commit d52d4655d5
22 changed files with 523 additions and 464 deletions

View File

@ -0,0 +1 @@
Don't confirm known Solana tokens' details.

View File

@ -1159,6 +1159,8 @@ static void _librust_qstrs(void) {
MP_QSTR_solana__transaction_contains_unknown_instructions;
MP_QSTR_solana__transaction_fee;
MP_QSTR_solana__transaction_requires_x_signers_template;
MP_QSTR_solana__unknown_token;
MP_QSTR_solana__unknown_token_address;
MP_QSTR_solana__unstake;
MP_QSTR_solana__unstake_question;
MP_QSTR_solana__vote_account;

View File

@ -1414,6 +1414,10 @@ pub enum TranslatedString {
words__chain = 1012, // "Chain"
words__token = 1013, // "Token"
instructions__tap = 1014, // "Tap"
#[cfg(feature = "universal_fw")]
solana__unknown_token = 1015, // "Unknown token"
#[cfg(feature = "universal_fw")]
solana__unknown_token_address = 1016, // "Unknown token address"
}
impl TranslatedString {
@ -2821,6 +2825,10 @@ impl TranslatedString {
(Self::words__chain, "Chain"),
(Self::words__token, "Token"),
(Self::instructions__tap, "Tap"),
#[cfg(feature = "universal_fw")]
(Self::solana__unknown_token, "Unknown token"),
#[cfg(feature = "universal_fw")]
(Self::solana__unknown_token_address, "Unknown token address"),
];
#[cfg(feature = "micropython")]
@ -3949,6 +3957,10 @@ impl TranslatedString {
#[cfg(feature = "universal_fw")]
(Qstr::MP_QSTR_solana__transaction_requires_x_signers_template, Self::solana__transaction_requires_x_signers_template),
#[cfg(feature = "universal_fw")]
(Qstr::MP_QSTR_solana__unknown_token, Self::solana__unknown_token),
#[cfg(feature = "universal_fw")]
(Qstr::MP_QSTR_solana__unknown_token_address, Self::solana__unknown_token_address),
#[cfg(feature = "universal_fw")]
(Qstr::MP_QSTR_solana__unstake, Self::solana__unstake),
#[cfg(feature = "universal_fw")]
(Qstr::MP_QSTR_solana__unstake_question, Self::solana__unstake_question),

View File

@ -799,6 +799,8 @@ class TR:
solana__transaction_contains_unknown_instructions: str = "Transaction contains unknown instructions."
solana__transaction_fee: str = "Transaction fee"
solana__transaction_requires_x_signers_template: str = "Transaction requires {0} signers which increases the fee."
solana__unknown_token: str = "Unknown token"
solana__unknown_token_address: str = "Unknown token address"
solana__unstake: str = "Unstake"
solana__unstake_question: str = "Unstake SOL from stake account?"
solana__vote_account: str = "Vote account"

View File

@ -25,16 +25,13 @@ class Definitions:
return cls(tokens)
def has_token(self, mint: bytes) -> bool:
return mint in self._tokens
def get_token(self, mint: bytes) -> SolanaTokenInfo | None:
return self._tokens.get(mint)
def get_token(self, mint: bytes) -> SolanaTokenInfo:
token = self._tokens.get(mint)
if token is not None:
return token
return SolanaTokenInfo(
mint=mint,
symbol="[UNKN]",
name="Unknown token",
)
def unknown_token(mint: bytes) -> SolanaTokenInfo:
return SolanaTokenInfo(
mint=mint,
symbol="[UNKN]",
name="Unknown token",
)

View File

@ -2,6 +2,8 @@ from typing import TYPE_CHECKING
from trezor.strings import format_amount, format_timestamp
from .definitions import unknown_token
if TYPE_CHECKING:
from .definitions import Definitions
@ -24,7 +26,7 @@ def format_token_amount(
value: int, definitions: Definitions, decimals: int, mint: bytes
) -> str:
formatted = format_amount(value, decimals=decimals)
token = definitions.get_token(mint)
token = definitions.get_token(mint) or unknown_token(mint)
return f"{formatted} {token.symbol}"

View File

@ -10,7 +10,6 @@ from trezor.ui.layouts import (
confirm_properties,
confirm_solana_recipient,
confirm_solana_tx,
confirm_value,
show_danger,
show_warning,
)
@ -137,8 +136,8 @@ async def confirm_instruction(
# account included in the transaction directly
if len(account_value) == 2:
account_description = f"{base58.encode(account_value[0])}"
if definitions.has_token(account_value[0]):
token = definitions.get_token(account_value[0])
token = definitions.get_token(account_value[0])
if token is not None:
account_description = f"{token.name}\n{account_description}"
elif account_value[0] == signer_public_key:
account_description = f"{account_description} ({TR.words__signer})"
@ -305,6 +304,7 @@ async def confirm_token_transfer(
destination_account: bytes,
token_account: bytes,
token: SolanaTokenInfo,
is_unknown: bool,
amount: int,
decimals: int,
fee: Fee,
@ -322,16 +322,18 @@ async def confirm_token_transfer(
items=items,
)
value = token.name + "\n" + base58.encode(token.mint)
if is_unknown:
from trezor.ui.layouts import confirm_solana_unknown_token_warning
await confirm_value(
title=TR.words__token,
value=value,
description="",
br_name="confirm_token_address",
br_code=ButtonRequestType.ConfirmOutput,
verb=TR.buttons__continue,
)
await confirm_solana_unknown_token_warning()
await confirm_address(
title=TR.words__address,
subtitle=TR.solana__unknown_token,
address=base58.encode(token.mint),
verb=TR.buttons__continue,
br_name="confirm_token_address",
br_code=ButtonRequestType.ConfirmOutput,
)
await confirm_custom_transaction(amount, decimals, token.symbol, fee, blockhash)

View File

@ -123,6 +123,7 @@ async def try_confirm_token_transfer_transaction(
blockhash: bytes,
additional_info: AdditionalTxInfo,
) -> bool:
from .definitions import unknown_token
from .layout import confirm_token_transfer
from .token_account import try_get_token_account_base_address
@ -155,10 +156,14 @@ async def try_confirm_token_transfer_transaction(
)
token = additional_info.definitions.get_token(token_mint)
is_unknown = token is None
if is_unknown:
token = unknown_token(token_mint)
await confirm_token_transfer(
token_account if base_address is None else base_address,
token_account,
token,
is_unknown,
total_token_amount,
transfer_token_instructions[0].decimals,
fee,

View File

@ -1062,6 +1062,11 @@ if not utils.BITCOIN_ONLY:
br_code=br_code,
)
def confirm_solana_unknown_token_warning() -> Awaitable[None]:
return show_danger(
"unknown_token_warning", content=TR.solana__unknown_token_address
)
def confirm_solana_recipient(
recipient: str,
title: str,

View File

@ -1041,6 +1041,13 @@ if not utils.BITCOIN_ONLY:
br_code=br_code,
)
def confirm_solana_unknown_token_warning() -> Awaitable[None]:
return show_danger(
"unknown_token_warning",
content=TR.words__know_what_your_doing,
title=TR.solana__unknown_token_address,
)
def confirm_solana_recipient(
recipient: str,
title: str,

View File

@ -746,8 +746,7 @@ if not utils.BITCOIN_ONLY:
def confirm_ethereum_unknown_contract_warning() -> Awaitable[None]:
return show_danger(
"unknown_contract_warning",
TR.ethereum__unknown_contract_address,
TR.words__know_what_your_doing,
content=f"{TR.ethereum__unknown_contract_address}. {TR.words__know_what_your_doing}",
verb_cancel=TR.send__cancel_sign,
)
@ -945,6 +944,13 @@ if not utils.BITCOIN_ONLY:
br_name=None,
)
def confirm_solana_unknown_token_warning() -> Awaitable[None]:
return show_danger(
"unknown_token_warning",
content=f"{TR.solana__unknown_token_address}. {TR.words__know_what_your_doing}",
verb_cancel=TR.send__cancel_sign,
)
def confirm_solana_recipient(
recipient: str,
title: str,

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "Podepisování adresy",
"ethereum__token_contract": "Kontrakt tokenu",
"ethereum__units_template": "Jednotky: {0}",
"ethereum__unknown_contract_address": "Neznámá adresa kontraktu.",
"ethereum__unknown_contract_address": "Neznámá adresa kontraktu",
"ethereum__unknown_token": "Neznámý token",
"ethereum__valid_signature": "Podpis je platný.",
"experimental_mode__enable": "Povolit experimentální funkce?",
@ -825,6 +825,8 @@
"solana__stake_withdrawal_warning_title": "Adresa autority oprávněné k výběru",
"solana__transaction_contains_unknown_instructions": "Transakce obsahuje neznámý pokyn.",
"solana__transaction_requires_x_signers_template": "Transakce vyžaduje {0} podepisujících osob, což zvyšuje poplatek.",
"solana__unknown_token": "Neznámý token",
"solana__unknown_token_address": "Neznámá adresa tokenu",
"solana__unstake": "Zrušit staking",
"solana__unstake_question": "Zrušit staking SOL z stake účtu?",
"solana__vote_account": "Hlasovací účet",

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "Signieradresse",
"ethereum__token_contract": "Tokenvertrag",
"ethereum__units_template": "{0} Einheiten",
"ethereum__unknown_contract_address": "Unbekannte Vertragsadresse.",
"ethereum__unknown_contract_address": "Unbekannte Vertragsadresse",
"ethereum__unknown_token": "Ungültiger Token",
"ethereum__valid_signature": "Die Signatur ist gültig.",
"experimental_mode__enable": "Experimentelle Funktionen aktivieren?",
@ -825,6 +825,8 @@
"solana__stake_withdrawal_warning_title": "Auszahlungsautoritätsadresse",
"solana__transaction_contains_unknown_instructions": "Transaktion enthält unbekannte Anweisungen.",
"solana__transaction_requires_x_signers_template": "Transaktion erfordert {0} Unterzeichner. Dadurch steigt die Gebühr.",
"solana__unknown_token": "Ungültiger Token",
"solana__unknown_token_address": "Unbekannte Token-Adresse",
"solana__unstake": "Entstaken",
"solana__unstake_question": "SOL von Staking-Konto entstaken?",
"solana__vote_account": "Abstimmungskonto",

View File

@ -801,6 +801,8 @@
"solana__transaction_contains_unknown_instructions": "Transaction contains unknown instructions.",
"solana__transaction_fee": "Transaction fee",
"solana__transaction_requires_x_signers_template": "Transaction requires {0} signers which increases the fee.",
"solana__unknown_token": "Unknown token",
"solana__unknown_token_address": "Unknown token address",
"solana__unstake": "Unstake",
"solana__unstake_question": "Unstake SOL from stake account?",
"solana__vote_account": "Vote account",

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "Dirección firma",
"ethereum__token_contract": "Contrato de token",
"ethereum__units_template": "{0} unidades",
"ethereum__unknown_contract_address": "Dirección de contrato desconocida.",
"ethereum__unknown_contract_address": "Dirección de contrato desconocida",
"ethereum__unknown_token": "Token desconocido",
"ethereum__valid_signature": "La firma es válida.",
"experimental_mode__enable": "¿Activar funciones experimentales?",
@ -830,6 +830,8 @@
"solana__stake_withdrawal_warning_title": "Dirección de la autoridad de retiro",
"solana__transaction_contains_unknown_instructions": "La transacción contiene instrucciones desconocidas.",
"solana__transaction_requires_x_signers_template": "La transacción requiere {0} firmantes, lo que aumenta la comisión.",
"solana__unknown_token": "Token desconocido",
"solana__unknown_token_address": "Dirección de token desconocida",
"solana__unstake": "Retirar stake",
"solana__unstake_question": "¿Retirar SOL de Everstake?",
"solana__vote_account": "Cuenta de votación",

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "Adr. de signature",
"ethereum__token_contract": "Contrat de jeton",
"ethereum__units_template": "{0} unités",
"ethereum__unknown_contract_address": "Adresse de contrat inconnue.",
"ethereum__unknown_contract_address": "Adresse de contrat inconnue",
"ethereum__unknown_token": "Jeton inconnu",
"ethereum__valid_signature": "Signature valide.",
"experimental_mode__enable": "Activer les fonct. expérimentales ?",
@ -825,6 +825,8 @@
"solana__stake_withdrawal_warning_title": "Adresse de lautorité de retrait",
"solana__transaction_contains_unknown_instructions": "La transaction contient des instructions inconnues.",
"solana__transaction_requires_x_signers_template": "La transaction nécessite {0} signataires, ce qui augmente les frais.",
"solana__unknown_token": "Jeton inconnu",
"solana__unknown_token_address": "Adresse jeton inconnue",
"solana__unstake": "Unstake",
"solana__unstake_question": "Terminer le staking de l'SOL sur compte de staking?",
"solana__vote_account": "Compte de vote",

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "Indirizzo di firma",
"ethereum__token_contract": "Contratto token",
"ethereum__units_template": "{0} unità",
"ethereum__unknown_contract_address": "Indirizzo del contratto sconosciuto.",
"ethereum__unknown_contract_address": "Indirizzo del contratto sconosciuto",
"ethereum__unknown_token": "Token sconosciuto",
"ethereum__valid_signature": "La firma è valida.",
"experimental_mode__enable": "Abilitare funzion. sperimentali?",
@ -813,6 +813,8 @@
"solana__multiple_signers": "Più firmatari",
"solana__transaction_contains_unknown_instructions": "La transazione contiene istruzioni sconosciute.",
"solana__transaction_requires_x_signers_template": "Poiché la transazione richiede {0} firmatari, la commissione è più elevata.",
"solana__unknown_token": "Token sconosciuto",
"solana__unknown_token_address": "Indirizzo token sconosciuto",
"stellar__account_merge": "Unione conti",
"stellar__account_thresholds": "Soglie conti",
"stellar__add_signer": "Aggiungi firmatario",

View File

@ -1013,5 +1013,7 @@
"1011": "ethereum__approve_revoke_from",
"1012": "words__chain",
"1013": "words__token",
"1014": "instructions__tap"
"1014": "instructions__tap",
"1015": "solana__unknown_token",
"1016": "solana__unknown_token_address"
}

View File

@ -358,7 +358,7 @@
"ethereum__title_signing_address": "End. assinatura",
"ethereum__token_contract": "Contrato Token",
"ethereum__units_template": "{0} unidades",
"ethereum__unknown_contract_address": "Endereço de contrato desconhecido.",
"ethereum__unknown_contract_address": "Endereço de contrato desconhecido",
"ethereum__unknown_token": "Token desconhecido",
"ethereum__valid_signature": "A assinatura é válida.",
"experimental_mode__enable": "Ativar recursos experimentais?",
@ -824,6 +824,8 @@
"solana__stake_withdrawal_warning_title": "Endereço da autoridade de saque",
"solana__transaction_contains_unknown_instructions": "A transação contém instruções desconhecidas.",
"solana__transaction_requires_x_signers_template": "A transação exige {0} signatários, o que aumenta a taxa.",
"solana__unknown_token": "Token desconhecido",
"solana__unknown_token_address": "Endereço de token desconhecido",
"solana__unstake": "Tirar do stake",
"solana__unstake_question": "Tirar SOL do stake no conta de staking?",
"solana__vote_account": "Conta de votação",

View File

@ -1,8 +1,8 @@
{
"current": {
"merkle_root": "19bb1db498ed8385e3af089ff612c3b0b5f28d9f726c8b096061c07a39115ff5",
"datetime": "2025-05-22T10:17:38.646558",
"commit": "a464ec4ee8da139f519d12cf638a2531e888c18e"
"merkle_root": "06c684a5913a1ba5ebbaa933b90f31111cde422ff72c07bfa1ea76edfd7b5c45",
"datetime": "2025-05-27T11:23:39.601630",
"commit": "a6eb3bc47c08b734fb872a5b8990cd59576bafab"
},
"history": [
{

View File

@ -726,6 +726,8 @@
"solana__multiple_signers": "Birden fazla imzalayan",
"solana__transaction_contains_unknown_instructions": "İşlem bilinmeyen talimatlar içeriyor.",
"solana__transaction_requires_x_signers_template": "İşlem için {0} imzalayan gerekiyor ve bu da ücreti artırıyor.",
"solana__unknown_token": "Bilinmeyen token",
"solana__unknown_token_address": "Bilinmeyen token adresi",
"stellar__account_merge": "Hesap Birleştirme",
"stellar__account_thresholds": "Hesap Eşikleri",
"stellar__add_signer": "İmzalayan Ekle",

File diff suppressed because it is too large Load Diff