Skip to content

Commit

Permalink
fuzz: omit test features
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Nov 7, 2024
1 parent f456c88 commit ecef22b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
24 changes: 20 additions & 4 deletions fuzz/fixture/src/feature_set.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
//! Runtime feature set.

use {super::proto::FeatureSet as ProtoFeatureSet, solana_sdk::feature_set::FeatureSet};
use {
super::proto::FeatureSet as ProtoFeatureSet,
solana_sdk::{feature_set::FeatureSet, pubkey::Pubkey},
};

// Omit "test features" (they have the same u64 ID).
pub static OMITTED_FEATURES: &[Pubkey] = &[
solana_sdk::feature_set::disable_sbpf_v1_execution::id(),
solana_sdk::feature_set::reenable_sbpf_v1_execution::id(),
];

impl From<ProtoFeatureSet> for FeatureSet {
fn from(value: ProtoFeatureSet) -> Self {
let mut feature_set = Self::default();
let inactive = std::mem::take(&mut feature_set.inactive);
let mut inactive = std::mem::take(&mut feature_set.inactive);
OMITTED_FEATURES.iter().for_each(|f| {
inactive.remove(f);
});

value.features.iter().for_each(|int_id| {
let discriminator = int_id.to_le_bytes();
Expand All @@ -26,9 +38,13 @@ impl From<FeatureSet> for ProtoFeatureSet {
let features = value
.active
.keys()
.map(|feature_id| {
.filter_map(|feature_id| {
if OMITTED_FEATURES.contains(feature_id) {
return None;
}
let discriminator = &feature_id.to_bytes()[0..8];
u64::from_le_bytes(discriminator.try_into().unwrap())
let int_id = u64::from_le_bytes(discriminator.try_into().unwrap());
Some(int_id)
})
.collect();

Expand Down
14 changes: 13 additions & 1 deletion harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,21 @@ impl Default for Mollusk {
solana_runtime::message_processor=debug,\
solana_runtime::system_instruction_processor=trace",
);
#[cfg(feature = "fuzz")]
let feature_set = {
// Omit "test features" (they have the same u64 ID).
let mut fs = FeatureSet::all_enabled();
fs.active
.remove(&solana_sdk::feature_set::disable_sbpf_v1_execution::id());
fs.active
.remove(&solana_sdk::feature_set::reenable_sbpf_v1_execution::id());
fs
};
#[cfg(not(feature = "fuzz"))]
let feature_set = FeatureSet::all_enabled();
Self {
compute_budget: ComputeBudget::default(),
feature_set: FeatureSet::all_enabled(),
feature_set,
fee_structure: FeeStructure::default(),
program_cache: ProgramCache::default(),
sysvars: Sysvars::default(),
Expand Down
19 changes: 16 additions & 3 deletions harness/tests/dump_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use {
mollusk_svm::{result::Check, Mollusk},
mollusk_svm_fuzz_fixture::Fixture,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey, system_instruction, system_program},
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, pubkey::Pubkey, system_instruction,
system_program,
},
std::path::Path,
};

Expand Down Expand Up @@ -59,6 +62,14 @@ fn clear() {
}
}

fn compare_feature_sets(from_fixture: &FeatureSet, from_mollusk: &FeatureSet) {
assert_eq!(from_fixture.active.len(), from_mollusk.active.len());
assert_eq!(from_fixture.inactive.len(), from_mollusk.inactive.len());
for f in from_fixture.active.keys() {
assert!(from_mollusk.active.get(&f).is_some());
}
}

#[test]
fn test_dump() {
clear();
Expand Down Expand Up @@ -100,7 +111,8 @@ fn test_dump() {
let blob_fixture_path = find_fixture(&FileType::Blob).unwrap();
let blob_fixture = Fixture::load_from_blob_file(&blob_fixture_path);
assert_eq!(blob_fixture.input.compute_budget, mollusk.compute_budget);
assert_eq!(blob_fixture.input.feature_set, mollusk.feature_set);
// Feature set matches, but it can't guarantee sorting.
compare_feature_sets(&blob_fixture.input.feature_set, &mollusk.feature_set);
assert_eq!(blob_fixture.input.sysvars.clock, mollusk.sysvars.clock);
assert_eq!(blob_fixture.input.sysvars.rent, mollusk.sysvars.rent);
assert_eq!(blob_fixture.input.program_id, instruction.program_id);
Expand All @@ -115,7 +127,8 @@ fn test_dump() {
let json_fixture_path = find_fixture(&FileType::Json).unwrap();
let json_fixture = Fixture::load_from_json_file(&json_fixture_path);
assert_eq!(json_fixture.input.compute_budget, mollusk.compute_budget);
assert_eq!(json_fixture.input.feature_set, mollusk.feature_set);
// Feature set matches, but it can't guarantee sorting.
compare_feature_sets(&json_fixture.input.feature_set, &mollusk.feature_set);
assert_eq!(json_fixture.input.sysvars.clock, mollusk.sysvars.clock);
assert_eq!(json_fixture.input.sysvars.rent, mollusk.sysvars.rent);
assert_eq!(json_fixture.input.program_id, instruction.program_id);
Expand Down

0 comments on commit ecef22b

Please sign in to comment.