Skip to content

Commit

Permalink
Merge pull request #13 from blooo-io/feat/LDG-129-implement-mintsign-…
Browse files Browse the repository at this point in the history
…method-and-tests

Feat/ldg 129 implement mintsign method and tests
  • Loading branch information
Z4karia authored Mar 1, 2023
2 parents 5d398ca + 04dfc8c commit a8a63d6
Show file tree
Hide file tree
Showing 41 changed files with 2,036 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --path "44'/1'
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 1
APPVERSION_N = 2
APPVERSION_N = 3
APPVERSION_P = 0
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ Need more information about the interface, the architecture, or general stuff ab

Smart contracts covered by this plugin are:

| Network | Version | Smart Contract |
| --- | --- | --- |
| Goerli | V0 | `0x6c304a1f99cecd3a9983001e943f3de00ed811d0`|
| Goerli | V0 | `0x9ea4571a739a1d644e17d34a86e7dee97609b256`|
| Network | Version | Smart Contract | Address |
| ---- | --- | ---- | --- |
| Goerli | V0 | MultiMintContractNFT | `0x6c304a1f99cecd3a9983001e943f3de00ed811d0` |
| Goerli | V0 | StableMultiMintERC721 | `0x9ea4571a739a1d644e17d34a86e7dee97609b256` |
| Goerli | V0 | MultiMint1155 | `0x12b180053db389b6200e6f646949e6ab7b385d40` |


On these smart contracts, the functions covered by this plugin are:

Expand All @@ -42,6 +44,7 @@ On these smart contracts, the functions covered by this plugin are:
|stableMint | 0x804b936f| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|mintSign | 0xf39247a9| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|mint (v2) | 0xa0712d68| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|mintSign (v2) | 0x657bb113| <table><tbody> <tr><td><code>uint256 tokenId</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> <tr><td><code>address pass</code></td></tr></tbody></table> |

## Build

Expand Down
19 changes: 13 additions & 6 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ static const uint8_t MINT_SIGN_SELECTOR[SELECTOR_SIZE] = {0xf3, 0x92, 0x47, 0xa9
// Selector: 0xa0712d68
static const uint8_t MINT_V2_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};

// Function: mintSign (v2)
// Selector: 0x657bb113
static const uint8_t MINT_SIGN_V2_SELECTOR[SELECTOR_SIZE] = {0x65, 0x7b, 0xb1, 0x13};

// Plugin uses 0x00000 as a dummy address to reprecent ETH.
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Array of all the different nft selectors.
const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {MINT_SELECTOR,
PRE_SALE_MINT_SELECTOR,
STABLE_MINT_SIGN_SELECTOR,
STABLE_MINT_SELECTOR,
MINT_SIGN_SELECTOR,
MINT_V2_SELECTOR};
const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {
MINT_SELECTOR,
PRE_SALE_MINT_SELECTOR,
STABLE_MINT_SIGN_SELECTOR,
STABLE_MINT_SELECTOR,
MINT_SIGN_SELECTOR,
MINT_V2_SELECTOR,
MINT_SIGN_V2_SELECTOR,
};
21 changes: 18 additions & 3 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@

void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;
msg->uiType = ETH_UI_TYPE_GENERIC;

// 2 additional screens are required to display the `token and `beneficiary` fields
msg->numScreens = 2;
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
case STABLE_MINT:
case MINT_SIGN:
case MINT_V2:
msg->numScreens = 2;
break;
case MINT_SIGN_V2:
msg->numScreens = 4;
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
msg->result = ETH_PLUGIN_RESULT_OK;
}
3 changes: 3 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void handle_init_contract(void *parameters) {
case MINT_V2:
context->next_param = AMOUNT;
break;
case MINT_SIGN_V2:
context->next_param = OFFSET;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
52 changes: 51 additions & 1 deletion src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ void handle_amount(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->amount, msg->parameter, sizeof(context->amount));
}

void handle_token_id(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->token_id, msg->parameter, sizeof(context->token_id));
}

void handle_address(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_address(context->address, msg->parameter, sizeof(context->address));
}

void handle_mint(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case AMOUNT: // tokenA
Expand All @@ -19,6 +27,44 @@ void handle_mint(ethPluginProvideParameter_t *msg, context_t *context) {
}
}

void handle_mint_sign_v2(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case OFFSET:
// Offset to the args tuple
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->offset));
context->next_param = SKIP;
break;
case SKIP:
// Skip the nb of objects in args tuple
// Already skipped 1 by going through this case
context->next_param = TOKEN_ID;
break;
case TOKEN_ID:
handle_token_id(msg, context);
context->next_param = AMOUNT;
break;
case AMOUNT:
handle_amount(msg, context);
context->next_param = SKIP_2;
break;
case SKIP_2:
// Skip the tokenGateId
// Already skipped 1 by going through this case
context->next_param = ADDRESS;
break;
case ADDRESS:
handle_address(msg, context);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

