diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index 634cdee..7a1bf53 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -51,6 +51,7 @@ 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: @@ -58,6 +59,7 @@ void handle_init_contract(ethPluginInitContract_t *msg) { 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: @@ -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: diff --git a/src/kiln_plugin.h b/src/kiln_plugin.h index 17a41ae..bbb5b27 100644 --- a/src/kiln_plugin.h +++ b/src/kiln_plugin.h @@ -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 { @@ -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, @@ -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; @@ -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; diff --git a/src/provide_parameter/eigenlayer.c b/src/provide_parameter/eigenlayer.c index 3ecc56a..b689a2d 100644 --- a/src/provide_parameter/eigenlayer.c +++ b/src/provide_parameter/eigenlayer.c @@ -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; } \ No newline at end of file diff --git a/src/provide_parameter/handle_provide_parameter.c b/src/provide_parameter/handle_provide_parameter.c index 7a1bf0d..2ad378d 100644 --- a/src/provide_parameter/handle_provide_parameter.c +++ b/src/provide_parameter/handle_provide_parameter.c @@ -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: @@ -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: diff --git a/src/provide_parameter/ocv1.c b/src/provide_parameter/ocv1.c new file mode 100644 index 0000000..83297c3 --- /dev/null +++ b/src/provide_parameter/ocv1.c @@ -0,0 +1,62 @@ +/******************************************************************************* + * + * ██╗ ██╗██╗██╗ ███╗ ██╗ + * ██║ ██╔╝██║██║ ████╗ ██║ + * █████╔╝ ██║██║ ██╔██╗ ██║ + * ██╔═██╗ ██║██║ ██║╚██╗██║ + * ██║ ██╗██║███████╗██║ ╚████║ + * ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═══╝ + * + * Kiln Ethereum Ledger App + * (c) 2022-2024 Kiln + * + * contact@kiln.fi + ********************************************************************************/ + +#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, ¶ms->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; + } +} \ No newline at end of file diff --git a/src/provide_parameter/provide_parameter.h b/src/provide_parameter/provide_parameter.h index 9e9da7b..272bdce 100644 --- a/src/provide_parameter/provide_parameter.h +++ b/src/provide_parameter/provide_parameter.h @@ -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); @@ -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);