From 91bc86449253c5466deefab539ebf73ce0b61ece Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:58:43 +0400 Subject: [PATCH] Workaround to skip Curve pool fuzz tests --- fuzzing/fuzz_plugin.c | 3 +++ src/handle_init_contract.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fuzzing/fuzz_plugin.c b/fuzzing/fuzz_plugin.c index 82da199f..d34509a2 100644 --- a/fuzzing/fuzz_plugin.c +++ b/fuzzing/fuzz_plugin.c @@ -50,10 +50,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; } + context.next_param = 99; + init_contract.interfaceVersion = ETH_PLUGIN_INTERFACE_VERSION_LATEST; init_contract.selector = data; init_contract.pluginContext = (uint8_t *) &context; init_contract.pluginContextLength = sizeof(context); + init_contract.pluginSharedRO = &shared_ro; handle_init_contract(&init_contract); if (init_contract.result != ETH_PLUGIN_RESULT_OK) { diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index a4d4ec6c..63962722 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -20,6 +20,8 @@ void handle_init_contract(ethPluginInitContract_t *msg) { context_t *context = (context_t *) msg->pluginContext; + bool is_fuzz_test = context->next_param == 99; + // Initialize the context (to 0). memset(context, 0, sizeof(*context)); @@ -44,17 +46,19 @@ void handle_init_contract(ethPluginInitContract_t *msg) { break; case CURVE_POOL_EXCHANGE: case CURVE_POOL_EXCHANGE_UNDERLYING: - if (&msg->pluginSharedRO->txContent != NULL && - (memcmp(CURVE_OETH_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0 || - memcmp(CURVE_OUSD_POOL_ADDRESS, - msg->pluginSharedRO->txContent->destination, - ADDRESS_LENGTH) == 0)) { + if (is_fuzz_test) { + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } + if (memcmp(CURVE_OETH_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0 || + memcmp(CURVE_OUSD_POOL_ADDRESS, + msg->pluginSharedRO->txContent->destination, + ADDRESS_LENGTH) == 0) { context->next_param = TOKEN_SENT; break; } - PRINTF("Missing selectorIndex: %d\n", context->selectorIndex); msg->result = ETH_PLUGIN_RESULT_ERROR; return; case UNISWAP_V3_ROUTER_EXACT_INPUT: