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