Skip to content

Commit 3d26bbe

Browse files
committed
flamenco, fuzz: consolidate fuzzing harnesses with production code
1 parent 96b1c90 commit 3d26bbe

File tree

11 files changed

+220
-508
lines changed

11 files changed

+220
-508
lines changed

src/discof/exec/fd_exec_tile.c

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct fd_exec_tile_ctx {
7373

7474
/* Current bank being executed. */
7575
fd_banks_t * banks;
76-
fd_bank_t * bank;
7776

7877
fd_capture_ctx_t * capture_ctx;
7978
};
@@ -94,96 +93,19 @@ scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
9493
/* clang-format on */
9594
}
9695

97-
static fd_funk_txn_t *
98-
funk_txn_get( fd_exec_tile_ctx_t * ctx ) {
99-
/* Query the funk transaction for the given slot. */
100-
fd_funk_txn_map_t * txn_map = fd_funk_txn_map( ctx->funk );
101-
if( FD_UNLIKELY( !txn_map->map ) ) {
102-
FD_LOG_ERR(( "Could not find valid funk transaction map" ));
103-
}
104-
fd_funk_txn_xid_t xid = { .ul = { ctx->slot, ctx->slot } };
105-
fd_funk_txn_start_read( ctx->funk );
106-
fd_funk_txn_t * funk_txn = fd_funk_txn_query( &xid, txn_map );
107-
if( FD_UNLIKELY( !funk_txn ) ) {
108-
FD_LOG_ERR(( "Could not find valid funk transaction" ));
109-
}
110-
fd_funk_txn_end_read( ctx->funk );
111-
return funk_txn;
112-
}
113-
114-
static fd_bank_t *
115-
bank_get( fd_exec_tile_ctx_t * ctx ) {
116-
return fd_banks_get_bank( ctx->banks, ctx->slot );
117-
}
118-
11996
static void
12097
execute_txn( fd_exec_tile_ctx_t * ctx ) {
121-
122-
FD_SPAD_FRAME_BEGIN( ctx->exec_spad ) {
123-
124-
ctx->exec_res = 0;
125-
126-
ctx->txn_ctx->funk_txn = funk_txn_get( ctx );
127-
if( FD_UNLIKELY( !ctx->txn_ctx->funk_txn ) ) {
128-
FD_LOG_CRIT(( "Could not get funk transaction for slot %lu", ctx->slot ));
129-
}
130-
131-
/* Get the bank for the given slot. */
13298
fd_banks_lock( ctx->banks );
133-
ctx->bank = bank_get( ctx );
134-
if( FD_UNLIKELY( !ctx->bank ) ) {
135-
FD_LOG_CRIT(( "Could not get bank for slot %lu", ctx->slot ));
136-
}
137-
138-
/* Setup and execute the transaction. */
139-
ctx->txn_ctx->bank = ctx->bank;
140-
ctx->txn_ctx->slot = fd_bank_slot_get( ctx->bank );
141-
ctx->txn_ctx->features = fd_bank_features_get( ctx->bank );
142-
143-
fd_txn_t const * txn_descriptor = TXN( &ctx->txn );
144-
fd_rawtxn_b_t raw_txn = {
145-
.raw = ctx->txn.payload,
146-
.txn_sz = (ushort)ctx->txn.payload_sz
147-
};
148-
149-
ctx->txn.flags = FD_TXN_P_FLAGS_SANITIZE_SUCCESS;
150-
151-
fd_exec_txn_ctx_setup( ctx->txn_ctx, txn_descriptor, &raw_txn );
152-
ctx->txn_ctx->capture_ctx = ctx->capture_ctx;
153-
154-
/* Set up the core account keys. These are the account keys directly
155-
passed in via the serialized transaction, represented as an array.
156-
Note that this does not include additional keys referenced in
157-
address lookup tables. */
158-
fd_executor_setup_txn_account_keys( ctx->txn_ctx );
159-
160-
if( FD_UNLIKELY( fd_executor_txn_verify( ctx->txn_ctx )!=0 ) ) {
161-
FD_LOG_WARNING(( "sigverify failed: %s", FD_BASE58_ENC_64_ALLOCA( (uchar *)ctx->txn_ctx->_txn_raw->raw+ctx->txn_ctx->txn_descriptor->signature_off ) ));
162-
ctx->txn.flags = 0U;
163-
ctx->exec_res = FD_RUNTIME_TXN_ERR_SIGNATURE_FAILURE;
164-
fd_banks_unlock( ctx->banks );
165-
return;
166-
}
167-
168-
ctx->exec_res = fd_runtime_pre_execute_check( &ctx->txn, ctx->txn_ctx );
169-
if( FD_UNLIKELY( !( ctx->txn.flags & FD_TXN_P_FLAGS_SANITIZE_SUCCESS ) ) ) {
170-
fd_banks_unlock( ctx->banks );
171-
return;
172-
}
173-
174-
/* Execute */
175-
ctx->txn.flags |= FD_TXN_P_FLAGS_EXECUTE_SUCCESS;
176-
177-
if( FD_LIKELY( !(ctx->txn.flags & FD_TXN_P_FLAGS_FEES_ONLY) ) ) {
178-
ctx->exec_res = fd_execute_txn( ctx->txn_ctx );
179-
}
180-
181-
if( FD_LIKELY( ctx->exec_res==FD_EXECUTOR_INSTR_SUCCESS ) ) {
182-
fd_txn_reclaim_accounts( ctx->txn_ctx );
183-
}
99+
ctx->exec_res = fd_runtime_prepare_and_execute_txn(
100+
ctx->banks,
101+
ctx->txn_ctx,
102+
&ctx->txn,
103+
ctx->exec_spad,
104+
ctx->slot,
105+
ctx->capture_ctx,
106+
1
107+
);
184108
fd_banks_unlock( ctx->banks );
185-
186-
} FD_SPAD_FRAME_END;
187109
}
188110

