Skip to content

Commit ae6232a

Browse files
committed
Revert "solfuzz: remove compute budget program fuzzer"
This reverts commit a3ad5b0.
1 parent af1b0c9 commit ae6232a

File tree

8 files changed

+386
-4
lines changed

8 files changed

+386
-4
lines changed

src/flamenco/runtime/tests/Local.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
$(call add-hdrs,harness/generated/context.pb.h,harness/generated/elf.pb.h,harness/generated/invoke.pb.h,harness/generated/txn.pb.h,harness/generated/block.pb.h,harness/generated/vm.pb.h,harness/generated/type.pb.h,harness/generated/shred.pb.h harness/generated/metadata.pb.h)
2-
$(call add-objs,harness/generated/context.pb harness/generated/elf.pb harness/generated/invoke.pb harness/generated/txn.pb harness/generated/block.pb harness/generated/vm.pb harness/generated/type.pb harness/generated/shred.pb harness/generated/metadata.pb,fd_flamenco)
1+
$(call add-hdrs,harness/generated/context.pb.h,harness/generated/elf.pb.h,harness/generated/invoke.pb.h,harness/generated/txn.pb.h,harness/generated/block.pb.h,harness/generated/vm.pb.h,harness/generated/type.pb.h,harness/generated/shred.pb.h harness/generated/metadata.pb.h harness/generated/pack.pb.h)
2+
$(call add-objs,harness/generated/context.pb harness/generated/elf.pb harness/generated/invoke.pb harness/generated/txn.pb harness/generated/block.pb harness/generated/vm.pb harness/generated/type.pb harness/generated/shred.pb harness/generated/metadata.pb harness/generated/pack.pb,fd_flamenco)
33

44
ifdef FD_HAS_INT128
55
ifdef FD_HAS_SECP256K1
6-
$(call add-hdrs,harness/fd_elf_harness.h harness/fd_instr_harness.h harness/fd_txn_harness.h harness/fd_block_harness.h harness/fd_harness_common.h harness/fd_vm_harness.h harness/fd_types_harness.h)
7-
$(call add-objs,harness/fd_elf_harness harness/fd_instr_harness harness/fd_txn_harness harness/fd_block_harness harness/fd_harness_common harness/fd_vm_harness harness/fd_types_harness,fd_flamenco_test)
6+
$(call add-hdrs,harness/fd_elf_harness.h harness/fd_instr_harness.h harness/fd_txn_harness.h harness/fd_block_harness.h harness/fd_harness_common.h harness/fd_vm_harness.h harness/fd_pack_harness.h harness/fd_types_harness.h)
7+
$(call add-objs,harness/fd_elf_harness harness/fd_instr_harness harness/fd_txn_harness harness/fd_block_harness harness/fd_harness_common harness/fd_vm_harness harness/fd_pack_harness harness/fd_types_harness,fd_flamenco_test)
88
$(call add-objs,harness/fd_exec_sol_compat,fd_flamenco_test)
99

1010
SOL_COMPAT_FLAGS:=-Wl,--undefined=fd_types_vt_by_name

src/flamenco/runtime/tests/harness/fd_exec_sol_compat.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "fd_block_harness.h"
1515
#include "fd_types_harness.h"
1616
#include "fd_vm_harness.h"
17+
#include "fd_pack_harness.h"
1718
#include "fd_elf_harness.h"
1819

1920
#include "generated/elf.pb.h"
@@ -889,6 +890,38 @@ int sol_compat_shred_parse_v1( uchar * out,
889890
return !!sol_compat_encode( out, out_sz, output, &fd_exec_test_accepts_shred_t_msg );
890891
}
891892

