Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return u64 from get_balance in the athcon FFI #140

Closed
poszu opened this issue Oct 10, 2024 · 1 comment · Fixed by #144
Closed

Return u64 from get_balance in the athcon FFI #140

poszu opened this issue Oct 10, 2024 · 1 comment · Fixed by #144
Assignees
Labels
bug Something isn't working

Comments

@poszu
Copy link
Collaborator

poszu commented Oct 10, 2024

Currently, the get_balance() function returns a athcon_uint256be:

/**
* Get balance callback function.
*
* This callback function is used by a VM to query the balance of the given account.
*
* @param context The pointer to the Host execution context.
* @param address The address of the account.
* @return The balance of the given account or 0 if the account does not exist.
*/
typedef athcon_uint256be (*athcon_get_balance_fn)(struct athcon_host_context *context,
const athcon_address *address);

Which is supposed to be a 256bit big-endian integer encoded in a byte array:

/**
* The alias for athcon_bytes32 to represent a big-endian 256-bit integer.
*/
typedef struct athcon_bytes32 athcon_uint256be;

There are two problems with it:

  • the athena balance is u64 so its inefficient to pass it as 256bits
  • it's supposed to be big-endian (according to the type description) but we put the value as little-endian there

IMHO, we should change the C API to return a uint64_t instead to avoid confusion, make it efficient and simplify the code.

@poszu poszu self-assigned this Oct 10, 2024
@poszu poszu added the bug Something isn't working label Oct 10, 2024
@lrettig
Copy link
Contributor

lrettig commented Oct 10, 2024

Good catch. We use u64 in go-spacemesh so we should do the same in Athena. In any case it's more general than uint256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants