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 3477 : fd_sbpf_syscall_func_t func ) {
8 3477 : if( FD_UNLIKELY( (!syscalls) | (!name) ) ) return FD_VM_ERR_INVAL;
9 :
10 3477 : fd_sbpf_syscalls_t * syscall = fd_sbpf_syscalls_insert( syscalls, (ulong)fd_murmur3_32( name, strlen( name ), 0U ) );
11 3477 : if( FD_UNLIKELY( !syscall ) ) return FD_VM_ERR_INVAL; /* name (or hash of name) already in map */
12 :
13 3477 : syscall->func = func;
14 3477 : syscall->name = name;
15 :
16 3477 : return FD_VM_SUCCESS;
17 3477 : }
18 :
19 : int
20 : fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
21 : ulong slot,
22 : fd_features_t const * features,
23 90 : uchar is_deploy ) {
24 90 : if( FD_UNLIKELY( !syscalls ) ) return FD_VM_ERR_INVAL;
25 :
26 90 : int enable_blake3_syscall = 0;
27 90 : int enable_last_restart_slot_syscall = 0;
28 90 : int enable_get_sysvar_syscall = 0;
29 90 : int enable_get_epoch_stake_syscall = 0;
30 90 : int enable_bls12_381_syscall = 0;
31 :
32 90 : if( slot ) {
33 36 : enable_blake3_syscall = FD_FEATURE_ACTIVE( slot, features, blake3_syscall_enabled );
34 36 : enable_last_restart_slot_syscall = FD_FEATURE_ACTIVE( slot, features, last_restart_slot_sysvar );
35 36 : enable_get_sysvar_syscall = FD_FEATURE_ACTIVE( slot, features, get_sysvar_syscall_enabled );
36 36 : enable_get_epoch_stake_syscall = FD_FEATURE_ACTIVE( slot, features, enable_get_epoch_stake_syscall );
37 36 : enable_bls12_381_syscall = FD_FEATURE_ACTIVE( slot, features, enable_bls12_381_syscall );
38 :
39 54 : } else { /* enable ALL */
40 :
41 54 : enable_blake3_syscall = 1;
42 54 : enable_last_restart_slot_syscall = 1;
43 54 : enable_get_sysvar_syscall = 1;
44 54 : enable_get_epoch_stake_syscall = 1;
45 54 : enable_bls12_381_syscall = 1;
46 :
47 54 : }
48 :
49 90 : fd_sbpf_syscalls_clear( syscalls );
50 :
51 90 : ulong syscall_cnt = 0UL;
52 :
53 3474 : # define REGISTER(name,func) do { \
54 3474 : if( FD_UNLIKELY( syscall_cnt>=fd_sbpf_syscalls_key_max() ) ) return FD_VM_ERR_FULL; \
55 3474 : int _err = fd_vm_syscall_register( syscalls, (name), (func) ); \
56 3474 : if( FD_UNLIKELY( _err ) ) return _err; \
57 3474 : syscall_cnt++; \
58 3474 : } 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 90 : REGISTER( "abort", fd_vm_syscall_abort );
63 90 : 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 90 : if ( FD_LIKELY( !is_deploy ) ) {
70 90 : REGISTER( "sol_alloc_free_", fd_vm_syscall_sol_alloc_free );
71 90 : }
72 :
73 : /* https://github.com/solana-labs/solana/blob/v1.18.1/sdk/program/src/syscalls/definitions.rs#L39 */
74 :
75 90 : REGISTER( "sol_log_", fd_vm_syscall_sol_log );
76 90 : REGISTER( "sol_log_64_", fd_vm_syscall_sol_log_64 );
77 90 : REGISTER( "sol_log_compute_units_", fd_vm_syscall_sol_log_compute_units );
78 90 : REGISTER( "sol_log_pubkey", fd_vm_syscall_sol_log_pubkey );
79 90 : REGISTER( "sol_create_program_address", fd_vm_syscall_sol_create_program_address );
80 90 : REGISTER( "sol_try_find_program_address", fd_vm_syscall_sol_try_find_program_address );
81 90 : REGISTER( "sol_sha256", fd_vm_syscall_sol_sha256 );
82 90 : REGISTER( "sol_keccak256", fd_vm_syscall_sol_keccak256 );
83 90 : # if FD_HAS_S2NBIGNUM
84 90 : REGISTER( "sol_secp256k1_recover", fd_vm_syscall_sol_secp256k1_recover );
85 : # else
86 : FD_LOG_ERR(( "This build does not include s2n-bignum, which is required to run a validator.\n"
87 : "To install s2n-bignum, re-run ./deps.sh, make distclean, and make -j" ));
88 : # endif
89 :
90 90 : if( enable_blake3_syscall )
91 84 : REGISTER( "sol_blake3", fd_vm_syscall_sol_blake3 );
92 :
93 90 : REGISTER( "sol_get_clock_sysvar", fd_vm_syscall_sol_get_clock_sysvar );
94 90 : REGISTER( "sol_get_epoch_schedule_sysvar", fd_vm_syscall_sol_get_epoch_schedule_sysvar );
95 :
96 90 : REGISTER( "sol_get_rent_sysvar", fd_vm_syscall_sol_get_rent_sysvar );
97 :
98 90 : if( FD_LIKELY( enable_last_restart_slot_syscall ) ) {
99 84 : REGISTER( "sol_get_last_restart_slot", fd_vm_syscall_sol_get_last_restart_slot_sysvar );
100 84 : }
101 :
102 90 : if( enable_get_sysvar_syscall ) {
103 84 : REGISTER( "sol_get_sysvar", fd_vm_syscall_sol_get_sysvar );
104 84 : }
105 :
106 90 : if( enable_get_epoch_stake_syscall ) {
107 84 : REGISTER( "sol_get_epoch_stake", fd_vm_syscall_sol_get_epoch_stake );
108 84 : }
109 :
110 90 : REGISTER( "sol_memcpy_", fd_vm_syscall_sol_memcpy );
111 90 : REGISTER( "sol_memmove_", fd_vm_syscall_sol_memmove );
112 90 : REGISTER( "sol_memcmp_", fd_vm_syscall_sol_memcmp );
113 90 : REGISTER( "sol_memset_", fd_vm_syscall_sol_memset );
114 90 : REGISTER( "sol_invoke_signed_c", fd_vm_syscall_cpi_c );
115 90 : REGISTER( "sol_invoke_signed_rust", fd_vm_syscall_cpi_rust );
116 90 : REGISTER( "sol_set_return_data", fd_vm_syscall_sol_set_return_data );
117 90 : REGISTER( "sol_get_return_data", fd_vm_syscall_sol_get_return_data );
118 90 : REGISTER( "sol_log_data", fd_vm_syscall_sol_log_data );
119 90 : REGISTER( "sol_get_processed_sibling_instruction", fd_vm_syscall_sol_get_processed_sibling_instruction );
120 90 : REGISTER( "sol_get_stack_height", fd_vm_syscall_sol_get_stack_height );
121 90 : REGISTER( "sol_get_epoch_rewards_sysvar", fd_vm_syscall_sol_get_epoch_rewards_sysvar );
122 :
123 90 : REGISTER( "sol_curve_validate_point", fd_vm_syscall_sol_curve_validate_point );
124 90 : REGISTER( "sol_curve_group_op", fd_vm_syscall_sol_curve_group_op );
125 90 : REGISTER( "sol_curve_multiscalar_mul", fd_vm_syscall_sol_curve_multiscalar_mul );
126 :
127 : // NOTE: sol_curve_pairing_map is defined but never implemented /
128 : // used, we can ignore it for now
129 : //REGISTER( "sol_curve_pairing_map", fd_vm_syscall_sol_curve_pairing_map );
130 :
131 90 : #if FD_HAS_INT128
132 90 : REGISTER( "sol_alt_bn128_group_op", fd_vm_syscall_sol_alt_bn128_group_op );
133 90 : REGISTER( "sol_alt_bn128_compression", fd_vm_syscall_sol_alt_bn128_compression );
134 90 : #endif /* FD_HAS_INT128 */
135 :
136 : //REGISTER( "sol_big_mod_exp", fd_vm_syscall_sol_big_mod_exp );
137 :
138 90 : REGISTER( "sol_poseidon", fd_vm_syscall_sol_poseidon );
139 :
140 : //REGISTER( "sol_remaining_compute_units", fd_vm_syscall_sol_remaining_compute_units );
141 :
142 90 : #if FD_HAS_BLST
143 90 : if( enable_bls12_381_syscall ) {
144 84 : REGISTER( "sol_curve_decompress", fd_vm_syscall_sol_curve_decompress );
145 84 : REGISTER( "sol_curve_pairing_map", fd_vm_syscall_sol_curve_pairing_map );
146 84 : }
147 : #else
148 : (void)enable_bls12_381_syscall;
149 : #endif /* FD_HAS_BLST */
150 :
151 90 : # undef REGISTER
152 :
153 90 : return FD_VM_SUCCESS;
154 90 : }
|