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 "fd_program_cache.h" 10 : #include "../../features/fd_features.h" 11 : #include "../../types/fd_types.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 0 : #define SIZE_OF_PROGRAM (36UL ) /* UpgradeableLoaderState::size_of_program() */ 20 0 : #define BUFFER_METADATA_SIZE (37UL ) /* UpgradeableLoaderState::size_of_buffer_metadata() */ 21 0 : #define PROGRAMDATA_METADATA_SIZE (45UL ) /* UpgradeableLoaderState::size_of_programdata_metadata() */ 22 0 : #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 0 : #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 : FD_PROTOTYPES_BEGIN 56 : 57 : /* Mirrors solana_sdk::transaction_context::BorrowedAccount::get_state() 58 : 59 : Acts on a fd_txn_account_t for ease of API use. 60 : 61 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L965-L969 */ 62 : 63 : fd_bpf_upgradeable_loader_state_t * 64 : fd_bpf_loader_program_get_state( fd_txn_account_t const * acct, 65 : fd_spad_t * spad, 66 : int * opt_err ); 67 : 68 : void 69 : fd_bpf_get_sbpf_versions( uint * sbpf_min_version, 70 : uint * sbpf_max_version, 71 : ulong slot, 72 : fd_features_t const * features ); 73 : 74 : int 75 : fd_deploy_program( fd_exec_instr_ctx_t * instr_ctx, 76 : fd_pubkey_t const * program_key, 77 : uchar const * programdata, 78 : ulong programdata_size, 79 : fd_spad_t * spad ); 80 : 81 : int 82 : fd_bpf_execute( fd_exec_instr_ctx_t * instr_ctx, 83 : fd_program_cache_entry_t const * cache_entry, 84 : uchar is_deprecated ); 85 : 86 : int 87 : fd_bpf_loader_program_execute( fd_exec_instr_ctx_t * instr_ctx ); 88 : 89 : /* Public APIs */ 90 : 91 : /* This function is called from `fd_runtime.c` and only performs the ELF and VM validation checks necessary 92 : to deploy a program, specifically for the core native program BPF migration. Since this call is done at 93 : the epoch boundary every time a new BPF core migration feature is activated, we need to mock up a transaction 94 : and instruction context for execution. We do not do any funk operations here - instead, the BPF cache entry 95 : will be created at the end of the block. Because of this, our logic is slightly different than Agave's. 96 : See the documentation for our `fd_deploy_program` for more information. 97 : 98 : https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L155-L233 */ 99 : int 100 : fd_directly_invoke_loader_v3_deploy( fd_bank_t * bank, 101 : fd_funk_t * funk, 102 : fd_funk_txn_xid_t const * xid, 103 : fd_pubkey_t const * program_key, 104 : uchar const * elf, 105 : ulong elf_sz, 106 : fd_spad_t * runtime_spad ); 107 : 108 : FD_PROTOTYPES_END 109 : 110 : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_bpf_loader_program_h */