Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
126 changes: 125 additions & 1 deletion common/protob/messages-definitions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum DefinitionType {
ETHEREUM_NETWORK = 0;
ETHEREUM_TOKEN = 1;
SOLANA_TOKEN = 2;
ETHEREUM_ERC7730_DISPLAY_FORMAT = 3;
}

// ****** CROSS-PARSEABILITY NOTE ******
Expand All @@ -23,9 +24,12 @@ enum DefinitionType {
//
// To achieve that, we vary the wire types of the fields in order:
//
// * EthereumNetworkInfo: varint, length-delimited, ...
// * EthereumNetworkInfo: varint, length-delimited, varint, ...
// * EthereumTokenInfo: length-delimited, varint, ...
// * SolanaTokenInfo: length-delimited, length-delimited, ...
// * EthereumERC7730DisplayFormat: varint, length-delimited, length-delimited, ...

// ****** ETHEREUM_NETWORK ******

/**
* Ethereum network definition.
Expand All @@ -38,6 +42,8 @@ message EthereumNetworkInfo {
required string name = 4;
}

// ****** ETHEREUM_TOKEN ******

/**
* Ethereum token definition.
* @embed
Expand All @@ -50,6 +56,8 @@ message EthereumTokenInfo {
required string name = 5;
}

// ****** SOLANA_TOKEN ******

/**
* Solana token definition.
* @embed
Expand All @@ -59,3 +67,119 @@ message SolanaTokenInfo {
required string symbol = 2;
required string name = 3;
}

// ****** ETHEREUM_ERC7730_DISPLAY_FORMAT ******

/**
* Solidity types.
* @embed
*/
enum EthereumABIType {
ABI_ADDRESS = 0;
ABI_UINT256 = 1;
ABI_UINT248 = 2;
ABI_UINT160 = 3;
ABI_UINT128 = 4;
ABI_UINT120 = 5;
ABI_UINT112 = 6;
ABI_UINT96 = 7;
ABI_UINT72 = 8;
ABI_UINT64 = 9;
ABI_UINT48 = 10;
ABI_UINT40 = 11;
ABI_UINT32 = 12;
ABI_UINT24 = 13;
ABI_UINT16 = 14;
ABI_UINT8 = 15;
ABI_BOOL = 16;
ABI_BYTES = 20;
ABI_STRING = 21;
}

/**
* Solidity struct / tuple.
* @embed
*/
message EthereumABITupleInfo {
repeated EthereumABIValueInfo fields = 1;
required bool is_dynamic = 2;
}

/**
* Ethereum ERC-20 function parameter.
* @embed
*/
message EthereumABIValueInfo {
// Exactly one of the following should be set:
optional EthereumABIType atomic = 1; // Atomic(parser)
optional EthereumABIType dynamic = 2; // Dynamic(parser)
optional EthereumABITupleInfo tuple = 3; // Tuple(fields, is_dynamic)
optional EthereumABIValueInfo array = 4; // Array(element_type)
}
Comment thread
ibz marked this conversation as resolved.

/**
* All available ERC-7730 field formatters.
* @embed
*/
enum EthereumERC7730FieldFormatterType {
FORMATTER_ADDRESS_NAME = 0;
FORMATTER_AMOUNT = 1;
FORMATTER_TOKEN_AMOUNT = 2;
FORMATTER_UNIT = 3;
}

/**
* ERC-7730 container path (paths starting with @).
* Note: keep this in sync with `ContainerPath` from `clear_signing.py`
* @embed
*/
enum EthereumERC7730ContainerPath {
FROM = 1;
VALUE = 2;
}

/**
* Path used in ERC-7730 field definitions to access values.
* We currently support two kinds of paths:
* * paths that access function parameters
* * container paths (starting with `@`)
* `$` and `#` paths are not supported.
* @embed
*/
message EthereumERC7730Path {
// Exactly one of the following should be set:
repeated uint32 path = 1; // eg. (0,) is encoded as [0], (1, 2) is encoded as [1, 2], etc.
optional EthereumERC7730ContainerPath container_path = 2;
}

/**
* Definition of a single field according to ERC-7730.
* @embed
*/
message EthereumERC7730FieldInfo {
required EthereumERC7730Path path = 1;
required string label = 2;
required EthereumERC7730FieldFormatterType formatter = 3;

// TokenAmountFormatter params
optional EthereumERC7730Path token_path = 4;
optional bytes threshold = 5;

// UnitFormatter params
optional uint32 decimals = 6;
optional string base = 7;
optional bool prefix = 8;
}

/**
* Ethereum ERC-7730 display format - corresponding to `DisplayFormat` in `clear_signing.py`.
* @embed
*/
message EthereumERC7730DisplayFormatInfo {
required uint64 chain_id = 1;
required bytes address = 2;
required bytes func_sig = 3;
required string intent = 4;
repeated EthereumABIValueInfo parameter_definitions = 5;
repeated EthereumERC7730FieldInfo field_definitions = 6;
}
12 changes: 8 additions & 4 deletions common/protob/messages-ethereum.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ message EthereumSignTxEIP1559 {
* @next EthereumTxAck
*/
message EthereumTxRequest {
// Request more information
optional uint32 data_length = 1; // Number of bytes being requested (<= 1024)

// Done. Return signature.
optional uint32 signature_v = 2; // Computed signature (recovery parameter, limited to 27 or 28)
optional bytes signature_r = 3; // Computed signature R component (256 bit)
optional bytes signature_s = 4; // Computed signature S component (256 bit)
Expand All @@ -123,7 +126,7 @@ message EthereumTxRequest {
* @next EthereumTxRequest
*/
message EthereumTxAck {
required bytes data_chunk = 1; // Bytes from transaction payload (<= 1024 bytes)
required bytes data_chunk = 1; // requested number of bytes from transaction payload (<= 1024)
}

/**
Expand Down Expand Up @@ -184,10 +187,11 @@ message EthereumTypedDataSignature {
}

/**
* Contains an encoded network and/or token definition. See external-definitions.md for details.
* Contains encoded network, token and ERC-7730 display format definitions. See external-definitions.md for details.
* @embed
*/
message EthereumDefinitions {
optional bytes encoded_network = 1; // encoded ethereum network
optional bytes encoded_token = 2; // encoded ethereum token
optional bytes encoded_network = 1; // encoded ethereum network
optional bytes encoded_token = 2; // encoded ethereum token
optional bytes encoded_erc7730_display_format = 3; // encoded ERC-7730 display format
}
6 changes: 6 additions & 0 deletions core/embed/upymod/qstrdefsport.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ Q(CardanoTxAuxiliaryDataSupplementType)
Q(CardanoTxOutputSerializationFormat)
Q(CardanoTxSigningMode)
Q(CardanoTxWitnessType)
Q(EthereumABIType)
Q(EthereumDataType)
Q(EthereumERC7730ContainerPath)
Q(EthereumERC7730FieldFormatterType)
Q(MoneroNetworkType)
Q(NEMImportanceTransferMode)
Q(NEMModificationType)
Expand Down Expand Up @@ -801,7 +804,10 @@ Q(trezor.enums.CardanoTxAuxiliaryDataSupplementType)
Q(trezor.enums.CardanoTxOutputSerializationFormat)
Q(trezor.enums.CardanoTxSigningMode)
Q(trezor.enums.CardanoTxWitnessType)
Q(trezor.enums.EthereumABIType)
Q(trezor.enums.EthereumDataType)
Q(trezor.enums.EthereumERC7730ContainerPath)
Q(trezor.enums.EthereumERC7730FieldFormatterType)
Q(trezor.enums.MoneroNetworkType)
Q(trezor.enums.NEMImportanceTransferMode)
Q(trezor.enums.NEMModificationType)
Expand Down
15 changes: 13 additions & 2 deletions core/src/apps/common/definitions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import TYPE_CHECKING

from trezor.messages import EthereumNetworkInfo, EthereumTokenInfo, SolanaTokenInfo
from trezor.messages import (
EthereumERC7730DisplayFormatInfo,
EthereumNetworkInfo,
EthereumTokenInfo,
SolanaTokenInfo,
)
from trezor.wire import DataError

if TYPE_CHECKING:
Expand All @@ -9,7 +14,11 @@

# NOTE: it's important all DefType variants can't be cross-parsed
DefType = TypeVar(
"DefType", EthereumNetworkInfo, EthereumTokenInfo, SolanaTokenInfo
"DefType",
EthereumNetworkInfo,
EthereumTokenInfo,
SolanaTokenInfo,
EthereumERC7730DisplayFormatInfo,
)


Expand All @@ -33,6 +42,8 @@ def decode_definition(definition: AnyBytes, expected_type: type[DefType]) -> Def
expected_type_number = DefinitionType.ETHEREUM_TOKEN
if expected_type.MESSAGE_NAME == SolanaTokenInfo.MESSAGE_NAME:
expected_type_number = DefinitionType.SOLANA_TOKEN
if expected_type.MESSAGE_NAME == EthereumERC7730DisplayFormatInfo.MESSAGE_NAME:
expected_type_number = DefinitionType.ETHEREUM_ERC7730_DISPLAY_FORMAT

try:
# first check format version
Expand Down
Loading
Loading