Line data Source code
1 : #include "fd_harness_common.h"
2 :
3 : ulong
4 0 : fd_runtime_fuzz_runner_align( void ) {
5 0 : return alignof(fd_runtime_fuzz_runner_t);
6 0 : }
7 :
8 : ulong
9 0 : fd_runtime_fuzz_runner_footprint( void ) {
10 0 : ulong txn_max = 4+fd_tile_cnt();
11 0 : uint rec_max = 1024;
12 :
13 0 : ulong l = FD_LAYOUT_INIT;
14 0 : l = FD_LAYOUT_APPEND( l, fd_runtime_fuzz_runner_align(), sizeof(fd_runtime_fuzz_runner_t) );
15 0 : l = FD_LAYOUT_APPEND( l, fd_funk_align(), fd_funk_footprint( txn_max, rec_max ) );
16 : /* Spad memory is not included in the footprint since its allocated separately at the beginning of a fuzzing run */
17 0 : return FD_LAYOUT_FINI( l, fd_runtime_fuzz_runner_align() );
18 0 : }
19 :
20 : fd_runtime_fuzz_runner_t *
21 : fd_runtime_fuzz_runner_new( void * mem,
22 : void * spad_mem,
23 : fd_bank_t * bank,
24 0 : ulong wksp_tag ) {
25 0 : ulong txn_max = 4+fd_tile_cnt();
26 0 : uint rec_max = 1024;
27 :
28 0 : FD_SCRATCH_ALLOC_INIT( l, mem );
29 0 : void * runner_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_runtime_fuzz_runner_align(), sizeof(fd_runtime_fuzz_runner_t) );
30 0 : void * funk_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_align(), fd_funk_footprint( txn_max, rec_max ) );
31 0 : FD_SCRATCH_ALLOC_FINI( l, fd_runtime_fuzz_runner_align() );
32 :
33 0 : fd_runtime_fuzz_runner_t * runner = runner_mem;
34 :
35 0 : fd_funk_t * funk = fd_funk_join( runner->funk, fd_funk_new( funk_mem, wksp_tag, (ulong)fd_tickcount(), txn_max, rec_max ) );
36 0 : if( FD_UNLIKELY( !funk ) ) {
37 0 : FD_LOG_WARNING(( "fd_funk_new() failed" ));
38 0 : return NULL;
39 0 : }
40 :
41 : /* Create spad */
42 0 : runner->spad = fd_spad_join( fd_spad_new( spad_mem, FD_RUNTIME_TRANSACTION_EXECUTION_FOOTPRINT_FUZZ ) );
43 0 : runner->wksp = fd_wksp_containing( runner->spad );
44 :
45 : /* Reuse the same bank for each iteration of the fuzzer */
46 0 : runner->bank = bank;
47 :
48 0 : return runner;
49 0 : }
50 :
51 : void *
52 0 : fd_runtime_fuzz_runner_delete( fd_runtime_fuzz_runner_t * runner ) {
53 0 : if( FD_UNLIKELY( !runner ) ) return NULL;
54 0 : void * shfunk;
55 0 : fd_funk_leave( runner->funk, &shfunk );
56 0 : fd_funk_delete( shfunk );
57 0 : if( FD_UNLIKELY( fd_spad_verify( runner->spad ) ) ) {
58 0 : FD_LOG_ERR(( "fd_spad_verify() failed" ));
59 0 : }
60 0 : if( FD_UNLIKELY( fd_spad_frame_used( runner->spad )!=0 ) ) {
61 0 : FD_LOG_ERR(( "stray spad frame frame_used=%lu", fd_spad_frame_used( runner->spad ) ));
62 0 : }
63 0 : runner->spad = NULL;
64 0 : return runner;
65 0 : }
66 :
67 : int
68 : fd_runtime_fuzz_load_account( fd_txn_account_t * acc,
69 : fd_funk_t * funk,
70 : fd_funk_txn_t * funk_txn,
71 : fd_exec_test_acct_state_t const * state,
72 0 : uchar reject_zero_lamports ) {
73 0 : if( reject_zero_lamports && state->lamports==0UL ) {
74 0 : return 0;
75 0 : }
76 :
77 0 : fd_txn_account_init( acc );
78 0 : ulong size = 0UL;
79 0 : if( state->data ) size = state->data->size;
80 :
81 0 : fd_pubkey_t pubkey[1]; memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
82 :
83 : /* Account must not yet exist */
84 0 : if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( funk, funk_txn, pubkey, NULL, NULL, NULL) ) ) {
85 0 : return 0;
86 0 : }
87 :
88 0 : assert( funk );
89 0 : int err = fd_txn_account_init_from_funk_mutable( /* acc */ acc,
90 0 : /* pubkey */ pubkey,
91 0 : /* funk */ funk,
92 0 : /* txn */ funk_txn,
93 0 : /* do_create */ 1,
94 0 : /* min_data_sz */ size );
95 0 : assert( err==FD_ACC_MGR_SUCCESS );
96 0 : if( state->data ) {
97 0 : acc->vt->set_data( acc, state->data->bytes, size );
98 0 : }
99 :
100 0 : acc->starting_lamports = state->lamports;
101 0 : acc->starting_dlen = size;
102 0 : acc->vt->set_lamports( acc, state->lamports );
103 0 : acc->vt->set_executable( acc, state->executable );
104 0 : acc->vt->set_rent_epoch( acc, state->rent_epoch );
105 0 : acc->vt->set_owner( acc, (fd_pubkey_t const *)state->owner );
106 :
107 : /* make the account read-only by default */
108 0 : acc->vt->set_readonly( acc );
109 :
110 0 : fd_txn_account_mutable_fini( acc, funk, funk_txn );
111 :
112 0 : return 1;
113 0 : }
114 :
115 : int
116 : fd_runtime_fuzz_restore_features( fd_features_t * features,
117 0 : fd_exec_test_feature_set_t const * feature_set ) {
118 0 : fd_features_disable_all( features );
119 0 : for( ulong j=0UL; j < feature_set->features_count; j++ ) {
120 0 : ulong prefix = feature_set->features[j];
121 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix );
122 0 : if( FD_UNLIKELY( !id ) ) {
123 0 : FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix ));
124 0 : return 0;
125 0 : }
126 : /* Enabled since genesis */
127 0 : fd_features_set( features, id, 0UL );
128 0 : }
129 0 : return 1;
130 0 : }
|