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

Generated by: LCOV version 1.14