Skip to content

Commit

Permalink
fix: I5-2
Browse files Browse the repository at this point in the history
  • Loading branch information
loicttn committed May 28, 2024
1 parent a5ad3d4 commit 339be93
Show file tree
Hide file tree
Showing 73 changed files with 78 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void handle_finalize(ethPluginFinalize_t *msg) {
{
lr_complete_queued_withdrawals_t *params =
&context->param_data.lr_complete_queued_withdrawals;
// function screen
msg->numScreens = 1;
// function screen + withdrawer
msg->numScreens = 2;
// one screen per strategy
msg->numScreens += params->strategies_count;
PRINTF("NUMBER OF STRATEGIES TO DISPLAY: %d\n", params->strategies_count);
Expand Down
11 changes: 9 additions & 2 deletions src/kiln_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef enum {
#define LR_STRATEGIES_COUNT 11
#define UNKNOWN_LR_ERC20 15 // must be > LR_STRATEGIES_COUNT < 16
#define UNKNOWN_LR_STRATEGY 15 // must be > LR_STRATEGIES_COUNT < 16
#define MAX_DISPLAYABLE_LR_STRATEGIES_COUNT (LR_STRATEGIES_COUNT * 3)
#define MAX_DISPLAYABLE_LR_STRATEGIES_COUNT 32 // must be > LR_STRATEGIES_COUNT
#define ERC20_DECIMALS 18
#define PARAM_OFFSET 32

Expand Down Expand Up @@ -214,6 +214,11 @@ typedef struct {
uint8_t strategies[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
} lr_queue_withdrawals_t;

// must be size of MAX_DISPLAYABLE_LR_STRATEGIES_COUNT
typedef struct {
uint32_t bits;
} bitfield;

typedef struct {
// -- utils
uint16_t parent_item_count;
Expand All @@ -232,6 +237,7 @@ typedef struct {
uint8_t withdrawals_offsets_checksum_value[CX_KECCAK_256_SIZE];

// -- display
uint8_t withdrawer[ADDRESS_LENGTH];
// list of strategies indexes **INCREMENTED BY 1** to display in the UI
// UNKNOWN_LR_STRATEGY is used to display the "unknown" strategy
// assumptions:
Expand All @@ -241,7 +247,8 @@ typedef struct {
// (ii) in practice there should not be more than (2 ** 4) - 2 known strategies
// (iii) the first 4 bytes are the withdrawal index, the next 4 bytes are the strategy index
uint8_t strategies[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
bool is_redelegated[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
// follows the strategies array indexes
bitfield is_redelegated;
} lr_complete_queued_withdrawals_t;

// ****************************************************************************
Expand Down
39 changes: 37 additions & 2 deletions src/provide_parameter/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@

#include "provide_parameter.h"

/**
* @brief Set a bit in a bitfield
*
* @param bf: bitfield to update
* @param index: index of the bit to update
* @param value: value to set the bit to (0 or 1)
*
*/
void set_bit(bitfield *bf, int index, bool value) {
if (index < 0 || index >= MAX_DISPLAYABLE_LR_STRATEGIES_COUNT) {
return; // Index out of range
}
if (value) {
bf->bits |= (1U << index);
} else {
bf->bits &= ~(1U << index);
}
}

/**
* @brief Compare two addresses
*
Expand Down Expand Up @@ -613,9 +632,25 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
case LRCQW_WITHDRAWALS__ITEM__DELEGATED_TO:
context->next_param = LRCQW_WITHDRAWALS__ITEM__WITHDRAWER;
break;
case LRCQW_WITHDRAWALS__ITEM__WITHDRAWER:
case LRCQW_WITHDRAWALS__ITEM__WITHDRAWER: {
{
uint8_t buffer[ADDRESS_LENGTH];
copy_address(buffer, msg->parameter, sizeof(buffer));
// we only support same withdrawer accross all the withdrawals
if (params->withdrawer[0] == '\0') {
memcpy(params->withdrawer, buffer, sizeof(params->withdrawer));
} else if (strcmp((const char *) params->withdrawer, (const char *) buffer) != 0) {
PRINTF("Unexpected withdrawer address, %s != expected %s\n",
msg->parameter,
params->withdrawer);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
}

context->next_param = LRCQW_WITHDRAWALS__ITEM__NONCE;
break;
}
case LRCQW_WITHDRAWALS__ITEM__NONCE:
context->next_param = LRCQW_WITHDRAWALS__ITEM__START_BLOCK;
break;
Expand Down Expand Up @@ -982,7 +1017,7 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
uint16_t value;
U2BE_from_parameter(msg->parameter, &value);
// if false, token is redelegated
params->is_redelegated[index] = value == 0;
set_bit(&(params->is_redelegated), index, value == 0);
PRINTF("RECEIVE AS TOKENS #%d: %d\n", index, value);
}
params->current_item_count -= 1;
Expand Down
29 changes: 26 additions & 3 deletions src/query_contract_ui/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@

#include "query_contract_ui.h"

/**
* @brief Get the bit at the given index
*
* @param bf: Bitfield to get the bit from
* @param index: Index of the bit to get
*
* @return int: The bit at the given index
*/
int get_bit(const bitfield *bf, int index) {
if (index < 0 || index >= MAX_DISPLAYABLE_LR_STRATEGIES_COUNT) {
return -1; // Index out of range
}
return (bf->bits & (1U << index)) != 0;
}

/**
* @brief UI for depositing into an EigenLayer strategy
*
Expand Down Expand Up @@ -131,16 +146,24 @@ bool complete_queued_withdrawals_ui(ethQueryContractUI_t *msg, context_t *contex
ret = true;
break;

case 1:
strlcpy(msg->title, "Withdrawer", msg->titleLength);
char address_buffer[ADDRESS_STR_LEN];
getEthDisplayableAddress(params->withdrawer, address_buffer, sizeof(address_buffer), 0);
strlcpy(msg->msg, address_buffer, msg->msgLength);
ret = true;
break;

default: {
{
// removing the first screen to current screen index
// removing the 2 known screens to current screen index
// to get the index of the withdrawal
uint8_t strategy_index = msg->screenIndex - 1;
uint8_t strategy_index = msg->screenIndex - 2;

if (strategy_index < params->strategies_count) {
uint8_t withdrawal_index = (params->strategies[strategy_index] >> 4) & 0x0F;

if (params->is_redelegated[withdrawal_index]) {
if (get_bit(&params->is_redelegated, withdrawal_index) == 1) {
strlcpy(msg->title, "Redelegate", msg->titleLength);
} else {
strlcpy(msg->title, "Withdraw", msg->titleLength);
Expand Down
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_1/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_1/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_1/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_1/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00012.png
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00013.png
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_8/00014.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00003.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00004.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00005.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00006.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00007.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00008.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals/00009.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_1/00003.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_1/00004.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_1/00005.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_1/00006.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00003.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00004.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00005.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00006.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00007.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00008.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00009.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00010.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00011.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00012.png
Binary file modified tests/snapshots/nanox_lrCompleteQueuedWithdrawals_8/00013.png
8 changes: 4 additions & 4 deletions tests/src/lrCompleteQueuedWithdrawals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 9 : 8;
const right_clicks = model.letter === 'S' ? 12 : 9;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -168,7 +168,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 6 : 5;
const right_clicks = model.letter === 'S' ? 9 : 6;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -244,7 +244,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 6 : 5;
const right_clicks = model.letter === 'S' ? 9 : 6;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -363,7 +363,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 13 : 12;
const right_clicks = model.letter === 'S' ? 16 : 13;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down

0 comments on commit 339be93

Please sign in to comment.