Skip to content

Commit

Permalink
better bip32 path compare
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed May 5, 2024
1 parent 3e405dc commit b85f9e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/commands/signtx/operations/stx_op_p2pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ bool stx_operation_p2pk_should_show_output_confirm_screen(
// if change index is < 20 then we approve it automatically
if (ctx->transaction.ui.output.bip32_path.path[4] < 20) return false;
// Check was it already approved then approve automatically
if (memcmp(&ctx->transaction.ui.output.bip32_path,
&ctx->transaction.last_approved_change,
sizeof(sign_transaction_bip32_path_t)) == 0)
if (stx_bip32_path_is_equal(&ctx->transaction.ui.output.bip32_path,
&ctx->transaction.last_approved_change))
return false;
}
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/commands/signtx/stx_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ static inline sign_transaction_output_info_type_e stx_output_info_type(

static inline bool stx_output_info_is_finished(const sign_transaction_output_info_ctx_t* ctx) {
return STX_OUTPUT_INFO_IS_TREE_SET(ctx) && STX_OUTPUT_INFO_IS_BOX_FINISHED(ctx);
}

static inline bool stx_bip32_path_is_equal(const sign_transaction_bip32_path_t* p1,
const sign_transaction_bip32_path_t* p2) {
return bip32_path_is_equal(p1->path, p1->len, p2->path, p2->len);
}
8 changes: 8 additions & 0 deletions src/common/bip32_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ bool bip32_path_validate(const uint32_t *bip32_path,
uint32_t type,
uint32_t coin,
bip32_path_validation_type_e vtype);

static inline bool bip32_path_is_equal(const uint32_t *bip32_path_1,
uint8_t bip32_path_1_len,
const uint32_t *bip32_path_2,
uint8_t bip32_path_2_len) {
return bip32_path_1_len == bip32_path_2_len &&
memcmp(bip32_path_1, bip32_path_2, bip32_path_1_len) == 0;
}

0 comments on commit b85f9e1

Please sign in to comment.