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

Generated by: LCOV version 1.14