LCOV - code coverage report
Current view: top level - flamenco/vm/syscall - fd_vm_syscall.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 99 99 100.0 %
Date: 2025-09-17 04:38:03 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.14