Skip to content

Commit f7de9c2

Browse files
committed
WIP
1 parent 7bbda7b commit f7de9c2

16 files changed

Lines changed: 3024 additions & 69 deletions

File tree

common/protob/messages-definitions.proto

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum DefinitionType {
1313
ETHEREUM_NETWORK = 0;
1414
ETHEREUM_TOKEN = 1;
1515
SOLANA_TOKEN = 2;
16+
ETHEREUM_ERC7730_DISPLAY_FORMAT = 3;
1617
}
1718

1819
// ****** CROSS-PARSEABILITY NOTE ******
@@ -23,9 +24,13 @@ enum DefinitionType {
2324
//
2425
// To achieve that, we vary the wire types of the fields in order:
2526
//
26-
// * EthereumNetworkInfo: varint, length-delimited, ...
27+
// * EthereumNetworkInfo: varint, length-delimited, varint, ...
2728
// * EthereumTokenInfo: length-delimited, varint, ...
2829
// * SolanaTokenInfo: length-delimited, length-delimited, ...
30+
// * EthereumERC7730DisplayFormat: varint, length-delimited, length-delimited, ...
31+
32+
33+
// ****** ETHEREUM_NETWORK ******
2934

3035
/**
3136
* Ethereum network definition.
@@ -38,6 +43,9 @@ message EthereumNetworkInfo {
3843
required string name = 4;
3944
}
4045

46+
47+
// ****** ETHEREUM_TOKEN ******
48+
4149
/**
4250
* Ethereum token definition.
4351
* @embed
@@ -50,6 +58,9 @@ message EthereumTokenInfo {
5058
required string name = 5;
5159
}
5260

61+
62+
// ****** SOLANA_TOKEN ******
63+
5364
/**
5465
* Solana token definition.
5566
* @embed
@@ -59,3 +70,101 @@ message SolanaTokenInfo {
5970
required string symbol = 2;
6071
required string name = 3;
6172
}
73+
74+
75+
// ****** ETHEREUM_ERC7730_DISPLAY_FORMAT ******
76+
77+
/**
78+
* Solidity types.
79+
* @embed
80+
*/
81+
enum EthereumABIType {
82+
ABI_ADDRESS = 0;
83+
ABI_BOOL = 1;
84+
ABI_BYTES = 2;
85+
ABI_BYTES4 = 3;
86+
ABI_BYTES8 = 4;
87+
ABI_BYTES32 = 5;
88+
ABI_STRING = 6;
89+
ABI_UINT8 = 7;
90+
ABI_UINT16 = 8;
91+
ABI_UINT24 = 9;
92+
ABI_UINT32 = 10;
93+
ABI_UINT64 = 11;
94+
ABI_UINT128 = 12;
95+
ABI_UINT160 = 13;
96+
ABI_UINT256 = 14;
97+
ABI_INT64 = 15;
98+
}
99+
100+
/**
101+
* Solidity struct / tuple.
102+
* @embed
103+
*/
104+
message EthereumABIStruct {
105+
repeated EthereumABIType fields = 1; // struct member types (leaf only)
106+
required bool is_dynamic = 2;
107+
}
108+
109+
/**
110+
* Ethereum ERC-20 function parameter.
111+
* @embed
112+
*/
113+
message EthereumERC20ABIValue {
114+
// Exactly one of the following should be set:
115+
optional EthereumABIType atomic = 1; // Atomic(parser)
116+
optional EthereumABIType dynamic = 2; // Dynamic(parser)
117+
optional EthereumABIStruct struct = 3; // Struct(fields, is_dynamic)
118+
optional EthereumABIType atomic_array = 4; // Array(Atomic(type))
119+
optional EthereumABIType dynamic_array = 5; // Array(Dynamic(type))
120+
optional EthereumABIStruct struct_array = 6; // Array(Struct(...))
121+
}
122+
123+
/**
124+
* All available ERC-7730 field formatters.
125+
* @embed
126+
*/
127+
enum EthereumERC7730FieldFormatterType {
128+
FORMATTER_ADDRESS_NAME = 0;
129+
FORMATTER_AMOUNT = 1;
130+
FORMATTER_TOKEN_AMOUNT = 2;
131+
FORMATTER_UNIT = 3;
132+
}
133+
134+
/**
135+
* Definition of a single field according to ERC-7730.
136+
* @embed
137+
*/
138+
message EthereumERC7730Field {
139+
// Path: either a ContainerPath or index tuple — mutually exclusive
140+
optional uint32 container_path = 1; // ContainerPath: From=1, Value=2, To=3, ChainId=4 - needs to match `ContainerPath` in `clear_signing.py`
141+
repeated uint32 path = 2; // eg. (0,) = [0], (1, 2) = [1, 2], etc.
142+
143+
// User-readable label
144+
required string label = 3;
145+
146+
required EthereumERC7730FieldFormatterType formatter = 4;
147+
148+
// TokenAmountFormatter params
149+
optional uint32 token_container_path = 6; // if token_path is a ContainerPath
150+
repeated uint32 token_path = 5; // token_path if it is a tuple
151+
optional bytes threshold = 7; // 32-byte big-endian threshold
152+
153+
// UnitFormatter params
154+
optional uint32 decimals = 8;
155+
optional string base = 9;
156+
optional bool prefix = 10;
157+
}
158+
159+
/**
160+
* Ethereum ERC-7730 display format - corresponding to `DisplayFormat` in `clear_signing.py`.
161+
* @embed
162+
*/
163+
message EthereumERC7730DisplayFormat {
164+
required uint64 chain_id = 1;
165+
required bytes address = 2;
166+
required bytes func_sig = 3;
167+
required string intent = 4;
168+
repeated EthereumERC20ABIValue parameter_definitions = 5;
169+
repeated EthereumERC7730Field field_definitions = 6;
170+
}

common/protob/messages-ethereum.proto

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,43 @@ message EthereumSignTxEIP1559 {
112112
* @next EthereumTxAck
113113
*/
114114
message EthereumTxRequest {
115+
// Request more information
115116
optional uint32 data_length = 1; // Number of bytes being requested (<= 1024)
117+
118+
// Done. Return signature.
116119
optional uint32 signature_v = 2; // Computed signature (recovery parameter, limited to 27 or 28)
117120
optional bytes signature_r = 3; // Computed signature R component (256 bit)
118121
optional bytes signature_s = 4; // Computed signature S component (256 bit)
122+
119123
}
120124

121125
/**
122126
* Request: Transaction payload data.
123127
* @next EthereumTxRequest
128+
* @next EthereumDefinitionRequest
124129
*/
125130
message EthereumTxAck {
126-
required bytes data_chunk = 1; // Bytes from transaction payload (<= 1024 bytes)
131+
required bytes data_chunk = 1; // requested number of bytes from transaction payload (<= 1024)
132+
}
133+
134+
/**
135+
* Structure representing a request for an ERC-20 function definition and the corresponding ERC-7730 display format.
136+
* @next EthereumDefinitionsAck
137+
*/
138+
message EthereumDefinitionRequest {
139+
required uint64 chain_id = 1;
140+
required bytes token_address = 2;
141+
required bytes func_sig = 3;
142+
}
143+
144+
/**
145+
* Request: Definitions payload data.
146+
* @next EthereumTxRequest
147+
* @next EthereumDefinitionRequest
148+
*/
149+
message EthereumDefinitionAck {
150+
required EthereumDefinitions definitions = 1;
151+
optional EthereumFunctionDefinition func_definition = 2;
127152
}
128153

129154
/**
@@ -188,6 +213,15 @@ message EthereumTypedDataSignature {
188213
* @embed
189214
*/
190215
message EthereumDefinitions {
191-
optional bytes encoded_network = 1; // encoded ethereum network
192-
optional bytes encoded_token = 2; // encoded ethereum token
216+
optional bytes encoded_network = 1; // encoded ethereum network
217+
optional bytes encoded_token = 2; // encoded ethereum token
218+
}
219+
220+
/**
221+
* Contains an encoded ERC-20 / ERC-7730 clear signing definition.
222+
* @embed
223+
*/
224+
message EthereumFunctionDefinition {
225+
required bytes encoded_function = 1; // encoded ERC-20 function definition with the corresponding ERC-7730 display format
193226
}
227+

core/embed/upymod/qstrdefsport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ Q(CardanoTxAuxiliaryDataSupplementType)
488488
Q(CardanoTxOutputSerializationFormat)
489489
Q(CardanoTxSigningMode)
490490
Q(CardanoTxWitnessType)
491+
Q(EthereumABIType)
491492
Q(EthereumDataType)
493+
Q(EthereumERC7730FieldFormatterType)
492494
Q(MoneroNetworkType)
493495
Q(NEMImportanceTransferMode)
494496
Q(NEMModificationType)
@@ -801,7 +803,9 @@ Q(trezor.enums.CardanoTxAuxiliaryDataSupplementType)
801803
Q(trezor.enums.CardanoTxOutputSerializationFormat)
802804
Q(trezor.enums.CardanoTxSigningMode)
803805
Q(trezor.enums.CardanoTxWitnessType)
806+
Q(trezor.enums.EthereumABIType)
804807
Q(trezor.enums.EthereumDataType)
808+
Q(trezor.enums.EthereumERC7730FieldFormatterType)
805809
Q(trezor.enums.MoneroNetworkType)
806810
Q(trezor.enums.NEMImportanceTransferMode)
807811
Q(trezor.enums.NEMModificationType)

core/src/apps/common/definitions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from typing import TYPE_CHECKING
22

3-
from trezor.messages import EthereumNetworkInfo, EthereumTokenInfo, SolanaTokenInfo
3+
from trezor.messages import (
4+
EthereumERC7730DisplayFormat,
5+
EthereumNetworkInfo,
6+
EthereumTokenInfo,
7+
SolanaTokenInfo,
8+
)
49
from trezor.wire import DataError
510

611
if TYPE_CHECKING:
@@ -9,7 +14,11 @@
914

1015
# NOTE: it's important all DefType variants can't be cross-parsed
1116
DefType = TypeVar(
12-
"DefType", EthereumNetworkInfo, EthereumTokenInfo, SolanaTokenInfo
17+
"DefType",
18+
EthereumNetworkInfo,
19+
EthereumTokenInfo,
20+
SolanaTokenInfo,
21+
EthereumERC7730DisplayFormat,
1322
)
1423

1524

@@ -33,6 +42,8 @@ def decode_definition(definition: AnyBytes, expected_type: type[DefType]) -> Def
3342
expected_type_number = DefinitionType.ETHEREUM_TOKEN
3443
if expected_type.MESSAGE_NAME == SolanaTokenInfo.MESSAGE_NAME:
3544
expected_type_number = DefinitionType.SOLANA_TOKEN
45+
if expected_type.MESSAGE_NAME == EthereumERC7730DisplayFormat.MESSAGE_NAME:
46+
expected_type_number = DefinitionType.ETHEREUM_ERC7730_DISPLAY_FORMAT
3647

3748
try:
3849
# first check format version

0 commit comments

Comments
 (0)