Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_executor_h
2 : #define HEADER_fd_src_flamenco_runtime_fd_executor_h
3 :
4 : #include "info/fd_instr_info.h"
5 : #include "../../util/spad/fd_spad.h"
6 : #include "../../disco/fd_txn_p.h"
7 : #include "sysvar/fd_sysvar_rent.h"
8 :
9 : /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L40-L47 */
10 2076 : #define FD_TRANSACTION_ACCOUNT_BASE_SIZE (64UL)
11 483 : #define FD_ADDRESS_LOOKUP_TABLE_BASE_SIZE (8248UL)
12 :
13 2571 : #define FD_FEE_PAYER_TXN_IDX (0UL)
14 :
15 : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx
16 : and fails in case of error. */
17 324 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do { \
18 324 : fd_exec_instr_ctx_t * _ctx = (ctx); \
19 324 : int err = fd_executor_consume_cus( _ctx->txn_out, (cost) ); \
20 324 : if( FD_UNLIKELY( err ) ) return err; \
21 324 : } while(0)
22 :
23 : // https://github.com/anza-xyz/agave/blob/2e6ca8c1f62db62c1db7f19c9962d4db43d0d550/sdk/src/fee.rs#L82
24 1008 : #define FD_ACCOUNT_DATA_COST_PAGE_SIZE ( 32UL * 1024UL )
25 :
26 : FD_PROTOTYPES_BEGIN
27 :
28 : /* fd_exec_instr_fn_t processes an instruction. Returns an error code
29 : in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */
30 :
31 : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx );
32 :
33 : /* Returns 1 if the given pubkey matches one of the BPF loader v1/v2/v3/v4
34 : program IDs, and 0 otherwise. */
35 : uchar
36 : fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey );
37 :
38 : int
39 : fd_executor_sanitize_txn_v1_config( fd_txn_in_t const * txn_in,
40 : fd_txn_out_t * txn_out );
41 :
42 : int
43 : fd_executor_verify_transaction( fd_bank_t const * bank,
44 : fd_txn_in_t const * txn_in,
45 : fd_txn_out_t * txn_out );
46 :
47 : int
48 : fd_executor_check_transactions( fd_runtime_t * runtime,
49 : fd_bank_t * bank,
50 : fd_txn_in_t const * txn_in,
51 : fd_txn_out_t * txn_out );
52 :
53 : /* fd_executor_txn_verify verifies the signatures of txn_p. If cache
54 : is non-NULL, it is used to speed up verification (the result is the
55 : same either way). */
56 : int
57 : fd_executor_txn_verify( fd_txn_p_t * txn_p,
58 : fd_sha512_t * shas[ FD_TXN_SIG_MAX ],
59 : fd_ed25519_cache_t * cache );
60 :
61 : /* https://github.com/anza-xyz/agave/blob/v4.2.0-beta.0/svm/src/rent_calculator.rs#L144-L178 */
62 : int
63 : fd_executor_check_static_account_rent_state_transition( ulong pre_exec_balance,
64 : ulong post_exec_balance,
65 : ulong data_size,
66 : fd_rent_t const * rent,
67 : int relax_post_exec_min_balance_check );
68 :
69 : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs
70 : instruction processing. Returns an error code in
71 : FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}.
72 :
73 : IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can
74 : be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to
75 : acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */
76 :
77 : int
78 : fd_execute_instr( fd_runtime_t * runtime,
79 : fd_bank_t * bank,
80 : fd_txn_in_t const * txn_in,
81 : fd_txn_out_t * txn_out,
82 : fd_instr_info_t * instr_info );
83 :
84 : /*
85 : Execute the given transaction.
86 :
87 : Makes changes to the accounts DB. */
88 : int
89 : fd_execute_txn( fd_runtime_t * runtime,
90 : fd_bank_t * bank,
91 : fd_txn_in_t const * txn_in,
92 : fd_txn_out_t * txn_out );
93 :
94 : int
95 : fd_executor_validate_transaction_fee_payer( fd_bank_t * bank,
96 : fd_txn_in_t const * txn_in,
97 : fd_txn_out_t * txn_out );
98 :
99 : int
100 : fd_executor_setup_accounts_for_txn( fd_runtime_t * runtime,
101 : fd_bank_t * bank,
102 : fd_txn_in_t const * txn_in,
103 : fd_txn_out_t * txn_out );
104 :
105 : void
106 : fd_executor_setup_accounts_for_txn_bundle( fd_runtime_t * runtime,
107 : fd_txn_in_t const * txn_in,
108 : fd_txn_out_t * txn_out );
109 :
110 : int
111 : fd_executor_setup_txn_alut_account_keys( fd_runtime_t * runtime,
112 : fd_bank_t * bank,
113 : fd_txn_in_t const * txn_in,
114 : fd_txn_out_t * txn_out );
115 :
116 : /* fd_executor_instr_strerror converts an FD_EXECUTOR_INSTR_ERR_{...}
117 : code into a human readable cstr. The lifetime of the returned
118 : pointer is infinite and the call itself is thread safe. The
119 : returned pointer is always to a non-NULL cstr. */
120 :
121 : FD_FN_CONST char const *
122 : fd_executor_instr_strerror( int err );
123 :
124 : int
125 : fd_executor_load_transaction_accounts( fd_bank_t * bank,
126 : fd_txn_in_t const * txn_in,
127 : fd_txn_out_t * txn_out );
128 :
129 : int
130 : fd_executor_validate_account_locks( fd_txn_out_t const * txn_out );
131 :
132 : int
133 : fd_executor_consume_cus( fd_txn_out_t * txn_out,
134 : ulong cus );
135 :
136 : /* We expose these only for the fuzzing harness.
137 : Normally you shouldn't be invoking these manually. */
138 : int
139 : fd_instr_stack_push( fd_runtime_t * runtime,
140 : fd_txn_in_t const * txn_in,
141 : fd_txn_out_t * txn_out,
142 : fd_instr_info_t * instr );
143 :
144 : int
145 : fd_instr_stack_pop( fd_runtime_t * runtime,
146 : fd_txn_out_t * txn_out,
147 : fd_instr_info_t const * instr );
148 :
149 : int
150 : fd_execute_instr_end( fd_exec_instr_ctx_t * instr_ctx,
151 : fd_instr_info_t const * instr,
152 : int instr_exec_result );
153 :
154 : FD_PROTOTYPES_END
155 :
156 : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */
|