Pointer width agnostic data type sizes #176
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We are using wasm to reuse our rust logic in our client libraries. Wasm uses the
wasm32-unknown-unknown
target which is on 32 bit architecture.Mango is using
usize
data type in many instruction and state structs, this is problematic for a few reasons.usize
docs:Mango code largely assumes usize is 8 bytes, which is expected with bpf and solana runtime, however wasm expects it to be 4 bytes, meaning it:
Fix
This PR changes every
usize
type used in instruction or state structs tou64
, which is the actual size ofusize
expected by the Mango program and clients, meaning this doesn't introduce any changes to the size of the ix or state data.u64
is converted tousize
where it was used in logic before, this is poses no issue as the conversion is trivial because bothu64
andusize
are the same size for thebpf
target.The only place where conversions are theoretically problematic is when converting from
u64
tousize
forwasm32
target, as theu64
value might be larger than what can fit intousize
(u32
). However since anyusize
value is use only for indexing, the current possible values all fit intou32
.Additionally the problematic conversions are only possible for wasm compiled code, meaning they are not possible in the solana runtime.