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

Generated by: LCOV version 1.14