Line data Source code
1 :
2 : #undef FD_SPAD_USE_HANDHOLDING
3 : #define FD_SPAD_USE_HANDHOLDING 1
4 :
5 : #include "fd_instr_harness.h"
6 : #include "../../sysvar/fd_sysvar.h"
7 : #include "../../sysvar/fd_sysvar_clock.h"
8 : #include "../../sysvar/fd_sysvar_epoch_schedule.h"
9 : #include "../../sysvar/fd_sysvar_recent_hashes.h"
10 : #include "../../sysvar/fd_sysvar_last_restart_slot.h"
11 : #include "../../sysvar/fd_sysvar_rent.h"
12 : #include "../../fd_system_ids.h"
13 :
14 : int
15 : fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner,
16 : fd_exec_instr_ctx_t * ctx,
17 : fd_exec_test_instr_context_t const * test_ctx,
18 0 : bool is_syscall ) {
19 :
20 0 : memset( ctx, 0, sizeof(fd_exec_instr_ctx_t) );
21 :
22 0 : fd_funk_t * funk = runner->funk;
23 :
24 : /* Generate unique ID for funk txn */
25 :
26 0 : fd_funk_txn_xid_t xid[1] = {0};
27 0 : xid[0] = fd_funk_generate_xid();
28 :
29 : /* Create temporary funk transaction and txn / slot / epoch contexts */
30 :
31 0 : fd_funk_txn_start_write( funk );
32 0 : fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( funk, NULL, xid, 1 );
33 0 : fd_funk_txn_end_write( funk );
34 :
35 : /* Allocate contexts */
36 0 : uchar * slot_ctx_mem = fd_spad_alloc( runner->spad,FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT );
37 0 : uchar * txn_ctx_mem = fd_spad_alloc( runner->spad,FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT );
38 :
39 0 : fd_exec_slot_ctx_t * slot_ctx = fd_exec_slot_ctx_join ( fd_exec_slot_ctx_new ( slot_ctx_mem ) );
40 0 : fd_exec_txn_ctx_t * txn_ctx = fd_exec_txn_ctx_join ( fd_exec_txn_ctx_new ( txn_ctx_mem ), runner->spad, fd_wksp_containing( runner->spad ) );
41 :
42 0 : assert( slot_ctx );
43 :
44 0 : ctx->txn_ctx = txn_ctx;
45 :
46 : /* Set up slot context */
47 :
48 0 : slot_ctx->funk_txn = funk_txn;
49 0 : slot_ctx->funk = funk;
50 :
51 : /* Bank manager */
52 0 : slot_ctx->banks = runner->banks;
53 0 : slot_ctx->bank = runner->bank;
54 0 : fd_banks_clear_bank( slot_ctx->banks, slot_ctx->bank );
55 :
56 0 : fd_features_t * features = fd_bank_features_modify( slot_ctx->bank );
57 0 : fd_exec_test_feature_set_t const * feature_set = &test_ctx->epoch_context.features;
58 0 : if( !fd_runtime_fuzz_restore_features( features, feature_set ) ) {
59 0 : return 0;
60 0 : }
61 :
62 : /* Set up epoch context. Defaults obtained from GenesisConfig::Default() */
63 :
64 0 : fd_rent_t * rent_bm = fd_bank_rent_modify( slot_ctx->bank );
65 0 : rent_bm->lamports_per_uint8_year = 3480;
66 0 : rent_bm->exemption_threshold = 2;
67 0 : rent_bm->burn_percent = 50;
68 :
69 : /* Blockhash queue init */
70 :
71 0 : ulong blockhash_seed; FD_TEST( fd_rng_secure( &blockhash_seed, sizeof(ulong) ) );
72 0 : fd_blockhashes_t * blockhashes = fd_blockhashes_init( fd_bank_block_hash_queue_modify( slot_ctx->bank ), blockhash_seed );
73 0 : fd_memset( fd_blockhash_deq_push_tail_nocopy( blockhashes->d.deque ), 0, sizeof(fd_hash_t) );
74 :
75 : /* Set up txn context */
76 :
77 0 : fd_wksp_t * funk_wksp = fd_funk_wksp( funk );
78 0 : fd_wksp_t * runtime_wksp = fd_wksp_containing( slot_ctx );
79 0 : ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, funk_txn );
80 0 : ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, funk->shmem );
81 :
82 : /* Set up mock txn descriptor */
83 0 : fd_txn_t * txn_descriptor = fd_spad_alloc( runner->spad, fd_txn_align(), fd_txn_footprint( 1UL, 0UL ) );
84 0 : txn_descriptor->transaction_version = FD_TXN_V0;
85 0 : txn_descriptor->acct_addr_cnt = (ushort)test_ctx->accounts_count;
86 :
87 0 : fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx,
88 0 : txn_ctx,
89 0 : funk_wksp,
90 0 : runtime_wksp,
91 0 : funk_txn_gaddr,
92 0 : funk_gaddr,
93 0 : NULL );
94 0 : fd_exec_txn_ctx_setup_basic( txn_ctx );
95 :
96 0 : txn_ctx->txn_descriptor = txn_descriptor;
97 0 : txn_ctx->compute_budget_details.compute_unit_limit = test_ctx->cu_avail;
98 0 : txn_ctx->compute_budget_details.compute_meter = test_ctx->cu_avail;
99 0 : txn_ctx->vote_accounts_pool = NULL;
100 0 : txn_ctx->spad = runner->spad;
101 0 : txn_ctx->instr_info_cnt = 1UL;
102 :
103 : /* Set up instruction context */
104 :
105 0 : fd_instr_info_t * info = fd_spad_alloc( runner->spad, 8UL, sizeof(fd_instr_info_t) );
106 0 : assert( info );
107 0 : memset( info, 0, sizeof(fd_instr_info_t) );
108 :
109 0 : if( test_ctx->data ) {
110 0 : info->data_sz = (ushort)test_ctx->data->size;
111 0 : info->data = test_ctx->data->bytes;
112 0 : }
113 :
114 0 : txn_ctx->instr_infos[ 0UL ] = *info;
115 :
116 : /* Prepare borrowed account table (correctly handles aliasing) */
117 :
118 0 : if( FD_UNLIKELY( test_ctx->accounts_count > MAX_TX_ACCOUNT_LOCKS ) ) {
119 0 : FD_LOG_NOTICE(( "too many accounts" ));
120 0 : return 0;
121 0 : }
122 :
123 : /* Load accounts into database */
124 :
125 0 : fd_txn_account_t * accts = txn_ctx->accounts;
126 0 : fd_memset( accts, 0, test_ctx->accounts_count * sizeof(fd_txn_account_t) );
127 0 : txn_ctx->accounts_cnt = test_ctx->accounts_count;
128 :
129 0 : int has_program_id = 0;
130 :
131 0 : for( ulong j=0UL; j < test_ctx->accounts_count; j++ ) {
132 0 : memcpy( &(txn_ctx->account_keys[j]), test_ctx->accounts[j].address, sizeof(fd_pubkey_t) );
133 0 : if( !fd_runtime_fuzz_load_account( &accts[j], funk, funk_txn, &test_ctx->accounts[j], 0 ) ) {
134 0 : return 0;
135 0 : }
136 :
137 0 : fd_txn_account_t * acc = &accts[j];
138 0 : if( acc->vt->get_meta( acc ) ) {
139 0 : uchar * data = fd_spad_alloc( txn_ctx->spad, FD_ACCOUNT_REC_ALIGN, FD_ACC_TOT_SZ_MAX );
140 0 : ulong dlen = acc->vt->get_data_len( acc );
141 0 : fd_memcpy( data, acc->vt->get_meta( acc ), sizeof(fd_account_meta_t)+dlen );
142 0 : fd_txn_account_init_from_meta_and_data_readonly( acc,
143 0 : (fd_account_meta_t const *)data,
144 0 : data + sizeof(fd_account_meta_t) );
145 0 : }
146 :
147 0 : if( !memcmp( accts[j].pubkey, test_ctx->program_id, sizeof(fd_pubkey_t) ) ) {
148 0 : has_program_id = 1;
149 0 : info->program_id = (uchar)txn_ctx->accounts_cnt;
150 0 : }
151 :
152 : /* Since the instructions sysvar is set as mutable at the txn level, we need to make it mutable here as well. */
153 0 : if( !memcmp( accts[j].pubkey, &fd_sysvar_instructions_id, sizeof(fd_pubkey_t) ) ) {
154 0 : acc->vt->set_mutable( acc );
155 0 : }
156 0 : }
157 :
158 : /* If the program id is not in the set of accounts it must be added to the set of accounts. */
159 0 : if( FD_UNLIKELY( !has_program_id ) ) {
160 0 : fd_txn_account_t * program_acc = &accts[ test_ctx->accounts_count ];
161 0 : fd_pubkey_t * program_key = &txn_ctx->account_keys[ txn_ctx->accounts_cnt ];
162 0 : fd_txn_account_init( program_acc );
163 0 : memcpy( program_key, test_ctx->program_id, sizeof(fd_pubkey_t) );
164 0 : memcpy( program_acc->pubkey, test_ctx->program_id, sizeof(fd_pubkey_t) );
165 0 : fd_account_meta_t * meta = fd_spad_alloc( txn_ctx->spad, alignof(fd_account_meta_t), sizeof(fd_account_meta_t) );
166 0 : fd_account_meta_init( meta );
167 0 : program_acc->vt->set_meta_mutable( program_acc, meta );
168 0 : info->program_id = (uchar)txn_ctx->accounts_cnt;
169 0 : txn_ctx->accounts_cnt++;
170 0 : }
171 :
172 : /* Load in executable accounts */
173 0 : for( ulong i = 0; i < txn_ctx->accounts_cnt; i++ ) {
174 0 : fd_txn_account_t * acc = &accts[i];
175 0 : if ( !fd_executor_pubkey_is_bpf_loader( acc->vt->get_owner( acc ) ) ) {
176 0 : continue;
177 0 : }
178 :
179 0 : fd_account_meta_t const * meta = acc->vt->get_meta( acc );
180 0 : if (meta == NULL) {
181 0 : fd_txn_account_setup_sentinel_meta_readonly( acc, txn_ctx->spad, txn_ctx->spad_wksp );
182 0 : continue;
183 0 : }
184 :
185 0 : if( FD_UNLIKELY( 0 == memcmp(meta->info.owner, fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t)) ) ) {
186 0 : int err = 0;
187 0 : fd_bpf_upgradeable_loader_state_t * program_loader_state = read_bpf_upgradeable_loader_state_for_program( txn_ctx,
188 0 : (ushort)i,
189 0 : &err );
190 :
191 0 : if( FD_UNLIKELY( !program_loader_state ) ) {
192 0 : continue;
193 0 : }
194 :
195 0 : if( !fd_bpf_upgradeable_loader_state_is_program( program_loader_state ) ) {
196 0 : continue;
197 0 : }
198 :
199 0 : fd_pubkey_t * programdata_acc = &program_loader_state->inner.program.programdata_address;
200 0 : if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( &txn_ctx->executable_accounts[txn_ctx->executable_cnt],
201 0 : programdata_acc,
202 0 : txn_ctx->funk,
203 0 : txn_ctx->funk_txn ) ) ) {
204 0 : continue;
205 0 : }
206 0 : txn_ctx->executable_cnt++;
207 0 : }
208 0 : }
209 :
210 : /* Fill missing sysvar accounts with defaults */
211 : /* We create mock accounts for each of the sysvars and hardcode the data fields before loading it into the account manager */
212 : /* We use Agave sysvar defaults for data field values */
213 :
214 : /* Clock */
215 : // https://github.com/firedancer-io/solfuzz-agave/blob/agave-v2.0/src/lib.rs#L466-L474
216 0 : fd_sol_sysvar_clock_t clock_[1];
217 0 : fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( funk, funk_txn, clock_ );
218 0 : if( !clock ) {
219 0 : fd_sol_sysvar_clock_t sysvar_clock = {
220 0 : .slot = 10UL,
221 0 : .epoch_start_timestamp = 0L,
222 0 : .epoch = 0UL,
223 0 : .leader_schedule_epoch = 0UL,
224 0 : .unix_timestamp = 0L
225 0 : };
226 0 : fd_sysvar_clock_write( slot_ctx, &sysvar_clock );
227 0 : }
228 :
229 : /* Epoch schedule */
230 : // https://github.com/firedancer-io/solfuzz-agave/blob/agave-v2.0/src/lib.rs#L476-L483
231 0 : fd_epoch_schedule_t epoch_schedule[1];
232 0 : if( FD_UNLIKELY( !fd_sysvar_epoch_schedule_read( funk, funk_txn, epoch_schedule ) ) ) {
233 0 : fd_epoch_schedule_t sysvar_epoch_schedule = {
234 0 : .slots_per_epoch = 432000UL,
235 0 : .leader_schedule_slot_offset = 432000UL,
236 0 : .warmup = 1,
237 0 : .first_normal_epoch = 14UL,
238 0 : .first_normal_slot = 524256UL
239 0 : };
240 0 : fd_sysvar_epoch_schedule_write( slot_ctx, &sysvar_epoch_schedule );
241 0 : }
242 :
243 : /* Rent */
244 : // https://github.com/firedancer-io/solfuzz-agave/blob/agave-v2.0/src/lib.rs#L487-L500
245 0 : fd_rent_t const * rent = fd_sysvar_rent_read( funk, funk_txn, runner->spad );
246 0 : if( !rent ) {
247 0 : fd_rent_t sysvar_rent = {
248 0 : .lamports_per_uint8_year = 3480UL,
249 0 : .exemption_threshold = 2.0,
250 0 : .burn_percent = 50
251 0 : };
252 0 : fd_sysvar_rent_write( slot_ctx, &sysvar_rent );
253 0 : }
254 :
255 0 : fd_sol_sysvar_last_restart_slot_t last_restart_slot_[1];
256 0 : fd_sol_sysvar_last_restart_slot_t const * last_restart_slot = fd_sysvar_last_restart_slot_read( funk, funk_txn, last_restart_slot_ );
257 0 : if( !last_restart_slot ) {
258 0 : fd_sol_sysvar_last_restart_slot_t restart = { .slot = 5000UL };
259 0 : fd_sysvar_account_update( slot_ctx, &fd_sysvar_last_restart_slot_id, &restart.slot, sizeof(ulong) );
260 0 : }
261 :
262 : /* Set slot bank variables */
263 0 : clock = fd_sysvar_clock_read( funk, funk_txn, clock_ );
264 :
265 0 : slot_ctx->bank->slot_ = clock->slot;
266 :
267 : /* Handle undefined behavior if sysvars are malicious (!!!) */
268 :
269 0 : if( fd_sysvar_epoch_schedule_read( funk, funk_txn, epoch_schedule ) ) {
270 0 : fd_bank_epoch_schedule_set( slot_ctx->bank, *epoch_schedule );
271 0 : }
272 :
273 : /* Override epoch bank rent setting */
274 0 : rent = fd_sysvar_rent_read( funk, funk_txn, runner->spad );
275 0 : if( rent ) {
276 0 : fd_bank_rent_set( slot_ctx->bank, *rent );
277 0 : }
278 :
279 : /* Override most recent blockhash if given */
280 0 : fd_recent_block_hashes_t const * rbh = fd_sysvar_recent_hashes_read( funk, funk_txn, runner->spad );
281 0 : if( rbh && !deq_fd_block_block_hash_entry_t_empty( rbh->hashes ) ) {
282 0 : fd_block_block_hash_entry_t const * last = deq_fd_block_block_hash_entry_t_peek_tail_const( rbh->hashes );
283 0 : if( last ) {
284 0 : fd_blockhashes_t * blockhashes = fd_bank_block_hash_queue_modify( slot_ctx->bank );
285 0 : fd_blockhashes_pop_new( blockhashes );
286 0 : fd_blockhash_info_t * info = fd_blockhashes_push_new( blockhashes, &last->blockhash );
287 0 : info->fee_calculator = last->fee_calculator;
288 :
289 0 : fd_bank_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature );
290 :
291 0 : fd_bank_prev_lamports_per_signature_set( slot_ctx->bank, last->fee_calculator.lamports_per_signature );
292 0 : }
293 0 : }
294 :
295 : /* Refresh the program cache */
296 0 : fd_runtime_fuzz_refresh_program_cache( slot_ctx, test_ctx->accounts, test_ctx->accounts_count, runner->spad );
297 :
298 : /* Load instruction accounts */
299 :
300 0 : if( FD_UNLIKELY( test_ctx->instr_accounts_count > MAX_TX_ACCOUNT_LOCKS ) ) {
301 0 : FD_LOG_NOTICE(( "too many instruction accounts" ));
302 0 : return 0;
303 0 : }
304 :
305 : /* Restore sysvar cache */
306 0 : fd_sysvar_cache_restore_fuzz( slot_ctx );
307 0 : ctx->sysvar_cache = fd_bank_sysvar_cache_modify( slot_ctx->bank );
308 :
309 0 : uchar acc_idx_seen[ FD_INSTR_ACCT_MAX ] = {0};
310 0 : for( ulong j=0UL; j < test_ctx->instr_accounts_count; j++ ) {
311 0 : uint index = test_ctx->instr_accounts[j].index;
312 0 : if( index >= test_ctx->accounts_count ) {
313 0 : FD_LOG_NOTICE( ( "instruction account index out of range (%u > %u)", index, test_ctx->instr_accounts_count ) );
314 0 : return 0;
315 0 : }
316 :
317 0 : fd_txn_account_t * acc = &accts[ index ];
318 :
319 : /* Setup instruction accounts */
320 0 : fd_instr_info_setup_instr_account( info,
321 0 : acc_idx_seen,
322 0 : (ushort)index,
323 0 : (ushort)j,
324 0 : (ushort)j,
325 0 : test_ctx->instr_accounts[j].is_writable,
326 0 : test_ctx->instr_accounts[j].is_signer );
327 :
328 0 : if( test_ctx->instr_accounts[j].is_writable ) {
329 0 : acc->vt->set_mutable( acc );
330 0 : }
331 0 : }
332 0 : info->acct_cnt = (uchar)test_ctx->instr_accounts_count;
333 :
334 : /* The remaining checks enforce that the program is in the accounts list. */
335 0 : bool found_program_id = false;
336 0 : for( uint i = 0; i < test_ctx->accounts_count; i++ ) {
337 0 : if( 0 == memcmp( test_ctx->accounts[i].address, test_ctx->program_id, sizeof(fd_pubkey_t) ) ) {
338 0 : info->program_id = (uchar) i;
339 0 : found_program_id = true;
340 0 : break;
341 0 : }
342 0 : }
343 :
344 : /* Early returning only happens in instruction execution. */
345 0 : if( !is_syscall && !found_program_id ) {
346 0 : FD_LOG_NOTICE(( " Unable to find program_id in accounts" ));
347 0 : return 0;
348 0 : }
349 :
350 0 : ctx->instr = info;
351 :
352 : /* Refresh the setup from the updated slot and epoch ctx. */
353 0 : fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx,
354 0 : txn_ctx,
355 0 : funk_wksp,
356 0 : runtime_wksp,
357 0 : funk_txn_gaddr,
358 0 : funk_gaddr,
359 0 : NULL );
360 :
361 0 : fd_log_collector_init( &ctx->txn_ctx->log_collector, 1 );
362 0 : fd_base58_encode_32( txn_ctx->account_keys[ ctx->instr->program_id ].uc, NULL, ctx->program_id_base58 );
363 :
364 0 : return 1;
365 0 : }
366 :
367 :
368 :
369 : void
370 : fd_runtime_fuzz_instr_ctx_destroy( fd_runtime_fuzz_runner_t * runner,
371 0 : fd_exec_instr_ctx_t * ctx ) {
372 0 : if( !ctx ) return;
373 0 : fd_funk_txn_t * funk_txn = ctx->txn_ctx->funk_txn;
374 :
375 0 : fd_funk_txn_cancel( runner->funk, funk_txn, 1 );
376 0 : }
377 :
378 :
379 : ulong
380 : fd_runtime_fuzz_instr_run( fd_runtime_fuzz_runner_t * runner,
381 : void const * input_,
382 : void ** output_,
383 : void * output_buf,
384 0 : ulong output_bufsz ) {
385 0 : fd_exec_test_instr_context_t const * input = fd_type_pun_const( input_ );
386 0 : fd_exec_test_instr_effects_t ** output = fd_type_pun( output_ );
387 :
388 : /* Convert the Protobuf inputs to a fd_exec context */
389 0 : fd_exec_instr_ctx_t ctx[1];
390 0 : if( !fd_runtime_fuzz_instr_ctx_create( runner, ctx, input, false ) ) {
391 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
392 0 : return 0UL;
393 0 : }
394 :
395 0 : fd_instr_info_t * instr = (fd_instr_info_t *) ctx->instr;
396 :
397 : /* Execute the test */
398 0 : int exec_result = fd_execute_instr(ctx->txn_ctx, instr);
399 :
400 : /* Allocate space to capture outputs */
401 :
402 0 : ulong output_end = (ulong)output_buf + output_bufsz;
403 0 : FD_SCRATCH_ALLOC_INIT( l, output_buf );
404 :
405 0 : fd_exec_test_instr_effects_t * effects =
406 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_instr_effects_t),
407 0 : sizeof (fd_exec_test_instr_effects_t) );
408 0 : if( FD_UNLIKELY( _l > output_end ) ) {
409 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
410 0 : return 0UL;
411 0 : }
412 0 : fd_memset( effects, 0, sizeof(fd_exec_test_instr_effects_t) );
413 :
414 : /* Capture error code */
415 :
416 0 : effects->result = -exec_result;
417 0 : effects->cu_avail = ctx->txn_ctx->compute_budget_details.compute_meter;
418 :
419 : /* Don't capture custom error codes if the program is a precompile */
420 0 : if( FD_LIKELY( effects->result ) ) {
421 0 : int program_id_idx = ctx->instr[ 0UL ].program_id;
422 0 : if( exec_result==FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR &&
423 0 : fd_executor_lookup_native_precompile_program( &ctx->txn_ctx->accounts[ program_id_idx ] )==NULL ) {
424 0 : effects->custom_err = ctx->txn_ctx->custom_err;
425 0 : }
426 0 : }
427 :
428 : /* Allocate space for captured accounts */
429 0 : ulong modified_acct_cnt = ctx->txn_ctx->accounts_cnt;
430 :
431 0 : fd_exec_test_acct_state_t * modified_accts =
432 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_acct_state_t),
433 0 : sizeof (fd_exec_test_acct_state_t) * modified_acct_cnt );
434 0 : if( FD_UNLIKELY( _l > output_end ) ) {
435 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
436 0 : return 0;
437 0 : }
438 0 : effects->modified_accounts = modified_accts;
439 0 : effects->modified_accounts_count = 0UL;
440 :
441 : /* Capture borrowed accounts */
442 :
443 0 : for( ulong j=0UL; j < ctx->txn_ctx->accounts_cnt; j++ ) {
444 0 : fd_txn_account_t * acc = &ctx->txn_ctx->accounts[j];
445 0 : if( !acc->vt->get_meta( acc ) ) {
446 0 : continue;
447 0 : }
448 :
449 0 : ulong modified_idx = effects->modified_accounts_count;
450 0 : assert( modified_idx < modified_acct_cnt );
451 :
452 0 : fd_exec_test_acct_state_t * out_acct = &effects->modified_accounts[ modified_idx ];
453 0 : memset( out_acct, 0, sizeof(fd_exec_test_acct_state_t) );
454 : /* Copy over account content */
455 :
456 0 : memcpy( out_acct->address, acc->pubkey, sizeof(fd_pubkey_t) );
457 0 : out_acct->lamports = acc->vt->get_lamports( acc );
458 0 : if( acc->vt->get_data_len( acc )>0UL ) {
459 0 : out_acct->data =
460 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(pb_bytes_array_t),
461 0 : PB_BYTES_ARRAY_T_ALLOCSIZE( acc->vt->get_data_len( acc ) ) );
462 0 : if( FD_UNLIKELY( _l > output_end ) ) {
463 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
464 0 : return 0UL;
465 0 : }
466 0 : out_acct->data->size = (pb_size_t)acc->vt->get_data_len( acc );
467 0 : fd_memcpy( out_acct->data->bytes, acc->vt->get_data( acc ), acc->vt->get_data_len( acc ) );
468 0 : }
469 :
470 0 : out_acct->executable = acc->vt->is_executable( acc );
471 0 : out_acct->rent_epoch = acc->vt->get_rent_epoch( acc );
472 0 : memcpy( out_acct->owner, acc->vt->get_owner( acc ), sizeof(fd_pubkey_t) );
473 :
474 0 : effects->modified_accounts_count++;
475 0 : }
476 :
477 : /* Capture return data */
478 0 : fd_txn_return_data_t * return_data = &ctx->txn_ctx->return_data;
479 0 : if( return_data->len>0UL ) {
480 0 : effects->return_data = FD_SCRATCH_ALLOC_APPEND(l, alignof(pb_bytes_array_t),
481 0 : PB_BYTES_ARRAY_T_ALLOCSIZE( return_data->len ) );
482 0 : if( FD_UNLIKELY( _l > output_end ) ) {
483 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
484 0 : return 0UL;
485 0 : }
486 0 : effects->return_data->size = (pb_size_t)return_data->len;
487 0 : fd_memcpy( effects->return_data->bytes, return_data->data, return_data->len );
488 0 : }
489 :
490 0 : ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL );
491 0 : fd_runtime_fuzz_instr_ctx_destroy( runner, ctx );
492 :
493 0 : *output = effects;
494 0 : return actual_end - (ulong)output_buf;
495 :
496 0 : }
|