Skip to content

Commit

Permalink
change to return the u64 rather than write it
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Mar 31, 2024
1 parent e6a7c9a commit 83ae29d
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions proposals/0133-syscall-get-epoch-stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,28 @@ 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
Expand All @@ -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.

0 comments on commit 83ae29d

Please sign in to comment.