Skip to content

Commit d906218

Browse files
EIP-7702 error handling cleanup
1 parent 7488e5a commit d906218

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src_features/signAuthorizationEIP7702/commands_7702.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// Avoid saving the full structure when parsing
1818
// Alternative option : add a callback to f_tlv_payload_handler
1919
static uint16_t g_7702_sw;
20-
static unsigned int g_7702_flags;
2120

2221
#define MAGIC_7702 5
2322

@@ -76,14 +75,15 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
7675
tlv_parse(payload, size, (f_tlv_data_handler) handle_auth_7702_struct, &auth_7702_ctx);
7776
if (to_free) mem_dealloc(size);
7877
if (!parsing_ret || !verify_auth_7702_struct(&auth_7702_ctx)) {
78+
g_7702_sw = APDU_RESPONSE_INVALID_DATA;
7979
return false;
8080
}
8181

8282
// Reject if not enabled
8383
if (!N_storage.eip7702_enable) {
8484
ui_error_no_7702();
8585
g_7702_sw = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
86-
return true;
86+
return false;
8787
}
8888

8989
// Compute the authorization hash
@@ -99,24 +99,24 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
9999
hashSize = rlpEncodeListHeader8(rlpDataSize, rlpTmp + 1, sizeof(rlpTmp) - 1);
100100
if (hashSize == 0) {
101101
g_7702_sw = APDU_RESPONSE_UNKNOWN;
102-
return true;
102+
return false;
103103
}
104104
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
105105
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3, 0, rlpTmp, hashSize + 1, NULL, 0));
106106
sw = hashRLP64(auth7702->chainId, rlpTmp, sizeof(rlpTmp));
107107
if (sw != APDU_NO_RESPONSE) {
108108
g_7702_sw = sw;
109-
return true;
109+
return false;
110110
}
111111
sw = hashRLP(auth7702->delegate, sizeof(auth7702->delegate), rlpTmp, sizeof(rlpTmp));
112112
if (sw != APDU_NO_RESPONSE) {
113113
g_7702_sw = sw;
114-
return true;
114+
return false;
115115
}
116116
sw = hashRLP64(auth7702->nonce, rlpTmp, sizeof(rlpTmp));
117117
if (sw != APDU_NO_RESPONSE) {
118118
g_7702_sw = sw;
119-
return true;
119+
return false;
120120
}
121121
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3,
122122
CX_LAST,
@@ -143,7 +143,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
143143
// Reject if not in the whitelist
144144
ui_error_no_7702_whitelist();
145145
g_7702_sw = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
146-
return true;
146+
return false;
147147
} else {
148148
strlcpy(strings.common.toAddress, delegateName, sizeof(strings.common.toAddress));
149149
}
@@ -153,7 +153,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
153153
sizeof(strings.common.toAddress),
154154
auth7702->chainId)) {
155155
g_7702_sw = APDU_RESPONSE_UNKNOWN;
156-
return true;
156+
return false;
157157
}
158158
#endif // HAVE_EIP7702_WHITELIST
159159
// * ChainId
@@ -178,22 +178,19 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
178178
}
179179

180180
ui_sign_7702_auth();
181-
g_7702_flags |= IO_ASYNCH_REPLY;
182-
g_7702_sw = APDU_NO_RESPONSE;
183181
return true;
184182

185183
end:
186184
// Internal error triggered by CX_CHECK
187185
g_7702_sw = APDU_RESPONSE_UNKNOWN;
188-
return true;
186+
return false;
189187
}
190188

191189
uint16_t handleSignEIP7702Authorization(uint8_t p1,
192190
const uint8_t *dataBuffer,
193191
uint8_t dataLength,
194192
unsigned int *flags) {
195-
g_7702_sw = APDU_RESPONSE_OK;
196-
g_7702_flags = *flags;
193+
g_7702_sw = APDU_RESPONSE_UNKNOWN;
197194
if (p1 == P1_FIRST_CHUNK) {
198195
if ((dataBuffer =
199196
parseBip32(dataBuffer, &dataLength, &tmpCtx.authSigningContext7702.bip32)) ==
@@ -202,10 +199,10 @@ uint16_t handleSignEIP7702Authorization(uint8_t p1,
202199
}
203200
}
204201
if (!tlv_from_apdu(p1 == P1_FIRST_CHUNK, dataLength, dataBuffer, &handleAuth7702TLV)) {
205-
return APDU_RESPONSE_INVALID_DATA;
202+
return g_7702_sw;
206203
}
207-
*flags = g_7702_flags;
208-
return g_7702_sw;
204+
*flags |= IO_ASYNCH_REPLY;
205+
return APDU_NO_RESPONSE;
209206
}
210207

211208
#endif // HAVE_EIP7702

0 commit comments

Comments
 (0)