Add erasure-coding/fuzzer to workspace (#7210)

* Add to workspace

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove dumb clones

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update Cargo.lock

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-05-12 00:55:45 +02:00
committed by GitHub
parent 7f391adf44
commit 7d8ecced0e
6 changed files with 31 additions and 32 deletions
+10
View File
@@ -2156,6 +2156,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "erasure_coding_fuzzer"
version = "0.9.41"
dependencies = [
"honggfuzz",
"polkadot-erasure-coding",
"polkadot-node-primitives",
"polkadot-primitives",
]
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.2.8" version = "0.2.8"
+1
View File
@@ -40,6 +40,7 @@ members = [
"cli", "cli",
"core-primitives", "core-primitives",
"erasure-coding", "erasure-coding",
"erasure-coding/fuzzer",
"primitives", "primitives",
"primitives/test-helpers", "primitives/test-helpers",
"runtime/common", "runtime/common",
+1 -2
View File
@@ -3,6 +3,7 @@ name = "erasure_coding_fuzzer"
version.workspace = true version.workspace = true
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
publish = false
[dependencies] [dependencies]
polkadot-erasure-coding = { path = ".." } polkadot-erasure-coding = { path = ".." }
@@ -17,5 +18,3 @@ path = "src/reconstruct.rs"
[[bin]] [[bin]]
name = "round_trip" name = "round_trip"
path = "src/round_trip.rs" path = "src/round_trip.rs"
[workspace]
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use honggfuzz::fuzz;
use polkadot_erasure_coding::*; use polkadot_erasure_coding::*;
use primitives::AvailableData; use primitives::AvailableData;
use honggfuzz::fuzz;
fn main() { fn main() {
loop { loop {
@@ -24,7 +24,7 @@ fn main() {
let (num_validators, chunk_input) = data; let (num_validators, chunk_input) = data;
let reconstructed: Result<AvailableData, _> = reconstruct_v1( let reconstructed: Result<AvailableData, _> = reconstruct_v1(
num_validators, num_validators,
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>() chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>(),
); );
println!("reconstructed {:?}", reconstructed); println!("reconstructed {:?}", reconstructed);
}); });
@@ -14,41 +14,33 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use honggfuzz::fuzz;
use polkadot_erasure_coding::*; use polkadot_erasure_coding::*;
use polkadot_primitives::PersistedValidationData;
use primitives::{AvailableData, BlockData, PoV}; use primitives::{AvailableData, BlockData, PoV};
use std::sync::Arc; use std::sync::Arc;
use honggfuzz::fuzz;
use polkadot_primitives::PersistedValidationData;
fn main() { fn main() {
loop { loop {
fuzz!(|data: &[u8]| { fuzz!(|data: &[u8]| {
let pov_block = PoV { let pov_block = PoV { block_data: BlockData(data.iter().cloned().collect()) };
block_data: BlockData(data.iter().cloned().collect()),
};
let available_data = AvailableData { let available_data = AvailableData {
pov: Arc::new(pov_block), pov: Arc::new(pov_block),
validation_data: PersistedValidationData::default(), validation_data: PersistedValidationData::default(),
}; };
let chunks = obtain_chunks_v1( let chunks = obtain_chunks_v1(10, &available_data).unwrap();
10,
&available_data,
).unwrap();
assert_eq!(chunks.len(), 10); assert_eq!(chunks.len(), 10);
// any 4 chunks should work. // any 4 chunks should work.
let reconstructed: AvailableData = reconstruct_v1( let reconstructed: AvailableData = reconstruct_v1(
10, 10,
[ [(&*chunks[1], 1), (&*chunks[4], 4), (&*chunks[6], 6), (&*chunks[9], 9)]
(&*chunks[1], 1), .iter()
(&*chunks[4], 4), .cloned(),
(&*chunks[6], 6), )
(&*chunks[9], 9), .unwrap();
].iter().cloned(),
).unwrap();
assert_eq!(reconstructed, available_data); assert_eq!(reconstructed, available_data);
println!("{:?}", reconstructed); println!("{:?}", reconstructed);
+8 -11
View File
@@ -599,13 +599,10 @@ mod tests {
fn append_with_works() { fn append_with_works() {
let acc = AccountIndex64 { network: None, index: 23 }; let acc = AccountIndex64 { network: None, index: 23 };
let mut m = MultiLocation { parents: 1, interior: X1(Parachain(42)) }; let mut m = MultiLocation { parents: 1, interior: X1(Parachain(42)) };
assert_eq!(m.append_with(X2(PalletInstance(3), acc.clone())), Ok(())); assert_eq!(m.append_with(X2(PalletInstance(3), acc)), Ok(()));
assert_eq!( assert_eq!(
m, m,
MultiLocation { MultiLocation { parents: 1, interior: X3(Parachain(42), PalletInstance(3), acc) }
parents: 1,
interior: X3(Parachain(42), PalletInstance(3), acc.clone())
}
); );
// cannot append to create overly long multilocation // cannot append to create overly long multilocation
@@ -614,8 +611,8 @@ mod tests {
parents: 254, parents: 254,
interior: X5(Parachain(42), OnlyChild, OnlyChild, OnlyChild, OnlyChild), interior: X5(Parachain(42), OnlyChild, OnlyChild, OnlyChild, OnlyChild),
}; };
let suffix: MultiLocation = (PalletInstance(3), acc.clone(), OnlyChild, OnlyChild).into(); let suffix: MultiLocation = (PalletInstance(3), acc, OnlyChild, OnlyChild).into();
assert_eq!(m.clone().append_with(suffix.clone()), Err(suffix)); assert_eq!(m.clone().append_with(suffix), Err(suffix));
} }
#[test] #[test]
@@ -636,7 +633,7 @@ mod tests {
// cannot prepend to create overly long multilocation // cannot prepend to create overly long multilocation
let mut m = MultiLocation { parents: 254, interior: X1(Parachain(42)) }; let mut m = MultiLocation { parents: 254, interior: X1(Parachain(42)) };
let prefix = MultiLocation { parents: 2, interior: Here }; let prefix = MultiLocation { parents: 2, interior: Here };
assert_eq!(m.prepend_with(prefix.clone()), Err(prefix)); assert_eq!(m.prepend_with(prefix), Err(prefix));
let prefix = MultiLocation { parents: 1, interior: Here }; let prefix = MultiLocation { parents: 1, interior: Here };
assert_eq!(m.prepend_with(prefix), Ok(())); assert_eq!(m.prepend_with(prefix), Ok(()));
@@ -658,11 +655,11 @@ mod tests {
assert_eq!(second, &Parachain(3)); assert_eq!(second, &Parachain(3));
let res = Here let res = Here
.pushed_with(first.clone()) .pushed_with(*first)
.unwrap() .unwrap()
.pushed_with(second.clone()) .pushed_with(*second)
.unwrap() .unwrap()
.pushed_with(third.clone()) .pushed_with(*third)
.unwrap(); .unwrap();
assert_eq!(m, res); assert_eq!(m, res);