void handle_provide_parameter(void *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;
Expand All @@ -29,7 +75,8 @@ void handle_provide_parameter(void *parameters) {
// Skip this step, and don't forget to decrease skipping counter.
context->skip--;
} else {
if ((context->offset) && msg->parameterOffset != context->checkpoint + context->offset) {
if ((context->offset) &&
msg->parameterOffset != context->checkpoint + context->offset + SELECTOR_SIZE) {
PRINTF("offset: %d, checkpoint: %d, parameterOffset: %d\n",
context->offset,
context->checkpoint,
Expand All @@ -46,6 +93,9 @@ void handle_provide_parameter(void *parameters) {
case MINT_V2:
handle_mint(msg, context);
break;
case MINT_SIGN_V2:
handle_mint_sign_v2(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ void handle_query_contract_id(void *parameters) {
case MINT_V2:
strlcpy(msg->version, "Mint", msg->versionLength);
break;
case MINT_SIGN_V2:
strlcpy(msg->version, "Mint Sign", msg->versionLength);
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
100 changes: 87 additions & 13 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,58 @@ static void set_amount_ui(ethQueryContractUI_t *msg, context_t *context) {
amountToString(context->amount, sizeof(context->amount), 0, "", msg->msg, msg->msgLength);
}

static void set_token_id_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Token ID", msg->titleLength);

amountToString(context->token_id, sizeof(context->token_id), 0, "", msg->msg, msg->msgLength);
}

static void set_address_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "Address", msg->titleLength);
msg->msg[0] = '0';
msg->msg[1] = 'x';
getEthAddressStringFromBinary((uint8_t *) context->address,
msg->msg + 2,
msg->pluginSharedRW->sha3,
0);
}

// Helper function that returns the enum corresponding to the screen that should be displayed.
static screens_t get_screen(const ethQueryContractUI_t *msg,
const context_t *context __attribute__((unused))) {
uint8_t index = msg->screenIndex;
switch (index) {
case 0:
return AMOUNT_SCREEN;
case 1:
return PAYABLE_AMOUNT_SCREEN;
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
case STABLE_MINT:
case MINT_SIGN:
case MINT_V2:
switch (index) {
case 0:
return AMOUNT_SCREEN;
case 1:
return PAYABLE_AMOUNT_SCREEN;
default:
return ERROR;
}
break;
case MINT_SIGN_V2:
switch (index) {
case 0:
return TOKEN_ID_SCREEN;
case 1:
return AMOUNT_SCREEN;
case 2:
return PAYABLE_AMOUNT_SCREEN;
case 3:
return ADDRESS_SCREEN;
default:
return ERROR;
}
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
return ERROR;
}
}
Expand All @@ -46,17 +88,49 @@ void handle_query_contract_ui(void *parameters) {
msg->result = ETH_PLUGIN_RESULT_OK;

screens_t screen = get_screen(msg, context);

switch (screen) {
case AMOUNT_SCREEN:
set_amount_ui(msg, context);
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
case STABLE_MINT:
case MINT_SIGN:
case MINT_V2:
switch (screen) {
case AMOUNT_SCREEN:
set_amount_ui(msg, context);
break;
case PAYABLE_AMOUNT_SCREEN:
set_payable_amount_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
break;
case PAYABLE_AMOUNT_SCREEN:
set_payable_amount_ui(msg, context);
case MINT_SIGN_V2:
switch (screen) {
case TOKEN_ID_SCREEN:
set_token_id_ui(msg, context);
break;
case AMOUNT_SCREEN:
set_amount_ui(msg, context);
break;
case PAYABLE_AMOUNT_SCREEN:
set_payable_amount_ui(msg, context);
break;
case ADDRESS_SCREEN:
set_address_ui(msg, context);
break;
default:
PRINTF("Received an invalid screenIndex\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
break;
default:
PRINTF("Received an invalid screenIndex\n");
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
}
}
21 changes: 19 additions & 2 deletions src/ledger_nft_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "eth_internals.h"
#include "eth_plugin_interface.h"

#define NUM_SELECTORS 6
#define NUM_SELECTORS 7
#define PLUGIN_NAME "Ledger NFT"
#define TOKEN_FOUND 1 << 1
#define SELECTOR_SIZE 4
Expand All @@ -15,18 +15,33 @@
extern const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH];

#define ADDRESS_IS_NETWORK_TOKEN(_addr) (!memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH))
typedef enum { MINT, PRE_SALE_MINT, STABLE_MINT_SIGN, STABLE_MINT, MINT_SIGN, MINT_V2 } selector_t;
typedef enum {
MINT,
PRE_SALE_MINT,
STABLE_MINT_SIGN,
STABLE_MINT,
MINT_SIGN,
MINT_V2,
MINT_SIGN_V2,
} selector_t;

// Enumeration used to parse the smart contract data.
typedef enum {
PAYABLE_AMOUNT,
AMOUNT,
OFFSET,
TOKEN_ID,
ADDRESS,
SKIP,
SKIP_2,
NONE,
} parameter;

typedef enum {
AMOUNT_SCREEN,
PAYABLE_AMOUNT_SCREEN,
TOKEN_ID_SCREEN,
ADDRESS_SCREEN,
ERROR,
} screens_t;

Expand All @@ -36,7 +51,9 @@ extern const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS];
typedef struct context_t {
// For display.
uint8_t amount[PARAMETER_LENGTH];
uint8_t token_id[PARAMETER_LENGTH];
uint8_t payable_amount[PARAMETER_LENGTH];
uint8_t address[ADDRESS_LENGTH];
uint8_t contract_address_sent[ADDRESS_LENGTH];
char ticker_sent[MAX_TICKER_LEN];

Expand Down
Loading

0 comments on commit a8a63d6

Please sign in to comment.