Skip to content

Commit 659107a

Browse files
EIP-7702 error handling cleanup
1 parent 85ff2c8 commit 659107a

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

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

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

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

8888
// Compute the authorization hash
@@ -98,24 +98,24 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
9898
hashSize = rlpEncodeListHeader8(rlpDataSize, rlpTmp + 1, sizeof(rlpTmp) - 1);
9999
if (hashSize == 0) {
100100
g_7702_sw = APDU_RESPONSE_UNKNOWN;
101-
return true;
101+
return false;
102102
}
103103
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
104104
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3, 0, rlpTmp, hashSize + 1, NULL, 0));
105105
sw = hashRLP64(auth7702->chainId, rlpTmp, sizeof(rlpTmp));
106106
if (sw != APDU_NO_RESPONSE) {
107107
g_7702_sw = sw;
108-
return true;
108+
return false;
109109
}
110110
sw = hashRLP(auth7702->delegate, sizeof(auth7702->delegate), rlpTmp, sizeof(rlpTmp));
111111
if (sw != APDU_NO_RESPONSE) {
112112
g_7702_sw = sw;
113-
return true;
113+
return false;
114114
}
115115
sw = hashRLP64(auth7702->nonce, rlpTmp, sizeof(rlpTmp));
116116
if (sw != APDU_NO_RESPONSE) {
117117
g_7702_sw = sw;
118-
return true;
118+
return false;
119119
}
120120
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3,
121121
CX_LAST,
@@ -142,7 +142,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
142142
// Reject if not in the whitelist
143143
ui_error_no_7702_whitelist();
144144
g_7702_sw = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
145-
return true;
145+
return false;
146146
} else {
147147
strlcpy(strings.common.toAddress, delegateName, sizeof(strings.common.toAddress));
148148
}
@@ -152,7 +152,7 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
152152
sizeof(strings.common.toAddress),
153153
auth7702->chainId)) {
154154
g_7702_sw = APDU_RESPONSE_UNKNOWN;
155-
return true;
155+
return false;
156156
}
157157
#endif // HAVE_EIP7702_WHITELIST
158158
// * ChainId
@@ -177,22 +177,19 @@ static bool handleAuth7702TLV(const uint8_t *payload, uint16_t size, bool to_fre
177177
}
178178

179179
ui_sign_7702_auth();
180-
g_7702_flags |= IO_ASYNCH_REPLY;
181-
g_7702_sw = APDU_NO_RESPONSE;
182180
return true;
183181

184182
end:
185183
// Internal error triggered by CX_CHECK
186184
g_7702_sw = APDU_RESPONSE_UNKNOWN;
187-
return true;
185+
return false;
188186
}
189187

190188
uint16_t handleSignEIP7702Authorization(uint8_t p1,
191189
const uint8_t *dataBuffer,
192190
uint8_t dataLength,
193191
unsigned int *flags) {
194-
g_7702_sw = APDU_RESPONSE_OK;
195-
g_7702_flags = *flags;
192+
g_7702_sw = APDU_RESPONSE_UNKNOWN;
196193
if (p1 == P1_FIRST_CHUNK) {
197194
if ((dataBuffer =
198195
parseBip32(dataBuffer, &dataLength, &tmpCtx.authSigningContext7702.bip32)) ==
@@ -201,10 +198,10 @@ uint16_t handleSignEIP7702Authorization(uint8_t p1,
201198
}
202199
}
203200
if (!tlv_from_apdu(p1 == P1_FIRST_CHUNK, dataLength, dataBuffer, &handleAuth7702TLV)) {
204-
return APDU_RESPONSE_INVALID_DATA;
201+
return g_7702_sw;
205202
}
206-
*flags = g_7702_flags;
207-
return g_7702_sw;
203+
*flags |= IO_ASYNCH_REPLY;
204+
return APDU_NO_RESPONSE;
208205
}
209206

210207
#endif // HAVE_EIP7702

0 commit comments

Comments
 (0)