LCOV - code coverage report
Current view: top level - flamenco/vm/syscall - fd_vm_syscall.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 96 96 100.0 %
Date: 2026-06-08 09:27:03 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "fd_vm_syscall.h"
       2             : #include "../../../ballet/murmur3/fd_murmur3.h"
       3             : 
       4             : int
       5             : fd_vm_syscall_register( fd_sbpf_syscalls_t *   syscalls,
       6             :                         char const *           name,
       7      182733 :                         fd_sbpf_syscall_func_t func ) {
       8      182733 :   if( FD_UNLIKELY( (!syscalls) | (!name) ) ) return FD_VM_ERR_INVAL;
       9             : 
      10      182733 :   fd_sbpf_syscalls_t * syscall = fd_sbpf_syscalls_insert( syscalls, (ulong)fd_murmur3_32( name, strlen( name ), 0U ) );
      11      182733 :   if( FD_UNLIKELY( !syscall ) ) return FD_VM_ERR_INVAL; /* name (or hash of name) already in map */
      12             : 
      13      182733 :   syscall->func = func;
      14      182733 :   syscall->name = name;
      15             : 
      16      182733 :   return FD_VM_SUCCESS;
      17      182733 : }
      18             : 
      19             : int
      20             : fd_vm_syscall_register_slot( fd_sbpf_syscalls_t *      syscalls,
      21             :                              ulong                     slot,
      22             :                              fd_features_t const *     features,
      23        4998 :                              uchar                     is_deploy ) {
      24        4998 :   if( FD_UNLIKELY( !syscalls ) ) return FD_VM_ERR_INVAL;
      25             : 
      26        4998 :   int enable_blake3_syscall            = 0;
      27        4998 :   int enable_last_restart_slot_syscall = 0;
      28        4998 :   int enable_get_sysvar_syscall        = 0;
      29        4998 :   int enable_get_epoch_stake_syscall   = 0;
      30        4998 :   int enable_bls12_381_syscall         = 0;
      31        4998 :   int enable_sha512_syscall            = 0;
      32             : 
      33        4998 :   if( slot ) {
      34        2493 :     enable_blake3_syscall            = FD_FEATURE_ACTIVE( slot, features, blake3_syscall_enabled );
      35        2493 :     enable_last_restart_slot_syscall = FD_FEATURE_ACTIVE( slot, features, last_restart_slot_sysvar );
      36        2493 :     enable_get_sysvar_syscall        = FD_FEATURE_ACTIVE( slot, features, get_sysvar_syscall_enabled );
      37        2493 :     enable_get_epoch_stake_syscall   = FD_FEATURE_ACTIVE( slot, features, enable_get_epoch_stake_syscall );
      38        2493 :     enable_bls12_381_syscall         = FD_FEATURE_ACTIVE( slot, features, enable_bls12_381_syscall );
      39        2493 :     enable_sha512_syscall            = FD_FEATURE_ACTIVE( slot, features, enable_sha512_syscall );
      40             : 
      41        2505 :   } else { /* enable ALL */
      42             : 
      43        2505 :     enable_blake3_syscall            = 1;
      44        2505 :     enable_last_restart_slot_syscall = 1;
      45        2505 :     enable_get_sysvar_syscall        = 1;
      46        2505 :     enable_get_epoch_stake_syscall   = 1;
      47        2505 :     enable_bls12_381_syscall         = 1;
      48        2505 :     enable_sha512_syscall            = 1;
      49             : 
      50        2505 :   }
      51             : 
      52        4998 :   fd_sbpf_syscalls_clear( syscalls );
      53             : 
      54        4998 :   ulong syscall_cnt = 0UL;
      55             : 
      56      182730 : # define REGISTER(name,func) do {                                                       \
      57      182730 :     if( FD_UNLIKELY( syscall_cnt>=fd_sbpf_syscalls_key_max() ) ) return FD_VM_ERR_FULL; \
      58      182730 :     int _err = fd_vm_syscall_register( syscalls, (name), (func) );                      \
      59      182730 :     if( FD_UNLIKELY( _err ) ) return _err;                                              \
      60      182730 :     syscall_cnt++;                                                                      \
      61      182730 :   } while(0)
      62             : 
      63             :   /* https://github.com/anza-xyz/agave/blob/v2.2.20/programs/bpf_loader/src/syscalls/mod.rs#L392-L396 */
      64             : 
      65        4998 :   REGISTER( "abort",                                 fd_vm_syscall_abort );
      66        4998 :   REGISTER( "sol_panic_",                            fd_vm_syscall_sol_panic );
      67             : 
      68             :   /* As of the activation of disable_deploy_of_alloc_free_syscall, which is activated on all networks,
      69             :      programs can no longer be deployed which use the sol_alloc_free_ syscall.
      70             : 
      71             :     https://github.com/anza-xyz/agave/blob/d6041c002bbcf1526de4e38bc18fa6e781c380e7/programs/bpf_loader/src/syscalls/mod.rs#L429 */
      72        4998 :   if ( FD_LIKELY( !is_deploy ) ) {
      73        4986 :     REGISTER( "sol_alloc_free_",                       fd_vm_syscall_sol_alloc_free );
      74        4986 :   }
      75             : 
      76             :   /* https://github.com/solana-labs/solana/blob/v1.18.1/sdk/program/src/syscalls/definitions.rs#L39 */
      77             : 
      78        4998 :   REGISTER( "sol_log_",                              fd_vm_syscall_sol_log );
      79        4998 :   REGISTER( "sol_log_64_",                           fd_vm_syscall_sol_log_64 );
      80        4998 :   REGISTER( "sol_log_compute_units_",                fd_vm_syscall_sol_log_compute_units );
      81        4998 :   REGISTER( "sol_log_pubkey",                        fd_vm_syscall_sol_log_pubkey );
      82        4998 :   REGISTER( "sol_create_program_address",            fd_vm_syscall_sol_create_program_address );
      83        4998 :   REGISTER( "sol_try_find_program_address",          fd_vm_syscall_sol_try_find_program_address );
      84        4998 :   REGISTER( "sol_sha256",                            fd_vm_syscall_sol_sha256 );
      85        4998 :   REGISTER( "sol_keccak256",                         fd_vm_syscall_sol_keccak256 );
      86        4998 : # if FD_HAS_S2NBIGNUM
      87        4998 :   REGISTER( "sol_secp256k1_recover",                 fd_vm_syscall_sol_secp256k1_recover );
      88             : # else
      89             :   FD_LOG_ERR(( "This build does not include s2n-bignum, which is required to run a validator.\n"
      90             :                "To install s2n-bignum, re-run ./deps.sh, make distclean, and make -j" ));
      91             : # endif
      92             : 
      93        4998 :   if( enable_blake3_syscall )
      94        2544 :     REGISTER( "sol_blake3",                          fd_vm_syscall_sol_blake3 );
      95             : 
      96        4998 :   if( enable_sha512_syscall )
      97        2544 :     REGISTER( "sol_sha512",                          fd_vm_syscall_sol_sha512 );
      98             : 
      99        4998 :   REGISTER( "sol_get_clock_sysvar",                  fd_vm_syscall_sol_get_clock_sysvar );
     100        4998 :   REGISTER( "sol_get_epoch_schedule_sysvar",         fd_vm_syscall_sol_get_epoch_schedule_sysvar );
     101             : 
     102        4998 :   REGISTER( "sol_get_rent_sysvar",                   fd_vm_syscall_sol_get_rent_sysvar );
     103             : 
     104        4998 :   if( FD_LIKELY( enable_last_restart_slot_syscall ) ) {
     105        2544 :     REGISTER( "sol_get_last_restart_slot",           fd_vm_syscall_sol_get_last_restart_slot_sysvar );
     106        2544 :   }
     107             : 
     108        4998 :   if( enable_get_sysvar_syscall ) {
     109        2544 :     REGISTER( "sol_get_sysvar",                      fd_vm_syscall_sol_get_sysvar );
     110        2544 :   }
     111             : 
     112        4998 :   if( enable_get_epoch_stake_syscall ) {
     113        2544 :     REGISTER( "sol_get_epoch_stake",                 fd_vm_syscall_sol_get_epoch_stake );
     114        2544 :   }
     115             : 
     116        4998 :   REGISTER( "sol_memcpy_",                           fd_vm_syscall_sol_memcpy );
     117        4998 :   REGISTER( "sol_memmove_",                          fd_vm_syscall_sol_memmove );
     118        4998 :   REGISTER( "sol_memcmp_",                           fd_vm_syscall_sol_memcmp );
     119        4998 :   REGISTER( "sol_memset_",                           fd_vm_syscall_sol_memset );
     120        4998 :   REGISTER( "sol_invoke_signed_c",                   fd_vm_syscall_cpi_c );
     121        4998 :   REGISTER( "sol_invoke_signed_rust",                fd_vm_syscall_cpi_rust );
     122        4998 :   REGISTER( "sol_set_return_data",                   fd_vm_syscall_sol_set_return_data );
     123        4998 :   REGISTER( "sol_get_return_data",                   fd_vm_syscall_sol_get_return_data );
     124        4998 :   REGISTER( "sol_log_data",                          fd_vm_syscall_sol_log_data );
     125        4998 :   REGISTER( "sol_get_processed_sibling_instruction", fd_vm_syscall_sol_get_processed_sibling_instruction );
     126        4998 :   REGISTER( "sol_get_stack_height",                  fd_vm_syscall_sol_get_stack_height );
     127        4998 :   REGISTER( "sol_get_epoch_rewards_sysvar",          fd_vm_syscall_sol_get_epoch_rewards_sysvar );
     128             : 
     129        4998 :   REGISTER( "sol_curve_validate_point",              fd_vm_syscall_sol_curve_validate_point );
     130        4998 :   REGISTER( "sol_curve_group_op",                    fd_vm_syscall_sol_curve_group_op );
     131        4998 :   REGISTER( "sol_curve_multiscalar_mul",             fd_vm_syscall_sol_curve_multiscalar_mul );
     132             : 
     133             :   // NOTE: sol_curve_pairing_map is defined but never implemented /
     134             :   // used, we can ignore it for now
     135             : //REGISTER( "sol_curve_pairing_map",                 fd_vm_syscall_sol_curve_pairing_map );
     136             : 
     137        4998 :   REGISTER( "sol_alt_bn128_group_op",                  fd_vm_syscall_sol_alt_bn128_group_op );
     138        4998 :   REGISTER( "sol_alt_bn128_compression",               fd_vm_syscall_sol_alt_bn128_compression );
     139             : 
     140             : //REGISTER( "sol_big_mod_exp",                       fd_vm_syscall_sol_big_mod_exp );
     141             : 
     142        4998 :   REGISTER( "sol_poseidon",                          fd_vm_syscall_sol_poseidon );
     143             : 
     144             : //REGISTER( "sol_remaining_compute_units",           fd_vm_syscall_sol_remaining_compute_units );
     145             : 
     146        4998 : #if FD_HAS_BLST
     147        4998 :   if( enable_bls12_381_syscall ) {
     148        2544 :     REGISTER( "sol_curve_decompress",                fd_vm_syscall_sol_curve_decompress );
     149        2544 :     REGISTER( "sol_curve_pairing_map",               fd_vm_syscall_sol_curve_pairing_map );
     150        2544 :   }
     151             : #else
     152             :   (void)enable_bls12_381_syscall;
     153             : #endif /* FD_HAS_BLST */
     154             : 
     155        4998 : # undef REGISTER
     156             : 
     157        4998 :   return FD_VM_SUCCESS;
     158        4998 : }

Generated by: LCOV version 1.14