893+
int
894+
sol_compat_pack_compute_budget_v1( uchar * out,
895+
ulong * out_sz,
896+
uchar const * in,
897+
ulong in_sz ) {
898+
fd_runtime_fuzz_runner_t * runner = sol_compat_setup_runner( );
899+
900+
fd_exec_test_pack_compute_budget_context_t input[1] = {0};
901+
void * res = sol_compat_decode( &input, in, in_sz, &fd_exec_test_pack_compute_budget_context_t_msg );
902+
if( res==NULL ) {
903+
sol_compat_cleanup_runner( runner );
904+
return 0;
905+
}
906+
907+
int ok = 0;
908+
FD_SPAD_FRAME_BEGIN( runner->spad ) {
909+
void * output = NULL;
910+
sol_compat_execute_wrapper( runner, input, &output, fd_runtime_fuzz_pack_cpb_run );
911+
912+
if( output ) {
913+
ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_pack_compute_budget_effects_t_msg );
914+
}
915+
} FD_SPAD_FRAME_END;
916+
917+
pb_release( &fd_exec_test_pack_compute_budget_context_t_msg, input );
918+
sol_compat_cleanup_runner( runner );
919+
920+
// Check wksp usage is 0
921+
sol_compat_check_wksp_usage();
922+
return ok;
923+
}
924+
892925
int
893926
sol_compat_type_execute_v1( uchar * out,
894927
ulong * out_sz,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "fd_pack_harness.h"
2+
#include "../../../../disco/pack/fd_compute_budget_program.h"
3+
4+
ulong
5+
fd_runtime_fuzz_pack_cpb_run( fd_runtime_fuzz_runner_t * _unused FD_PARAM_UNUSED,
6+
void const * input_,
7+
void ** output_,
8+
void * output_buf,
9+
ulong output_bufsz ){
10+
fd_exec_test_pack_compute_budget_context_t const * input = fd_type_pun_const( input_ );
11+
fd_exec_test_pack_compute_budget_effects_t ** output = fd_type_pun( output_ );
12+
13+
ulong output_end = (ulong) output_buf + output_bufsz;
14+
FD_SCRATCH_ALLOC_INIT( l, output_buf );
15+
16+
fd_exec_test_pack_compute_budget_effects_t * effects =
17+
FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_pack_compute_budget_effects_t),
18+
sizeof (fd_exec_test_pack_compute_budget_effects_t) );
19+
if( FD_UNLIKELY( _l > output_end ) ) {
20+
return 0UL;
21+
}
22+
*effects = (fd_exec_test_pack_compute_budget_effects_t) FD_EXEC_TEST_PACK_COMPUTE_BUDGET_EFFECTS_INIT_ZERO;
23+
24+
fd_compute_budget_program_state_t cbp_state[1];
25+
fd_compute_budget_program_init( cbp_state );
26+
do {
27+
28+
int ok = 1;
29+
for( ulong i=0UL; i<input->instr_datas_count; ++i ){
30+
pb_bytes_array_t * instr_data = input->instr_datas[i];
31+
// Reject if any of the instructions fail to parse
32+
if( !fd_compute_budget_program_parse( instr_data->bytes, instr_data->size, cbp_state ) ) {
33+
ok = 0;
34+
break;
35+
};
36+
}
37+
38+
if( !ok ) {
39+
effects->is_empty = 1;
40+
break;
41+
}
42+
ulong rewards;
43+
uint compute_unit_limit;
44+
ulong loaded_accounts_data_cost = 0UL;
45+
fd_compute_budget_program_finalize( cbp_state,
46+
input->instr_datas_count,
47+
&rewards,
48+
&compute_unit_limit,
49+
&loaded_accounts_data_cost );
50+
effects->rewards = rewards;
51+
effects->compute_unit_limit = compute_unit_limit;
52+
53+
/* If not set, use defaults. See:
54+
https://github.com/firedancer-io/firedancer/blob/688cb04408cf20b0600d900900cdbebebd181e5b/src/ballet/pack/fd_compute_budget_program.h#L64-L70
55+
https://github.com/firedancer-io/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/runtime-transaction/src/compute_budget_instruction_details.rs#L49-L101
56+
*/
57+
effects->heap_sz = !!( cbp_state->flags & FD_COMPUTE_BUDGET_PROGRAM_FLAG_SET_HEAP ) ? cbp_state->heap_size : FD_VM_HEAP_DEFAULT;
58+
effects->loaded_acct_data_sz = !!( cbp_state->flags & FD_COMPUTE_BUDGET_PROGRAM_FLAG_SET_LOADED_DATA_SZ ) ? cbp_state->loaded_acct_data_sz : FD_COMPUTE_BUDGET_MAX_LOADED_DATA_SZ;
59+
} while(0);
60+
61+
ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL );
62+
63+
*output = effects;
64+
return actual_end - (ulong) output_buf;
65+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef HEADER_fd_src_flamenco_runtime_tests_fd_pack_harness_h
2+
#define HEADER_fd_src_flamenco_runtime_tests_fd_pack_harness_h
3+
4+
#include "fd_instr_harness.h"
5+
#include "generated/pack.pb.h"
6+
7+
FD_PROTOTYPES_BEGIN
8+
9+
ulong
10+
fd_runtime_fuzz_pack_cpb_run( fd_runtime_fuzz_runner_t * _unused , /* fd_runtime_fuzz_runner_t */
11+
void const * input_,
12+
void ** output_,
13+
void * output_buf,
14+
ulong output_bufsz );
15+
16+
FD_PROTOTYPES_END
17+
18+
#endif /* HEADER_fd_src_flamenco_runtime_tests_fd_pack_harness_h */

src/flamenco/runtime/tests/harness/generated/pack.pb.c

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/runtime/tests/harness/generated/pack.pb.h

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/runtime/tests/harness/generated/pack_runtime.pb.c

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)