-
Notifications
You must be signed in to change notification settings - Fork 118
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
[x/programs] Improve overflow checks #600
Conversation
I think we should refactor how we handle uint64 & int64. I updated the PR to reduce our risk of overflow and allowing greater functionality with signed integers. In the codebase we were restricting call params to our wasm programs to only
Because of WASM's nature we should default to using |
In addition to #429 we need to make sure our wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense one last nit 🙏
- ensure safe conversion from int64 to int32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very close!
Co-authored-by: Sam Batschelet <[email protected]> Signed-off-by: Sam Liokumovich <[email protected]>
@hexfusion should I also check the return value for overflow in this function? pub extern "C" fn alloc(len: usize) -> *mut u8 { |
Well we should ensure that all the conversions are safe for Alloc. I think we still need to check uint64 -> int32 here in golang? Not sure how practical that overflow would be but doesn't hurt. hypersdk/x/programs/runtime/memory.go Lines 77 to 82 in 8a71911
the export to alloc takes an i32 as param and usize can't be negative so I am not sure if something strange could happen there I suppose you could check against |
// ensure memory pointer is fits in an i64 | ||
// to avoid potential issues when passing | ||
// across wasm boundary | ||
assert!(i64::try_from(ptr as u64).is_ok()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
This PR improves overflow handling and generally improves developer UX by allowing not restricting
Call
params sent to the Program to be uint64.