Skip to content

Commit

Permalink
fix(ocv1+eigen): missing parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
loicttn committed Dec 10, 2024
1 parent af6c102 commit e327f29
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ 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:
Expand Down Expand Up @@ -85,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
20 changes: 20 additions & 0 deletions src/kiln_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ 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 {
Expand Down Expand Up @@ -142,6 +151,11 @@ typedef enum {

// 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 @@ -213,6 +227,10 @@ 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;
Expand Down Expand Up @@ -314,6 +332,8 @@ 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;
Expand Down
27 changes: 27 additions & 0 deletions src/provide_parameter/eigenlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,4 +1144,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;
}
9 changes: 2 additions & 7 deletions src/provide_parameter/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ 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:
Expand Down Expand Up @@ -69,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
62 changes: 62 additions & 0 deletions src/provide_parameter/ocv1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
*
* ██╗ ██╗██╗██╗ ███╗ ██╗
* ██║ ██╔╝██║██║ ████╗ ██║
* █████╔╝ ██║██║ ██╔██╗ ██║
* ██╔═██╗ ██║██║ ██║╚██╗██║
* ██║ ██╗██║███████╗██║ ╚████║
* ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═══╝
*
* Kiln Ethereum Ledger App
* (c) 2022-2024 Kiln
*
* [email protected]
********************************************************************************/

#include "provide_parameter.h"

void handle_v1_withdraw_funcs(ethPluginProvideParameter_t *msg, context_t *context) {
// **************************************************************************
// FUNCTION TO PARSE
// **************************************************************************
//
// function f(
// bytes
// )
//
// **************************************************************************
// example:
//
// function withdrawEL(
// bytes validatorPubkey
// ) external
//
// [ 0] selector
// [ 4] validatorPubkeyoffset
// [ 36] validatorPubkeylength
// [ 68] validatorPubkey_chunk_0
// [ 100] validatorPubkey_chunk_1
//

v1_withdraw_funcs_t *params = &context->param_data.v1_withdraw_funcs;

switch (context->next_param) {
case V1_WFUNCS_BYTES_OFFSET:
context->next_param = V1_WFUNCS_BYTES_LENGTH;
break;
case V1_WFUNCS_BYTES_LENGTH:
U2BE_from_parameter(msg->parameter, &params->current_item_count);
context->next_param = V1_WFUNCS_BYTES__ITEMS;
break;
case V1_WFUNCS_BYTES__ITEMS:
params->current_item_count -= 1;
if (params->current_item_count == 0) {
context->next_param = V1_WFUNCS_UNEXPECTED_PARAMETER;
}
break;
default:
PRINTF("Param not supported: %d\n", context->next_param);
msg->result = ETH_PLUGIN_RESULT_ERROR;
return;
}
}
3 changes: 3 additions & 0 deletions src/provide_parameter/provide_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "kiln_plugin.h"

void handle_v1_withdraw_funcs(ethPluginProvideParameter_t *msg, context_t *context);

void handle_v2_request_exit(ethPluginProvideParameter_t *msg, context_t *context);
void handle_v2_claim(ethPluginProvideParameter_t *msg, context_t *context);
void handle_v2_multiclaim(ethPluginProvideParameter_t *msg, context_t *context);
Expand All @@ -28,3 +30,4 @@ void handle_lr_deposit_into_strategy(ethPluginProvideParameter_t *msg, context_t
void handle_lr_queue_withdrawals(ethPluginProvideParameter_t *msg, context_t *context);
void handle_lr_complete_queued_withdrawals(ethPluginProvideParameter_t *msg, context_t *context);
void handle_lr_delegate_to(ethPluginProvideParameter_t *msg, context_t *context);
void handle_lr_undelegate(ethPluginProvideParameter_t *msg, context_t *context);

0 comments on commit e327f29

Please sign in to comment.