From 3aaa14278b5e7c08f07834836d5024d6adc23065 Mon Sep 17 00:00:00 2001 From: n4l5u0r <59141606+n4l5u0r@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:01:13 +0100 Subject: [PATCH] test: fuzz --- .github/workflows/cflite_pr.yml | 6 ++-- fuzzing/fuzz_tx_parser.c | 61 +++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml index 8b185d05..618d0af5 100644 --- a/.github/workflows/cflite_pr.yml +++ b/.github/workflows/cflite_pr.yml @@ -1,9 +1,9 @@ name: ClusterFuzzLite PR fuzzing on: workflow_dispatch: - # pull_request: - # paths: - # - '**' + pull_request: + paths: + - "**" permissions: read-all jobs: PR: diff --git a/fuzzing/fuzz_tx_parser.c b/fuzzing/fuzz_tx_parser.c index 2874b899..38518db9 100644 --- a/fuzzing/fuzz_tx_parser.c +++ b/fuzzing/fuzz_tx_parser.c @@ -2,38 +2,49 @@ #include #include #include - -#include "transaction/deserialize.h" -#include "transaction/utils.h" -#include "transaction/types.h" -#include "format.h" - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +#include "buffer.h" +#include "signTransfer.h" + +#define ADDRESS_LEN 20 +void format_hex(const uint8_t* data, size_t dataLen, char* dst, size_t dstLen); +void format_fpu64(char* dst, size_t dstLen, uint64_t value, uint8_t decimals); + +typedef enum { + PARSING_OK = 1, + MEMO_PARSING_ERROR = -1, + WRONG_LENGTH_ERROR = -7, + TYPE_PARSING_ERROR = -8, + SENDER_PARSING_ERROR = -9, + RECIPIENT_PARSING_ERROR = -10, + AMOUNT_PARSING_ERROR = -11, + PARSING_ERROR = -12 +} parser_status_e; + +// #include "transaction/deserialize.h" +// #include "transaction/utils.h" +// #include "transaction/types.h" +// #include "format.h" + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { buffer_t buf = {.ptr = data, .size = size, .offset = 0}; - transaction_ctx_t tx; + signTransferContext_t tx; parser_status_e status; - char address[21] = {0}; - char amount[21] = {0}; memset(&tx, 0, sizeof(tx)); - status = simple_transfer_deserialize(&buf, &tx); + volatile unsigned int flags = 0; + handleSignTransfer((uint8_t*) data, &flags); + status = (parser_status_e) flags; if (status == PARSING_OK) { - // Format recipient address - format_hex(tx.transaction.simple_transfer.recipient, ADDRESS_LEN, address, sizeof(address)); - printf("recipient: %s\n", address); - - // Format sender address - format_hex(tx.transaction.simple_transfer.sender, ADDRESS_LEN, address, sizeof(address)); - printf("sender: %s\n", address); - - // Format amount - format_fpu64(amount, - sizeof(amount), - tx.transaction.simple_transfer.value, - 3); // exponent of smallest unit is 3 - printf("amount: %s\n", amount); + // Print the display string which should contain formatted transaction info + printf("Display string: %s\n", tx.displayStr); + + // Print the amount + printf("Display amount: %s\n", tx.displayAmount); + + // Print the state + printf("State: %d\n", tx.state); } return 0;