-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat(zink-codegen)/added bound checks for primitive numbers #282
base: main
Are you sure you want to change the base?
Conversation
Hi @sobuur0 , thanks for the contributions! please include the tests of bound checks in |
@clearloop for this is it only the example that remains |
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.
Thanks for the contribution! Introducing a trait for the bound checks make sense!
However, we can not use rust library's check_add because the WASM IR output, instead, we need to append extra logic for checking them on our own.
Yes, we need to create example under /examples
for testing our implementation, for example /examples/safe_math
!
When you meet any questions while working on the PR, no hesitate to request for a review via github, you can find it on the top right of the github UI!
btw please add your polygon address in the PR description, once the PR get merged, will transfer the bounty to the address provided in the PR ^ ^
($t:ty) => { | ||
impl SafeArithmetic for $t { | ||
fn safe_add(self, rhs: Self) -> Self { | ||
self.checked_add(rhs) |
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.
we can not use the checked_add
from rust library because it will generate verbose bytecode in the WASM IR, instead, we need to append EVM assembly opcodes to operations, for example
fn safe_add(self, rhs: Self) -> Self {
// the return value r is now on stack
let r = self.add(rhs);
if r > Self::MAX {
zink::revert!("...");
}
r
}
Same for all of the other operations
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.
@clearloop i'm having some imports issue, where should i place the logic?
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.
replace them into your current functions of the SafeArithmetic trait, could please elaborate which kind of import issues you are facing?
Resolves #154
0x0be5B36E45BA0246fb33e0f915ed459d9fcC249d