Skip to content

Commit

Permalink
fix(lr): invalid state transitions + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loicttn committed Apr 28, 2024
1 parent 8c0d7bb commit 43d3d0e
Show file tree
Hide file tree
Showing 97 changed files with 48 additions and 112 deletions.
12 changes: 11 additions & 1 deletion src/kiln_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ typedef struct {
// list of strategies indexes **INCREMENTED BY 1** to display in the UI
// 0 is reserved for end of array
// UNKNOW_LR_STRATEGY is used to display the "unknown" strategy
// assumptions:
// (i) in practice, we should not encounter more than
// LR_STRATEGIES_COUNT +~ a few potential unsupported
// strategies in the plugin. So * 3 should be a good enough buffer.
Expand All @@ -201,19 +202,28 @@ typedef struct {
// -- utils
uint16_t parent_item_count;
uint16_t current_item_count;
// -- total values
uint16_t relegations_count;
uint8_t withdrawals_count;
uint16_t strategies_count;

// -- display
uint16_t strategies_count;
char withdrawer[ADDRESS_STR_LEN];
// list of strategies indexes **INCREMENTED BY 1** to display in the UI
// 0 is reserved for end of array
// UNKNOW_LR_STRATEGY is used to display the "unknown" strategy
// assumptions:
// (i) in practice, we should not encounter more than
// LR_STRATEGIES_COUNT +~ a few potential unsupported
// strategies in the plugin. So * 3 should be a good enough buffer.
// (ii) in practice there should not be more than (2 ** 8) - 2 known strategies
uint8_t strategies[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
// follows the indexes of the strategies array in this structure.
// value is the withdrawal number
// assumptions:
// (i) in practice, we should not encounter more than
// 255 strategies in queued withdrawal calls
uint8_t withdrawals[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
// follows the indexes of the strategies array in this structure
bool is_redelegated[MAX_DISPLAYABLE_LR_STRATEGIES_COUNT];
} lr_complete_queued_withdrawals_t;
Expand Down
22 changes: 16 additions & 6 deletions src/provide_parameter/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool compare_addresses(const char a[ADDRESS_STR_LEN], const char b[ADDRESS_STR_L
*
* @returns index of the erc20 in the context or UNKNOW_LR_STRATEGY if not found
*/
int find_lr_known_erc20(const char address[ADDRESS_STR_LEN]) {
uint8_t find_lr_known_erc20(const char address[ADDRESS_STR_LEN]) {
for (size_t i = 0; i < LR_STRATEGIES_COUNT; i++) {
if (compare_addresses(address, lr_erc20_addresses[i])) {
return i;
Expand All @@ -58,7 +58,7 @@ int find_lr_known_erc20(const char address[ADDRESS_STR_LEN]) {
*
* @returns index of the strategy in the context or UNKNOW_LR_STRATEGY if not found
*/
int find_lr_known_strategy(const char address[ADDRESS_STR_LEN]) {
uint8_t find_lr_known_strategy(const char address[ADDRESS_STR_LEN]) {
for (size_t i = 0; i < LR_STRATEGIES_COUNT; i++) {
if (compare_addresses(address, lr_strategy_addresses[i])) {
return i;
Expand Down Expand Up @@ -211,7 +211,7 @@ void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *co
char address_buffer[ADDRESS_STR_LEN];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);

int strategy_index = find_lr_known_strategy(address_buffer);
uint8_t strategy_index = find_lr_known_strategy(address_buffer);
params->strategies[params->strategies_count] =
(strategy_index != UNKNOW_LR_STRATEGY) ? strategy_index + 1
: UNKNOW_LR_STRATEGY;
Expand Down Expand Up @@ -442,13 +442,16 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
char address_buffer[ADDRESS_STR_LEN];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);

int strategy_index = find_lr_known_strategy(address_buffer);
uint8_t strategy_index = find_lr_known_strategy(address_buffer);
if (params->strategies_count < MAX_DISPLAYABLE_LR_STRATEGIES_COUNT) {
params->withdrawals[params->strategies_count] = params->withdrawals_count;

params->strategies[params->strategies_count] =
(strategy_index != UNKNOW_LR_STRATEGY) ? strategy_index + 1
: UNKNOW_LR_STRATEGY;

PRINTF("STRATEGY #: %d STRATEGY: %d\n",
PRINTF("WITHDRAWAL #: %d STRATEGY #: %d STRATEGY: %d\n",
params->parent_item_count,
params->strategies_count,
strategy_index);
}
Expand All @@ -470,6 +473,8 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con

if (params->current_item_count == 0 && params->parent_item_count > 0) {
// shares array is empty AND we have other queuedWithdrawals to parse
params->parent_item_count -= 1;
params->withdrawals_count += 1;
context->next_param = LRCQW_WITHDRAWALS__ITEM__STAKER;
} else {
context->next_param = LRCQW_WITHDRAWALS__ITEM__SHARES__ITEMS;
Expand All @@ -483,6 +488,7 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
if (params->current_item_count == 0) {
// we arrive at the end of the Withdrawal struct
params->parent_item_count -= 1;
params->withdrawals_count += 1;
if (params->parent_item_count == 0) {
// we arrive at the end of the Withdrawals array
context->next_param = LRCQW_TOKENS_LENGTH;
Expand Down Expand Up @@ -537,6 +543,7 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
params->current_item_count -= 1;
if (params->current_item_count == 0) {
// we arrive at the end of the tokens array
params->parent_item_count -= 1;
if (params->parent_item_count == 0) {
// if we don't have other Withdrawals to parse
context->next_param = LRCQW_MIDDLEWARE_TIMES_INDEXES_LENGTH;
Expand Down Expand Up @@ -590,8 +597,11 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
{
uint16_t index = params->relegations_count - params->current_item_count;

uint16_t value;
U2BE_from_parameter(msg->parameter, &value);
// if false, token is redelegated
params->is_redelegated[index] = msg->parameter[0] == 0;
params->is_redelegated[index] = value == 0;
PRINTF("RECEIVE AS TOKENS #%d: %d\n", index, value);
}
params->current_item_count -= 1;
if (params->current_item_count == 0) {
Expand Down
8 changes: 5 additions & 3 deletions src/query_contract_ui/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ bool complete_queued_withdrawals_ui(ethQueryContractUI_t *msg, context_t *contex
{
// removing the first screen to current screen index
// to get the index of the withdrawal
uint8_t withdrawal_index = msg->screenIndex - 2;
uint8_t strategy_index = msg->screenIndex - 2;
uint8_t withdrawal_index = params->withdrawals[strategy_index];
PRINTF("strat: %d || withdrawal_index: %d\n", strategy_index, withdrawal_index);

if (withdrawal_index < params->strategies_count) {
if (strategy_index < params->strategies_count) {
if (params->is_redelegated[withdrawal_index]) {
strlcpy(msg->title, "Redelegate", msg->titleLength);
} else {
strlcpy(msg->title, "Withdraw", msg->titleLength);
}
uint8_t strategy = params->strategies[withdrawal_index];

uint8_t strategy = params->strategies[strategy_index];
if (strategy == UNKNOW_LR_STRATEGY || strategy - 1 >= LR_STRATEGIES_COUNT) {
strlcpy(msg->msg, "UNKNOWN", msg->msgLength);
} else {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
Binary file modified tests/snapshots/nanos_lrCompleteQueuedWithdrawals_1/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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 removed tests/snapshots/nanos_lrQueueWithdrawal/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00005.png
Diff not rendered.
Binary file removed tests/snapshots/nanos_lrQueueWithdrawal/00006.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
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_1/00007.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed tests/snapshots/nanox_lrQueueWithdrawal/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanox_lrQueueWithdrawal/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanox_lrQueueWithdrawal/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanox_lrQueueWithdrawal/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanox_lrQueueWithdrawal/00004.png
Diff not rendered.
88 changes: 0 additions & 88 deletions tests/src/lrCompleteQueuedWithdrawal.test.js

This file was deleted.

16 changes: 8 additions & 8 deletions tests/src/lrCompleteQueuedWithdrawals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 11 : 9;
const right_clicks = model.letter === 'S' ? 12 : 9;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -144,7 +144,7 @@ nano_models.forEach(function (model) {
],
],
[0],
[true]
[false]
);

let unsignedTx = genericTx;
Expand All @@ -164,7 +164,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 11 : 9;
const right_clicks = model.letter === 'S' ? 9 : 6;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -220,7 +220,7 @@ nano_models.forEach(function (model) {
],
],
[0],
[false]
[true]
);

let unsignedTx = genericTx;
Expand All @@ -240,7 +240,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 11 : 9;
const right_clicks = model.letter === 'S' ? 9 : 6;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand Down Expand Up @@ -339,7 +339,7 @@ nano_models.forEach(function (model) {
],
],
[0, 0, 1],
[false, true, false]
[false, true, true, false, true, true, true, true]
);

let unsignedTx = genericTx;
Expand All @@ -359,12 +359,12 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 17 : 15;
const right_clicks = model.letter === 'S' ? 16 : 13;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
'.',
model.name + '_lrCompleteQueuedWithdrawals_4',
model.name + '_lrCompleteQueuedWithdrawals_8',
[right_clicks, 0]
);
await tx;
Expand Down
14 changes: 8 additions & 6 deletions tests/src/lrQueueWithdrawals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 8 : 6;
const right_clicks = model.letter === 'S' ? 9 : 7;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand All @@ -54,7 +54,7 @@ nano_models.forEach(function (model) {
);
await tx;
}),
30000
10000
);

test(
Expand Down Expand Up @@ -100,7 +100,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 12 : 10;
const right_clicks = model.letter === 'S' ? 13 : 11;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand All @@ -109,7 +109,8 @@ nano_models.forEach(function (model) {
[right_clicks, 0]
);
await tx;
})
}),
10000
);

test(
Expand Down Expand Up @@ -155,7 +156,7 @@ nano_models.forEach(function (model) {
}
);
const tx = eth.signTransaction("44'/60'/0'/0", serializedTx, resolution);
const right_clicks = model.letter === 'S' ? 12 : 10;
const right_clicks = model.letter === 'S' ? 13 : 11;

await waitForAppScreen(sim);
await sim.navigateAndCompareSnapshots(
Expand All @@ -164,6 +165,7 @@ nano_models.forEach(function (model) {
[right_clicks, 0]
);
await tx;
})
}),
10000
);
});

0 comments on commit 43d3d0e

Please sign in to comment.