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_bpf_program_util.h" 10 : 11 : /* https://github.com/anza-xyz/agave/blob/77daab497df191ef485a7ad36ed291c1874596e5/programs/bpf_loader/src/lib.rs#L67-L69 */ 12 : #define DEFAULT_LOADER_COMPUTE_UNITS (570UL ) 13 : #define DEPRECATED_LOADER_COMPUTE_UNITS (1140UL) 14 : #define UPGRADEABLE_LOADER_COMPUTE_UNITS (2370UL) 15 : 16 : /* https://github.com/anza-xyz/agave/blob/77daab497df191ef485a7ad36ed291c1874596e5/sdk/program/src/bpf_loader_upgradeable.rs#L29-L120 */ 17 0 : #define SIZE_OF_PROGRAM (36UL ) /* UpgradeableLoaderState::size_of_program() */ 18 0 : #define BUFFER_METADATA_SIZE (37UL ) /* UpgradeableLoaderState::size_of_buffer_metadata() */ 19 0 : #define PROGRAMDATA_METADATA_SIZE (45UL ) /* UpgradeableLoaderState::size_of_programdata_metadata() */ 20 0 : #define SIZE_OF_UNINITIALIZED (4UL ) /* UpgradeableLoaderState::size_of_uninitialized() */ 21 : 22 : /* InstructionError conversions 23 : https://github.com/anza-xyz/agave/blob/ced98f1ebe73f7e9691308afa757323003ff744f/sdk/program/src/program_error.rs#L127-L160 */ 24 0 : #define BUILTIN_BIT_SHIFT (32UL) 25 : 26 0 : #define CUSTOM_ZERO ((1UL) << BUILTIN_BIT_SHIFT) 27 0 : #define INVALID_ARGUMENT ((2UL) << BUILTIN_BIT_SHIFT) 28 0 : #define INVALID_INSTRUCTION_DATA ((3UL) << BUILTIN_BIT_SHIFT) 29 0 : #define INVALID_ACCOUNT_DATA ((4UL) << BUILTIN_BIT_SHIFT) 30 0 : #define ACCOUNT_DATA_TOO_SMALL ((5UL) << BUILTIN_BIT_SHIFT) 31 0 : #define INSUFFICIENT_FUNDS ((6UL) << BUILTIN_BIT_SHIFT) 32 0 : #define INCORRECT_PROGRAM_ID ((7UL) << BUILTIN_BIT_SHIFT) 33 0 : #define MISSING_REQUIRED_SIGNATURES ((8UL) << BUILTIN_BIT_SHIFT) 34 0 : #define ACCOUNT_ALREADY_INITIALIZED ((9UL) << BUILTIN_BIT_SHIFT) 35 0 : #define UNINITIALIZED_ACCOUNT ((10UL) << BUILTIN_BIT_SHIFT) 36 0 : #define NOT_ENOUGH_ACCOUNT_KEYS ((11UL) << BUILTIN_BIT_SHIFT) 37 0 : #define ACCOUNT_BORROW_FAILED ((12UL) << BUILTIN_BIT_SHIFT) 38 0 : #define MAX_SEED_LENGTH_EXCEEDED ((13UL) << BUILTIN_BIT_SHIFT) 39 0 : #define INVALID_SEEDS ((14UL) << BUILTIN_BIT_SHIFT) 40 0 : #define BORSH_IO_ERROR ((15UL) << BUILTIN_BIT_SHIFT) 41 0 : #define ACCOUNT_NOT_RENT_EXEMPT ((16UL) << BUILTIN_BIT_SHIFT) 42 0 : #define UNSUPPORTED_SYSVAR ((17UL) << BUILTIN_BIT_SHIFT) 43 0 : #define ILLEGAL_OWNER ((18UL) << BUILTIN_BIT_SHIFT) 44 0 : #define MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED ((19UL) << BUILTIN_BIT_SHIFT) 45 0 : #define INVALID_ACCOUNT_DATA_REALLOC ((20UL) << BUILTIN_BIT_SHIFT) 46 0 : #define MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED ((21UL) << BUILTIN_BIT_SHIFT) 47 0 : #define BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS ((22UL) << BUILTIN_BIT_SHIFT) 48 0 : #define INVALID_ACCOUNT_OWNER ((23UL) << BUILTIN_BIT_SHIFT) 49 0 : #define ARITHMETIC_OVERFLOW ((24UL) << BUILTIN_BIT_SHIFT) 50 0 : #define IMMUTABLE ((25UL) << BUILTIN_BIT_SHIFT) 51 0 : #define INCORRECT_AUTHORITY ((26UL) << BUILTIN_BIT_SHIFT) 52 : 53 : FD_PROTOTYPES_BEGIN 54 : 55 : /* Mirrors solana_sdk::transaction_context::BorrowedAccount::get_state() 56 : 57 : Acts on a fd_txn_account_t for ease of API use. 58 : 59 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L965-L969 */ 60 : 61 : fd_bpf_upgradeable_loader_state_t * 62 : fd_bpf_loader_program_get_state( fd_txn_account_t const * acc, 63 : fd_spad_t * spad, 64 : int * err ); 65 : 66 : int 67 : fd_deploy_program( fd_exec_instr_ctx_t * instr_ctx, 68 : uchar const * programdata, 69 : ulong programdata_size, 70 : fd_spad_t * spad ); 71 : 72 : int 73 : fd_bpf_execute( fd_exec_instr_ctx_t * instr_ctx, fd_sbpf_validated_program_t const * prog, uchar is_deprecated ); 74 : 75 : int 76 : fd_bpf_loader_program_execute( fd_exec_instr_ctx_t * instr_ctx ); 77 : 78 : /* read_bpf_upgradeable_loader_state_for_program allocates and returns the 79 : bpf loader state for a given program id account within the scope of a txn. */ 80 : 81 : fd_bpf_upgradeable_loader_state_t * 82 : read_bpf_upgradeable_loader_state_for_program( fd_exec_txn_ctx_t * txn_ctx, 83 : ushort program_id, 84 : int * opt_err ); 85 : 86 : /* Public APIs */ 87 : 88 : /* This function is called from `fd_runtime.c` and only performs the ELF and VM validation checks necessary 89 : to deploy a program, specifically for the core native program BPF migration. Since this call is done at 90 : the epoch boundary every time a new BPF core migration feature is activated, we need to mock up a transaction 91 : and instruction context for execution. We do not do any funk operations here - instead, the BPF cache entry 92 : will be created at the end of the block. Because of this, our logic is slightly different than Agave's. 93 : See the documentation for our `fd_deploy_program` for more information. 94 : 95 : https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L155-L233 */ 96 : int 97 : fd_directly_invoke_loader_v3_deploy( fd_exec_slot_ctx_t * slot_ctx, 98 : uchar const * elf, 99 : ulong elf_sz, 100 : fd_spad_t * runtime_spad ); 101 : 102 : FD_PROTOTYPES_END 103 : 104 : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_bpf_loader_program_h */