-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fuzzing and Organisation for Runtime Arithmetic Types #3745
Comments
Are you suggesting putting the contents of I'm a little confused about what you suggest for fuzzing. Currently this is the only code that uses random values, and it seems to be checking more for accuracy than panics: substrate/core/sr-primitives/src/sr_arithmetic.rs Lines 1200 to 1243 in ddd7368
Should something like cargo fuzz be used?
|
@hacky1997 Also, I cannot be sure, but be aware that this issue might grow a bit as we might find some good bugs in the arithmetic code while fuzzing (hopefully!) :) |
I think the cyclic dependency could be overcome, it depends on what we actually need for our computation. |
What are we actually fuzzing for here? I've found accuracy problems with #[test]
fn mul_by_best_effort_is_accurate() {
let a = 2475880078642818143838273536;
let b = 18014399314788352;
let c = 1190036353683150593851392;
assert_eq!(multiply_by_rational_best_effort(a, b, c), mul_div(a, b, c));
} but those sort of thing can be found easily by adding substrate/core/sr-primitives/src/sr_arithmetic.rs Lines 1230 to 1234 in 062748f
|
the fuzzing would be to detect abnormal accuracy. I think ideally accuracy should be proved to be good enough but in the current design it is not. I don't know what is multiply_by_rational_best_effort worst case. We know best effort is not perfect but should be ok accurate. (and maybe replaced by multi limb arithmetic soon) Also It could also detect some wrong implementation. |
The current implementation, so the user can chose. The PR that I linked above will merge these two and hopefully there will be one that will always return accurately as long as the result fits in u128. I think it will be good if whoever wants to work on this also keep track on the other PR. |
and see here for details of the current impls #3456 |
@expenses the PR is merged. One can start working on this now, if desired :) |
Thanks! |
sr_arithmetic.rs
.Optionally
add_assign
instead ofadd
. Also read and apply the suggestions here.The text was updated successfully, but these errors were encountered: