Skip to content

Commit

Permalink
Add warning contract data
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Oct 13, 2023
1 parent 9b7e484 commit f450ec0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ bool is_opsender(const uint8_t script[], size_t script_len) {
return is_opcontract((uint8_t *) script, script_len, OP_SENDER);
}

bool is_contract(const uint8_t script[], size_t script_len) {
return is_opcreate(script, script_len) || is_opcall(script, script_len);
}

bool get_script_sender_address(uint8_t *buffer, size_t size, uint8_t *script) {
uint8_t *pkh = 0;
unsigned int pkhSize = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/common/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ bool is_opcall(const uint8_t script[], size_t script_len);

bool is_opsender(const uint8_t script[], size_t script_len);

bool is_contract(const uint8_t script[], size_t script_len);

/**
* Returns the size in bytes of the minimal push opcode for <n>, where n a uint32_t.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/handler/sign_psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ static bool read_outputs(dispatcher_context_t *dc,
output_info_t output;
memset(&output, 0, sizeof(output));
bool isOpSender = false;
bool isContract = false;

output_keys_callback_data_t callback_data = {.output = &output,
.placeholder_info = placeholder_info};
Expand Down Expand Up @@ -1438,6 +1439,14 @@ static bool read_outputs(dispatcher_context_t *dc,
// external output, user needs to validate
++external_outputs_count;

// check if output contract data is allowed
isContract = is_contract(output.in_out.scriptPubKey, output.in_out.scriptPubKey_len);
if(isContract && !N_storage.dataAllowed) {
ui_warn_contract_data(dc);
SEND_SW(dc, SW_SIGNATURE_FAIL);
return false;
}

if (!dry_run &&
!display_output(dc, st, cur_output_index, external_outputs_count, &output))
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/ui/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ bool ui_warn_nondefault_sighash(dispatcher_context_t *context) {
return io_ui_process(context, true);
}

bool ui_warn_contract_data(dispatcher_context_t *context) {
ui_warning_contract_data();
return io_ui_process(context, true);
}

bool ui_transaction_prompt(dispatcher_context_t *context,
const int external_outputs_total_count,
const bool sign_sender) {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ bool ui_warn_unverified_segwit_inputs(dispatcher_context_t *context);

bool ui_warn_nondefault_sighash(dispatcher_context_t *context);

bool ui_warn_contract_data(dispatcher_context_t *context);

bool ui_validate_output(dispatcher_context_t *context,
int index,
int total_count,
Expand Down Expand Up @@ -179,6 +181,8 @@ bool ui_post_processing_confirm_transaction(dispatcher_context_t *context, bool

bool ui_post_processing_confirm_message(dispatcher_context_t *context, bool success);

void ui_warning_contract_data(void);

#ifdef HAVE_NBGL
bool ui_transaction_prompt(dispatcher_context_t *context,
const int external_outputs_total_count,
Expand Down
27 changes: 27 additions & 0 deletions src/ui/display_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,27 @@ UX_STEP_CB(ux_sign_message_accept_new,
set_ux_flow_response(true),
{&C_icon_validate_14, "Sign", "message"});

#ifdef TARGET_NANOS
UX_STEP_CB(
ux_warning_contract_data_step,
bnnn_paging,
set_ux_flow_response(false),
{
"Error",
"Blind signing must be enabled in Settings",
});
#else
UX_STEP_CB(
ux_warning_contract_data_step,
pnn,
set_ux_flow_response(false),
{
&C_icon_crossmark,
"Blind signing must be",
"enabled in Settings",
});
#endif

// FLOW to display BIP32 path and a message hash to sign:
// #1 screen: certificate icon + "Sign message"
// #2 screen: display BIP32 Path
Expand Down Expand Up @@ -424,6 +445,8 @@ UX_FLOW(ux_sign_sender_transaction_flow,
&ux_sign_sender_step,
&ux_display_reject_step);

UX_FLOW(ux_warning_contract_data_flow, &ux_warning_contract_data_step);

void ui_display_pubkey_flow(void) {
ux_flow_init(0, ux_display_pubkey_flow, NULL);
}
Expand Down Expand Up @@ -492,4 +515,8 @@ void ui_accept_transaction_flow(bool is_self_transfer, bool sign_sender) {
}
}

void ui_warning_contract_data(void) {
ux_flow_init(0, ux_warning_contract_data_flow, NULL);
}

#endif // HAVE_BAGL
1 change: 1 addition & 0 deletions src/ui/menu_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ static void toggle_setting(volatile bool* setting, const ux_flow_step_t* ui_step
static void switch_settings_blind_signing(void) {
toggle_setting(&N_storage.dataAllowed, &ux_settings_flow_blind_signing_step);
}

#endif // HAVE_BAGL

0 comments on commit f450ec0

Please sign in to comment.