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