-
Notifications
You must be signed in to change notification settings - Fork 1
feat: signal bits and authority outputs #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
13bc742
b99892e
254771d
1c16ec7
bf2e575
296e146
a7ce0d7
d9e8adc
6776d97
9256cb2
7b0639d
7de584f
7068697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # Compilation of Ledger's app | ||
| src/glyphs.c | ||
| src/glyphs.h | ||
| build/ | ||
| bin/ | ||
| debug/ | ||
| dep/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,18 @@ | |
| #include "../common/buffer.h" | ||
| #include "types.h" | ||
|
|
||
| bool is_authority_output(uint8_t token_data) { | ||
| return (token_data & TOKEN_DATA_AUTHORITY_MASK) > 0; | ||
| } | ||
|
|
||
| bool is_mint_authority(uint8_t token_data, uint64_t value) { | ||
| return is_authority_output(token_data) && value == MINT_AUTHORITY_MASK; | ||
| } | ||
|
|
||
| bool is_melt_authority(uint8_t token_data, uint64_t value) { | ||
| return is_authority_output(token_data) && value == MELT_AUTHORITY_MASK; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here! |
||
| } | ||
|
|
||
| /** | ||
| * XXX: considering only P2PKH, without timelock | ||
| * Validates that a script has the format of P2PKH. Throws an exception if doesn't. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,12 +13,15 @@ | |
| #include "../hathor.h" | ||
| #include "../storage.h" | ||
| #include "../sw.h" | ||
| #include "../transaction/deserialize.h" | ||
| #include "action/validate.h" | ||
| #include "display.h" | ||
| #include "menu.h" | ||
|
|
||
| static action_validate_cb g_validate_callback; | ||
| static char g_amount[30]; | ||
| static char g_authority[30]; | ||
| static bool g_is_authority; | ||
| static char g_output_index[10]; | ||
| static char g_address[B58_ADDRESS_LEN]; | ||
| static char g_token_symbol[MAX_TOKEN_SYMBOL_LEN + 1]; | ||
|
|
@@ -60,6 +63,13 @@ UX_STEP_NOCB(ux_display_address_step, | |
| .title = "Address", | ||
| .text = g_address, | ||
| }); | ||
| // Step with title/text for authority | ||
| UX_STEP_NOCB(ux_display_authority_step, | ||
| bnnn_paging, | ||
| { | ||
| .title = "Authority", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have room for "Token Authority"? Or is it too big? |
||
| .text = g_authority, | ||
| }); | ||
| // Step with title/text for amount | ||
| UX_STEP_NOCB(ux_display_amount_step, | ||
| bnnn_paging, | ||
|
|
@@ -200,6 +210,15 @@ int ui_display_tx_confirm() { | |
| return 0; | ||
| } | ||
|
|
||
| // SIGN_TX: confirm authority output | ||
| UX_FLOW(ux_display_tx_authority_output_flow, | ||
| &ux_display_review_output_step, // Output <curr>/<total> | ||
| &ux_display_address_step, // address | ||
| &ux_display_authority_step, // Mint authority or Melt authority | ||
| &ux_display_approve_step, // accept => decode next component and redisplay if needed | ||
| &ux_display_reject_step, // reject => return error | ||
| FLOW_LOOP); | ||
|
|
||
| // SIGN_TX: confirm output | ||
| UX_FLOW(ux_display_tx_output_flow, | ||
| &ux_display_review_output_step, // Output <curr>/<total> | ||
|
|
@@ -276,6 +295,8 @@ bool skip_change_outputs() { | |
|
|
||
| /** | ||
| * Prepare the UX screen values of the current output to confirm | ||
| * Returns true if we have no more outputs on buffer to show. | ||
| * Returns false if the next output is ready to be shown to the user for confirmation. | ||
| */ | ||
| bool prepare_display_output() { | ||
| // Check we have confirmed all outputs before attempting to display | ||
|
|
@@ -314,8 +335,11 @@ bool prepare_display_output() { | |
| base58_encode(address, ADDRESS_LEN, b58address, B58_ADDRESS_LEN); | ||
| memmove(g_address, b58address, B58_ADDRESS_LEN); | ||
|
|
||
| // set g_ammount (HTR value) | ||
| // Clean amount and authority | ||
| memset(g_amount, 0, sizeof(g_amount)); | ||
| memset(g_authority, 0, sizeof(g_authority)); | ||
|
|
||
| // Get token symbol | ||
| int8_t token_index = output.token_data & TOKEN_DATA_INDEX_MASK; | ||
| char symbol[MAX_TOKEN_SYMBOL_LEN + 1]; | ||
| uint8_t symbol_len; | ||
|
|
@@ -330,9 +354,34 @@ bool prepare_display_output() { | |
| strlcpy(symbol, token->symbol, MAX_TOKEN_SYMBOL_LEN + 1); | ||
| symbol_len = strlen(token->symbol); | ||
| } | ||
| strlcpy(g_amount, symbol, MAX_TOKEN_SYMBOL_LEN + 1); | ||
| g_amount[symbol_len] = ' '; | ||
| format_value(output.value, g_amount + symbol_len + 1); | ||
|
|
||
| if (is_authority_output(output.token_data)) { | ||
| g_is_authority = true; | ||
| // set g_authority | ||
| strlcpy(g_authority, symbol, MAX_TOKEN_SYMBOL_LEN + 1); | ||
| g_authority[symbol_len] = ' '; | ||
| if (is_mint_authority(output.token_data, output.value)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't you showing what action is being performed? I mean, you can have a mint authority with the following actions: (i) minting, (ii) destroying, and (iii) delegating. |
||
| strlcpy(g_authority + symbol_len + 1, "Mint", 30); | ||
| } else { | ||
| if (is_melt_authority(output.token_data, output.value)) { | ||
| strlcpy(g_authority + symbol_len + 1, "Melt", 30); | ||
| } else { | ||
| // This authority is unknown, so we treat it as invalid | ||
| PRINTF("[-] Unknown authority received in value %d\n", output.value); | ||
| explicit_bzero(&G_context, sizeof(G_context)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we clear globals here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is clearing the global context. |
||
| io_send_sw(SW_INVALID_TX); | ||
| ui_menu_main(); | ||
r4mmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
r4mmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } else { | ||
| g_is_authority = false; | ||
| // set g_ammount (HTR value) | ||
| strlcpy(g_amount, symbol, MAX_TOKEN_SYMBOL_LEN + 1); | ||
| g_amount[symbol_len] = ' '; | ||
| format_value(output.value, g_amount + symbol_len + 1); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -356,7 +405,11 @@ int ui_display_tx_outputs() { | |
| // skip changes, return ok if there is no more on buffer | ||
| if (prepare_display_output()) return 0; | ||
| g_validate_callback = &ui_confirm_output; // show next until need more | ||
| ux_flow_init(0, ux_display_tx_output_flow, NULL); | ||
| if (g_is_authority) { | ||
| ux_flow_init(0, ux_display_tx_authority_output_flow, NULL); | ||
| } else { | ||
| ux_flow_init(0, ux_display_tx_output_flow, NULL); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
&& (value & MINT_AUTHORITY_MASK) > 0, shouldn't it?The same for melt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is the Mint+Melt case, where an output is authority for both mint and melt.
This edge case may be complicated for the user so I decided not to allow this case in the Ledger app.
Do you think we should allow this case as a special
Mint+Melt outputon the UI?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to limit this but I don't see as this complicated, we could show exactly as you wrote:
Mint + MeltorMint and Melt.If we decide to leave this out, we should just make clear in the design
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve reopened this thread to address the issue. I believe we need to correctly implement the logic in these methods, while managing the mint and melt permissions elsewhere. The current approach might be misleading and prone to errors during future updates.
Regarding the minting and melting capabilities, I found the previous discussion a bit confusing. It doesn’t seem possible to mint and melt the same token simultaneously. So, the real question is whether a token authority should have both capabilities. I believe they should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to put the reason the discussion was closed, this was meant to be discussed and implemented on another PR.
We can block this PR to solve this issue but this can easily be implemented later depending on the decision.