From c082f295364e17570deabacf177834bd398cddf3 Mon Sep 17 00:00:00 2001 From: Joe C Date: Mon, 1 Apr 2024 09:17:14 -0500 Subject: [PATCH] change to return the `u64` rather than write it --- proposals/0133-syscall-get-epoch-stake.md | 38 ++++++++++------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/proposals/0133-syscall-get-epoch-stake.md b/proposals/0133-syscall-get-epoch-stake.md index ed1bc3b2..29e57d70 100644 --- a/proposals/0133-syscall-get-epoch-stake.md +++ b/proposals/0133-syscall-get-epoch-stake.md @@ -57,35 +57,35 @@ The specification for the proposed syscall is as follows: * Retrieves the total active stake delegated to a vote account for the current * epoch. * - * @param var_addr VM memory address to copy the retrieved data to. - * @param vote_address A pointer to 32 bytes representing the vote address. - * @return A 64-bit unsigned integer error code: - * - 0 if the operation is successful. - * - Non-zero error code. - * - * If the operation is not successful, data will not be written to the - * provided VM memory address. + * @param vote_addr A pointer to 32 bytes representing the vote address. + * @return A 64-bit unsigned integer representing the total + * active stake delegated to the vote account at the + * provided address. */ -uint64_t sol_get_epoch_stake( - /* r1 */ uint8_t * var_addr, - /* r2 */ void const * vote_address, -); +uint64_t sol_get_epoch_stake(/* r1 */ void const * vote_addr); ``` -`var_addr` must be the starting address of 8 bytes of writable VM memory to -store the `u64` response. If not, the syscall will abort the VM with an access -violation. - If the provided vote address corresponds to an account that is not a vote account or does not exist, the syscall will write `0` for active stake. +### Control Flow + +The syscall aborts the virtual machine if not all bytes in VM memory range +`[vote_addr, vote_addr + 32)` are readable. + +Otherwise, the syscall returns a `u64` integer representing the total active +stake delegated to the vote account at the provided address. + +If the provided vote address corresponds to an account that is not a vote +account or does not exist, the syscall will return `0` for active stake. + ### Compute Unit Usage The syscall will always attempt to consume the same amount of CUs regardless of control flow. ``` -(32 / cpi_per_u) + (8 / cpi_per_u) +syscall_base + (32/cpi_per_u) + mem_op_base ``` - `syscall_base`: Base cost of a sysvall. @@ -102,7 +102,3 @@ This new syscall introduces the same security considerations as the rest of the syscalls in the existing interface, which manipulate raw pointers to VM memory and must be implemented with care. -A potential pitfall in the implementation could come when comparing the act of -writing a `0` to the VM memory for active stake versus returning a `0` for -success. The two should not be conflated. -