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