189111
static void

src/discof/writer/fd_writer_tile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ after_frag( fd_writer_tile_ctx_t * ctx,
243243
if( FD_UNLIKELY( msg->exec_tile_id!=in_idx ) ) {
244244
FD_LOG_CRIT(( "exec_tile_id %u should be == in_idx %lu", msg->exec_tile_id, in_idx ));
245245
}
246-
fd_exec_txn_ctx_t * txn_ctx = ctx->txn_ctx[ in_idx ];
247-
int exec_res = txn_ctx->exec_err;
246+
fd_exec_txn_ctx_t * txn_ctx = ctx->txn_ctx[ in_idx ];
248247

249248
fd_banks_lock( ctx->banks );
250249
ctx->bank = fd_banks_get_bank( ctx->banks, txn_ctx->slot );
@@ -276,7 +275,6 @@ after_frag( fd_writer_tile_ctx_t * ctx,
276275
ctx->funk,
277276
ctx->funk_txn,
278277
txn_ctx,
279-
exec_res,
280278
ctx->spad,
281279
ctx->bank,
282280
ctx->capture_ctx );

src/flamenco/runtime/fd_executor.c

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,23 +1371,12 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
13711371
}
13721372

13731373
void
1374-
fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx ) {
1375-
for( ushort i=0; i<txn_ctx->accounts_cnt; i++ ) {
1376-
fd_txn_account_t * acc_rec = &txn_ctx->accounts[i];
1377-
1378-
/* An account writable iff it is writable AND it is not being
1379-
demoted. If this criteria is not met, the account should not be
1380-
marked as touched via updating its most recent slot. */
1381-
if( !fd_exec_txn_ctx_account_is_writable_idx( txn_ctx, i ) ) {
1382-
continue;
1383-
}
1384-
1385-
fd_txn_account_set_slot( acc_rec, txn_ctx->slot );
1386-
1387-
if( !fd_txn_account_get_lamports( acc_rec ) ) {
1388-
fd_txn_account_set_data_len( acc_rec, 0UL );
1389-
fd_txn_account_clear_owner( acc_rec );
1390-
}
1374+
fd_executor_reclaim_account( fd_exec_txn_ctx_t * txn_ctx,
1375+
fd_txn_account_t * account ) {
1376+
fd_txn_account_set_slot( account, txn_ctx->slot );
1377+
if( FD_UNLIKELY( fd_txn_account_get_lamports( account )==0UL ) ) {
1378+
fd_txn_account_set_data_len( account, 0UL );
1379+
fd_txn_account_clear_owner( account );
13911380
}
13921381
}
13931382

@@ -1557,34 +1546,6 @@ fd_executor_setup_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ) {
15571546
fd_executor_setup_instr_infos_from_txn_instrs( txn_ctx );
15581547
}
15591548

1560-
/* Stuff to be done before multithreading can begin */
1561-
int
1562-
fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx,
1563-
fd_exec_txn_ctx_t * txn_ctx,
1564-
fd_txn_t const * txn_descriptor,
1565-
fd_rawtxn_b_t const * txn_raw ) {
1566-
1567-
fd_funk_t * funk = slot_ctx->funk;
1568-
fd_wksp_t * funk_wksp = fd_funk_wksp( funk );
1569-
ulong funk_txn_gaddr = fd_wksp_gaddr( funk_wksp, slot_ctx->funk_txn );
1570-
ulong funk_gaddr = fd_wksp_gaddr( funk_wksp, slot_ctx->funk->shmem );
1571-
1572-
/* Init txn ctx */
1573-
fd_exec_txn_ctx_new( txn_ctx );
1574-
fd_exec_txn_ctx_from_exec_slot_ctx( slot_ctx,
1575-
txn_ctx,
1576-
funk_wksp,
1577-
funk_txn_gaddr,
1578-
funk_gaddr,
1579-
NULL );
1580-
fd_exec_txn_ctx_setup( txn_ctx, txn_descriptor, txn_raw );
1581-
1582-
/* Set up the core account keys */
1583-
fd_executor_setup_txn_account_keys( txn_ctx );
1584-
1585-
return FD_RUNTIME_EXECUTE_SUCCESS;
1586-
}
1587-
15881549
int
15891550
fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx ) {
15901551
fd_sha512_t * shas[ FD_TXN_ACTUAL_SIG_MAX ];
@@ -1607,10 +1568,10 @@ fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx ) {
16071568
/* Verify signatures */
16081569
int res = fd_ed25519_verify_batch_single_msg( msg, msg_sz, signatures, pubkeys, shas, signature_cnt );
16091570
if( FD_UNLIKELY( res != FD_ED25519_SUCCESS ) ) {
1610-
return -1;
1571+
return FD_RUNTIME_TXN_ERR_SIGNATURE_FAILURE;
16111572
}
16121573

1613-
return 0;
1574+
return FD_RUNTIME_EXECUTE_SUCCESS;
16141575
}
16151576

16161577
int

src/flamenco/runtime/fd_executor.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ int
7373
fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
7474
fd_instr_info_t * instr_info );
7575

76-
int
77-
fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx,
78-
fd_exec_txn_ctx_t * txn_ctx,
79-
fd_txn_t const * txn_descriptor,
80-
fd_rawtxn_b_t const * txn_raw );
81-
8276
/*
8377
Execute the given transaction.
8478
@@ -106,7 +100,8 @@ int
106100
fd_executor_txn_check( fd_exec_txn_ctx_t * txn_ctx );
107101

108102
void
109-
fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx );
103+
fd_executor_reclaim_account( fd_exec_txn_ctx_t * txn_ctx,
104+
fd_txn_account_t * account );
110105

111106
/* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a
112107
human readable cstr. The lifetime of the returned pointer is

0 commit comments

Comments
 (0)