Skip to content
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

Fix/qs issues #10

Merged
merged 13 commits into from
Jan 30, 2025
5 changes: 5 additions & 0 deletions src/contracts.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ static const uint32_t KILN_LR_DELEGATE_TO_SELECTOR = 0xeea9064b;
// --- cast sig "undelegate(address)"
static const uint32_t KILN_LR_UNDELEGATE_SELECTOR = 0xda8be864;

const char ocv2_exit_queues[OCV2_MAX_EXIT_QUEUES][ADDRESS_STR_LEN] = {
"0x8d6Fd650500f82c7D978a440348e5a9b886943bF", // Kiln
"0x86358F7B33b599c484e0335B8Ee4f7f7f92d8b60" // Coinbase
};

const char lr_strategy_addresses[LR_STRATEGIES_COUNT][ADDRESS_STR_LEN] = {
"0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc", // cbETH
"0x93c4b944D05dfe6df7645A86cd2206016c51564D", // stETH
Expand Down
15 changes: 15 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
void handle_finalize(ethPluginFinalize_t *msg) {
context_t *context = (context_t *) msg->pluginContext;

// if any of the parsers did not complete, we return an error
if (context->next_param != V1_WFUNCS_UNEXPECTED_PARAMETER &&
context->next_param != V2_REQUEST_EXIT_UNEXPECTED_PARAMETER &&
context->next_param != V2_CLAIM_UNEXPECTED_PARAMETER &&
context->next_param != V2_MULTICLAIM_UNEXPECTED_PARAMETER &&
context->next_param != LR_UNDELEGATE_UNEXPECTED_PARAMETER &&
context->next_param != LR_DEPOSIT_INTO_STRATEGY_UNEXPECTED_PARAMETER &&
context->next_param != LR_QUEUE_WITHDRAWALS_UNEXPECTED_PARAMETER &&
context->next_param != LRCQW_UNEXPECTED_PARAMETER &&
context->next_param != LR_DELEGATE_TO_UNEXPECTED_PARAMETER) {
PRINTF("Parser did not complete: next_param is %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}

msg->uiType = ETH_UI_TYPE_GENERIC;

switch (context->selectorIndex) {
Expand Down
9 changes: 9 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,27 @@ void handle_init_contract(ethPluginInitContract_t *msg) {

switch (context->selectorIndex) {
case KILN_V1_DEPOSIT:
break;
case KILN_V1_WITHDRAW:
case KILN_V1_WITHDRAW_EL:
case KILN_V1_WITHDRAW_CL:
case KILN_V1_BATCH_WITHDRAW:
case KILN_V1_BATCH_WITHDRAW_EL:
case KILN_V1_BATCH_WITHDRAW_CL:
case KILN_V1_REQUEST_EXIT:
context->next_param = V1_WFUNCS_BYTES_OFFSET;
break;

case KILN_V2_STAKE:
break;
case KILN_V2_REQUEST_EXIT:
context->next_param = V2_REQUEST_EXIT_AMOUNT;
break;
case KILN_V2_MULTICLAIM:
context->next_param = V2_MULTICLAIM_EXIT_QUEUES_OFFSET;
break;
case KILN_V2_CLAIM:
context->next_param = V2_CLAIM_TICKET_IDS_OFFSET;
break;

case KILN_LR_DEPOSIT_INTO_STRATEGY:
Expand All @@ -79,6 +87,7 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
context->next_param = LR_DELEGATE_TO_OPERATOR;
break;
case KILN_LR_UNDELEGATE:
context->next_param = LR_UNDELEGATE_ADDRESS;
break;

default:
Expand Down
88 changes: 87 additions & 1 deletion src/kiln_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,70 @@ typedef enum {
#define MAX_DISPLAYABLE_LR_STRATEGIES_COUNT 32 // must be > LR_STRATEGIES_COUNT
#define ERC20_DECIMALS 18
#define PARAM_OFFSET 32
#define OCV2_MAX_EXIT_QUEUES 2

extern const char ocv2_exit_queues[OCV2_MAX_EXIT_QUEUES][ADDRESS_STR_LEN];
extern const char lr_strategy_addresses[LR_STRATEGIES_COUNT][ADDRESS_STR_LEN];
extern const char lr_erc20_addresses[LR_STRATEGIES_COUNT][ADDRESS_STR_LEN];
extern const char lr_tickers[LR_STRATEGIES_COUNT][MAX_TICKER_LEN];
extern const char lr_kiln_operator_address[ADDRESS_STR_LEN];

// ****************************************************************************

// Parameters and state machines for OCV1 parsing

typedef enum {
V1_WFUNCS_UNEXPECTED_PARAMETER = 0,
V1_WFUNCS_BYTES_OFFSET,
V1_WFUNCS_BYTES_LENGTH,
V1_WFUNCS_BYTES__ITEMS,
} v1_withdraw_funcs_parameters;

// Parameters and state machines for OCV2 parsing

typedef enum {
V2_REQUEST_EXIT_UNEXPECTED_PARAMETER = 0,
V2_REQUEST_EXIT_AMOUNT,
} v2_request_exit_parameters;

typedef enum {
V2_CLAIM_UNEXPECTED_PARAMETER = 0,
V2_CLAIM_TICKET_IDS_OFFSET,
V2_CLAIM_CASK_IDS_OFFSET,
V2_CLAIM_MAX_CLAIM_DEPTH,
V2_CLAIM_TICKET_IDS_LENGTH,
V2_CLAIM_TICKET_IDS__ITEMS,
V2_CLAIM_CASK_IDS_LENGTH,
V2_CLAIM_CASK_IDS__ITEMS,
} v2_claim;

typedef enum {
V2_MULTICLAIM_UNEXPECTED_PARAMETER = 0,
V2_MULTICLAIM_EXIT_QUEUES_OFFSET,
V2_MULTICLAIM_TICKET_IDS_OFFSET,
V2_MULTICLAIM_CASK_IDS_OFFSET,

V2_MULTICLAIM_EXIT_QUEUES_LENGTH,
V2_MULTICLAIM_EXIT_QUEUES__ITEMS,

V2_MULTICLAIM_TICKETIDS_LENGTH,
V2_MULTICLAIM_TICKETIDS__OFFSET_ITEMS,
V2_MULTICLAIM_TICKETIDS__ITEM_LENGTH,
V2_MULTICLAIM_TICKETIDS__ITEM__ITEMS,

V2_MULTICLAIM_CASKIDS_LENGTH,
V2_MULTICLAIM_CASKIDS__OFFSET_ITEMS,
V2_MULTICLAIM_CASKIDS__ITEM_LENGTH,
V2_MULTICLAIM_CASKIDS__ITEM__ITEMS,
} v2_multiclaim_parameters;

// Parameters and state machines for EigenLayer parsing

typedef enum {
LR_UNDELEGATE_UNEXPECTED_PARAMETER = 0,
LR_UNDELEGATE_ADDRESS,
} lr_undelegate_parameters;

typedef enum {
LR_DEPOSIT_INTO_STRATEGY_UNEXPECTED_PARAMETER = 0,
LR_DEPOSIT_INTO_STRATEGY_STRATEGY,
Expand Down Expand Up @@ -173,6 +227,33 @@ typedef enum {

// Parsing structures

typedef struct {
uint16_t current_item_count;
} v1_withdraw_funcs_t;

typedef struct {
uint8_t amount[INT256_LENGTH];
} v2_request_exit_t;

typedef struct {
// -- utils
uint16_t cask_ids_offset;

uint16_t current_item_count;
} v2_claim_t;

typedef struct {
// -- utils
uint16_t ticket_ids_offset;
uint16_t cask_ids_offset;
uint8_t checksum_preview[CX_KECCAK_256_SIZE];
uint8_t checksum_value[CX_KECCAK_256_SIZE];
uint32_t cached_offset;

uint16_t parent_item_count;
uint16_t current_item_count;
} v2_multiclaim_t;

typedef struct {
int strategy_to_display;
int erc20_to_display;
Expand Down Expand Up @@ -254,12 +335,17 @@ typedef struct {
// ****************************************************************************
// * SHARED PLUGIN CONTEXT MEMORY
// ****************************************************************************
// [100] receiveAsTokens_offset

typedef struct context_t {
uint8_t next_param;

union {
v1_withdraw_funcs_t v1_withdraw_funcs;

v2_request_exit_t v2_request_exit;
v2_claim_t v2_claim;
v2_multiclaim_t v2_multiclaim;

lr_deposit_t lr_deposit;
lr_delegate_to_t lr_delegate_to;
lr_queue_withdrawals_t lr_queue_withdrawals;
Expand Down
68 changes: 57 additions & 11 deletions src/provide_parameter/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void handle_lr_deposit_into_strategy(ethPluginProvideParameter_t *msg, context_t
// [ 68] amount

uint8_t buffer[ADDRESS_LENGTH];
char address_buffer[ADDRESS_STR_LEN];
char address_buffer[ADDRESS_STR_LEN + 1];

switch (context->next_param) {
case LR_DEPOSIT_INTO_STRATEGY_STRATEGY:
Expand Down Expand Up @@ -217,7 +217,11 @@ void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *co
case LR_QUEUE_WITHDRAWALS_QWITHDRAWALS_LENGTH:
U2BE_from_parameter(msg->parameter, &params->queued_withdrawals_count);
params->current_item_count = params->queued_withdrawals_count;
context->next_param = LR_QUEUE_WITHDRAWALS__QWITHDRAWALS_STRUCT_OFFSET;
if (params->current_item_count == 0) {
context->next_param = LR_QUEUE_WITHDRAWALS_UNEXPECTED_PARAMETER;
} else {
context->next_param = LR_QUEUE_WITHDRAWALS__QWITHDRAWALS_STRUCT_OFFSET;
}
break;

// ********************************************************************
Expand Down Expand Up @@ -319,7 +323,7 @@ void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *co
{
uint8_t buffer[ADDRESS_LENGTH];
copy_address(buffer, msg->parameter, sizeof(buffer));
char address_buffer[ADDRESS_STR_LEN];
char address_buffer[ADDRESS_STR_LEN + 1];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);
// we only support same withdrawer accross all the withdrawals
if (params->withdrawer[0] == '\0') {
Expand Down Expand Up @@ -368,7 +372,7 @@ void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *co
{
uint8_t buffer[ADDRESS_LENGTH];
copy_address(buffer, msg->parameter, sizeof(buffer));
char address_buffer[ADDRESS_STR_LEN];
char address_buffer[ADDRESS_STR_LEN + 1];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);

uint8_t strategy_index = find_lr_known_strategy(address_buffer);
Expand All @@ -391,7 +395,22 @@ void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *co
// get number of items to parse
U2BE_from_parameter(msg->parameter, &params->current_item_count);

context->next_param = LR_QUEUE_WITHDRAWALS__QWITHDRAWALS__SHARES_ITEM;
if (params->current_item_count == 0) {
// here we arrive at the end of the queuedWithdrawal array element

// check if there are other queuedWithdrawals to parse
params->queued_withdrawals_count -= 1;
if (params->queued_withdrawals_count == 0) {
// if not we finished parsing
context->next_param = LR_QUEUE_WITHDRAWALS_UNEXPECTED_PARAMETER;
} else {
// if there are other queuedWithdrawals we go back to parsing the
// next queueWithdrawal struct
context->next_param = LR_QUEUE_WITHDRAWALS__QWITHDRAWALS_STRATEGIES_OFFSET;
}
} else {
context->next_param = LR_QUEUE_WITHDRAWALS__QWITHDRAWALS__SHARES_ITEM;
}
break;
case LR_QUEUE_WITHDRAWALS__QWITHDRAWALS__SHARES_ITEM:
// we skip parsing shares item as they are not needed for clearsigning
Expand Down Expand Up @@ -699,7 +718,7 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
{
uint8_t buffer[ADDRESS_LENGTH];
copy_address(buffer, msg->parameter, sizeof(buffer));
char address_buffer[ADDRESS_STR_LEN];
char address_buffer[ADDRESS_STR_LEN + 1];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);

uint8_t strategy_index = find_lr_known_strategy(address_buffer);
Expand Down Expand Up @@ -909,7 +928,7 @@ void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, con
{
uint8_t buffer[ADDRESS_LENGTH];
copy_address(buffer, msg->parameter, sizeof(buffer));
char address_buffer[ADDRESS_STR_LEN];
char address_buffer[ADDRESS_STR_LEN + 1];
getEthDisplayableAddress(buffer, address_buffer, sizeof(address_buffer), 0);

uint8_t token_index = find_lr_known_erc20(address_buffer);
Expand Down Expand Up @@ -1075,7 +1094,7 @@ void handle_lr_delegate_to(ethPluginProvideParameter_t *msg, context_t *context)
switch (context->next_param) {
case LR_DELEGATE_TO_OPERATOR: {
{
uint8_t buffer[ADDRESS_LENGTH];
uint8_t buffer[ADDRESS_LENGTH + 1];
copy_address(buffer, msg->parameter, sizeof(buffer));
getEthDisplayableAddress(buffer,
params->operator_address,
Expand Down Expand Up @@ -1132,9 +1151,9 @@ void handle_lr_delegate_to(ethPluginProvideParameter_t *msg, context_t *context)
break;
case LR_DELEGATE_TO_SIGNATURE_SIG_ITEMS:
// we skip parsing signature items as they are not needed for clearsigning

params->current_item_count -= 1;
if (params->current_item_count == 0) {
if (params->current_item_count >= PARAMETER_LENGTH) {
params->current_item_count -= PARAMETER_LENGTH;
} else {
context->next_param = LR_DELEGATE_TO_UNEXPECTED_PARAMETER;
}
break;
Expand All @@ -1144,4 +1163,31 @@ void handle_lr_delegate_to(ethPluginProvideParameter_t *msg, context_t *context)
return;
}
msg->result = ETH_PLUGIN_RESULT_OK;
}

void handle_lr_undelegate(ethPluginProvideParameter_t *msg, context_t *context) {
// **************************************************************************
// FUNCTION TO PARSE
// **************************************************************************
//
// function undelegate(
// address staker
// ) external
//
// **************************************************************************
// example
// [0] selector
// [4] address

switch (context->next_param) {
case LR_UNDELEGATE_ADDRESS: {
context->next_param = LR_UNDELEGATE_UNEXPECTED_PARAMETER;
break;
}
default:
PRINTF("Param not supported: %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
msg->result = ETH_PLUGIN_RESULT_OK;
}
15 changes: 7 additions & 8 deletions src/provide_parameter/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,24 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
case KILN_V1_WITHDRAW:
case KILN_V1_WITHDRAW_EL:
case KILN_V1_WITHDRAW_CL:
msg->result = ETH_PLUGIN_RESULT_OK;
break;
case KILN_V1_BATCH_WITHDRAW:
case KILN_V1_BATCH_WITHDRAW_EL:
case KILN_V1_BATCH_WITHDRAW_CL:
msg->result = ETH_PLUGIN_RESULT_OK;
break;

case KILN_V1_REQUEST_EXIT:
msg->result = ETH_PLUGIN_RESULT_OK;
handle_v1_withdraw_funcs(msg, context);
break;

case KILN_V2_STAKE:
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
case KILN_V2_REQUEST_EXIT:
handle_v2_request_exit(msg, context);
break;
case KILN_V2_MULTICLAIM:
handle_v2_multiclaim(msg, context);
break;
case KILN_V2_CLAIM:
msg->result = ETH_PLUGIN_RESULT_OK;
handle_v2_claim(msg, context);
break;

case KILN_LR_DEPOSIT_INTO_STRATEGY:
Expand All @@ -65,7 +64,7 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
handle_lr_delegate_to(msg, context);
break;
case KILN_LR_UNDELEGATE:
msg->result = ETH_PLUGIN_RESULT_OK;
handle_lr_undelegate(msg, context);
break;

default:
Expand Down
Loading
Loading