mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 16:01:04 +00:00
Add a fuzzer for the erasure coding (#2021)
* Commit a fuzzer for the erase coding * Replace tabs with spaces for the erase coding fuzzer * Apply suggestions from code review Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
+2621
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "erasure_coding_fuzzer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Vincent Ulitzsch <vincent@srlabs.de>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
polkadot-erasure-coding = { path = ".." }
|
||||||
|
honggfuzz = "0.5"
|
||||||
|
primitives = { package = "polkadot-primitives", path = "../../primitives/" }
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "reconstruct_fuzzer"
|
||||||
|
path = "src/reconstruct.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "round_trip"
|
||||||
|
path = "src/round_trip.rs"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
use polkadot_erasure_coding::*;
|
||||||
|
use primitives::v1::AvailableData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use honggfuzz::fuzz;
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
loop {
|
||||||
|
fuzz!(|data: (usize, Vec<(Vec<u8>, usize)>)| {
|
||||||
|
let (num_validators, chunk_input) = data;
|
||||||
|
if num_validators <= 1 || num_validators > 10_000 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let reconstructed: Result<AvailableData, _> = reconstruct_v1(
|
||||||
|
num_validators,
|
||||||
|
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>()
|
||||||
|
);
|
||||||
|
println!("reconstructed {:?}", reconstructed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
use polkadot_erasure_coding::*;
|
||||||
|
use primitives::v1::{AvailableData, BlockData, PoV};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use honggfuzz::fuzz;
|
||||||
|
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
loop {
|
||||||
|
fuzz!(|data: &[u8]| {
|
||||||
|
let pov_block = PoV {
|
||||||
|
block_data: BlockData(data.iter().cloned().collect()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let available_data = AvailableData {
|
||||||
|
pov: Arc::new(pov_block),
|
||||||
|
validation_data: Default::default(),
|
||||||
|
};
|
||||||
|
let chunks = obtain_chunks_v1(
|
||||||
|
10,
|
||||||
|
&available_data,
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(chunks.len(), 10);
|
||||||
|
|
||||||
|
// any 4 chunks should work.
|
||||||
|
let reconstructed: AvailableData = reconstruct_v1(
|
||||||
|
10,
|
||||||
|
[
|
||||||
|
(&*chunks[1], 1),
|
||||||
|
(&*chunks[4], 4),
|
||||||
|
(&*chunks[6], 6),
|
||||||
|
(&*chunks[9], 9),
|
||||||
|
].iter().cloned(),
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(reconstructed, available_data);
|
||||||
|
println!("{:?}", reconstructed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user