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

Generated by: LCOV version 1.14