Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Move sr-arithmetic to a new crate and add in a fuzzer #3799

Merged
merged 70 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
963a14d
Split up sr_arithmetic.rs
expenses Oct 11, 2019
0bc870d
Add some basic fuzzing
expenses Oct 11, 2019
b1a9793
Add more tests
expenses Oct 11, 2019
dc8cc41
Add printing to fuzzing
expenses Oct 11, 2019
ee26625
Clean things up
expenses Oct 11, 2019
38597b9
Remove arbitrary
expenses Oct 11, 2019
c7c5888
Remove comments
expenses Oct 11, 2019
cd2db5d
More cleaning, fix small error that was causing a panic
expenses Oct 11, 2019
8a0ef6b
Add rational128
expenses Oct 11, 2019
562cdff
Remove old random tests
expenses Oct 11, 2019
c66f882
introduce panic
expenses Oct 11, 2019
7adc99d
fuzzing should panic properly
expenses Oct 11, 2019
c28ae3f
Bit of cleanup
expenses Oct 11, 2019
77a8cbb
Add a test uncovered via fuzzing that fails!
expenses Oct 11, 2019
1fe1a9f
Few small changes
expenses Oct 11, 2019
40c0708
Move sr-arithmetic to its own crate
expenses Oct 11, 2019
c7f5345
Fix fuzzing
expenses Oct 11, 2019
20813dd
Got rid of fuzzer Cargo.lock
expenses Oct 11, 2019
4aa7dd5
Added no_std
expenses Oct 11, 2019
e8cbb1d
re-export assert_eq_error_rate
expenses Oct 11, 2019
ed264e5
Merge branch 'master' of https://github.com/paritytech/substrate into…
expenses Oct 11, 2019
f4c5154
bump impl and spec version
expenses Oct 11, 2019
85f8487
re add convert into
expenses Oct 11, 2019
03dd42e
Add an ignore to the test
expenses Oct 12, 2019
aeb6a1d
Enabled benchmarking
expenses Oct 12, 2019
117f818
Reindent
expenses Oct 12, 2019
458edbd
Clean up biguint fuzzer
expenses Oct 12, 2019
419bc5a
Clean up biguint more
expenses Oct 13, 2019
89f6b06
shuffle sr-primitives/traits about
expenses Oct 13, 2019
8fb2890
Remove unused dependencies
expenses Oct 13, 2019
5eb310a
Apply clippy suggestions
expenses Oct 13, 2019
316f562
upgrade primitive-types versions
expenses Oct 13, 2019
ac9a2f2
Run tests against num-bigint
expenses Oct 13, 2019
5a21213
Get rid of allocation in assert_biguints_eq
expenses Oct 13, 2019
99f366e
Merge branch 'master' of https://github.com/paritytech/substrate into…
expenses Oct 14, 2019
2123d00
Add an optimisation to multiply_by_rational
expenses Oct 14, 2019
dc651e4
rename parts_per_x -> per_things
expenses Oct 14, 2019
2acc346
Change fuzzer cargo.toml
expenses Oct 14, 2019
38650cf
Remove allocation from BigUint PartialEq impl
expenses Oct 14, 2019
a377d3e
Remove accidental indentation
expenses Oct 14, 2019
ae25a41
Renmove Lazy and Convert traits
expenses Oct 14, 2019
20a0488
Copy assert_eq_error_rate macro back to sr-primitives
expenses Oct 14, 2019
17933d1
Add documentation to fuzzers
expenses Oct 14, 2019
7c80be9
fix sr-primitives assert_eq_error_rate
expenses Oct 14, 2019
c5616c2
add cfg(test)
expenses Oct 15, 2019
c082792
Update core/sr-arithmetic/src/traits.rs
expenses Oct 15, 2019
7878cec
Update core/sr-arithmetic/src/traits.rs
expenses Oct 15, 2019
5387c96
Update core/sr-arithmetic/fuzzer/src/biguint.rs
expenses Oct 15, 2019
98cdb31
Allow rounding up in rational128
expenses Oct 15, 2019
42f6521
Merge branch 'sr-arithmetic-fuzzing' of https://github.com/expenses/s…
expenses Oct 15, 2019
3ac8b87
Make changes to biguint.rs
expenses Oct 15, 2019
41cfa3a
Update core/sr-arithmetic/src/traits.rs
expenses Oct 15, 2019
99099c9
Final touches
expenses Oct 15, 2019
85a790b
Merge branch 'sr-arithmetic-fuzzing' of https://github.com/expenses/s…
expenses Oct 15, 2019
e32f887
Convert to num_bigint::BigUint to compare
expenses Oct 15, 2019
883272c
remove unused mut
expenses Oct 15, 2019
1209939
more small changes
expenses Oct 15, 2019
7202e2d
shuffle sr-primitives trait imports
expenses Oct 15, 2019
1cadf86
more code review
expenses Oct 15, 2019
a934f37
Merge branch 'master' into sr-arithmetic-fuzzing
expenses Oct 17, 2019
2dd9c31
move assert_eq_error_rate to lib.rs
expenses Oct 17, 2019
9a02591
Update core/sr-arithmetic/fuzzer/src/biguint.rs
expenses Oct 17, 2019
d58d6d3
Get rid of S
expenses Oct 17, 2019
9dd0688
Merge branch 'sr-arithmetic-fuzzing' of https://github.com/expenses/s…
expenses Oct 17, 2019
ab5ec37
Simplify rational128 honggfuzz link
expenses Oct 17, 2019
dcf169c
Insignificantly change rational128 fuzzing code
expenses Oct 18, 2019
f51e484
Fix merge conflict
expenses Oct 18, 2019
900c305
Slightly tidy up some of the arithmetic logic
expenses Oct 18, 2019
79e4348
Get rid of sr_arithmetic again(?) and fix sr-primitives/weights
expenses Oct 18, 2019
0a843c8
Apply updates to sr_arithmetic.rs to crate
expenses Oct 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 86 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ members = [
"core/service/test",
"core/session",
"core/sr-api-macros",
"core/sr-arithmetic",
"core/sr-arithmetic/fuzzer",
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
"core/sr-io",
"core/sr-primitives",
"core/sr-staking-primitives",
Expand Down
26 changes: 26 additions & 0 deletions core/sr-arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "sr-arithmetic"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
num-traits = { version = "0.2.8", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
integer-sqrt = "0.1.2"

[dev-dependencies]
primitive-types = "0.6.0"
rand = "0.7.2"

[features]
bench = []
default = ["std"]
std = [
"serde",
"num-traits/std",
"rstd/std",
"codec/std",
]
2 changes: 2 additions & 0 deletions core/sr-arithmetic/fuzzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hfuzz_target
hfuzz_workspace
20 changes: 20 additions & 0 deletions core/sr-arithmetic/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "sr-arithmetic-fuzzer"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
honggfuzz = "0.5"
sr-arithmetic = { path = ".." }
primitive-types = "0.6"
num-bigint = { git = "https://github.com/expenses/num-bigint", branch = "as-slice" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is fuzz code, it is okay to depend on git dependencies, but is there any other way to not depend on this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's not quite ideal, but to compare the BigUint implementations I need access to the underlying slice, so I had to use my own branch. I'll try and make a PR for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-num/num-bigint#12 does what I want, but the repo seems to be moving pretty slowly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as fuzzer is part of workspace then the test-suite will fail if this branch is changed, I think this is not fine, not sure what the best way to solve this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for the function fn assert_biguints_eq(a: &BigUint, b: &num_bigint::BigUint)
I think you can come up with a solution by converting a into num_bigint and use the partialeq implementation of num_bigint.

Or you can use the function https://docs.rs/num-bigint/0.2.3/num_bigint/struct.BigUint.html#method.to_radix_be or https://docs.rs/num-bigint/0.2.3/num_bigint/struct.BigUint.html#method.to_radix_le

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider this? I suppose you can go to to_str_radix and then easily convert every 4 chunks into a Single.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting to num_bigint::BigUint seems like the easiest approach for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will give this a try, think it is possible to build the thing from str_radix

num-traits = "*"
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

[[bin]]
name = "biguint"
path = "src/biguint.rs"

[[bin]]
name = "rational128"
path = "src/rational128.rs"