Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fuzz: block fuzzing #3261

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions src/flamenco/runtime/fd_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ fd_runtime_execute_txns_in_waves_tpool( fd_exec_slot_ctx_t * slot_ctx,
fd_spad_t * * spads,
ulong spads_cnt );

int
fd_runtime_block_sysvar_update_pre_execute( fd_exec_slot_ctx_t * slot_ctx );

void
fd_runtime_calculate_fee ( fd_exec_txn_ctx_t * txn_ctx,
fd_txn_t const * txn_descriptor,
Expand Down
581 changes: 462 additions & 119 deletions src/flamenco/runtime/tests/fd_exec_instr_test.c

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/flamenco/runtime/tests/fd_exec_instr_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "generated/invoke.pb.h"
#include "generated/txn.pb.h"
#include "generated/vm.pb.h"
#include "generated/block.pb.h"
#include "../../../funk/fd_funk.h"
#include "../../vm/fd_vm.h"
#include "../../../ballet/murmur3/fd_murmur3.h"
Expand Down Expand Up @@ -111,6 +112,22 @@ fd_exec_txn_test_run( fd_exec_instr_test_runner_t * runner, // Runner only conta
void * output_buf,
ulong output_bufsz );

/*
Executes several transactions within a single slot. A few things to know when using this harness...
- All sysvars are assumed to have been provided in the context
- This does not test sigverify
- Epoch boundaries are NOT tested
- Tested Firedancer code is `fd_runtime_execute_txns_in_waves_tpool` and `fd_runtime_block_execute_finalize_tpool`
- Associated entrypoint tested in Agave is `confirm_slot_entries` (except sigverify is removed and verify_ticks is included)
- Recent blockhashes sysvar account must NOT be provided in the input account states. Instead, the sysvar is populated through the input blockhash queue.
*/
ulong
fd_exec_block_test_run( fd_exec_instr_test_runner_t * runner,
void const * input_,
void ** output_,
void * output_buf,
ulong output_bufsz );

/* Loads an ELF binary (in input->elf.data()).
output_buf points to a memory region of output_bufsz bytes where the
result is allocated into. During execution, the contents of
Expand Down
36 changes: 36 additions & 0 deletions src/flamenco/runtime/tests/fd_exec_sol_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,42 @@ sol_compat_txn_execute_v1( uchar * out,
return ok;
}

int
sol_compat_block_execute_v1( uchar * out,
ulong * out_sz,
uchar const * in,
ulong in_sz ) {
// Setup
ulong fmem[ 64 ];
fd_exec_instr_test_runner_t * runner = sol_compat_setup_scratch_and_runner( fmem );

// Decode context
fd_exec_test_txn_context_t input[1] = {0};
void * res = sol_compat_decode( &input, in, in_sz, &fd_exec_test_txn_context_t_msg );
if ( res==NULL ) {
sol_compat_cleanup_scratch_and_runner( runner );
return 0;
}

// Execute
void * output = NULL;
sol_compat_execute_wrapper( runner, input, &output, fd_exec_block_test_run );

// Encode effects
int ok = 0;
if( output ) {
ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_txn_result_t_msg );
}

// Cleanup
pb_release( &fd_exec_test_txn_context_t_msg, input );
sol_compat_cleanup_scratch_and_runner( runner );

// Check wksp usage is 0
sol_compat_check_wksp_usage();
return ok;
}

int
sol_compat_elf_loader_v1( uchar * out,
ulong * out_sz,
Expand Down
18 changes: 18 additions & 0 deletions src/flamenco/runtime/tests/generated/block.pb.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 151 additions & 0 deletions src/flamenco/runtime/tests/generated/block.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/flamenco/runtime/tests/generated/context.pb.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 44 additions & 8 deletions src/flamenco/runtime/tests/generated/context.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/flamenco/runtime/tests/generated/txn.pb.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/flamenco/types/fd_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.