LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_bpf_program_util.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 1 1 100.0 %
Date: 2025-07-01 05:00:49 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_program_fd_bpf_program_util_h
       2             : #define HEADER_fd_src_flamenco_runtime_program_fd_bpf_program_util_h
       3             : 
       4             : #include "../../fd_flamenco_base.h"
       5             : #include "../fd_acc_mgr.h"
       6             : #include "../context/fd_exec_slot_ctx.h"
       7             : #include "../../vm/syscall/fd_vm_syscall.h"
       8             : #include "../fd_system_ids.h"
       9             : 
      10             : struct fd_sbpf_validated_program {
      11             :   ulong magic;
      12             : 
      13             :    /* For any programs that fail verification, we retain this flag for the current epoch to
      14             :       prevent any reverification attempts for the remainder of the epoch (instead of
      15             :       removing them from the cache). When `failed_verification` is set, the value of all other
      16             :       fields in this struct are undefined. */
      17             :    uchar failed_verification;
      18             : 
      19             :    /* Stores the last epoch verification checks were ran for a program. Programs are reverified
      20             :       the first time they are mentioned in a transaction in an epoch, and then never again
      21             :       until the next epoch. This is because feature set changes across the epoch boundary can
      22             :       make existing deployed programs invalid. If `last_epoch_verification_ran` != current epoch,
      23             :       then we run the verification and update `failed_verification` if it fails. */
      24             :    ulong last_epoch_verification_ran;
      25             : 
      26             :    ulong entry_pc;
      27             :    ulong text_cnt;
      28             :    ulong text_off;
      29             :    ulong text_sz;
      30             : 
      31             :    ulong rodata_sz;
      32             : 
      33             :   /* We keep the pointer to the calldests raw memory around, so that we can easily copy the entire
      34             :      data structures (including the private header) later. */
      35             :    void *                calldests_shmem;
      36             :    fd_sbpf_calldests_t * calldests;
      37             :    uchar *               rodata;
      38             : 
      39             :    /* SBPF version, SIMD-0161 */
      40             :    ulong sbpf_version;
      41             : };
      42             : typedef struct fd_sbpf_validated_program fd_sbpf_validated_program_t;
      43             : 
      44             : /* arbitrary unique value, in this case
      45             :    echo -n "fd_sbpf_validated_program" | sha512sum | head -c 16 */
      46          12 : #define FD_SBPF_VALIDATED_PROGRAM_MAGIC 0xfd5540ddc5a33496
      47             : 
      48             : FD_PROTOTYPES_BEGIN
      49             : 
      50             : fd_sbpf_validated_program_t *
      51             : fd_sbpf_validated_program_new( void * mem, fd_sbpf_elf_info_t const * elf_info );
      52             : 
      53             : ulong
      54             : fd_sbpf_validated_program_align( void );
      55             : 
      56             : ulong
      57             : fd_sbpf_validated_program_footprint( fd_sbpf_elf_info_t const * elf_info );
      58             : 
      59             : /* FIXME: Implement this (or remove?) */
      60             : ulong
      61             : fd_sbpf_validated_program_from_sbpf_program( fd_sbpf_program_t const *     prog,
      62             :                                              fd_sbpf_validated_program_t * valid_prog );
      63             : 
      64             : int
      65             : fd_bpf_scan_and_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx,
      66             :                                                 fd_spad_t *          runtime_spad );
      67             : 
      68             : int
      69             : fd_bpf_scan_and_create_bpf_program_cache_entry_para( fd_exec_slot_ctx_t *    slot_ctx,
      70             :                                                      fd_spad_t *             runtime_spad,
      71             :                                                      fd_exec_para_cb_ctx_t * exec_para_ctx );
      72             : 
      73             : int
      74             : fd_bpf_load_cache_entry( fd_funk_t const *                    funk,
      75             :                          fd_funk_txn_t const *                funk_txn,
      76             :                          fd_pubkey_t const *                  program_pubkey,
      77             :                          fd_sbpf_validated_program_t const ** valid_prog );
      78             : 
      79             : void
      80             : fd_bpf_get_sbpf_versions( uint *                sbpf_min_version,
      81             :                           uint *                sbpf_max_version,
      82             :                           ulong                 slot,
      83             :                           fd_features_t const * features );
      84             : 
      85             : /* Parses the programdata from a program account. Returns a pointer to the program data
      86             :    and sets `out_program_data_len` on success. Returns NULL on failure or if the program
      87             :    account is not owned by a BPF loader program ID, and leaves `out_program_data_len`
      88             :    in an undefined state. Reasons for failure vary on the loader version. See the respective
      89             :    functions in this file for more details. */
      90             : uchar const *
      91             : fd_bpf_get_programdata_from_account( fd_funk_t const *        funk,
      92             :                                      fd_funk_txn_t const *    funk_txn,
      93             :                                      fd_txn_account_t const * program_acc,
      94             :                                      ulong *                  out_program_data_len,
      95             :                                      fd_spad_t *              runtime_spad );
      96             : 
      97             : /* Updates the program cache for a single program. This function is called for every program
      98             :    that is referenced in a transaction, plus every single account in a lookup table referenced
      99             :    in the transaction. This function...
     100             :    - Reads the programdata from an account, given the pubkey
     101             :    - Creates a program cache entry for the program if it doesn't exist in the cache already
     102             :    - Reverifies programs every epoch
     103             :       - Lazily reverifies programs as they are invoked in a transaction (only once per program per epoch)
     104             :       - Invalidates programs that fail verification until the next epoch
     105             :       - Updates the program cache entry for the program after reverification (syscalls, calldests, etc)
     106             : 
     107             :    With this design, the program cache is designed to only grow as new programs are deployed / invoked. If a program fails
     108             :    verification, it stays in the cache so that repeated calls won't DOS the validator by forcing reverifications (since we
     109             :    won't be able to distinguish failed verifications from new deployments). */
     110             : void
     111             : fd_bpf_program_update_program_cache( fd_exec_slot_ctx_t * slot_ctx,
     112             :                                      fd_pubkey_t const *  program_pubkey,
     113             :                                      fd_spad_t *          runtime_spad );
     114             : 
     115             : FD_PROTOTYPES_END
     116             : 
     117             : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_bpf_program_util_h */

Generated by: LCOV version 1.14