@@ -174,16 +174,37 @@ static bool field_hash_domain_special_fields(const void *const field_ptr,
174
174
uint8_t data_length ) {
175
175
const char * key ;
176
176
uint8_t keylen ;
177
+ const char * ethermint_vc = "cosmos" ;
177
178
178
179
key = get_struct_field_keyname (field_ptr , & keylen );
179
180
// copy contract address into context
180
181
if (strncmp (key , "verifyingContract" , keylen ) == 0 ) {
181
- if (data_length != sizeof (eip712_context -> contract_addr )) {
182
- apdu_response_code = APDU_RESPONSE_INVALID_DATA ;
183
- PRINTF ("Unexpected verifyingContract length!\n" );
184
- return false;
182
+ switch (struct_field_type (field_ptr )) {
183
+ case TYPE_SOL_ADDRESS :
184
+ if (data_length > sizeof (eip712_context -> contract_addr )) {
185
+ apdu_response_code = APDU_RESPONSE_INVALID_DATA ;
186
+ PRINTF ("Error: verifyingContract too big\n" );
187
+ return false;
188
+ }
189
+ break ;
190
+ case TYPE_SOL_STRING :
191
+ // hardcoded check for their non-standard implementation
192
+ if ((data_length != strlen (ethermint_vc )) ||
193
+ (strncmp ((char * ) data , ethermint_vc , data_length ) != 0 )) {
194
+ apdu_response_code = APDU_RESPONSE_INVALID_DATA ;
195
+ PRINTF ("Error: non standard verifyingContract\n" );
196
+ return false;
197
+ }
198
+ break ;
199
+ default :
200
+ apdu_response_code = APDU_RESPONSE_INVALID_DATA ;
201
+ PRINTF ("Error: unexpected type for verifyingContract (%u)!\n" ,
202
+ struct_field_type (field_ptr ));
203
+ return false;
185
204
}
186
205
memcpy (eip712_context -> contract_addr , data , data_length );
206
+ explicit_bzero (& eip712_context -> contract_addr [data_length ],
207
+ sizeof (eip712_context -> contract_addr ) - data_length );
187
208
} else if (strncmp (key , "chainId" , keylen ) == 0 ) {
188
209
eip712_context -> chain_id = u64_from_BE (data , data_length );
189
210
}
0 commit comments