Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Commit 6a43f0f

Browse files
committed
fix(decompression): move concrete fixtures to test-fixtures crate
1 parent 8f8c7ea commit 6a43f0f

File tree

7 files changed

+95
-30
lines changed

7 files changed

+95
-30
lines changed

fuel-zkvm-primitives-prover/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ thiserror = { version = "2.0.3" }
1919

2020
[dev-dependencies]
2121
rand = { version = "0.9.0" }
22+
23+
[features]
24+
test-helpers = []
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod block_execution_game;
22

3-
pub mod decompression_gzip_game;
3+
pub mod decompression_game;

fuel-zkvm-primitives-prover/src/games/decompression_gzip_game.rs renamed to fuel-zkvm-primitives-prover/src/games/decompression_game.rs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl Blob {
4646
self._inner
4747
}
4848

49-
#[cfg(test)]
50-
fn from_inner(inner: [u8; 131072]) -> Self {
49+
#[cfg(feature = "test-helpers")]
50+
pub fn from_inner(inner: [u8; 131072]) -> Self {
5151
Self {
5252
_inner: Box::new(inner),
5353
}
@@ -83,7 +83,7 @@ pub struct Input {
8383
// a set of blobs make up a compressed bundle
8484
// a compressed bundle is made of several bundles
8585
// each bundle is made of several da compressed block
86-
raw_da_blobs: Vec<Blob>,
86+
pub raw_da_blobs: Vec<Blob>,
8787
}
8888

8989
sol! {
@@ -289,29 +289,4 @@ mod tests {
289289
assert_eq!(result.first_block_height, U256::from(first_height));
290290
assert_eq!(result.last_block_height, U256::from(last_height));
291291
}
292-
293-
#[test]
294-
fn prove_succeeds__with_real_data() {
295-
let blobs = include_bytes!("decompression_gzip_game/mainnet_blobs.bin");
296-
let blobs: Vec<Vec<u8>> = bincode::deserialize(blobs).unwrap();
297-
298-
let blobs = blobs
299-
.iter()
300-
.map(|blob| {
301-
let mut blob_array = [0; 131072];
302-
blob_array.copy_from_slice(&blob[8..]);
303-
Blob::from_inner(blob_array)
304-
})
305-
.collect::<Vec<_>>();
306-
307-
let input = Input {
308-
raw_da_blobs: blobs,
309-
};
310-
311-
let input_bytes = bincode::serialize(&input).unwrap();
312-
313-
let result = prove(&input_bytes).unwrap();
314-
315-
assert!(result.first_block_height < result.last_block_height);
316-
}
317292
}

fuel-zkvm-primitives-test-fixtures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tokio = { workspace = true }
3535

3636
[dev-dependencies]
3737
bincode = { workspace = true }
38-
fuel-zkvm-primitives-prover = { workspace = true }
38+
fuel-zkvm-primitives-prover = { workspace = true, features = ["test-helpers"] }
3939
rayon = "1.10.0"
4040

4141
[features]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//! Decompression proving game test fixtures
2+
3+
use clap::builder::PossibleValue;
4+
use std::sync::OnceLock;
5+
6+
/// Random blob sets from mainnet DA
7+
#[cfg_attr(
8+
feature = "enhanced_enums",
9+
derive(enum_iterator::Sequence, clap::ValueEnum)
10+
)]
11+
#[cfg_attr(feature = "enhanced_enums", clap(rename_all = "snake_case"))]
12+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13+
#[allow(non_camel_case_types)]
14+
#[derive(Debug, Copy, Clone)]
15+
pub enum BlobSet {
16+
/// Random blob set 0
17+
Blob_14133451_14136885,
18+
}
19+
20+
/// Get prover input for a particular blobset
21+
pub fn get_blobset_input(blobset: BlobSet) -> Vec<u8> {
22+
match blobset {
23+
BlobSet::Blob_14133451_14136885 => {
24+
include_bytes!("decompression_fixtures/fixtures/Blob_14133451_14136885.bin").to_vec()
25+
}
26+
}
27+
}
28+
29+
static FIXTURE_VARIANTS: OnceLock<Vec<Fixture>> = OnceLock::new();
30+
31+
/// Get all fixtures
32+
pub fn all_fixtures() -> &'static Vec<Fixture> {
33+
FIXTURE_VARIANTS.get_or_init(|| enum_iterator::all::<Fixture>().collect())
34+
}
35+
36+
/// Fixtures for the prover
37+
#[derive(Debug, Clone, enum_iterator::Sequence)]
38+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
39+
pub enum Fixture {
40+
/// Blob set
41+
BlobSet(BlobSet),
42+
}
43+
44+
impl Fixture {
45+
/// Get the prover input for the fixture
46+
pub fn get_input_for_fixture(&self) -> Vec<u8> {
47+
match self {
48+
Fixture::BlobSet(blobset) => get_blobset_input(*blobset),
49+
}
50+
}
51+
}
52+
53+
impl clap::ValueEnum for Fixture {
54+
fn value_variants<'a>() -> &'a [Self] {
55+
all_fixtures().as_slice()
56+
}
57+
58+
fn to_possible_value(&self) -> Option<PossibleValue> {
59+
match self {
60+
Fixture::BlobSet(blobset) => blobset.to_possible_value(),
61+
}
62+
}
63+
}
64+
65+
#[cfg(test)]
66+
mod tests {
67+
use super::*;
68+
use fuel_zkvm_primitives_prover::games::decompression_game::prove;
69+
70+
#[test]
71+
fn test_all_fixtures() -> Result<(), String> {
72+
for fixture in all_fixtures() {
73+
let prover_input = fixture.get_input_for_fixture();
74+
75+
if prover_input.is_empty() {
76+
return Err(format!("Fixture '{:?}' has empty prover input", fixture));
77+
}
78+
79+
let result = prove(&prover_input).unwrap();
80+
81+
assert!(result.first_block_height < result.last_block_height);
82+
}
83+
84+
Ok(())
85+
}
86+
}
512 KB
Binary file not shown.

fuel-zkvm-primitives-test-fixtures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
use tai64 as _;
1010

1111
pub mod block_execution_fixtures;
12+
pub mod decompression_fixtures;

0 commit comments

Comments
 (0)