Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_tests_harness_fd_solfuzz_private_h
2 : #define HEADER_fd_src_flamenco_runtime_tests_harness_fd_solfuzz_private_h
3 :
4 : /* fd_solfuzz_private.h contains internal components for the solfuzz
5 : Protobuf shim. */
6 :
7 : #include "fd_solfuzz.h"
8 : #include "../../features/fd_features.h"
9 : #include "../../../ballet/nanopb/pb_encode.h"
10 : #include "../../../ballet/nanopb/pb_decode.h"
11 : #include "generated/context.pb.h"
12 :
13 : FD_PROTOTYPES_BEGIN
14 :
15 : /* Creates / overwrites an account in funk given an input account state.
16 : On success, loads the account into `acc`. Optionally, reject any zero-lamport
17 : accounts from being loaded in. */
18 : int
19 : fd_runtime_fuzz_load_account( fd_txn_account_t * acc,
20 : fd_funk_t * funk,
21 : fd_funk_txn_t * funk_txn,
22 : fd_exec_test_acct_state_t const * state,
23 : uchar reject_zero_lamports );
24 :
25 : /* Activates features in the runtime given an input feature set. Fails if a passed-in feature
26 : is unknown / not supported. */
27 : int
28 : fd_runtime_fuzz_restore_features( fd_features_t * features,
29 : fd_exec_test_feature_set_t const * feature_set );
30 :
31 : void
32 : fd_runtime_fuzz_refresh_program_cache( fd_exec_slot_ctx_t * slot_ctx,
33 : fd_exec_test_acct_state_t const * acct_states,
34 : ulong acct_states_count,
35 : fd_spad_t * runtime_spad );
36 :
37 : typedef ulong( exec_test_run_fn_t )( fd_solfuzz_runner_t *,
38 : void const *,
39 : void **,
40 : void *,
41 : ulong );
42 :
43 : static inline void
44 : fd_solfuzz_execute_wrapper( fd_solfuzz_runner_t * runner,
45 : void * input,
46 : void ** output,
47 0 : exec_test_run_fn_t * exec_test_run_fn ) {
48 :
49 0 : ulong out_bufsz = 100000000; /* 100 MB */
50 0 : void * out0 = fd_spad_alloc( runner->spad, 1UL, out_bufsz );
51 0 : FD_TEST( out_bufsz <= fd_spad_alloc_max( runner->spad, 1UL ) );
52 :
53 0 : ulong out_used = exec_test_run_fn( runner, input, output, out0, out_bufsz );
54 0 : if( FD_UNLIKELY( !out_used ) ) {
55 0 : *output = NULL;
56 0 : }
57 :
58 0 : }
59 :
60 : /* Utils */
61 :
62 : static FD_FN_UNUSED void *
63 : sol_compat_decode_lenient( void * decoded,
64 : uchar const * in,
65 : ulong in_sz,
66 0 : pb_msgdesc_t const * decode_type ) {
67 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
68 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
69 0 : if( !decode_ok ) {
70 0 : pb_release( decode_type, decoded );
71 0 : return NULL;
72 0 : }
73 0 : return decoded;
74 0 : }
75 :
76 : static FD_FN_UNUSED void *
77 : sol_compat_decode( void * decoded,
78 : uchar const * in,
79 : ulong in_sz,
80 0 : pb_msgdesc_t const * decode_type ) {
81 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
82 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
83 0 : if( !decode_ok ) {
84 0 : pb_release( decode_type, decoded );
85 0 : return NULL;
86 0 : }
87 0 : ulong size;
88 0 : if( FD_UNLIKELY( !pb_get_encoded_size( &size, decode_type, decoded ) ) ) {
89 0 : pb_release( decode_type, decoded );
90 0 : return NULL;
91 0 : }
92 0 : if( FD_UNLIKELY( size != in_sz ) ) {
93 0 : pb_release( decode_type, decoded );
94 0 : return NULL;
95 0 : }
96 0 : return decoded;
97 0 : }
98 :
99 : static FD_FN_UNUSED void const *
100 : sol_compat_encode( uchar * out,
101 : ulong * out_sz,
102 : void const * to_encode,
103 0 : pb_msgdesc_t const * encode_type ) {
104 0 : pb_ostream_t ostream = pb_ostream_from_buffer( out, *out_sz );
105 0 : int encode_ok = pb_encode( &ostream, encode_type, to_encode );
106 0 : if( !encode_ok ) {
107 0 : return NULL;
108 0 : }
109 0 : *out_sz = ostream.bytes_written;
110 0 : return to_encode;
111 0 : }
112 :
113 : FD_PROTOTYPES_END
114 :
115 : #endif /* HEADER_fd_src_flamenco_runtime_tests_harness_fd_solfuzz_private_h */
|