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