LCOV - code coverage report
Current view: top level - flamenco/vm/syscall - fd_vm_syscall.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 108 108 100.0 %
Date: 2025-01-08 12:08:44 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     9274365 :                         fd_sbpf_syscall_func_t func ) {
       7     9274365 :   if( FD_UNLIKELY( (!syscalls) | (!name) ) ) return FD_VM_ERR_INVAL;
       8             : 
       9     9274365 :   fd_sbpf_syscalls_t * syscall = fd_sbpf_syscalls_insert( syscalls, fd_murmur3_32( name, strlen( name ), 0U ) );
      10     9274365 :   if( FD_UNLIKELY( !syscall ) ) return FD_VM_ERR_INVAL; /* name (or hash of name) already in map */
      11             : 
      12     9274365 :   syscall->func = func;
      13     9274365 :   syscall->name = name;
      14             : 
      15     9274365 :   return FD_VM_SUCCESS;
      16     9274365 : }
      17             : 
      18             : int
      19             : fd_vm_syscall_register_slot( fd_sbpf_syscalls_t *       syscalls,
      20             :                              fd_exec_slot_ctx_t const * slot_ctx,
      21      338043 :                              uchar is_deploy ) {
      22      338043 :   if( FD_UNLIKELY( !syscalls ) ) return FD_VM_ERR_INVAL;
      23             : 
      24      338043 :   int enable_blake3_syscall                = 0;
      25      338043 :   int enable_curve25519_syscall            = 0;
      26      338043 :   int enable_poseidon_syscall              = 0;
      27      338043 :   int enable_alt_bn128_syscall             = 0;
      28      338043 :   int enable_alt_bn128_compression_syscall = 0;
      29      338043 :   int enable_last_restart_slot_syscall     = 0;
      30      338043 :   int enable_get_sysvar_syscall            = 0;
      31      338043 :   int enable_get_epoch_stake_syscall       = 0;
      32      338043 :   int enable_epoch_rewards_syscall         = 0;
      33             : 
      34      338043 :   int disable_fees_sysvar                  = 0;
      35             : 
      36      338043 :   if( slot_ctx ) {
      37             : 
      38      324741 :     enable_blake3_syscall                = FD_FEATURE_ACTIVE( slot_ctx, blake3_syscall_enabled );
      39      324741 :     enable_curve25519_syscall            = FD_FEATURE_ACTIVE( slot_ctx, curve25519_syscall_enabled );
      40      324741 :     enable_poseidon_syscall              = FD_FEATURE_ACTIVE( slot_ctx, enable_poseidon_syscall );
      41      324741 :     enable_alt_bn128_syscall             = FD_FEATURE_ACTIVE( slot_ctx, enable_alt_bn128_syscall );
      42      324741 :     enable_alt_bn128_compression_syscall = FD_FEATURE_ACTIVE( slot_ctx, enable_alt_bn128_compression_syscall );
      43      324741 :     enable_last_restart_slot_syscall     = FD_FEATURE_ACTIVE( slot_ctx, last_restart_slot_sysvar );
      44      324741 :     enable_get_sysvar_syscall            = FD_FEATURE_ACTIVE( slot_ctx, get_sysvar_syscall_enabled );
      45      324741 :     enable_get_epoch_stake_syscall       = FD_FEATURE_ACTIVE( slot_ctx, 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      324741 :     enable_epoch_rewards_syscall         = FD_FEATURE_ACTIVE( slot_ctx, enable_partitioned_epoch_reward ) ||
      48      324741 :                                            FD_FEATURE_ACTIVE( slot_ctx, partitioned_epoch_rewards_superfeature );
      49             : 
      50      324741 :     disable_fees_sysvar                  = FD_FEATURE_ACTIVE( slot_ctx, disable_fees_sysvar );
      51             : 
      52      324741 :   } else { /* enable ALL */
      53             : 
      54       13302 :     enable_blake3_syscall                = 1;
      55       13302 :     enable_curve25519_syscall            = 1;
      56       13302 :     enable_poseidon_syscall              = 1;
      57       13302 :     enable_alt_bn128_syscall             = 1;
      58       13302 :     enable_alt_bn128_compression_syscall = 1;
      59       13302 :     enable_last_restart_slot_syscall     = 1;
      60       13302 :     enable_get_sysvar_syscall            = 1;
      61       13302 :     enable_get_epoch_stake_syscall       = 1;
      62       13302 :     enable_epoch_rewards_syscall         = 1;
      63             : 
      64       13302 :   }
      65             : 
      66      338043 :   fd_sbpf_syscalls_clear( syscalls );
      67             : 
      68      338043 :   ulong syscall_cnt = 0UL;
      69             : 
      70     9274362 : # define REGISTER(name,func) do {                                                       \
      71     9274362 :     if( FD_UNLIKELY( syscall_cnt>=fd_sbpf_syscalls_key_max() ) ) return FD_VM_ERR_FULL; \
      72     9274362 :     int _err = fd_vm_syscall_register( syscalls, (name), (func) );                      \
      73     9274362 :     if( FD_UNLIKELY( _err ) ) return _err;                                              \
      74     9274362 :     syscall_cnt++;                                                                      \
      75     9274362 :   } while(0)
      76             : 
      77             :   /* Firedancer only (FIXME: HMMMM) */
      78             : 
      79      338043 :   REGISTER( "abort",                                 fd_vm_syscall_abort );
      80      338043 :   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      338043 :   if ( FD_LIKELY( !is_deploy ) ) {
      87      337119 :     REGISTER( "sol_alloc_free_",                       fd_vm_syscall_sol_alloc_free );
      88      337119 :   }
      89             : 
      90             :   /* https://github.com/solana-labs/solana/blob/v1.18.1/sdk/program/src/syscalls/definitions.rs#L39 */
      91             : 
      92      338043 :   REGISTER( "sol_log_",                              fd_vm_syscall_sol_log );
      93      338043 :   REGISTER( "sol_log_64_",                           fd_vm_syscall_sol_log_64 );
      94      338043 :   REGISTER( "sol_log_compute_units_",                fd_vm_syscall_sol_log_compute_units );
      95      338043 :   REGISTER( "sol_log_pubkey",                        fd_vm_syscall_sol_log_pubkey );
      96      338043 :   REGISTER( "sol_create_program_address",            fd_vm_syscall_sol_create_program_address );
      97      338043 :   REGISTER( "sol_try_find_program_address",          fd_vm_syscall_sol_try_find_program_address );
      98      338043 :   REGISTER( "sol_sha256",                            fd_vm_syscall_sol_sha256 );
      99      338043 :   REGISTER( "sol_keccak256",                         fd_vm_syscall_sol_keccak256 );
     100      338043 :   REGISTER( "sol_secp256k1_recover",                 fd_vm_syscall_sol_secp256k1_recover );
     101             : 
     102      338043 :   if( enable_blake3_syscall )
     103       14019 :     REGISTER( "sol_blake3",                          fd_vm_syscall_sol_blake3 );
     104             : 
     105      338043 :   REGISTER( "sol_get_clock_sysvar",                  fd_vm_syscall_sol_get_clock_sysvar );
     106      338043 :   REGISTER( "sol_get_epoch_schedule_sysvar",         fd_vm_syscall_sol_get_epoch_schedule_sysvar );
     107             : 
     108      338043 :   if( !disable_fees_sysvar )
     109      333693 :     REGISTER( "sol_get_fees_sysvar",                 fd_vm_syscall_sol_get_fees_sysvar );
     110             : 
     111      338043 :   REGISTER( "sol_get_rent_sysvar",                   fd_vm_syscall_sol_get_rent_sysvar );
     112             : 
     113      338043 :   if( FD_LIKELY( enable_last_restart_slot_syscall ) ) {
     114       14019 :     REGISTER( "sol_get_last_restart_slot",           fd_vm_syscall_sol_get_last_restart_slot_sysvar );
     115       14019 :   }
     116             : 
     117      338043 :   if( enable_get_sysvar_syscall ) {
     118       13317 :     REGISTER( "sol_get_sysvar",                      fd_vm_syscall_sol_get_sysvar );
     119       13317 :   }
     120             : 
     121      338043 :   if( enable_get_epoch_stake_syscall ) {
     122       13302 :     REGISTER( "sol_get_epoch_stake",                 fd_vm_syscall_sol_get_epoch_stake );
     123       13302 :   }
     124             : 
     125      338043 :   REGISTER( "sol_memcpy_",                           fd_vm_syscall_sol_memcpy );
     126      338043 :   REGISTER( "sol_memmove_",                          fd_vm_syscall_sol_memmove );
     127      338043 :   REGISTER( "sol_memcmp_",                           fd_vm_syscall_sol_memcmp );
     128      338043 :   REGISTER( "sol_memset_",                           fd_vm_syscall_sol_memset );
     129      338043 :   REGISTER( "sol_invoke_signed_c",                   fd_vm_syscall_cpi_c );
     130      338043 :   REGISTER( "sol_invoke_signed_rust",                fd_vm_syscall_cpi_rust );
     131      338043 :   REGISTER( "sol_set_return_data",                   fd_vm_syscall_sol_set_return_data );
     132      338043 :   REGISTER( "sol_get_return_data",                   fd_vm_syscall_sol_get_return_data );
     133      338043 :   REGISTER( "sol_log_data",                          fd_vm_syscall_sol_log_data );
     134      338043 :   REGISTER( "sol_get_processed_sibling_instruction", fd_vm_syscall_sol_get_processed_sibling_instruction );
     135      338043 :   REGISTER( "sol_get_stack_height",                  fd_vm_syscall_sol_get_stack_height );
     136             : 
     137      338043 :   if( enable_curve25519_syscall ) {
     138       13977 :     REGISTER( "sol_curve_validate_point",            fd_vm_syscall_sol_curve_validate_point );
     139       13977 :     REGISTER( "sol_curve_group_op",                  fd_vm_syscall_sol_curve_group_op );
     140       13977 :     REGISTER( "sol_curve_multiscalar_mul",           fd_vm_syscall_sol_curve_multiscalar_mul );
     141       13977 :   }
     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      338043 :   if( enable_alt_bn128_syscall )
     148       14022 :     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      338043 :   if( enable_epoch_rewards_syscall )
     153       13989 :     REGISTER( "sol_get_epoch_rewards_sysvar",        fd_vm_syscall_sol_get_epoch_rewards_sysvar );
     154             : 
     155      338043 :   if( enable_poseidon_syscall )
     156       13902 :     REGISTER( "sol_poseidon",                        fd_vm_syscall_sol_poseidon );
     157             : 
     158             : //REGISTER( "sol_remaining_compute_units",           fd_vm_syscall_sol_remaining_compute_units );
     159             : 
     160      338043 :   if( enable_alt_bn128_compression_syscall )
     161       13974 :     REGISTER( "sol_alt_bn128_compression",           fd_vm_syscall_sol_alt_bn128_compression );
     162             : 
     163      338043 : # undef REGISTER
     164             : 
     165      338043 :   return FD_VM_SUCCESS;
     166      338043 : }

Generated by: LCOV version 1.14