Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_program_fd_bpf_loader_program_h
2 : #define HEADER_fd_src_flamenco_runtime_program_fd_bpf_loader_program_h
3 :
4 : /* fd_bpf_loader_v3_program.h is the third version of the BPF loader
5 : program.
6 :
7 : Address: BPFLoaderUpgradeab1e11111111111111111111111 */
8 :
9 : #include "../../progcache/fd_progcache_rec.h"
10 : #include "../../features/fd_features.h"
11 : #include "../../../funk/fd_funk_base.h"
12 :
13 : /* https://github.com/anza-xyz/agave/blob/77daab497df191ef485a7ad36ed291c1874596e5/programs/bpf_loader/src/lib.rs#L67-L69 */
14 : #define DEFAULT_LOADER_COMPUTE_UNITS (570UL )
15 : #define DEPRECATED_LOADER_COMPUTE_UNITS (1140UL)
16 : #define UPGRADEABLE_LOADER_COMPUTE_UNITS (2370UL)
17 :
18 : /* https://github.com/anza-xyz/agave/blob/77daab497df191ef485a7ad36ed291c1874596e5/sdk/program/src/bpf_loader_upgradeable.rs#L29-L120 */
19 3 : #define SIZE_OF_PROGRAM (36UL ) /* UpgradeableLoaderState::size_of_program() */
20 9 : #define BUFFER_METADATA_SIZE (37UL ) /* UpgradeableLoaderState::size_of_buffer_metadata() */
21 147 : #define PROGRAMDATA_METADATA_SIZE (45UL ) /* UpgradeableLoaderState::size_of_programdata_metadata() */
22 9 : #define SIZE_OF_UNINITIALIZED (4UL ) /* UpgradeableLoaderState::size_of_uninitialized() */
23 :
24 : /* InstructionError conversions
25 : https://github.com/anza-xyz/agave/blob/ced98f1ebe73f7e9691308afa757323003ff744f/sdk/program/src/program_error.rs#L127-L160 */
26 51 : #define BUILTIN_BIT_SHIFT (32UL)
27 :
28 0 : #define CUSTOM_ZERO ((1UL) << BUILTIN_BIT_SHIFT)
29 0 : #define INVALID_ARGUMENT ((2UL) << BUILTIN_BIT_SHIFT)
30 0 : #define INVALID_INSTRUCTION_DATA ((3UL) << BUILTIN_BIT_SHIFT)
31 0 : #define INVALID_ACCOUNT_DATA ((4UL) << BUILTIN_BIT_SHIFT)
32 0 : #define ACCOUNT_DATA_TOO_SMALL ((5UL) << BUILTIN_BIT_SHIFT)
33 0 : #define INSUFFICIENT_FUNDS ((6UL) << BUILTIN_BIT_SHIFT)
34 0 : #define INCORRECT_PROGRAM_ID ((7UL) << BUILTIN_BIT_SHIFT)
35 0 : #define MISSING_REQUIRED_SIGNATURES ((8UL) << BUILTIN_BIT_SHIFT)
36 0 : #define ACCOUNT_ALREADY_INITIALIZED ((9UL) << BUILTIN_BIT_SHIFT)
37 0 : #define UNINITIALIZED_ACCOUNT ((10UL) << BUILTIN_BIT_SHIFT)
38 0 : #define NOT_ENOUGH_ACCOUNT_KEYS ((11UL) << BUILTIN_BIT_SHIFT)
39 0 : #define ACCOUNT_BORROW_FAILED ((12UL) << BUILTIN_BIT_SHIFT)
40 0 : #define MAX_SEED_LENGTH_EXCEEDED ((13UL) << BUILTIN_BIT_SHIFT)
41 0 : #define INVALID_SEEDS ((14UL) << BUILTIN_BIT_SHIFT)
42 0 : #define BORSH_IO_ERROR ((15UL) << BUILTIN_BIT_SHIFT)
43 0 : #define ACCOUNT_NOT_RENT_EXEMPT ((16UL) << BUILTIN_BIT_SHIFT)
44 0 : #define UNSUPPORTED_SYSVAR ((17UL) << BUILTIN_BIT_SHIFT)
45 0 : #define ILLEGAL_OWNER ((18UL) << BUILTIN_BIT_SHIFT)
46 0 : #define MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED ((19UL) << BUILTIN_BIT_SHIFT)
47 0 : #define INVALID_ACCOUNT_DATA_REALLOC ((20UL) << BUILTIN_BIT_SHIFT)
48 0 : #define MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED ((21UL) << BUILTIN_BIT_SHIFT)
49 0 : #define BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS ((22UL) << BUILTIN_BIT_SHIFT)
50 0 : #define INVALID_ACCOUNT_OWNER ((23UL) << BUILTIN_BIT_SHIFT)
51 0 : #define ARITHMETIC_OVERFLOW ((24UL) << BUILTIN_BIT_SHIFT)
52 0 : #define IMMUTABLE ((25UL) << BUILTIN_BIT_SHIFT)
53 0 : #define INCORRECT_AUTHORITY ((26UL) << BUILTIN_BIT_SHIFT)
54 :
55 : /* UpgradeableLoaderInstruction wire format (u32 discriminant).
56 :
57 : https://github.com/anza-xyz/agave/blob/v2.2.6/sdk/program/src/bpf_loader_upgradeable.rs */
58 :
59 0 : #define FD_BPF_INSTR_INITIALIZE_BUFFER (0U)
60 0 : #define FD_BPF_INSTR_WRITE (1U)
61 0 : #define FD_BPF_INSTR_DEPLOY_WITH_MAX_DATA_LEN (2U)
62 0 : #define FD_BPF_INSTR_UPGRADE (3U)
63 0 : #define FD_BPF_INSTR_SET_AUTHORITY (4U)
64 24 : #define FD_BPF_INSTR_CLOSE (5U)
65 0 : #define FD_BPF_INSTR_EXTEND_PROGRAM (6U)
66 12 : #define FD_BPF_INSTR_SET_AUTHORITY_CHECKED (7U)
67 12 : #define FD_BPF_INSTR_MIGRATE (8U)
68 0 : #define FD_BPF_INSTR_EXTEND_PROGRAM_CHECKED (9U)
69 :
70 : /* Per-variant payload structs.
71 :
72 : The `write` variant uses zero-copy for its `bytes` field: after a
73 : successful decode `bytes` points directly into the caller-owned
74 : instruction buffer, and the caller must keep that buffer alive for
75 : the lifetime of the decoded struct. */
76 :
77 : struct fd_bpf_instruction_write {
78 : uint offset;
79 : uchar const * bytes;
80 : ulong bytes_len;
81 : };
82 : typedef struct fd_bpf_instruction_write fd_bpf_instruction_write_t;
83 :
84 : struct fd_bpf_instruction_deploy_with_max_data_len {
85 : ulong max_data_len;
86 : };
87 : typedef struct fd_bpf_instruction_deploy_with_max_data_len fd_bpf_instruction_deploy_with_max_data_len_t;
88 :
89 : struct fd_bpf_instruction_extend_program {
90 : uint additional_bytes;
91 : };
92 : typedef struct fd_bpf_instruction_extend_program fd_bpf_instruction_extend_program_t;
93 :
94 : struct fd_bpf_instruction_extend_program_checked {
95 : uint additional_bytes;
96 : };
97 : typedef struct fd_bpf_instruction_extend_program_checked fd_bpf_instruction_extend_program_checked_t;
98 :
99 : union fd_bpf_instruction_inner {
100 : fd_bpf_instruction_write_t write;
101 : fd_bpf_instruction_deploy_with_max_data_len_t deploy_with_max_data_len;
102 : fd_bpf_instruction_extend_program_t extend_program;
103 : fd_bpf_instruction_extend_program_checked_t extend_program_checked;
104 : };
105 : typedef union fd_bpf_instruction_inner fd_bpf_instruction_inner_t;
106 :
107 : struct fd_bpf_instruction {
108 : uint discriminant;
109 : fd_bpf_instruction_inner_t inner;
110 : };
111 : typedef struct fd_bpf_instruction fd_bpf_instruction_t;
112 :
113 : /* UpgradeableLoaderState wire format (u32 discriminant).
114 :
115 : https://github.com/anza-xyz/agave/blob/v2.2.6/sdk/program/src/bpf_loader_upgradeable.rs */
116 :
117 24 : #define FD_BPF_STATE_UNINITIALIZED (0U)
118 45 : #define FD_BPF_STATE_BUFFER (1U)
119 54 : #define FD_BPF_STATE_PROGRAM (2U)
120 63 : #define FD_BPF_STATE_PROGRAM_DATA (3U)
121 :
122 : /* State struct field layout MUST be preserved: callers initialize and
123 : read these fields by name (e.g. `state.inner.buffer.has_authority_address`,
124 : `state.inner.program.programdata_address`, etc). */
125 :
126 : struct fd_bpf_state_buffer {
127 : fd_pubkey_t authority_address;
128 : uchar has_authority_address;
129 : };
130 : typedef struct fd_bpf_state_buffer fd_bpf_state_buffer_t;
131 :
132 : struct fd_bpf_state_program {
133 : fd_pubkey_t programdata_address;
134 : };
135 : typedef struct fd_bpf_state_program fd_bpf_state_program_t;
136 :
137 : struct fd_bpf_state_program_data {
138 : ulong slot;
139 : fd_pubkey_t upgrade_authority_address;
140 : uchar has_upgrade_authority_address;
141 : };
142 : typedef struct fd_bpf_state_program_data fd_bpf_state_program_data_t;
143 :
144 : union fd_bpf_state_inner {
145 : fd_bpf_state_buffer_t buffer;
146 : fd_bpf_state_program_t program;
147 : fd_bpf_state_program_data_t program_data;
148 : };
149 : typedef union fd_bpf_state_inner fd_bpf_state_inner_t;
150 :
151 : struct fd_bpf_state {
152 : uint discriminant;
153 : fd_bpf_state_inner_t inner;
154 : };
155 : typedef struct fd_bpf_state fd_bpf_state_t;
156 :
157 : /* fd_bpf_instruction_decode parses a bincode-encoded
158 : UpgradeableLoaderInstruction from [data, data+data_sz).
159 : Variable-length fields (`write.bytes`) point directly into `data`, so
160 : callers must keep that buffer alive. Trailing bytes beyond the parsed
161 : region are accepted (matches Agave's default `allow_trailing_bytes()`).
162 : Returns 0 on success, -1 on malformed input. */
163 :
164 : static inline int
165 : fd_bpf_instruction_decode( fd_bpf_instruction_t * out,
166 : uchar const * data,
167 6 : ulong data_sz ) {
168 6 : uchar const * _payload = data;
169 6 : ulong const _payload_sz = data_sz;
170 6 : ulong _i = 0UL;
171 :
172 6 : # define CHECK( cond ) { if( FD_UNLIKELY( !(cond) ) ) { return -1; } }
173 6 : # define CHECK_LEFT( n ) CHECK( (n)<=(_payload_sz-_i) )
174 6 : # define INC( n ) (_i += (ulong)(n))
175 6 : # define CURSOR (_payload+_i)
176 :
177 6 : CHECK_LEFT( 4UL );
178 6 : uint disc = FD_LOAD( uint, CURSOR ); INC( 4UL );
179 6 : out->discriminant = disc;
180 :
181 6 : switch( disc ) {
182 :
183 0 : case FD_BPF_INSTR_WRITE: {
184 0 : fd_bpf_instruction_write_t * w = &out->inner.write;
185 0 : CHECK_LEFT( 4UL ); w->offset = FD_LOAD( uint, CURSOR ); INC( 4UL );
186 0 : CHECK_LEFT( 8UL ); w->bytes_len = FD_LOAD( ulong, CURSOR ); INC( 8UL );
187 0 : CHECK_LEFT( w->bytes_len );
188 0 : w->bytes = w->bytes_len ? CURSOR : NULL;
189 0 : INC( w->bytes_len );
190 0 : return 0;
191 0 : }
192 :
193 0 : case FD_BPF_INSTR_DEPLOY_WITH_MAX_DATA_LEN: {
194 0 : fd_bpf_instruction_deploy_with_max_data_len_t * d = &out->inner.deploy_with_max_data_len;
195 0 : CHECK_LEFT( 8UL );
196 0 : d->max_data_len = FD_LOAD( ulong, CURSOR ); INC( 8UL );
197 0 : return 0;
198 0 : }
199 :
200 0 : case FD_BPF_INSTR_EXTEND_PROGRAM: {
201 0 : fd_bpf_instruction_extend_program_t * e = &out->inner.extend_program;
202 0 : CHECK_LEFT( 4UL );
203 0 : e->additional_bytes = FD_LOAD( uint, CURSOR ); INC( 4UL );
204 0 : return 0;
205 0 : }
206 :
207 0 : case FD_BPF_INSTR_EXTEND_PROGRAM_CHECKED: {
208 0 : fd_bpf_instruction_extend_program_checked_t * e = &out->inner.extend_program_checked;
209 0 : CHECK_LEFT( 4UL );
210 0 : e->additional_bytes = FD_LOAD( uint, CURSOR ); INC( 4UL );
211 0 : return 0;
212 0 : }
213 :
214 0 : case FD_BPF_INSTR_INITIALIZE_BUFFER:
215 0 : case FD_BPF_INSTR_UPGRADE:
216 0 : case FD_BPF_INSTR_SET_AUTHORITY:
217 6 : case FD_BPF_INSTR_CLOSE:
218 6 : case FD_BPF_INSTR_SET_AUTHORITY_CHECKED:
219 6 : case FD_BPF_INSTR_MIGRATE:
220 6 : return 0;
221 :
222 0 : default: return -1;
223 6 : }
224 :
225 6 : # undef CHECK
226 6 : # undef CHECK_LEFT
227 6 : # undef INC
228 6 : # undef CURSOR
229 6 : }
230 :
231 : /* fd_bpf_upgradeable_loader_program_instruction_encode serializes an
232 : UpgradeableLoaderInstruction into [buf, buf+bufsz). On success stores
233 : the number of bytes written to *out_sz and returns 0. Returns -1 on
234 : short buffer or unknown discriminant. */
235 :
236 : static inline int
237 : fd_bpf_instruction_encode( fd_bpf_instruction_t const * in,
238 : uchar * buf,
239 : ulong bufsz,
240 6 : ulong * out_sz ) {
241 6 : uchar * const _payload = buf;
242 6 : ulong const _payload_sz = bufsz;
243 6 : ulong _i = 0UL;
244 :
245 6 : # define CHECK_LEFT( n ) { if( FD_UNLIKELY( (n)>(_payload_sz-_i) ) ) { return -1; } }
246 6 : # define INC( n ) (_i += (ulong)(n))
247 6 : # define CURSOR (_payload+_i)
248 :
249 6 : CHECK_LEFT( 4UL ); FD_STORE( uint, CURSOR, in->discriminant ); INC( 4UL );
250 :
251 6 : switch( in->discriminant ) {
252 :
253 0 : case FD_BPF_INSTR_WRITE: {
254 0 : fd_bpf_instruction_write_t const * w = &in->inner.write;
255 0 : CHECK_LEFT( 4UL ); FD_STORE( uint, CURSOR, w->offset ); INC( 4UL );
256 0 : CHECK_LEFT( 8UL ); FD_STORE( ulong, CURSOR, w->bytes_len ); INC( 8UL );
257 0 : if( w->bytes_len ) {
258 0 : CHECK_LEFT( w->bytes_len );
259 0 : fd_memcpy( CURSOR, w->bytes, w->bytes_len );
260 0 : INC( w->bytes_len );
261 0 : }
262 0 : break;
263 0 : }
264 :
265 0 : case FD_BPF_INSTR_DEPLOY_WITH_MAX_DATA_LEN: {
266 0 : fd_bpf_instruction_deploy_with_max_data_len_t const * d = &in->inner.deploy_with_max_data_len;
267 0 : CHECK_LEFT( 8UL );
268 0 : FD_STORE( ulong, CURSOR, d->max_data_len ); INC( 8UL );
269 0 : break;
270 0 : }
271 :
272 0 : case FD_BPF_INSTR_EXTEND_PROGRAM: {
273 0 : fd_bpf_instruction_extend_program_t const * e = &in->inner.extend_program;
274 0 : CHECK_LEFT( 4UL );
275 0 : FD_STORE( uint, CURSOR, e->additional_bytes ); INC( 4UL );
276 0 : break;
277 0 : }
278 :
279 0 : case FD_BPF_INSTR_EXTEND_PROGRAM_CHECKED: {
280 0 : fd_bpf_instruction_extend_program_checked_t const * e = &in->inner.extend_program_checked;
281 0 : CHECK_LEFT( 4UL );
282 0 : FD_STORE( uint, CURSOR, e->additional_bytes ); INC( 4UL );
283 0 : break;
284 0 : }
285 :
286 0 : case FD_BPF_INSTR_INITIALIZE_BUFFER:
287 0 : case FD_BPF_INSTR_UPGRADE:
288 0 : case FD_BPF_INSTR_SET_AUTHORITY:
289 6 : case FD_BPF_INSTR_CLOSE:
290 6 : case FD_BPF_INSTR_SET_AUTHORITY_CHECKED:
291 6 : case FD_BPF_INSTR_MIGRATE:
292 6 : break;
293 :
294 0 : default: return -1;
295 6 : }
296 :
297 6 : *out_sz = _i;
298 :
299 6 : # undef CHECK_LEFT
300 6 : # undef INC
301 6 : # undef CURSOR
302 :
303 6 : return 0;
304 6 : }
305 :
306 : /* fd_bpf_state_decode parses a bincode-encoded
307 : UpgradeableLoaderState from [data, data+data_sz). The output struct
308 : has no variable-length fields, so the decoder performs a fixed-size
309 : copy and does not retain any pointer into `data`. Trailing bytes
310 : beyond the parsed region are accepted (matches Agave's top-level
311 : `bincode::deserialize` which uses `allow_trailing_bytes()`). Returns
312 : 0 on success, -1 on malformed input. */
313 :
314 : static inline int
315 : fd_bpf_state_decode( fd_bpf_state_t * out,
316 : uchar const * data,
317 69 : ulong data_sz ) {
318 69 : uchar const * _payload = data;
319 69 : ulong const _payload_sz = data_sz;
320 69 : ulong _i = 0UL;
321 :
322 249 : # define CHECK( cond ) { if( FD_UNLIKELY( !(cond) ) ) { return -1; } }
323 195 : # define CHECK_LEFT( n ) CHECK( (n)<=(_payload_sz-_i) )
324 195 : # define INC( n ) (_i += (ulong)(n))
325 93 : # define CURSOR (_payload+_i)
326 :
327 69 : CHECK_LEFT( 4UL );
328 69 : uint disc = FD_LOAD( uint, CURSOR ); INC( 4UL );
329 69 : out->discriminant = disc;
330 :
331 69 : switch( disc ) {
332 :
333 0 : case FD_BPF_STATE_UNINITIALIZED:
334 0 : return 0;
335 :
336 21 : case FD_BPF_STATE_BUFFER: {
337 21 : fd_bpf_state_buffer_t * b = &out->inner.buffer;
338 21 : CHECK_LEFT( 1UL ); uchar tag = *CURSOR; INC( 1UL );
339 21 : CHECK( tag<=1 );
340 21 : b->has_authority_address = tag;
341 21 : if( tag ) {
342 18 : CHECK_LEFT( 32UL );
343 18 : fd_memcpy( b->authority_address.key, CURSOR, 32UL ); INC( 32UL );
344 18 : } else {
345 3 : fd_memset( b->authority_address.key, 0, 32UL );
346 3 : }
347 21 : return 0;
348 21 : }
349 :
350 12 : case FD_BPF_STATE_PROGRAM: {
351 12 : fd_bpf_state_program_t * p = &out->inner.program;
352 12 : CHECK_LEFT( 32UL );
353 12 : fd_memcpy( p->programdata_address.key, CURSOR, 32UL ); INC( 32UL );
354 12 : return 0;
355 12 : }
356 :
357 33 : case FD_BPF_STATE_PROGRAM_DATA: {
358 33 : fd_bpf_state_program_data_t * pd = &out->inner.program_data;
359 33 : CHECK_LEFT( 8UL ); pd->slot = FD_LOAD( ulong, CURSOR ); INC( 8UL );
360 33 : CHECK_LEFT( 1UL ); uchar tag = *CURSOR; INC( 1UL );
361 33 : CHECK( tag<=1 );
362 33 : pd->has_upgrade_authority_address = tag;
363 33 : if( tag ) {
364 9 : CHECK_LEFT( 32UL );
365 9 : fd_memcpy( pd->upgrade_authority_address.key, CURSOR, 32UL ); INC( 32UL );
366 24 : } else {
367 24 : fd_memset( pd->upgrade_authority_address.key, 0, 32UL );
368 24 : }
369 33 : return 0;
370 33 : }
371 :
372 3 : default: return -1;
373 69 : }
374 :
375 69 : # undef CHECK
376 69 : # undef CHECK_LEFT
377 69 : # undef INC
378 69 : # undef CURSOR
379 69 : }
380 :
381 : /* fd_bpf_state_encode serializes an UpgradeableLoaderState into
382 : [buf, buf+bufsz). On success stores the number of bytes written to
383 : *out_sz and returns 0. Returns -1 on short buffer or unknown
384 : discriminant. */
385 :
386 : static inline int
387 : fd_bpf_state_encode( fd_bpf_state_t const * in,
388 : uchar * buf,
389 : ulong bufsz,
390 24 : ulong * out_sz ) {
391 24 : uchar * const _payload = buf;
392 24 : ulong const _payload_sz = bufsz;
393 24 : ulong _i = 0UL;
394 :
395 60 : # define CHECK_LEFT( n ) { if( FD_UNLIKELY( (n)>(_payload_sz-_i) ) ) { return -1; } }
396 60 : # define INC( n ) (_i += (ulong)(n))
397 30 : # define CURSOR (_payload+_i)
398 :
399 24 : CHECK_LEFT( 4UL ); FD_STORE( uint, CURSOR, in->discriminant ); INC( 4UL );
400 :
401 24 : switch( in->discriminant ) {
402 :
403 6 : case FD_BPF_STATE_UNINITIALIZED:
404 6 : break;
405 :
406 9 : case FD_BPF_STATE_BUFFER: {
407 9 : fd_bpf_state_buffer_t const * b = &in->inner.buffer;
408 9 : CHECK_LEFT( 1UL ); *CURSOR = (uchar)( !!b->has_authority_address ); INC( 1UL );
409 9 : if( b->has_authority_address ) {
410 6 : CHECK_LEFT( 32UL );
411 6 : fd_memcpy( CURSOR, b->authority_address.key, 32UL ); INC( 32UL );
412 6 : }
413 9 : break;
414 9 : }
415 :
416 9 : case FD_BPF_STATE_PROGRAM: {
417 3 : fd_bpf_state_program_t const * p = &in->inner.program;
418 3 : CHECK_LEFT( 32UL );
419 3 : fd_memcpy( CURSOR, p->programdata_address.key, 32UL ); INC( 32UL );
420 3 : break;
421 3 : }
422 :
423 6 : case FD_BPF_STATE_PROGRAM_DATA: {
424 6 : fd_bpf_state_program_data_t const * pd = &in->inner.program_data;
425 6 : CHECK_LEFT( 8UL ); FD_STORE( ulong, CURSOR, pd->slot ); INC( 8UL );
426 6 : CHECK_LEFT( 1UL ); *CURSOR = (uchar)( !!pd->has_upgrade_authority_address ); INC( 1UL );
427 6 : if( pd->has_upgrade_authority_address ) {
428 6 : CHECK_LEFT( 32UL );
429 6 : fd_memcpy( CURSOR, pd->upgrade_authority_address.key, 32UL ); INC( 32UL );
430 6 : }
431 6 : break;
432 6 : }
433 :
434 6 : default: return -1;
435 24 : }
436 :
437 24 : *out_sz = _i;
438 :
439 24 : # undef CHECK_LEFT
440 24 : # undef INC
441 24 : # undef CURSOR
442 :
443 24 : return 0;
444 24 : }
445 :
446 : /* fd_bpf_state_size returns the bincode-exact wire size for
447 : encoding. Returns 0 for unknown discriminants. */
448 :
449 : static inline ulong
450 6 : fd_bpf_state_size( fd_bpf_state_t const * in ) {
451 6 : switch( in->discriminant ) {
452 6 : case FD_BPF_STATE_UNINITIALIZED: return 4UL;
453 0 : case FD_BPF_STATE_BUFFER: return 4UL + 1UL + (in->inner.buffer.has_authority_address ? 32UL : 0UL);
454 0 : case FD_BPF_STATE_PROGRAM: return 4UL + 32UL;
455 0 : case FD_BPF_STATE_PROGRAM_DATA: return 4UL + 8UL + 1UL + (in->inner.program_data.has_upgrade_authority_address ? 32UL : 0UL);
456 0 : default: return 0UL;
457 6 : }
458 6 : }
459 :
460 : FD_PROTOTYPES_BEGIN
461 :
462 : /* Mirrors solana_sdk::transaction_context::BorrowedAccount::get_state()
463 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L965-L969 */
464 :
465 : int
466 : fd_bpf_loader_program_get_state( fd_account_meta_t const * meta,
467 : fd_bpf_state_t * state );
468 :
469 : int
470 : fd_deploy_program( fd_exec_instr_ctx_t * instr_ctx,
471 : uchar const * programdata,
472 : ulong programdata_size,
473 : int disable_sbpf_v0_v1_v2_deployment );
474 :
475 : /* SIMD-0500 finalize gate. Returns
476 : FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA when `feature_active` is
477 : non-zero and the ELF embedded in `programdata` parses as
478 : SBPFv0/v1/v2; FD_EXECUTOR_INSTR_SUCCESS otherwise. */
479 : int
480 : fd_bpf_loader_finalize_v3_check( int feature_active,
481 : uchar const * programdata,
482 : ulong programdata_len );
483 :
484 : int
485 : fd_bpf_execute( fd_exec_instr_ctx_t * instr_ctx,
486 : fd_progcache_rec_t const * program,
487 : uchar is_deprecated );
488 :
489 : int
490 : fd_bpf_loader_program_execute( fd_exec_instr_ctx_t * instr_ctx );
491 :
492 : FD_PROTOTYPES_END
493 :
494 : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_bpf_loader_program_h */
|