Skip to content

Commit

Permalink
test: fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
n4l5u0r committed Dec 11, 2024
1 parent 77e7c24 commit 3aaa142
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cflite_pr.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: ClusterFuzzLite PR fuzzing
on:
workflow_dispatch:
# pull_request:
# paths:
# - '**'
pull_request:
paths:
- "**"
permissions: read-all
jobs:
PR:
Expand Down
61 changes: 36 additions & 25 deletions fuzzing/fuzz_tx_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,49 @@
#include <stdint.h>
#include <string.h>
#include <sys/types.h>

#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;
Expand Down

0 comments on commit 3aaa142

Please sign in to comment.