Skip to content

Commit 48cd531

Browse files
flamenco, runtime: implement static_instruction_limit
1 parent 8922713 commit 48cd531

File tree

11 files changed

+154
-10
lines changed

11 files changed

+154
-10
lines changed

src/flamenco/features/fd_features_generated.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,12 @@ fd_feature_id_t const ids[] = {
17031703
.name = "provide_instruction_data_offset_in_vm_r2",
17041704
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },
17051705

1706+
{ .index = offsetof(fd_features_t, static_instruction_limit)>>3,
1707+
.id = {"\x4b\x3e\xa0\x91\xa9\xb6\xb5\xda\x05\x3a\x32\x6f\x7c\x18\xd9\x0d\x60\x87\x99\x76\xfb\xc6\x6f\x18\xc1\xfa\x37\x38\x94\x41\xc1\xf9"},
1708+
/* 64ixypL1HPu8WtJhNSMb9mSgfFaJvsANuRkTbHyuLfnx */
1709+
.name = "static_instruction_limit",
1710+
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },
1711+
17061712
{ .index = ULONG_MAX }
17071713
};
17081714
/* TODO replace this with fd_map_perfect */
@@ -1958,6 +1964,7 @@ fd_feature_id_query( ulong prefix ) {
19581964
case 0x8c7bee4552d93e0c: return &ids[ 246 ];
19591965
case 0x866094bbfe00a7c6: return &ids[ 247 ];
19601966
case 0x7c4802b8ba3fa849: return &ids[ 248 ];
1967+
case 0xdab5b6a991a03e4b: return &ids[ 249 ];
19611968
default: break;
19621969
}
19631970
return NULL;
@@ -2212,4 +2219,5 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, fix_alt_bn128_pairing_length_check
22122219
FD_STATIC_ASSERT( offsetof( fd_features_t, poseidon_enforce_padding )>>3==246UL, layout );
22132220
FD_STATIC_ASSERT( offsetof( fd_features_t, relax_intrabatch_account_locks )>>3==247UL, layout );
22142221
FD_STATIC_ASSERT( offsetof( fd_features_t, provide_instruction_data_offset_in_vm_r2 )>>3==248UL, layout );
2222+
FD_STATIC_ASSERT( offsetof( fd_features_t, static_instruction_limit )>>3==249UL, layout );
22152223
FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );

src/flamenco/features/fd_features_generated.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#endif
99

1010
/* FEATURE_ID_CNT is the number of features in ids */
11-
#define FD_FEATURE_ID_CNT (249UL)
11+
#define FD_FEATURE_ID_CNT (250UL)
1212

1313
/* Feature set ID calculated from all feature names */
14-
#define FD_FEATURE_SET_ID (4167120720U)
14+
#define FD_FEATURE_SET_ID (3098242546U)
1515

1616
union fd_features {
1717
ulong f[ FD_FEATURE_ID_CNT ];
@@ -265,5 +265,6 @@ union fd_features {
265265
/* 0x8c7bee4552d93e0c */ ulong poseidon_enforce_padding;
266266
/* 0x866094bbfe00a7c6 */ ulong relax_intrabatch_account_locks;
267267
/* 0x7c4802b8ba3fa849 */ ulong provide_instruction_data_offset_in_vm_r2;
268+
/* 0xdab5b6a991a03e4b */ ulong static_instruction_limit;
268269
};
269270
};

src/flamenco/features/feature_map.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,6 @@
247247
{"name":"fix_alt_bn128_pairing_length_check","pubkey":"bnYzodLwmybj7e1HAe98yZrdJTd7we69eMMLgCXqKZm"},
248248
{"name":"poseidon_enforce_padding","pubkey":"poUdAqRXXsNmfqAZ6UqpjbeYgwBygbfQLEvWSqVhSnb"},
249249
{"name":"relax_intrabatch_account_locks","pubkey":"ENTRYnPAoT5Swwx73YDGzMp3XnNH1kxacyvLosRHza1i"},
250-
{"name":"provide_instruction_data_offset_in_vm_r2","pubkey":"5xXZc66h4UdB6Yq7FzdBxBiRAFMMScMLwHxk2QZDaNZL"}
250+
{"name":"provide_instruction_data_offset_in_vm_r2","pubkey":"5xXZc66h4UdB6Yq7FzdBxBiRAFMMScMLwHxk2QZDaNZL"},
251+
{"name":"static_instruction_limit","pubkey":"64ixypL1HPu8WtJhNSMb9mSgfFaJvsANuRkTbHyuLfnx"}
251252
]

