-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Correctly check for overflow in add, mul and pow #6452
Correctly check for overflow in add, mul and pow #6452
Conversation
This is not a vm issue, the instruction that's supposed to revert is getting optimized away. Likely the compiler doesn't consider panic-on-invalid-input side effect. Not sure if the compiler behavior is expected or not. Investigationif the function looks like this: #[test(should_revert)]
fn math_0th_root_fail() {
let _res = asm(r1: 100, r2: 0, r3) {
log flag r1 r2 zero;
mroo r3 r1 r2;
log flag r1 r2 r3;
log one one one one;
r3: u8
};
} Then the test passes as expected. However, if we remove the middle log, i.e.: #[test(should_revert)]
fn math_0th_root_fail() {
let _res = asm(r1: 100, r2: 0, r3) {
log flag r1 r2 zero;
mroo r3 r1 r2;
log one one one one;
r3: u8
};
} Then the test fails. Let's look at the bytecode. Compile with For the first version, i.e. without logging r3 , the bytecode looks like this:
However, when we introduce the log in the code in the second version, we get:
So it seems like the mroo is completely missing in the first version. |
…tps://github.com/FuelLabs/sway into swaystar123/proper_overflow_unsafe_math_checking
…tps://github.com/FuelLabs/sway into swaystar123/proper_overflow_unsafe_math_checking
Co-authored-by: Cameron Carstens <[email protected]>
…tps://github.com/FuelLabs/sway into swaystar123/proper_overflow_unsafe_math_checking
Co-authored-by: Cameron Carstens <[email protected]>
Co-authored-by: Cameron Carstens <[email protected]>
…tps://github.com/FuelLabs/sway into swaystar123/proper_overflow_unsafe_math_checking
…ar123/proper_overflow_unsafe_math_checking
…tps://github.com/FuelLabs/sway into swaystar123/proper_overflow_unsafe_math_checking
Description
Adds flag checks for overflow in core lib, properly cap values if overflow is enabled
Checklist
Breaking*
orNew Feature
labels where relevant.