Line data Source code
1 : #undef FD_SPAD_USE_HANDHOLDING
2 : #define FD_SPAD_USE_HANDHOLDING 1
3 :
4 : #include "fd_solfuzz_private.h"
5 : #include "fd_instr_harness.h"
6 : #include "../fd_executor.h"
7 : #include "../fd_runtime.h"
8 : #include "../program/fd_bpf_loader_program.h"
9 : #include "../program/fd_loader_v4_program.h"
10 : #include "../program/fd_precompiles.h"
11 : #include "../fd_system_ids.h"
12 : #include "../../accdb/fd_accdb_admin_v1.h"
13 : #include "../../log_collector/fd_log_collector.h"
14 : #include <assert.h>
15 :
16 : void
17 : fd_solfuzz_pb_instr_ctx_create( fd_solfuzz_runner_t * runner,
18 : fd_exec_instr_ctx_t * ctx,
19 : fd_exec_test_instr_context_t const * test_ctx,
20 0 : bool is_syscall ) {
21 :
22 0 : memset( ctx, 0, sizeof(fd_exec_instr_ctx_t) );
23 :
24 : /* Generate unique ID for funk txn */
25 :
26 0 : fd_funk_txn_xid_t xid[1] = {{ .ul={ LONG_MAX, LONG_MAX } }};
27 :
28 : /* Create temporary funk transaction and txn / slot / epoch contexts */
29 :
30 0 : fd_funk_txn_xid_t parent_xid; fd_funk_txn_xid_set_root( &parent_xid );
31 0 : fd_accdb_attach_child ( runner->accdb_admin, &parent_xid, xid );
32 0 : fd_progcache_txn_attach_child( runner->progcache_admin, &parent_xid, xid );
33 :
34 0 : fd_txn_in_t * txn_in = fd_spad_alloc( runner->spad, alignof(fd_txn_in_t), sizeof(fd_txn_in_t) );
35 0 : fd_txn_out_t * txn_out = fd_spad_alloc( runner->spad, alignof(fd_txn_out_t), sizeof(fd_txn_out_t) );
36 :
37 0 : fd_log_collector_t * log = fd_spad_alloc( runner->spad, alignof(fd_log_collector_t), sizeof(fd_log_collector_t) );
38 :
39 0 : fd_runtime_t * runtime = runner->runtime;
40 :
41 0 : runtime->log.log_collector = log;
42 :
43 0 : ctx->txn_out = txn_out;
44 0 : ctx->txn_in = txn_in;
45 :
46 0 : memset( txn_out->accounts.account, 0, sizeof(fd_accdb_rw_t) * MAX_TX_ACCOUNT_LOCKS );
47 :
48 0 : memset( txn_out->accounts.account, 0, sizeof(fd_accdb_rw_t) * MAX_TX_ACCOUNT_LOCKS );
49 :
50 : /* Bank manager */
51 0 : fd_banks_clear_bank( runner->banks, runner->bank, 4UL );
52 :
53 0 : fd_features_t * features = fd_bank_features_modify( runner->bank );
54 0 : fd_exec_test_feature_set_t const * feature_set = &test_ctx->epoch_context.features;
55 0 : if( !fd_solfuzz_pb_restore_features( features, feature_set ) ) {
56 0 : FD_LOG_ERR(( "invariant violation: unsupported feature ID" ));
57 0 : }
58 :
59 : /* Blockhash queue init */
60 :
61 0 : ulong blockhash_seed; FD_TEST( fd_rng_secure( &blockhash_seed, sizeof(ulong) ) );
62 0 : fd_blockhashes_t * blockhashes = fd_blockhashes_init( fd_bank_block_hash_queue_modify( runner->bank ), blockhash_seed );
63 0 : fd_memset( fd_blockhash_deq_push_tail_nocopy( blockhashes->d.deque ), 0, sizeof(fd_hash_t) );
64 :
65 : /* Set up mock txn descriptor and payload
66 : FIXME: More fields may need to be initialized. This seems to be
67 : the minimal set of fields needed to retain full context for
68 : precompile execution. */
69 0 : fd_txn_p_t * txn = fd_spad_alloc_check( runner->spad, alignof(fd_txn_p_t), sizeof(fd_txn_p_t) );
70 0 : fd_txn_t * txn_descriptor = TXN( txn );
71 0 : if( test_ctx->data ) {
72 0 : memcpy( txn->payload, test_ctx->data->bytes, test_ctx->data->size );
73 0 : txn->payload_sz = test_ctx->data->size;
74 0 : } else {
75 0 : txn->payload_sz = 0;
76 0 : }
77 0 : txn_descriptor->transaction_version = FD_TXN_VLEGACY;
78 0 : txn_descriptor->acct_addr_cnt = (ushort)test_ctx->accounts_count;
79 0 : txn_descriptor->instr_cnt = 1;
80 0 : txn_descriptor->instr[0] = (fd_txn_instr_t) {
81 0 : .acct_cnt = (ushort)test_ctx->accounts_count,
82 0 : .data_off = 0,
83 0 : .data_sz = (ushort)txn->payload_sz,
84 0 : };
85 :
86 0 : runtime->log.enable_log_collector = 0;
87 :
88 0 : fd_compute_budget_details_new( &txn_out->details.compute_budget );
89 0 : runtime->instr.stack_sz = 0;
90 0 : txn_out->accounts.cnt = 0UL;
91 0 : runtime->accounts.executable_cnt = 0UL;
92 :
93 0 : txn_out->details.programs_to_reverify_cnt = 0UL;
94 0 : txn_out->details.loaded_accounts_data_size = 0UL;
95 0 : txn_out->details.accounts_resize_delta = 0L;
96 :
97 0 : memset( txn_out->details.return_data.program_id.key, 0, sizeof(fd_pubkey_t) );
98 0 : txn_out->details.return_data.len = 0;
99 :
100 0 : runtime->log.capture_ctx = NULL;
101 0 : runtime->log.dump_proto_ctx = NULL;
102 0 : runtime->log.txn_dump_ctx = NULL;
103 :
104 0 : runtime->instr.trace_length = 1UL;
105 :
106 0 : txn_out->err.exec_err = 0;
107 0 : txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_NONE;
108 0 : runtime->instr.current_idx = 0;
109 :
110 0 : txn_in->txn = txn;
111 0 : txn_out->details.compute_budget.compute_unit_limit = test_ctx->cu_avail;
112 0 : txn_out->details.compute_budget.compute_meter = test_ctx->cu_avail;
113 0 : runtime->log.enable_vm_tracing = runner->enable_vm_tracing;
114 0 : runtime->log.tracing_mem = runner->enable_vm_tracing ?
115 0 : fd_spad_alloc_check( runner->spad, FD_RUNTIME_VM_TRACE_STATIC_ALIGN, FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT * FD_MAX_INSTRUCTION_STACK_DEPTH ) :
116 0 : NULL;
117 :
118 : /* Set up instruction context */
119 0 : fd_instr_info_t * info = &runtime->instr.trace[ 0UL ];
120 0 : memset( info, 0, sizeof(fd_instr_info_t) );
121 0 : info->stack_height = 1;
122 :
123 0 : if( test_ctx->data ) {
124 0 : if( FD_UNLIKELY( test_ctx->data->size>FD_INSTR_DATA_MAX ) ) {
125 0 : FD_LOG_ERR(( "invariant violation: instr data sz is too large %u > %lu", test_ctx->data->size, FD_INSTR_DATA_MAX ));
126 0 : }
127 0 : info->data_sz = (ushort)test_ctx->data->size;
128 0 : memcpy( info->data, test_ctx->data->bytes, info->data_sz );
129 0 : }
130 :
131 : /* Prepare borrowed account table (correctly handles aliasing) */
132 :
133 0 : if( FD_UNLIKELY( test_ctx->accounts_count > MAX_TX_ACCOUNT_LOCKS ) ) {
134 0 : FD_LOG_ERR(( "invariant violation: too many accounts (%lu > %lu)",
135 0 : (ulong)test_ctx->accounts_count, (ulong)MAX_TX_ACCOUNT_LOCKS ));
136 0 : }
137 :
138 : /* Load accounts into database */
139 :
140 0 : fd_account_meta_t * metas[MAX_TX_ACCOUNT_LOCKS] = {0};
141 0 : txn_out->accounts.cnt = test_ctx->accounts_count;
142 :
143 0 : int has_program_id = 0;
144 :
145 0 : for( ulong j=0UL; j < test_ctx->accounts_count; j++ ) {
146 0 : fd_pubkey_t * acc_key = (fd_pubkey_t *)test_ctx->accounts[j].address;
147 :
148 0 : memcpy( &(txn_out->accounts.keys[j]), test_ctx->accounts[j].address, sizeof(fd_pubkey_t) );
149 0 : runtime->accounts.refcnt[j] = 0UL;
150 :
151 0 : uchar * data = fd_spad_alloc( runner->spad, FD_ACCOUNT_REC_ALIGN, FD_ACC_TOT_SZ_MAX );
152 0 : fd_account_meta_t * meta = (fd_account_meta_t *)data;
153 0 : uint dlen = test_ctx->accounts[j].data ? test_ctx->accounts[j].data->size : 0U;
154 0 : if( test_ctx->accounts[j].data ) {
155 0 : fd_memcpy( meta+1, test_ctx->accounts[j].data->bytes, dlen );
156 0 : }
157 0 : meta->dlen = dlen;
158 0 : meta->lamports = test_ctx->accounts[j].lamports;
159 0 : meta->executable = test_ctx->accounts[j].executable;
160 0 : fd_memcpy( meta->owner, test_ctx->accounts[j].owner, sizeof(fd_pubkey_t) );
161 0 : metas[j] = meta;
162 0 : fd_accdb_rw_init_nodb( &txn_out->accounts.account[j], acc_key, metas[j], FD_RUNTIME_ACC_SZ_MAX );
163 0 : txn_out->accounts.keys[j] = *acc_key;
164 :
165 0 : if( !memcmp( acc_key, test_ctx->program_id, sizeof(fd_pubkey_t) ) ) {
166 0 : has_program_id = 1;
167 0 : info->program_id = (uchar)txn_out->accounts.cnt;
168 0 : }
169 0 : }
170 :
171 : /* If the program id is not in the set of accounts it must be added to the set of accounts. */
172 0 : if( FD_UNLIKELY( !has_program_id ) ) {
173 0 : fd_pubkey_t * program_key = &txn_out->accounts.keys[ txn_out->accounts.cnt ];
174 0 : memcpy( program_key, test_ctx->program_id, sizeof(fd_pubkey_t) );
175 :
176 0 : fd_account_meta_t * meta = fd_spad_alloc( runner->spad, alignof(fd_account_meta_t), sizeof(fd_account_meta_t) );
177 0 : fd_account_meta_init( meta );
178 :
179 0 : txn_out->accounts.account[test_ctx->accounts_count].meta = meta;
180 :
181 0 : info->program_id = (uchar)txn_out->accounts.cnt;
182 0 : txn_out->accounts.cnt++;
183 0 : }
184 :
185 : /* Load in executable accounts */
186 0 : for( ulong i = 0; i < txn_out->accounts.cnt; i++ ) {
187 :
188 0 : fd_account_meta_t * meta = txn_out->accounts.account[i].meta;
189 0 : if( !fd_executor_pubkey_is_bpf_loader( fd_type_pun( meta->owner ) ) ) {
190 0 : continue;
191 0 : }
192 :
193 0 : if( FD_UNLIKELY( !memcmp( meta->owner, fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t) ) ) ) {
194 0 : fd_bpf_upgradeable_loader_state_t program_loader_state[1];
195 0 : int err = fd_bpf_loader_program_get_state( meta, program_loader_state );
196 0 : if( FD_UNLIKELY( err!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
197 0 : continue;
198 0 : }
199 :
200 0 : if( !fd_bpf_upgradeable_loader_state_is_program( program_loader_state ) ) {
201 0 : continue;
202 0 : }
203 :
204 0 : fd_pubkey_t * programdata_acc = &program_loader_state->inner.program.programdata_address;
205 :
206 0 : meta = NULL;
207 0 : for( ulong j=0UL; j<test_ctx->accounts_count; j++ ) {
208 0 : if( !memcmp( test_ctx->accounts[j].address, programdata_acc, sizeof(fd_pubkey_t) ) ) {
209 0 : meta = txn_out->accounts.account[j].meta;
210 0 : break;
211 0 : }
212 0 : }
213 0 : if( FD_UNLIKELY( meta==NULL ) ) {
214 0 : continue;
215 0 : }
216 :
217 0 : FD_TEST( runtime->accounts.executable_cnt < MAX_TX_ACCOUNT_LOCKS );
218 0 : fd_accdb_ro_t * ro = &runtime->accounts.executable[ runtime->accounts.executable_cnt ];
219 0 : fd_accdb_ro_init_nodb( ro, programdata_acc, meta );
220 0 : runtime->accounts.executable_cnt++;
221 0 : } else if( FD_UNLIKELY( !memcmp( meta->owner, fd_solana_bpf_loader_program_id.key, sizeof(fd_pubkey_t) ) ||
222 0 : !memcmp( meta->owner, fd_solana_bpf_loader_deprecated_program_id.key, sizeof(fd_pubkey_t) ) ) ) {
223 0 : meta = txn_out->accounts.account[i].meta;
224 0 : } else if( !memcmp( meta->owner, fd_solana_bpf_loader_v4_program_id.key, sizeof(fd_pubkey_t) ) ) {
225 0 : int err;
226 0 : fd_loader_v4_state_t const * state = fd_loader_v4_get_state( fd_account_data( meta ), meta->dlen, &err );
227 0 : if( FD_UNLIKELY( err ) ) {
228 0 : continue;
229 0 : }
230 :
231 : /* The program must be deployed or finalized. */
232 0 : if( FD_UNLIKELY( fd_loader_v4_status_is_retracted( state ) ) ) {
233 0 : continue;
234 0 : }
235 0 : meta = txn_out->accounts.account[i].meta;
236 0 : }
237 :
238 0 : FD_SPAD_FRAME_BEGIN( runner->spad ) {
239 0 : uchar * scratch = fd_spad_alloc( runner->spad, FD_FUNK_REC_ALIGN, meta->dlen );
240 0 : fd_progcache_inject_rec( runner->progcache_admin,
241 0 : &txn_out->accounts.keys[i],
242 0 : meta,
243 0 : features,
244 0 : fd_bank_slot_get( runner->bank ),
245 0 : scratch,
246 0 : meta->dlen );
247 0 : } FD_SPAD_FRAME_END;
248 0 : }
249 :
250 0 : fd_funk_txn_xid_t exec_xid[1] = {{ .ul={ fd_bank_slot_get( runner->bank ), runner->bank->data->idx } }};
251 0 : fd_accdb_attach_child ( runner->accdb_admin, xid, exec_xid );
252 0 : fd_progcache_txn_attach_child( runner->progcache_admin, xid, exec_xid );
253 :
254 : /* Load instruction accounts */
255 :
256 0 : if( FD_UNLIKELY( test_ctx->instr_accounts_count > FD_INSTR_ACCT_MAX ) ) {
257 0 : FD_LOG_ERR(( "invariant violation: too many instruction accounts (%lu > %lu)",
258 0 : (ulong)test_ctx->instr_accounts_count, (ulong)FD_INSTR_ACCT_MAX ));
259 0 : }
260 :
261 : /* Restore sysvar cache */
262 0 : fd_sysvar_cache_t * sysvar_cache = fd_bank_sysvar_cache_modify( runner->bank );
263 0 : ctx->sysvar_cache = sysvar_cache;
264 0 : for( ulong i=0UL; i<txn_out->accounts.cnt; i++ ) {
265 0 : fd_sysvar_cache_restore_from_ref( sysvar_cache, txn_out->accounts.account[i].ro );
266 0 : }
267 :
268 0 : ctx->runtime = runtime;
269 :
270 0 : fd_sol_sysvar_clock_t clock_[1];
271 0 : fd_sol_sysvar_clock_t * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, clock_ );
272 0 : FD_TEST( clock );
273 0 : fd_bank_slot_set( runner->bank, clock->slot );
274 :
275 0 : fd_epoch_schedule_t epoch_schedule_[1];
276 0 : fd_epoch_schedule_t * epoch_schedule = fd_sysvar_cache_epoch_schedule_read( ctx->sysvar_cache, epoch_schedule_ );
277 0 : FD_TEST( epoch_schedule );
278 0 : fd_bank_epoch_schedule_set( runner->bank, *epoch_schedule );
279 :
280 0 : fd_rent_t rent_[1];
281 0 : fd_rent_t * rent = fd_sysvar_cache_rent_read( ctx->sysvar_cache, rent_ );
282 0 : FD_TEST( rent );
283 0 : fd_bank_rent_set( runner->bank, *rent );
284 :
285 0 : fd_block_block_hash_entry_t const * deq = fd_sysvar_cache_recent_hashes_join_const( ctx->sysvar_cache );
286 0 : FD_TEST( deq );
287 0 : if( !deq_fd_block_block_hash_entry_t_empty( deq ) ) {
288 0 : fd_block_block_hash_entry_t const * last = deq_fd_block_block_hash_entry_t_peek_tail_const( deq );
289 0 : if( last ) {
290 0 : fd_blockhashes_t * blockhashes = fd_bank_block_hash_queue_modify( runner->bank );
291 0 : fd_blockhashes_pop_new( blockhashes );
292 0 : fd_blockhash_info_t * info = fd_blockhashes_push_new( blockhashes, &last->blockhash );
293 0 : info->fee_calculator = last->fee_calculator;
294 :
295 0 : fd_bank_rbh_lamports_per_sig_set( runner->bank, last->fee_calculator.lamports_per_signature );
296 0 : }
297 0 : }
298 0 : fd_sysvar_cache_recent_hashes_leave_const( ctx->sysvar_cache, deq );
299 :
300 0 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0};
301 0 : for( ulong j=0UL; j < test_ctx->instr_accounts_count; j++ ) {
302 0 : uint index = test_ctx->instr_accounts[j].index;
303 0 : if( index >= test_ctx->accounts_count ) {
304 0 : FD_LOG_ERR(( "invariant violation: instruction account index out of range (%u > %u)",
305 0 : index, test_ctx->instr_accounts_count ));
306 0 : }
307 :
308 : /* Setup instruction accounts */
309 0 : fd_instr_info_setup_instr_account( info,
310 0 : acc_idx_seen,
311 0 : (ushort)index,
312 0 : (ushort)j,
313 0 : (ushort)j,
314 0 : test_ctx->instr_accounts[j].is_writable,
315 0 : test_ctx->instr_accounts[j].is_signer );
316 0 : }
317 0 : info->acct_cnt = (ushort)test_ctx->instr_accounts_count;
318 :
319 : /* The remaining checks enforce that the program is in the accounts list. */
320 0 : bool found_program_id = false;
321 0 : for( uint i = 0; i < test_ctx->accounts_count; i++ ) {
322 0 : if( 0 == memcmp( test_ctx->accounts[i].address, test_ctx->program_id, sizeof(fd_pubkey_t) ) ) {
323 0 : info->program_id = (uchar) i;
324 0 : found_program_id = true;
325 0 : break;
326 0 : }
327 0 : }
328 :
329 : /* For non-syscalls (instruction execution), program_id must be in the input accounts.
330 : For syscalls, we skip this check because the program_id was already added to
331 : txn_out->accounts at lines 169-181 if it wasn't in the input. */
332 0 : if( !is_syscall && !found_program_id ) {
333 0 : FD_LOG_ERR(( "invariant violation: Unable to find program_id in accounts" ));
334 0 : }
335 :
336 0 : ctx->instr = info;
337 0 : ctx->runtime->progcache = runner->progcache;
338 0 : ctx->runtime->accdb = runner->accdb;
339 :
340 0 : runtime->log.enable_log_collector = 0;
341 :
342 0 : fd_log_collector_init( ctx->runtime->log.log_collector, 1 );
343 0 : fd_base58_encode_32( txn_out->accounts.keys[ ctx->instr->program_id ].uc, NULL, ctx->program_id_base58 );
344 0 : }
345 :
346 : void
347 : fd_solfuzz_pb_instr_ctx_destroy( fd_solfuzz_runner_t * runner,
348 0 : fd_exec_instr_ctx_t * ctx ) {
349 0 : if( !ctx ) return;
350 0 : fd_accdb_v1_clear( runner->accdb_admin );
351 0 : fd_progcache_clear( runner->progcache_admin );
352 :
353 : /* In order to check for leaks in the workspace, we need to compact the
354 : allocators. Without doing this, empty superblocks may be retained
355 : by the fd_alloc instance, which mean we cannot check for leaks. */
356 0 : fd_alloc_compact( fd_accdb_admin_v1_funk( runner->accdb_admin )->alloc );
357 0 : fd_alloc_compact( runner->progcache_admin->funk->alloc );
358 0 : }
359 :
360 : ulong
361 : fd_solfuzz_pb_instr_run( fd_solfuzz_runner_t * runner,
362 : void const * input_,
363 : void ** output_,
364 : void * output_buf,
365 0 : ulong output_bufsz ) {
366 0 : fd_exec_test_instr_context_t const * input = fd_type_pun_const( input_ );
367 0 : fd_exec_test_instr_effects_t ** output = fd_type_pun( output_ );
368 :
369 : /* Convert the Protobuf inputs to a fd_exec context */
370 0 : fd_exec_instr_ctx_t ctx[1];
371 0 : fd_solfuzz_pb_instr_ctx_create( runner, ctx, input, false );
372 :
373 0 : fd_instr_info_t * instr = (fd_instr_info_t *) ctx->instr;
374 :
375 : /* Execute the test */
376 0 : int exec_result = fd_execute_instr( ctx->runtime, runner->bank, ctx->txn_in, ctx->txn_out, instr );
377 :
378 : /* Allocate space to capture outputs */
379 0 : ulong output_end = (ulong)output_buf + output_bufsz;
380 0 : FD_SCRATCH_ALLOC_INIT( l, output_buf );
381 :
382 0 : fd_exec_test_instr_effects_t * effects =
383 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_instr_effects_t),
384 0 : sizeof (fd_exec_test_instr_effects_t) );
385 0 : if( FD_UNLIKELY( _l > output_end ) ) {
386 0 : fd_solfuzz_pb_instr_ctx_destroy( runner, ctx );
387 0 : return 0UL;
388 0 : }
389 0 : fd_memset( effects, 0, sizeof(fd_exec_test_instr_effects_t) );
390 :
391 : /* Capture error code */
392 :
393 0 : effects->result = -exec_result;
394 0 : effects->cu_avail = ctx->txn_out->details.compute_budget.compute_meter;
395 :
396 : /* Don't capture custom error codes if the program is a precompile */
397 0 : if( FD_LIKELY( effects->result ) ) {
398 0 : int program_id_idx = ctx->instr[ 0UL ].program_id;
399 0 : if( exec_result==FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR &&
400 0 : fd_executor_lookup_native_precompile_program( &ctx->txn_out->accounts.keys[ program_id_idx ] )==NULL ) {
401 0 : effects->custom_err = ctx->txn_out->err.custom_err;
402 0 : }
403 0 : }
404 :
405 : /* Allocate space for captured accounts */
406 0 : ulong modified_acct_cnt = ctx->txn_out->accounts.cnt;
407 :
408 0 : fd_exec_test_acct_state_t * modified_accts =
409 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_acct_state_t),
410 0 : sizeof (fd_exec_test_acct_state_t) * modified_acct_cnt );
411 0 : if( FD_UNLIKELY( _l > output_end ) ) {
412 0 : fd_solfuzz_pb_instr_ctx_destroy( runner, ctx );
413 0 : return 0;
414 0 : }
415 0 : effects->modified_accounts = modified_accts;
416 0 : effects->modified_accounts_count = 0UL;
417 :
418 : /* Capture borrowed accounts */
419 :
420 0 : for( ulong j=0UL; j < ctx->txn_out->accounts.cnt; j++ ) {
421 0 : fd_pubkey_t * acc_key = &ctx->txn_out->accounts.keys[j];
422 0 : fd_account_meta_t * acc = ctx->txn_out->accounts.account[j].meta;
423 0 : if( !acc ) {
424 0 : continue;
425 0 : }
426 :
427 0 : ulong modified_idx = effects->modified_accounts_count;
428 0 : assert( modified_idx < modified_acct_cnt );
429 :
430 0 : fd_exec_test_acct_state_t * out_acct = &effects->modified_accounts[ modified_idx ];
431 0 : memset( out_acct, 0, sizeof(fd_exec_test_acct_state_t) );
432 : /* Copy over account content */
433 :
434 0 : memcpy( out_acct->address, acc_key, sizeof(fd_pubkey_t) );
435 0 : out_acct->lamports = acc->lamports;
436 0 : if( acc->dlen>0UL ) {
437 0 : out_acct->data =
438 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(pb_bytes_array_t),
439 0 : PB_BYTES_ARRAY_T_ALLOCSIZE( acc->dlen ) );
440 0 : if( FD_UNLIKELY( _l > output_end ) ) {
441 0 : fd_solfuzz_pb_instr_ctx_destroy( runner, ctx );
442 0 : return 0UL;
443 0 : }
444 0 : out_acct->data->size = (pb_size_t)acc->dlen;
445 0 : fd_memcpy( out_acct->data->bytes, fd_account_data( acc ), acc->dlen );
446 0 : }
447 :
448 0 : out_acct->executable = acc->executable;
449 0 : memcpy( out_acct->owner, acc->owner, sizeof(fd_pubkey_t) );
450 :
451 0 : effects->modified_accounts_count++;
452 0 : }
453 :
454 : /* Capture return data */
455 0 : fd_txn_return_data_t * return_data = &ctx->txn_out->details.return_data;
456 0 : if( return_data->len>0UL ) {
457 0 : effects->return_data = FD_SCRATCH_ALLOC_APPEND(l, alignof(pb_bytes_array_t),
458 0 : PB_BYTES_ARRAY_T_ALLOCSIZE( return_data->len ) );
459 0 : if( FD_UNLIKELY( _l > output_end ) ) {
460 0 : fd_solfuzz_pb_instr_ctx_destroy( runner, ctx );
461 0 : return 0UL;
462 0 : }
463 0 : effects->return_data->size = (pb_size_t)return_data->len;
464 0 : fd_memcpy( effects->return_data->bytes, return_data->data, return_data->len );
465 0 : }
466 :
467 0 : ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL );
468 0 : fd_solfuzz_pb_instr_ctx_destroy( runner, ctx );
469 :
470 0 : *output = effects;
471 0 : return actual_end - (ulong)output_buf;
472 0 : }
|