Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h
2 : #define HEADER_fd_src_flamenco_runtime_tests_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 "../../../third_party/nanopb/pb_encode.h"
10 : #include "../../../third_party/nanopb/pb_decode.h"
11 : #include "generated/context.pb.h"
12 :
13 : FD_PROTOTYPES_BEGIN
14 :
15 : /* Creates / overwrites an account in the accdb given an input account
16 : state. On success, loads the account into acc. Optionally, reject
17 : any zero-lamport accounts from being loaded in. */
18 : int
19 : fd_solfuzz_pb_load_account( fd_runtime_t * runtime,
20 : fd_accdb_t * accdb,
21 : fd_accdb_fork_id_t fork_id,
22 : fd_exec_test_acct_state_t const * state,
23 : ulong acc_idx );
24 :
25 : /* Restores the fee rate governor in the bank from the given protobuf
26 : fee rate governor. */
27 : void
28 : fd_solfuzz_pb_restore_fee_rate_governor( fd_bank_t * bank,
29 : fd_exec_test_fee_rate_governor_t const * fee_rate_governor );
30 :
31 : /* Initializes the blockhash queue in the bank from the given protobuf
32 : blockhash queue entries. */
33 : void
34 : fd_solfuzz_pb_restore_blockhash_queue( fd_bank_t * bank,
35 : fd_exec_test_blockhash_queue_entry_t const * entries,
36 : ulong entries_cnt );
37 :
38 : /* Retrieves the slot number from the clock sysvar account within the
39 : given account states list. Throws FD_LOG_ERR if the clock sysvar
40 : is not found or is malformed. */
41 : ulong
42 : fd_solfuzz_pb_get_slot( fd_exec_test_acct_state_t const * acct_states,
43 : ulong acct_states_cnt );
44 :
45 : /* Activates features in the runtime given an input feature set. Fails
46 : if a passed-in feature is unknown / not supported. */
47 : int
48 : fd_solfuzz_pb_restore_features( fd_features_t * features,
49 : fd_exec_test_feature_set_t const * feature_set );
50 :
51 : /* Due to how Firedancer's VM CU accounting works, when
52 : virtual_address_space_adjustments is enabled and execution
53 : fails with the CU meter exhausted, we cannot compare the data
54 : region of the accounts with Agave. This function clears the
55 : data field on each captured account in this case. */
56 : void
57 : fd_solfuzz_direct_mapping_handle_cu_exhaustion( fd_solfuzz_runner_t * runner,
58 : ulong cu_avail,
59 : int has_err,
60 : fd_exec_test_acct_state_t * accounts,
61 : pb_size_t accounts_cnt );
62 :
63 : /* Create feature accounts for all active features in the given feature
64 : set, with an activation slot of 0. Skip any feature whose pubkey
65 : already appears in acct_states so the caller-supplied state wins
66 : (matches solfuzz-agave's accounts_to_store filter). */
67 : void
68 : fd_solfuzz_pb_create_feature_accounts( fd_accdb_t * accdb,
69 : fd_accdb_fork_id_t fork_id,
70 : fd_exec_test_feature_set_t const * feature_set,
71 : fd_exec_test_acct_state_t const * acct_states,
72 : pb_size_t acct_states_count );
73 :
74 : typedef ulong( exec_test_run_pb_fn_t )( fd_solfuzz_runner_t *,
75 : void const *,
76 : void **,
77 : void *,
78 : ulong );
79 :
80 : static inline void
81 : fd_solfuzz_pb_execute_wrapper( fd_solfuzz_runner_t * runner,
82 : void const * input,
83 : void ** output,
84 0 : exec_test_run_pb_fn_t * exec_test_run_fn ) {
85 0 : ulong out_bufsz = 100000000; /* 100 MB */
86 0 : void * out0 = fd_spad_alloc( runner->spad, 1UL, out_bufsz );
87 0 : FD_TEST( out_bufsz <= fd_spad_alloc_max( runner->spad, 1UL ) );
88 :
89 0 : ulong out_used = exec_test_run_fn( runner, input, output, out0, out_bufsz );
90 0 : if( FD_UNLIKELY( !out_used ) ) {
91 0 : *output = NULL;
92 0 : }
93 0 : }
94 :
95 : /* Utils */
96 :
97 : static FD_FN_UNUSED void *
98 : sol_compat_decode_lenient( void * decoded,
99 : uchar const * in,
100 : ulong in_sz,
101 0 : pb_msgdesc_t const * decode_type ) {
102 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
103 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
104 0 : if( !decode_ok ) {
105 0 : pb_release( decode_type, decoded );
106 0 : return NULL;
107 0 : }
108 0 : return decoded;
109 0 : }
110 :
111 : static FD_FN_UNUSED void *
112 : sol_compat_decode( void * decoded,
113 : uchar const * in,
114 : ulong in_sz,
115 0 : pb_msgdesc_t const * decode_type ) {
116 0 : pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
117 0 : int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
118 0 : if( !decode_ok ) {
119 0 : pb_release( decode_type, decoded );
120 0 : return NULL;
121 0 : }
122 0 : ulong size;
123 0 : if( FD_UNLIKELY( !pb_get_encoded_size( &size, decode_type, decoded ) ) ) {
124 0 : pb_release( decode_type, decoded );
125 0 : return NULL;
126 0 : }
127 0 : if( FD_UNLIKELY( size != in_sz ) ) {
128 0 : pb_release( decode_type, decoded );
129 0 : return NULL;
130 0 : }
131 0 : return decoded;
132 0 : }
133 :
134 : static FD_FN_UNUSED void const *
135 : sol_compat_encode( uchar * out,
136 : ulong * out_sz,
137 : void const * to_encode,
138 0 : pb_msgdesc_t const * encode_type ) {
139 0 : pb_ostream_t ostream = pb_ostream_from_buffer( out, *out_sz );
140 0 : int encode_ok = pb_encode( &ostream, encode_type, to_encode );
141 0 : if( !encode_ok ) {
142 0 : return NULL;
143 0 : }
144 0 : *out_sz = ostream.bytes_written;
145 0 : return to_encode;
146 0 : }
147 :
148 : FD_PROTOTYPES_END
149 :
150 : #endif /* HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h */
|