Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_vm_syscall_fd_vm_syscall_h
2 : #define HEADER_fd_src_flamenco_vm_syscall_fd_vm_syscall_h
3 :
4 : #include "../fd_vm_private.h"
5 : #include "fd_vm_cpi.h" /* FIXME: REFINE THIS MORE */
6 : #include "../../runtime/fd_runtime.h" /* FIXME: REFINE THIS MORE */
7 : #include "../../runtime/context/fd_exec_instr_ctx.h"
8 : #include "../../log_collector/fd_log_collector.h"
9 :
10 : #define FD_VM_RETURN_DATA_MAX (1024UL) /* FIXME: DOCUMENT AND DOES THIS BELONG HERE? */
11 : /* https://github.com/solana-labs/solana/blob/2afde1b028ed4593da5b6c735729d8994c4bfac6/sdk/program/src/pubkey.rs#L22 */
12 :
13 : /* FIXME: CONSIDER NOT PREFIXING SYSCALLS WITH SOL_? (OR MAYBE THIS
14 : IS NECESSARY TO DISAMBIGUATE SOLANA SYSCALLS FROM NON-SOLANA?
15 : SYSCALLS? */
16 :
17 : /* FD_VM_SYSCALL_DECL declares a prototype of a syscall. When a
18 : syscall implementation is called, the syscall will see a precise
19 : reporting VM's state at time of the syscall. Notably:
20 :
21 : - vm->pc will be at the syscall instruction
22 : - vm->ic will include the syscall instruction
23 : - vm->cu will include the 1 cu cost of the syscall instruction.
24 : Further, it will be positive.
25 :
26 : r1,r2,r3,r4,r5 are the values in r1,r2,r3,r4,r5 at time of the
27 : syscall.
28 :
29 : When a syscall implementation returns FD_VM_SUCCESS, *_r0 should hold
30 : the application return error value it wants to place in r0.
31 :
32 : When an syscall implementation returns FD_VM_ERR, the syscall is
33 : considered to have faulted the VM. It ideally should not have set
34 : *_r0 (or changed any vm state, except vm->cu, though that often isn't
35 : practical).
36 :
37 : It is the syscall's responsibility to deduct from vm->cu its specific
38 : cost model (not including the syscall instruction itself). As such,
39 : when a syscall returns SIGCOST, it should have set vm->cu to zero.
40 : When it returns anything else, it should have set cu to something in
41 : [1,cu_at_function_entry].
42 :
43 : To mitigate risks of from syscall implementations that do not
44 : strictly enforce this and other similar risks that can affect
45 : bookkeeping, on return from a syscall, the VM will:
46 :
47 : - Ignore updates to pc, ic and frame_cnt.
48 : - Ignore updates to cu that increase it.
49 : - Treat updates to cu that zero it as SIGCOST.
50 : - Treat SIGCOST returns that didn't update cu to zero as zeroing it.
51 :
52 : FIXME: ADD NO SETTING OF R0 ON VM_ERR IN VM_INTERP. */
53 :
54 : #define FD_VM_SYSCALL_DECL(name) \
55 : int \
56 : fd_vm_syscall_##name( void * _vm, \
57 : ulong r1, \
58 : ulong r2, \
59 : ulong r3, \
60 : ulong r4, \
61 : ulong r5, \
62 : ulong * _ret )
63 :
64 : FD_PROTOTYPES_BEGIN
65 :
66 : /* fd_vm_syscall_util *************************************************/
67 :
68 : /* syscall(b6fc1a11) "abort"
69 : Abort program execution and fail transaction.
70 :
71 : Inputs:
72 :
73 : r1 - ignored
74 : r2 - ignored
75 : r3 - ignored
76 : r4 - ignored
77 : r5 - ignored
78 :
79 : Return:
80 :
81 : FD_VM_ERR_ABORT: *_ret unchanged. vm->cu unchanged.
82 :
83 : FIXME: SHOULD THIS BE NAMED "SOL_ABORT"? */
84 :
85 : FD_VM_SYSCALL_DECL( abort );
86 :
87 : /* syscall(686093bb) "sol_panic_"
88 : Log panic message, abort program execution, and fail transaction.
89 :
90 : Inputs:
91 :
92 : r1 - msg, byte VM pointer, indexed [0,msg_sz), FIXME: WHEN IS NULL OKAY?
93 : r2 - msg_sz, FIXME: IS 0 OKAY?
94 : r3 - ignored
95 : r4 - ignored
96 : r5 - ignored
97 :
98 : Return:
99 :
100 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
101 : vm->cu==0.
102 :
103 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
104 : decremented and vm->cu>0.
105 :
106 : FD_VM_ERR_PANIC: *_ret unchanged. *_ret unchanged. vm->cu
107 : decremented and vm->cu>0. */
108 :
109 : FD_VM_SYSCALL_DECL( sol_panic );
110 :
111 : /* syscall(207559bd) "sol_log_"
112 : Write message to log.
113 :
114 : Inputs:
115 :
116 : r1 - msg, byte VM pointer, indexed [0,msg_sz), FIXME: WHEN IS NULL OKAY?
117 : r2 - msg_sz, FIXME: IS 0 OKAY?
118 : r3 - ignored
119 : r4 - ignored
120 : r5 - ignored
121 :
122 : Return:
123 :
124 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
125 : vm->cu==0.
126 :
127 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
128 : decremented and vm->cu>0.
129 :
130 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
131 :
132 : IMPORTANT SAFETY TIP! The log message will be silently truncated
133 : if there was not enough room for the message in the syscall log
134 : when called. */
135 :
136 : FD_VM_SYSCALL_DECL( sol_log );
137 :
138 : /* syscall(5c2a3178) "sol_log_64_"
139 : Write r1:5 to the log as a hexadecimal
140 :
141 : Inputs:
142 :
143 : r1 - ulong
144 : r2 - ulong
145 : r3 - ulong
146 : r4 - ulong
147 : r5 - ulong
148 :
149 : Return:
150 :
151 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
152 : vm->cu==0.
153 :
154 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
155 :
156 : IMPORTANT SAFETY TIP! The log message will be silently truncated
157 : if there was not enough room for the message in the syscall log
158 : when called. */
159 :
160 : FD_VM_SYSCALL_DECL( sol_log_64 );
161 :
162 : /* syscall(7ef088ca) "sol_log_pubkey"
163 : Write the base58 encoding of 32 byte array to the log.
164 :
165 : Inputs:
166 :
167 : r1 - pubkey, byte VM pointer, indexed [0,32)
168 : r2 - ignored
169 : r3 - ignored
170 : r4 - ignored
171 : r5 - ignored
172 :
173 : Return:
174 :
175 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
176 : vm->cu==0.
177 :
178 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
179 : decremented and vm->cu>0.
180 :
181 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
182 :
183 : IMPORTANT SAFETY TIP! The log message will be silently truncated
184 : if there was not enough room for the message in the syscall log
185 : when called. */
186 :
187 : FD_VM_SYSCALL_DECL( sol_log_pubkey );
188 :
189 : /* syscall(52ba5096) "sol_log_compute_units_"
190 : Write remaining compute unit count to log.
191 :
192 : Inputs:
193 :
194 : r1 - ignored
195 : r2 - ignored
196 : r3 - ignored
197 : r4 - ignored
198 : r5 - ignored
199 :
200 : Return:
201 :
202 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
203 : vm->cu==0.
204 :
205 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
206 : The value logged will be the value of cu when between when the
207 : syscall completed and the next interation starts and will be
208 : postive.
209 :
210 : IMPORTANT SAFETY TIP! The log message will be silently truncated
211 : if there was not enough room for the message in the syscall log
212 : when called. */
213 :
214 : FD_VM_SYSCALL_DECL( sol_log_compute_units );
215 :
216 : /* syscall(FIXME) "sol_log_data"
217 : Write the base64 encoded cnt data slices to the log.
218 :
219 : Inputs:
220 :
221 : r1 - slice, ulong pair VM pointer, indexed [0,cnt), FIXME: WHEN IS NULL OKAY?
222 : r2 - cnt, FIXME: IS 0 OKAY?
223 : r3 - ignored
224 : r4 - ignored
225 : r5 - ignored
226 :
227 : slice[i] holds the ulong pair:
228 : mem, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
229 : sz, FIXME: IS 0 OKAY?
230 :
231 : Return:
232 :
233 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
234 : vm->cu==0.
235 :
236 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
237 : decremented and vm->cu>0.
238 :
239 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
240 :
241 : IMPORTANT SAFETY TIP! The log message will be silently truncated
242 : if there was not enough room for the message in the syscall log
243 : when called. */
244 :
245 : FD_VM_SYSCALL_DECL( sol_log_data );
246 :
247 : /* syscall(FIXME) "sol_alloc_free"
248 : DEPRECATED ... dynamic heap allocation support
249 :
250 : Inputs:
251 :
252 : r1 - sz, ignored if vaddr is not 0
253 : r2 - free_vaddr, byte VM pointer
254 : r3 - ignored
255 : r4 - ignored
256 : r5 - ignored
257 :
258 : Return:
259 :
260 : All cases return FD_VM_SUCCESS and leave vm->cu unchanged.
261 :
262 : If free_vaddr is 0, this is "malloc"-like:
263 :
264 : Let the VM heap region cover bytes [heap_start,heap_end) with
265 : heap_start<=heap_end. If the request was satisfied, on return,
266 : *_ret will point to a range of heap bytes [*_ret,*_ret+sz) that
267 : does not overlap with any other current allocation such that
268 : heap_start<=*_ret<=*_ret+sz<=heap_end. This includes the zero sz
269 : case (note that the zero sz case might return the same value as a
270 : previous zero sz case and/or return the exact value of heap_end).
271 :
272 : If the request cannot be satisfied, *_ret=0 on return and the
273 : heap unchanged.
274 :
275 : IMPORTANT SAFETY TIP! If the VM has check_align set, this
276 : location will have at least 8 byte alignment. Otherwise, this
277 : location will have no particular alignment. Note that this
278 : implies allocations done by this syscall do not conform to the
279 : usual alignment requirements of a standard malloc call for older
280 : VM code.
281 :
282 : If vaddr is not-zero, this is "free"-like. Since the underlying
283 : implementation is necessarily a bump allocator (see implementation
284 : for more details), the specific value is ignored and *_ret=0 on
285 : return. */
286 :
287 : FD_VM_SYSCALL_DECL( sol_alloc_free );
288 :
289 : /* syscall(FIXME) "sol_memcpy"
290 : Copy sz bytes from src to dst. src and dst should not overlap.
291 :
292 : Inputs:
293 :
294 : r1 - dst, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
295 : r2 - src, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY? FIXME: WHEN IS SRC==DST OKAY?
296 : r3 - sz, FIXME: IS 0 okay?
297 : r4 - ignored
298 : r5 - ignored
299 :
300 : Return:
301 :
302 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
303 : vm->cu==0.
304 :
305 : FD_VM_ERR_MEM_OVERLAP: address ranges for src and dst overlap
306 : (either partially or fully). Empty address ranges are considered
307 : to never overlap (FIXME: CHECK THIS IS DESIRED). *_ret unchanged.
308 : vm->cu decremented and vm->cu>0. FIXME: CONSIDER USING A DIFFERENT
309 : ERR CODE?
310 :
311 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
312 : decremented and vm->cu>0.
313 :
314 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
315 : On return, dst[i]==src[i] for i in [0,sz). */
316 :
317 : FD_VM_SYSCALL_DECL( sol_memcpy );
318 :
319 : /* syscall(FIXME) "sol_memcmp"
320 : Compare sz bytes at m0 to m1
321 :
322 : Inputs:
323 :
324 : r1 - m0, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
325 : r2 - m1, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
326 : r3 - sz, FIXME: IS SZ 0 OKAY?
327 : r4 - out, int VM pointer
328 : r5 - ignored
329 :
330 : Return:
331 :
332 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
333 : vm->cu==0.
334 :
335 : FD_VM_ERR_SIGSEGV: bad address range (including out not 4 byte
336 : aligned). *_ret unchanged. vm->cu decremented and vm->cu>0.
337 : Strict alignment is only required when the VM has check_align set.
338 :
339 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
340 : On return, *_out will hold a positive / zero / negative number if
341 : the region at m0 lexicographically compares strictly greater than /
342 : equal to / strictly less than the region at m1 when treated as
343 : uchars. Specifically, if the regions are different, *_out will be
344 : (int)m0[i] - (int)m1[i] where i is the first differing byte.
345 :
346 : IMPORANT SAFETY TIP! Note that, strangely, this returns the result
347 : in memory instead via *_ret like a libc-style memcmp would. */
348 :
349 : FD_VM_SYSCALL_DECL( sol_memcmp );
350 :
351 : /* syscall(FIXME) "sol_memset"
352 : Set sz bytes at dst to the byte value c.
353 :
354 : Inputs:
355 :
356 : r1 - dst, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
357 : r2 - c, bits [8,64) ignored (FIXME: CHECK SOLANA DOES THIS)
358 : r3 - sz, FIXME: IS SZ 0 OKAY?
359 : r4 - ignored
360 : r5 - ignored
361 :
362 : Return:
363 :
364 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
365 : vm->cu==0.
366 :
367 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
368 : decremented and vm->cu>0.
369 :
370 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
371 : On return, dst[i]==(uchar)(c & 255UL) for i in [0,sz). */
372 :
373 : FD_VM_SYSCALL_DECL( sol_memset );
374 :
375 : /* syscall(FIXME) "sol_memmove"
376 : Copy sz bytes from src to dst. src and dst can overlap.
377 :
378 : Inputs:
379 :
380 : r1 - dst, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
381 : r2 - src, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
382 : r3 - sz, FIXME: IS SZ 0 OKAY?
383 : r4 - ignored
384 : r5 - ignored
385 :
386 : Return:
387 :
388 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
389 : vm->cu==0.
390 :
391 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
392 : decremented and vm->cu>0.
393 :
394 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
395 : On return, dst[i]==src_as_it_was_before_the_call[i] for i in
396 : [0,sz). */
397 :
398 : FD_VM_SYSCALL_DECL( sol_memmove );
399 :
400 : /* fd_vm_syscall_runtime **********************************************/
401 :
402 : /* syscall(FIXME) "sol_get_clock_sysvar"
403 : syscall(FIXME) "sol_get_epoch_schedule_sysvar"
404 : syscall(FIXME) "sol_get_fees_sysvar"
405 : syscall(FIXME) "sol_get_rent_sysvar"
406 : syscall(FIXME) "sol_get_last_restart_slot_sysvar"
407 : Get various sysvar values
408 :
409 : Inputs:
410 :
411 : r1 - out, {clock,schedule,fees,rent,last_restart_slot} VM pointer
412 : r2 - ignored
413 : r3 - ignored
414 : r4 - ignored
415 : r5 - ignored
416 :
417 : Return:
418 :
419 : FD_VM_ERR_SIGCALL: the VM is not running within the Solana runtime.
420 : *_ret unchanged. vm->cu unchanged.
421 :
422 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
423 : vm->cu==0.
424 :
425 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
426 : decremented and vm->cu>0. out should have:
427 : | align | sz
428 : clock | 8 | 40
429 : schedule | 1 | 40 ... FIXME: CHECK THIS IS CORRECT!
430 : fees | 8 | 8
431 : rent | 8 | 24
432 : last restart slot | 8 | 8
433 : Strict alignment is only required when the VM has check_align set.
434 :
435 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0.
436 : On return, *out will hold the value of the appropriate sysvar. */
437 :
438 : FD_VM_SYSCALL_DECL( sol_get_clock_sysvar );
439 : FD_VM_SYSCALL_DECL( sol_get_epoch_schedule_sysvar );
440 : FD_VM_SYSCALL_DECL( sol_get_fees_sysvar );
441 : FD_VM_SYSCALL_DECL( sol_get_rent_sysvar );
442 : FD_VM_SYSCALL_DECL( sol_get_last_restart_slot_sysvar );
443 :
444 : /* syscall(FIXME) "sol_get_stack_height"
445 :
446 : Inputs:
447 :
448 : r1 - ignored
449 : r2 - ignored
450 : r3 - ignored
451 : r4 - ignored
452 : r5 - ignored
453 :
454 : Return:
455 :
456 : FD_VM_ERR_SIGCALL: the VM is not running within the Solana runtime.
457 : *_ret unchanged. vm->cu unchanged.
458 :
459 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
460 : vm->cu==0.
461 :
462 : FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu
463 : decremented and vm->cu>0.
464 :
465 : FD_VM_SUCCESS: success. *_ret=stack_height. vm->cu decremented
466 : and vm->cu>0. */
467 :
468 : FD_VM_SYSCALL_DECL( sol_get_stack_height );
469 :
470 : /* syscall(FIXME) "sol_get_return_data"
471 : Get the return data and program id associated with it.
472 :
473 : Inputs:
474 :
475 : r1 - dst, byte VM pointer, indexed [0,dst_max), FIXME: WHEN IS NULL OKAY?
476 : r2 - dst_max, FIXME: IS 0 OKAY?
477 : r3 - program_id, byte VM pointer, indexed [0,32)
478 : r4 - ignored
479 : r5 - ignored
480 :
481 : Return:
482 :
483 : FD_VM_ERR_SIGCALL: the VM is not running within the Solana runtime.
484 : *_ret unchanged. vm->cu unchanged.
485 :
486 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
487 : vm->cu==0.
488 :
489 : FD_VM_ERR_MEM_OVERLAP: dst and program_id address ranges overlap.
490 : *_ret unchanged. vm->cu decremented and vm->cu>0. (FIXME: ERR
491 : CODE) (FIXME: overlap currently checked against the acutal amount
492 : copied into dst which is <=dst_max ... DOUBLE CHECK THIS AGAINST
493 : THE SOLANA IMPLEMENTATION.)
494 :
495 : FD_VM_ERR_SIGSEGV: bad address range for dst and/or program_id.
496 : *_ret unchanged. Compute budget decremented. (FIXME: dst address
497 : range currently checked aginst the actual amount copied into dst,
498 : which is <=dst_max ... DOUBLE CHECK THIS AGAINST THE SOLANA
499 : IMPLEMENTATION.)
500 :
501 : FD_VM_SUCCESS: success. *_ret=return_data_sz. vm->cu decremented
502 : and vm->cu>0. On return, if dst_max was non-zero, dst holds the
503 : leading min(return_data_sz,dst_max) bytes of return data (as such,
504 : if return_data_sz>dst_max, the value returned in the buffer was
505 : truncated). Any trailing bytes of dst are unchanged. program_id
506 : holds the program_id associated with the return data.
507 :
508 : If dst_max was zero, dst and program_id are untouched. (FIXME: IS
509 : THIS CORRECT BEHAVIOR FOR PROGRAM_ID?) */
510 :
511 : FD_VM_SYSCALL_DECL( sol_get_return_data );
512 :
513 : /* syscall(FIXME) "sol_set_return_data"
514 : Set the return data. The return data will be associated with the
515 : caller's program ID.
516 :
517 : Inputs:
518 :
519 : r1 - src, byte VM pointer, indexed [0,src_sz), FIXME: WHEN IS NULL OKAY?
520 : r2 - src_sz, FIXME: IS 0 OKAY?
521 : r3 - ignored
522 : r4 - ignored
523 : r5 - ignored
524 :
525 : Return:
526 :
527 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
528 : vm->cu decremented and vm->cu>0.
529 :
530 : FD_VM_ERR_RETURN_DATA_TOO_LARGE: src_sz too large. *_ret
531 : unchanged. vm->cu decremented and vm->cu>0.
532 :
533 : FD_VM_ERR_PERM: bad address range for src. *_ret unchanged.
534 : vm->cu decremented and vm->cu>0.
535 :
536 : FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0. */
537 :
538 : FD_VM_SYSCALL_DECL( sol_set_return_data );
539 :
540 : /* FIXME: NOT IMPLEMENTED YET ... IGNORES ALL ARGUMENTS AND RETURNS
541 : FD_VM_ERR_UNSUP. (MAYBE GROUP WITH CPI OR PDA?)*/
542 :
543 : FD_VM_SYSCALL_DECL( sol_get_processed_sibling_instruction );
544 :
545 : /* fd_vm_syscall_pda **************************************************/
546 :
547 : /* syscall(9377323c) "sol_create_program_address"
548 :
549 : Compute SHA-256 hash of <program ID> .. &[&[u8]] .. <PDA Marker>
550 : and check whether result is an Ed25519 curve point.
551 :
552 : Inputs:
553 :
554 : arg0 - seed, ulong pair (FIXME: TRIPLE?) VM pointer, indexed [0,seed_cnt), FIXME: WHEN IS NULL OKAY?
555 : arg1 - seed_cnt, FIXME: IS 0 OKAY?
556 : arg2 - program_id, byte VM pointer, indexed [0,32) (FIXME: DOUBLE CHECK SIZE / ALIGN REQ)
557 : arg3 - out, byte VM pointer, indexed [0,32) (FIXME: DOUBLE CHECK SIZE)
558 : arg4 - ignored
559 :
560 : seed[i] holds the ulong pair (FIXME: TRIPLE?):
561 : mem, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
562 : sz, FIXME: IS 0 OKAY?
563 :
564 : Return:
565 :
566 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
567 : Compute budget decremented.
568 :
569 : FD_VM_ERR_PERM: seed_cnt and/or seed[i].sz too large (FIXME: USE
570 : DIFFERENT ERR CODE), bad address range for program_id, seed,
571 : seed[i].mem and/or out (including 8-byte alignment for seed if the
572 : VM has check_align set). *_ret unchanged. Compute budget
573 : decremented.
574 :
575 : FD_VM_SUCCESS: success. If *_ret==0, a PDA was created and
576 : stored at out. If *_ret==1, create failed and out was unchanged.
577 : Compute budget decremented. */
578 :
579 : FD_VM_SYSCALL_DECL( sol_create_program_address );
580 :
581 : /* syscall(48504a38) "sol_try_find_program_address"
582 :
583 : Repeatedly derive program address while incrementing nonce in seed
584 : list until a point is found that is not a valid Ed25519 curve point.
585 :
586 : Inputs:
587 :
588 : arg0 - seed, ulong pair (FIXME: TRIPLE?) VM pointer, indexed [0,seed_cnt), FIXME: WHEN IS NULL OKAY?
589 : arg1 - seed_cnt, FIXME: IS 0 OKAY?
590 : arg2 - program_id, byte VM pointer, indexed [0,32) (FIXME: DOUBLE CHECK SIZE / ALIGN REQ)
591 : arg3 - out, byte VM pointer, indexed [0,32) (FIXME: DOUBLE CHECK SIZE)
592 : arg4 - bump_seed, byte VM pointer, indexed [0,1)
593 :
594 : seed[i] holds the ulong pair (FIXME: TRIPLE?):
595 : mem, byte VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
596 : sz, FIXME: IS 0 OKAY?
597 :
598 : Return:
599 :
600 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
601 : Compute budget decremented.
602 :
603 : FD_VM_ERR_PERM: seed_cnt and/or seed[i].sz too large (FIXME: USE
604 : DIFFERENT ERR CODE), bad address range for program_id, seed,
605 : seed[i].mem, out and/or bump_seed (including 8-byte alignment for
606 : seed if the VM has check_align set). *_ret unchanged. Compute
607 : budget decremented.
608 :
609 : FD_VM_SUCCESS: success. If *_ret==0, a PDA was found and stored at
610 : out and the suffix stored at bump_seed. If *_ret==1, no PDA was
611 : found and out and bump_seed were unchanged. Compute budget
612 : decremented. */
613 :
614 : FD_VM_SYSCALL_DECL( sol_try_find_program_address );
615 :
616 : /* fd_vm_syscall_cpi **************************************************/
617 :
618 : /* Represents an account for a CPI */
619 : /* FIXME: DOES THIS GO HERE? MAYBE GROUP WITH ADMIN OR OUTSIDE SYSCALL? */
620 :
621 : struct fd_instruction_account {
622 : ushort index_in_transaction;
623 : ushort index_in_caller;
624 : ushort index_in_callee;
625 : uint is_signer;
626 : uint is_writable;
627 : };
628 :
629 : typedef struct fd_instruction_account fd_instruction_account_t;
630 :
631 : /* Prepare instruction method */
632 : /* FIXME: DOES THIS GO HERE? MAYBE GROUP WITH ADMIN OR OUTSIDE SYSCALL? */
633 :
634 : int
635 : fd_vm_prepare_instruction( fd_instr_info_t const * caller_instr,
636 : fd_instr_info_t * callee_instr,
637 : fd_exec_instr_ctx_t * instr_ctx,
638 : fd_instruction_account_t instruction_accounts[256],
639 : ulong * instruction_accounts_cnt,
640 : fd_pubkey_t const * signers,
641 : ulong signers_cnt );
642 :
643 : /* syscall(a22b9c85) "sol_invoke_signed_c"
644 : Dispatch a cross program invocation. Inputs are in C ABI.
645 :
646 : FIXME: BELT SAND AND DOCUMENT */
647 :
648 : FD_VM_SYSCALL_DECL( cpi_c );
649 :
650 : /* syscall(d7449092) "sol_invoke_signed_rust"
651 : Dispatch a cross program invocation. Inputs are in Rust ABI.
652 :
653 : FIXME: BELT SAND AND DOCUMENT */
654 :
655 : FD_VM_SYSCALL_DECL( cpi_rust );
656 :
657 : /* fd_vm_syscall_crypto ***********************************************/
658 :
659 : /* FD_VM_SYSCALL_SOL_ALT_BN128_{ADD,SUB,MUL,PAIRING} specifies the curve operation. */
660 :
661 99 : #define FD_VM_SYSCALL_SOL_ALT_BN128_ADD ( 0UL) /* add */
662 : #define FD_VM_SYSCALL_SOL_ALT_BN128_SUB ( 1UL) /* add inverse */
663 10743 : #define FD_VM_SYSCALL_SOL_ALT_BN128_MUL ( 2UL) /* scalar mult */
664 2865 : #define FD_VM_SYSCALL_SOL_ALT_BN128_PAIRING ( 3UL) /* pairing */
665 :
666 : /* FD_VM_SYSCALL_SOL_ALT_BN128_{...}COMPRESS specifies the (de)compress operation. */
667 :
668 1203 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G1_COMPRESS ( 0UL) /* compress point in G1 */
669 1203 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G1_DECOMPRESS ( 1UL) /* decompress point in G1 */
670 1587 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G2_COMPRESS ( 2UL) /* compress point in G2 */
671 1587 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G2_DECOMPRESS ( 3UL) /* decompress point in G2 */
672 :
673 : /* FD_VM_SYSCALL_SOL_ALT_BN128_{...}_SZ specifies the size of inputs/outputs for the Alt_BN128 curve. */
674 :
675 6450 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G1_SZ ( 64UL) /* size of a point in G1 */
676 792 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G1_COMPRESSED_SZ ( 32UL) /* size of a compressed point in G2 */
677 1200 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G2_SZ (128UL) /* size of a point in G2 */
678 912 : #define FD_VM_SYSCALL_SOL_ALT_BN128_G2_COMPRESSED_SZ ( 64UL) /* size of a compressed point in G2 */
679 : #define FD_VM_SYSCALL_SOL_ALT_BN128_SCALAR_SZ ( 32UL) /* size of a scalar */
680 1437 : #define FD_VM_SYSCALL_SOL_ALT_BN128_PAIRING_INPUT_EL_SZ (192UL) /* size of G1 + G2 */
681 2874 : #define FD_VM_SYSCALL_SOL_ALT_BN128_PAIRING_OUTPUT_SZ ( 32UL) /* size of pairing syscall result, i.e. 0 or 1 as 256-bit int ¯\_(ツ)_/¯ */
682 :
683 : /* syscall(FIXME) sol_alt_bn128_group_op computes operations on the Alt_BN128 curve,
684 : including point addition in G1, scalar multiplication in G1, and pairing.
685 : See SIMD-0129.
686 :
687 : FIXME: DOCUMENT */
688 :
689 : FD_VM_SYSCALL_DECL( sol_alt_bn128_group_op );
690 :
691 : /* syscall(FIXME) sol_alt_bn128_compression allows to compress or decompress points
692 : in G1 or G2 groups over the Alt_BN128 curve.
693 : See SIMD-0129.
694 :
695 : FIXME: DOCUMENT */
696 :
697 : FD_VM_SYSCALL_DECL( sol_alt_bn128_compression );
698 :
699 : /* syscall(FIXME) "sol_blake3"
700 : syscall(FIXME) "sol_keccak256"
701 : syscall(FIXME) "sol_sha256"
702 :
703 : Inputs:
704 :
705 : arg0 - slice, ulong pair VM pointer, indexed [0,cnt), FIXME: WHEN IS NULL OKAY?
706 : arg1 - cnt, FIXME: IS 0 OKAY?
707 : arg2 - hash, byte VM pointer, indexed [0,32)
708 : arg3 - ignored
709 : arg4 - ignored
710 :
711 : slice[i] holds the ulong pair:
712 : mem, byte vector VM pointer, indexed [0,sz), FIXME: WHEN IS NULL OKAY?
713 : sz, FIXME: IS 0 OKAY?
714 :
715 : Return:
716 :
717 : FD_VM_ERR_INVAL: cnt too large. *_ret unchanged.
718 :
719 : FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged.
720 : Compute budget decremented.
721 :
722 : FD_VM_ERR_PERM: bad address range for slice, hash and/or
723 : slice[i].addr (including slice not 8 byte aligned if the VM has
724 : check_align set). *_ret unchanged. Compute budget decremented.
725 :
726 : FD_VM_SUCCESS: success. *_ret=0 and hash[i] holds the hash of the
727 : concatentation of the slices. Compute budget decremented. */
728 :
729 : FD_VM_SYSCALL_DECL( sol_blake3 );
730 : FD_VM_SYSCALL_DECL( sol_keccak256 );
731 : FD_VM_SYSCALL_DECL( sol_sha256 );
732 :
733 : /* syscall(FIXME) sol_poseidon computes the Poseidon hash on an array of input values.
734 : See SIMD-0129.
735 :
736 : FIXME: DOCUMENT */
737 :
738 : #define FD_VM_SYSCALL_SOL_POSEIDON_MAX_VALS 12UL
739 :
740 : FD_VM_SYSCALL_DECL( sol_poseidon ); /* Light protocol flavor */
741 :
742 : /* syscall(FIXME) "sol_secp256k1_recover"
743 :
744 : FIXME: BELT SAND AND DOCUMENT */
745 :
746 : FD_VM_SYSCALL_DECL( sol_secp256k1_recover );
747 :
748 : /* fd_vm_syscall_curve ************************************************/
749 :
750 : /* FD_VM_SYSCALL_SOL_CURVE_CURVE25519_{...} specifies the curve ID */
751 :
752 165 : #define FD_VM_SYSCALL_SOL_CURVE_CURVE25519_EDWARDS ( 0UL) /* ed25519 */
753 174 : #define FD_VM_SYSCALL_SOL_CURVE_CURVE25519_RISTRETTO ( 1UL) /* ristretto255 */
754 :
755 : /* FD_VM_SYSCALL_SOL_CURVE_{...} specifies the curve operation */
756 :
757 48 : #define FD_VM_SYSCALL_SOL_CURVE_ADD ( 0UL) /* add */
758 45 : #define FD_VM_SYSCALL_SOL_CURVE_SUB ( 1UL) /* add inverse */
759 141 : #define FD_VM_SYSCALL_SOL_CURVE_MUL ( 2UL) /* scalar mul */
760 :
761 : /* FD_VM_SYSCALL_SOL_CURVE_CURVE25519_{...}_SZ specifies the size of inputs/outputs. */
762 :
763 12 : #define FD_VM_SYSCALL_SOL_CURVE_CURVE25519_POINT_SZ (32UL) /* point (compressed) */
764 12 : #define FD_VM_SYSCALL_SOL_CURVE_CURVE25519_SCALAR_SZ (32UL) /* scalar */
765 :
766 : /* syscall(FIXME) sol_curve_validate_point
767 :
768 : FIXME: BELT SAND AND DOCUMENT */
769 :
770 : FD_VM_SYSCALL_DECL( sol_curve_validate_point );
771 :
772 : /* syscall(FIXME) sol_curve_validate_point
773 :
774 : FIXME: BELT SAND AND DOCUMENT */
775 :
776 : FD_VM_SYSCALL_DECL( sol_curve_group_op );
777 :
778 : /* syscall(FIXME) sol_curve_validate_point
779 :
780 : FIXME: BELT SAND AND DOCUMENT */
781 :
782 : FD_VM_SYSCALL_DECL( sol_curve_multiscalar_mul );
783 :
784 : int
785 : fd_vm_derive_pda( fd_vm_t * vm,
786 : fd_pubkey_t const * program_id,
787 : ulong program_id_vaddr,
788 : ulong seeds_vaddr,
789 : ulong seeds_cnt,
790 : uchar * bump_seed,
791 : fd_pubkey_t * out );
792 :
793 : FD_PROTOTYPES_END
794 :
795 : #endif /* HEADER_src_flamenco_vm_syscall_fd_vm_syscall_h */
|