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