Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h 2 : #define HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h 3 : 4 : #include "../fd_bank.h" 5 : #include "fd_bpf_loader_program.h" 6 : 7 0 : #define FD_CORE_BPF_MIGRATION_TARGET_BUILTIN (0) 8 0 : #define FD_CORE_BPF_MIGRATION_TARGET_STATELESS (1) 9 : 10 : /* https://github.com/anza-xyz/agave/blob/v2.3.0/builtins/src/core_bpf_migration.rs#L17-L43 11 : Configuration for migrating a built-in program to Core BPF. 12 : - `migration_target` is one of 13 : FD_CORE_BPF_MIGRATION_TARGET_{BUILTIN,STATELESS}. */ 14 : struct fd_core_bpf_migration_config { 15 : fd_pubkey_t const * source_buffer_address; 16 : fd_pubkey_t * upgrade_authority_address; 17 : ulong enable_feature_offset; 18 : uchar migration_target; 19 : fd_pubkey_t const * builtin_program_id; 20 : fd_hash_t const * verified_build_hash; 21 : }; 22 : typedef struct fd_core_bpf_migration_config fd_core_bpf_migration_config_t; 23 : 24 : /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/prototypes.rs#L7-L13 25 : Transitions of built-in programs at epoch boundaries when features are activated */ 26 : struct fd_builtin_program { 27 : fd_pubkey_t const * pubkey; 28 : char const * data; 29 : ulong enable_feature_offset; 30 : fd_core_bpf_migration_config_t const * core_bpf_migration_config; 31 : }; 32 : typedef struct fd_builtin_program fd_builtin_program_t; 33 : 34 : /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/prototypes.rs#L31-L35 35 : Transitions of stateless built-in programs at epoch boundaries when features are activated */ 36 : struct fd_stateless_builtin_program { 37 : fd_pubkey_t const * pubkey; 38 : fd_core_bpf_migration_config_t const * core_bpf_migration_config; 39 : }; 40 : typedef struct fd_stateless_builtin_program fd_stateless_builtin_program_t; 41 : 42 : /* It's technically possible to craft a buffer account that can cause 43 : the temporary ProgramData account data buffer to exceed 44 : FD_RUNTIME_ACC_SZ_MAX. 45 : 46 : This is because PROGRAMDATA_METADATA_SIZE is 8 bytes larger than 47 : BUFFER_METADATA_SIZE, so the worst-case size of the temporary 48 : account buffer is FD_RUNTIME_ACC_SZ_MAX + 8 bytes. 49 : 50 : To be conservative, and obvious, we use FD_RUNTIME_ACC_SZ_MAX + 51 : PROGRAMDATA_METADATA_SIZE. 52 : 53 : Such a buffer account will not be deployed, because the derived 54 : ProgramData size will exceed MAX_PERMITTED_DATA_LENGTH, but we still 55 : need to ensure that the temporary ProgramData account buffer is 56 : large enough. */ 57 : 58 : struct fd_tmp_account { 59 : fd_pubkey_t pubkey; 60 : fd_pubkey_t owner; 61 : ulong lamports; 62 : int executable; 63 : uchar data[PROGRAMDATA_METADATA_SIZE + FD_RUNTIME_ACC_SZ_MAX]__attribute__((aligned(8UL))); 64 : ulong data_sz; 65 : }; 66 : typedef struct fd_tmp_account fd_tmp_account_t; 67 : 68 : FD_PROTOTYPES_BEGIN 69 : 70 : /* Initialize the builtin program accounts */ 71 : void 72 : fd_builtin_programs_init( fd_bank_t * bank, 73 : fd_accdb_t * accdb, 74 : fd_capture_ctx_t * capture_ctx ); 75 : 76 : void 77 : fd_write_builtin_account( fd_bank_t * bank, 78 : fd_accdb_t * accdb, 79 : fd_capture_ctx_t * capture_ctx, 80 : fd_pubkey_t const pubkey, 81 : void const * data, 82 : ulong sz ); 83 : 84 : fd_builtin_program_t const * 85 : fd_builtins( void ); 86 : 87 : ulong 88 : fd_num_builtins( void ); 89 : 90 : fd_stateless_builtin_program_t const * 91 : fd_stateless_builtins( void ); 92 : 93 : ulong 94 : fd_num_stateless_builtins( void ); 95 : 96 : /* `migrated_yet` is an output value thats set based on the rules below: 97 : 98 : | Return Value | *migrated_yet | Description | 99 : |--------------|-------------------|--------------------------------------------------------------------------| 100 : | 0 | 0 | Program is not a migrating builtin program | 101 : | 1 | 0 | Program is a migrating builtin program id, BUT has not been migrated yet | 102 : | 1 | 1 | Program is a migrating builtin program id, AND has been migrated to BPF | 103 : */ 104 : uchar 105 : fd_is_migrating_builtin_program( fd_bank_t const * bank, 106 : fd_pubkey_t const * pubkey, 107 : uchar * migrated_yet ); 108 : 109 : uchar 110 : fd_is_non_migrating_builtin_program( fd_pubkey_t const * pubkey ); 111 : 112 : void 113 : fd_migrate_builtin_to_core_bpf( fd_bank_t * bank, 114 : fd_accdb_t * accdb, 115 : fd_runtime_stack_t * runtime_stack, 116 : fd_core_bpf_migration_config_t const * config, 117 : fd_capture_ctx_t * capture_ctx ); 118 : 119 : void 120 : fd_upgrade_core_bpf_program( fd_bank_t * bank, 121 : fd_accdb_t * accdb, 122 : fd_runtime_stack_t * runtime_stack, 123 : fd_pubkey_t const * builtin_program_id, 124 : fd_pubkey_t const * source_buffer_address, 125 : fd_capture_ctx_t * capture_ctx ); 126 : 127 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.2/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L402-L408 */ 128 : void 129 : fd_upgrade_loader_v2_program_with_loader_v3_program( fd_bank_t * bank, 130 : fd_accdb_t * accdb, 131 : fd_runtime_stack_t * runtime_stack, 132 : fd_pubkey_t const * loader_v2_program_address, 133 : fd_pubkey_t const * source_buffer_address, 134 : int allow_prefunded, 135 : fd_capture_ctx_t * capture_ctx ); 136 : 137 : FD_PROTOTYPES_END 138 : 139 : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h */