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_xid_t const * xid,
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_bank_t * bank,
33 : fd_funk_t * funk,
34 : fd_funk_txn_xid_t const * xid,
35 : fd_exec_test_acct_state_t const * acct_states,
36 : ulong acct_states_count,
37 : fd_spad_t * runtime_spad );
38 :
39 : typedef ulong( exec_test_run_fn_t )( fd_solfuzz_runner_t *,
40 : void const *,
41 : void **,
42 : void *,
43 : ulong );
44 :
45 : static inline void
46 : fd_solfuzz_execute_wrapper( fd_solfuzz_runner_t * runner,
47 : void * input,
48 : void ** output,
49 0 : exec_test_run_fn_t * exec_test_run_fn ) {
50 :
51 0 : ulong out_bufsz = 100000000; /* 100 MB */
52 0 : void * out0 = fd_spad_alloc( runner->spad, 1UL, out_bufsz );
53 0 : FD_TEST( out_bufsz <= fd_spad_alloc_max( runner->spad, 1UL ) );
54 :
55 0 : ulong out_used = exec_test_run_fn( runner, input, output, out0, out_bufsz );
56 0 : if( FD_UNLIKELY( !out_used ) ) {
57 0 : *output = NULL;
58 0 : }
59 :
60 0 : }
61 :
62 : /* Utils */
63 :
64 : static FD_FN_UNUSED void *
65 : sol_compat_decode_lenient( void * decoded,
66 : uchar const * in,
67 : ulong in_sz,
68 0 : pb_msgdesc_t const * decode_type ) {
69 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
70 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
71 0 : if( !decode_ok ) {
72 0 : pb_release( decode_type, decoded );
73 0 : return NULL;
74 0 : }
75 0 : return decoded;
76 0 : }
77 :
78 : static FD_FN_UNUSED void *
79 : sol_compat_decode( void * decoded,
80 : uchar const * in,
81 : ulong in_sz,
82 0 : pb_msgdesc_t const * decode_type ) {
83 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
84 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
85 0 : if( !decode_ok ) {
86 0 : pb_release( decode_type, decoded );
87 0 : return NULL;
88 0 : }
89 0 : ulong size;
90 0 : if( FD_UNLIKELY( !pb_get_encoded_size( &size, decode_type, decoded ) ) ) {
91 0 : pb_release( decode_type, decoded );
92 0 : return NULL;
93 0 : }
94 0 : if( FD_UNLIKELY( size != in_sz ) ) {
95 0 : pb_release( decode_type, decoded );
96 0 : return NULL;
97 0 : }
98 0 : return decoded;
99 0 : }
100 :
101 : static FD_FN_UNUSED void const *
102 : sol_compat_encode( uchar * out,
103 : ulong * out_sz,
104 : void const * to_encode,
105 0 : pb_msgdesc_t const * encode_type ) {
106 0 : pb_ostream_t ostream = pb_ostream_from_buffer( out, *out_sz );
107 0 : int encode_ok = pb_encode( &ostream, encode_type, to_encode );
108 0 : if( !encode_ok ) {
109 0 : return NULL;
110 0 : }
111 0 : *out_sz = ostream.bytes_written;
112 0 : return to_encode;
113 0 : }
114 :
115 : FD_PROTOTYPES_END
116 :
117 : #endif /* HEADER_fd_src_flamenco_runtime_tests_harness_fd_solfuzz_private_h */
|