66
77enum {
88 TAG_STRUCT_VERSION = 0x00 ,
9- TAG_DERIVATION_IDX = 0x01 ,
10- TAG_DELEGATE_ADDR = 0x02 ,
11- TAG_CHAIN_ID = 0x03 ,
12- TAG_NONCE = 0x04 ,
9+ TAG_DELEGATE_ADDR = 0x01 ,
10+ TAG_CHAIN_ID = 0x02 ,
11+ TAG_NONCE = 0x03 ,
1312};
1413
1514enum {
1615 BIT_VERSION ,
17- BIT_DERIVATION_IDX ,
1816 BIT_DELEGATE_ADDR ,
1917 BIT_CHAIN_ID ,
2018 BIT_NONCE ,
2119};
2220
2321#define STRUCT_VERSION 0x01
24- #define MASK_ALL \
25- (SET_BIT(BIT_VERSION) | SET_BIT(BIT_DERIVATION_IDX) | SET_BIT(BIT_DELEGATE_ADDR) | \
26- SET_BIT(BIT_CHAIN_ID) | SET_BIT(BIT_NONCE))
22+ #define MASK_ALL \
23+ (SET_BIT(BIT_VERSION) | SET_BIT(BIT_DELEGATE_ADDR) | SET_BIT(BIT_CHAIN_ID) | SET_BIT(BIT_NONCE))
2724
2825static bool handle_version (const s_tlv_data * data , s_auth_7702_ctx * context ) {
2926 if (data -> length != sizeof (uint8_t )) {
3027 return false;
3128 }
3229 context -> mask_parsed |= SET_BIT (BIT_VERSION );
33- return (data -> value [0 ] == STRUCT_VERSION );
34- }
35-
36- static bool handle_derivation_idx (const s_tlv_data * data , s_auth_7702_ctx * context ) {
37- uint32_t idx ;
38- if (data -> length != sizeof (uint32_t )) {
39- return false;
40- }
41- if (context -> auth_7702 .bip32 .length == MAX_BIP32_PATH ) {
42- return false;
43- }
44- idx = read_u32_be (data -> value , 0 );
45- context -> auth_7702 .bip32 .path [context -> auth_7702 .bip32 .length ] = idx ;
46- context -> auth_7702 .bip32 .length ++ ;
47- context -> mask_parsed |= SET_BIT (BIT_DERIVATION_IDX );
30+ context -> version = data -> value [0 ];
4831 return true;
4932}
5033
5134static bool handle_delegate_addr (const s_tlv_data * data , s_auth_7702_ctx * context ) {
52- if (data -> length != sizeof (context -> auth_7702 .delegate )) {
35+ uint8_t buf [sizeof (context -> auth_7702 .delegate )];
36+
37+ if (data -> length > sizeof (buf )) {
5338 return false;
5439 }
55- memmove (context -> auth_7702 .delegate , data -> value , sizeof (context -> auth_7702 .delegate ));
40+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
41+ memmove (context -> auth_7702 .delegate , buf , sizeof (buf ));
5642 context -> mask_parsed |= SET_BIT (BIT_DELEGATE_ADDR );
5743 return true;
5844}
5945
6046static bool handle_chain_id (const s_tlv_data * data , s_auth_7702_ctx * context ) {
61- if (data -> length != sizeof (uint64_t )) {
47+ uint8_t buf [sizeof (context -> auth_7702 .chainId )];
48+
49+ if (data -> length > sizeof (buf )) {
6250 return false;
6351 }
64- context -> auth_7702 .chainId = read_u64_be (data -> value , 0 );
52+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
53+ context -> auth_7702 .chainId = read_u64_be (buf , 0 );
6554 context -> mask_parsed |= SET_BIT (BIT_CHAIN_ID );
6655 return true;
6756}
6857
6958static bool handle_nonce (const s_tlv_data * data , s_auth_7702_ctx * context ) {
70- if (data -> length != sizeof (uint64_t )) {
59+ uint8_t buf [sizeof (context -> auth_7702 .nonce )];
60+
61+ if (data -> length > sizeof (buf )) {
7162 return false;
7263 }
73- context -> auth_7702 .nonce = read_u64_be (data -> value , 0 );
64+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
65+ context -> auth_7702 .nonce = read_u64_be (buf , 0 );
7466 context -> mask_parsed |= SET_BIT (BIT_NONCE );
7567 return true;
7668}
@@ -82,9 +74,6 @@ bool handle_auth_7702_struct(const s_tlv_data *data, s_auth_7702_ctx *context) {
8274 case TAG_STRUCT_VERSION :
8375 ret = handle_version (data , context );
8476 break ;
85- case TAG_DERIVATION_IDX :
86- ret = handle_derivation_idx (data , context );
87- break ;
8877 case TAG_DELEGATE_ADDR :
8978 ret = handle_delegate_addr (data , context );
9079 break ;
@@ -101,8 +90,8 @@ bool handle_auth_7702_struct(const s_tlv_data *data, s_auth_7702_ctx *context) {
10190 return ret ;
10291}
10392
104- bool verify_auth_7702_struct (s_auth_7702_ctx * context ) {
105- return ((context -> mask_parsed & MASK_ALL ) == MASK_ALL );
93+ bool verify_auth_7702_struct (const s_auth_7702_ctx * context ) {
94+ return ((context -> mask_parsed & MASK_ALL ) == MASK_ALL ) && ( context -> version == STRUCT_VERSION ) ;
10695}
10796
108- #endif // HAVE_EIP7702
97+ #endif // HAVE_EIP7702
0 commit comments