src/flamenco/runtime/Local.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ ifdef FD_HAS_HOSTED
5555
ifdef FD_HAS_SECP256K1
5656
$(call make-unit-test,test_bank,test_bank,fd_flamenco fd_funk fd_ballet fd_util)
5757
$(call run-unit-test,test_bank,)
58+
$(call make-unit-test,test_static_instruction_limit,test_static_instruction_limit,fd_flamenco fd_funk fd_ballet fd_util)
59+
$(call run-unit-test,test_static_instruction_limit,)
5860
endif
5961
endif
6062

src/flamenco/runtime/fd_executor.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,18 @@ fd_executor_check_transactions( fd_runtime_t * runtime,
401401
402402
https://github.com/anza-xyz/agave/blob/v2.3.1/runtime/src/bank.rs#L5725-L5753 */
403403
int
404-
fd_executor_verify_transaction( fd_bank_t * bank,
404+
fd_executor_verify_transaction( fd_bank_t const * bank,
405405
fd_txn_in_t const * txn_in,
406406
fd_txn_out_t * txn_out ) {
407407
int err = FD_RUNTIME_EXECUTE_SUCCESS;
408408

409+
/* SIMD-0160: enforce static limit on number of instructions.
410+
https://github.com/anza-xyz/agave/blob/v3.1.4/runtime/src/bank.rs#L4710-L4716 */
411+
if( FD_UNLIKELY( FD_FEATURE_ACTIVE_BANK( bank, static_instruction_limit ) &&
412+
TXN( txn_in->txn )->instr_cnt > FD_MAX_INSTRUCTION_TRACE_LENGTH ) ) {
413+
return FD_RUNTIME_TXN_ERR_SANITIZE_FAILURE;
414+
}
415+
409416
/* https://github.com/anza-xyz/agave/blob/v2.2.13/svm/src/transaction_processor.rs#L566-L569 */
410417
err = fd_executor_compute_budget_program_execute_instructions( bank, txn_in, txn_out );
411418
if( FD_UNLIKELY( err ) ) return err;

src/flamenco/runtime/fd_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ uchar
4040
fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey );
4141

4242
int
43-
fd_executor_verify_transaction( fd_bank_t * bank,
43+
fd_executor_verify_transaction( fd_bank_t const * bank,
4444
fd_txn_in_t const * txn_in,
4545
fd_txn_out_t * txn_out );
4646

src/flamenco/runtime/program/fd_builtin_programs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fd_num_precompiles( void ) {
336336
}
337337

338338
uchar
339-
fd_is_migrating_builtin_program( fd_bank_t * bank,
339+
fd_is_migrating_builtin_program( fd_bank_t const * bank,
340340
fd_pubkey_t const * pubkey,
341341
uchar * migrated_yet ) {
342342
*migrated_yet = 0;

src/flamenco/runtime/program/fd_builtin_programs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fd_num_stateless_builtins( void );
9595
| 1 | 1 | Program is a migrating builtin program id, AND has been migrated to BPF |
9696
*/
9797
uchar
98-
fd_is_migrating_builtin_program( fd_bank_t * bank,
98+
fd_is_migrating_builtin_program( fd_bank_t const * bank,
9999
fd_pubkey_t const * pubkey,
100100
uchar * migrated_yet );
101101

src/flamenco/runtime/program/fd_compute_budget_program.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT (3000UL)
1515

1616
FD_FN_PURE static inline uchar
17-
get_program_kind( fd_bank_t * bank,
17+
get_program_kind( fd_bank_t const * bank,
1818
fd_txn_in_t const * txn_in,
1919
fd_txn_instr_t const * instr ) {
2020
fd_acct_addr_t const * txn_accs = fd_txn_get_acct_addrs( TXN( txn_in->txn ), txn_in->txn->payload );
@@ -114,7 +114,7 @@ fd_sanitize_compute_unit_limits( fd_txn_out_t * txn_out ) {
114114
115115
https://github.com/anza-xyz/agave/blob/v2.3.1/compute-budget-instruction/src/compute_budget_instruction_details.rs#L54-L99 */
116116
int
117-
fd_executor_compute_budget_program_execute_instructions( fd_bank_t * bank,
117+
fd_executor_compute_budget_program_execute_instructions( fd_bank_t const * bank,
118118
fd_txn_in_t const * txn_in,
119119
fd_txn_out_t * txn_out ) {
120120
fd_compute_budget_details_t * details = &txn_out->details.compute_budget;

src/flamenco/runtime/program/fd_compute_budget_program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int
3030
fd_sanitize_compute_unit_limits( fd_txn_out_t * txn_out );
3131

3232
int
33-
fd_executor_compute_budget_program_execute_instructions( fd_bank_t * bank,
33+
fd_executor_compute_budget_program_execute_instructions( fd_bank_t const * bank,
3434
fd_txn_in_t const * txn_in,
3535
fd_txn_out_t * txn_out );
3636

0 commit comments

Comments
 (0)