Skip to content

Commit

Permalink
refactor(eqvoc): bugfix fd_eqvoc_test, rework APIs, and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lidatong committed Dec 9, 2024
1 parent 16b28c2 commit 0f73258
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 480 deletions.
8 changes: 5 additions & 3 deletions src/ballet/shred/fd_shred.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct __attribute__((packed)) fd_shred {

union {
/* Common data shred header */
struct __attribute__((packed)) {
struct __attribute__((packed)) fd_shred_data {
/* Slot number difference between this block and the parent block.
parent_off <= slot.
Always greater than zero, except for slot 0, in which case the
Expand All @@ -220,7 +220,7 @@ struct __attribute__((packed)) fd_shred {
} data;

/* Common coding shred header */
struct __attribute__((packed)) {
struct __attribute__((packed)) fd_shred_code {
/* Total number of data shreds in slot. Must be positive. */
/* 0x53 */ ushort data_cnt;

Expand All @@ -234,6 +234,8 @@ struct __attribute__((packed)) fd_shred {
};
};
typedef struct fd_shred fd_shred_t;
typedef struct fd_shred_data fd_shred_data_t;
typedef struct fd_shred_code fd_shred_code_t;

FD_PROTOTYPES_BEGIN

Expand Down Expand Up @@ -406,7 +408,7 @@ fd_shred_code_payload( fd_shred_t const * shred ) {
of the chained Merkle root. U.B. if the shred is not a chained
variant. */
FD_FN_CONST static inline ulong
fd_shred_chain_offset( uchar variant ) {
fd_shred_chain_off( uchar variant ) {
ulong type = fd_shred_type( variant );
return fd_ulong_if( type & FD_SHRED_TYPEMASK_CODE, FD_SHRED_MAX_SZ, FD_SHRED_MIN_SZ )
- FD_SHRED_MERKLE_ROOT_SZ
Expand Down
8 changes: 4 additions & 4 deletions src/ballet/shred/fuzz_shred_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ LLVMFuzzerTestOneInput( uchar const * data,
assert( !fd_shred_is_resigned( type ) );
BOUNDS_CHECK ( fd_shred_code_payload( shred ), fd_shred_payload_sz( shred ) );
BOUNDS_CHECK ( fd_shred_merkle_nodes( shred ), fd_shred_merkle_sz( variant ) );
BOUNDS_CHECK_OFF( fd_shred_chain_offset( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_chain_off( variant ), FD_SHRED_MERKLE_ROOT_SZ );
break;

case FD_SHRED_TYPE_MERKLE_DATA_CHAINED:
Expand All @@ -112,7 +112,7 @@ LLVMFuzzerTestOneInput( uchar const * data,
assert( !fd_shred_is_resigned( type ) );
BOUNDS_CHECK ( fd_shred_data_payload( shred ), fd_shred_payload_sz( shred ) );
BOUNDS_CHECK ( fd_shred_merkle_nodes( shred ), fd_shred_merkle_sz( variant ) );
BOUNDS_CHECK_OFF( fd_shred_chain_offset( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_chain_off( variant ), FD_SHRED_MERKLE_ROOT_SZ );
break;

case FD_SHRED_TYPE_MERKLE_CODE_CHAINED_RESIGNED:
Expand All @@ -124,7 +124,7 @@ LLVMFuzzerTestOneInput( uchar const * data,
assert( fd_shred_is_resigned( type ) );
BOUNDS_CHECK ( fd_shred_code_payload( shred ), fd_shred_payload_sz( shred ) );
BOUNDS_CHECK ( fd_shred_merkle_nodes( shred ), fd_shred_merkle_sz( variant ) );
BOUNDS_CHECK_OFF( fd_shred_chain_offset( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_chain_off( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_retransmitter_sig_off( shred ), FD_SHRED_SIGNATURE_SZ );
break;

Expand All @@ -137,7 +137,7 @@ LLVMFuzzerTestOneInput( uchar const * data,
assert( fd_shred_is_resigned( type ) );
BOUNDS_CHECK ( fd_shred_data_payload( shred ), fd_shred_payload_sz( shred ) );
BOUNDS_CHECK ( fd_shred_merkle_nodes( shred ), fd_shred_merkle_sz( variant ) );
BOUNDS_CHECK_OFF( fd_shred_chain_offset( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_chain_off( variant ), FD_SHRED_MERKLE_ROOT_SZ );
BOUNDS_CHECK_OFF( fd_shred_retransmitter_sig_off( shred ), FD_SHRED_SIGNATURE_SZ );
break;

Expand Down
Loading

0 comments on commit 0f73258

Please sign in to comment.