Skip to content

Commit 09bfce2

Browse files
authored
harness: put precompile libs behind feature flag (#166)
1 parent dcbf26e commit 09bfce2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

harness/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ fuzz-fd = [
2525
"dep:mollusk-svm-fuzz-fs",
2626
]
2727
invocation-inspect-callback = []
28+
precompiles = ["dep:agave-precompiles"]
2829
serde = [
2930
"dep:serde",
3031
"mollusk-svm-result/serde",
3132
]
3233

3334
[dependencies]
3435
agave-feature-set = { workspace = true }
35-
agave-precompiles = { workspace = true }
36+
agave-precompiles = { workspace = true, optional = true }
3637
agave-syscalls = { workspace = true }
3738
bincode = { workspace = true }
3839
serde = { workspace = true, features = ["derive"], optional = true }

harness/src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ pub mod sysvar;
452452
pub use mollusk_svm_result as result;
453453
#[cfg(any(feature = "fuzz", feature = "fuzz-fd"))]
454454
use mollusk_svm_result::Compare;
455+
#[cfg(feature = "precompiles")]
456+
use solana_precompile_error::PrecompileError;
455457
#[cfg(feature = "invocation-inspect-callback")]
456458
use solana_transaction_context::InstructionAccount;
457459
use {
@@ -466,7 +468,6 @@ use {
466468
solana_compute_budget::compute_budget::ComputeBudget,
467469
solana_hash::Hash,
468470
solana_instruction::{AccountMeta, Instruction},
469-
solana_precompile_error::PrecompileError,
470471
solana_program_runtime::invoke_context::{EnvironmentConfig, InvokeContext},
471472
solana_pubkey::Pubkey,
472473
solana_svm_callback::InvokeContextCallback,
@@ -579,6 +580,7 @@ impl CheckContext for Mollusk {
579580
}
580581

581582
struct MolluskInvokeContextCallback<'a> {
583+
#[cfg_attr(not(feature = "precompiles"), allow(dead_code))]
582584
feature_set: &'a FeatureSet,
583585
epoch_stake: &'a EpochStake,
584586
}
@@ -592,12 +594,19 @@ impl InvokeContextCallback for MolluskInvokeContextCallback<'_> {
592594
self.epoch_stake.get(vote_address).copied().unwrap_or(0)
593595
}
594596

597+
#[cfg(feature = "precompiles")]
595598
fn is_precompile(&self, program_id: &Pubkey) -> bool {
596599
agave_precompiles::is_precompile(program_id, |feature_id| {
597600
self.feature_set.is_active(feature_id)
598601
})
599602
}
600603

604+
#[cfg(not(feature = "precompiles"))]
605+
fn is_precompile(&self, _program_id: &Pubkey) -> bool {
606+
false
607+
}
608+
609+
#[cfg(feature = "precompiles")]
601610
fn process_precompile(
602611
&self,
603612
program_id: &Pubkey,
@@ -612,6 +621,16 @@ impl InvokeContextCallback for MolluskInvokeContextCallback<'_> {
612621
Err(PrecompileError::InvalidPublicKey)
613622
}
614623
}
624+
625+
#[cfg(not(feature = "precompiles"))]
626+
fn process_precompile(
627+
&self,
628+
_program_id: &Pubkey,
629+
_data: &[u8],
630+
_instruction_datas: Vec<&[u8]>,
631+
) -> Result<(), solana_precompile_error::PrecompileError> {
632+
panic!("precompiles feature not enabled");
633+
}
615634
}
616635

617636
impl Mollusk {

harness/src/program.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod loader_keys {
3131
};
3232
}
3333

34+
#[cfg(feature = "precompiles")]
3435
pub mod precompile_keys {
3536
use solana_pubkey::Pubkey;
3637
pub use solana_sdk_ids::{
@@ -46,6 +47,15 @@ pub mod precompile_keys {
4647
}
4748
}
4849

50+
#[cfg(not(feature = "precompiles"))]
51+
pub mod precompile_keys {
52+
use solana_pubkey::Pubkey;
53+
54+
pub(crate) fn is_precompile(_program_id: &Pubkey) -> bool {
55+
false
56+
}
57+
}
58+
4959
pub struct ProgramCache {
5060
cache: Rc<RefCell<ProgramCacheForTxBatch>>,
5161
// This stinks, but the `ProgramCacheForTxBatch` doesn't offer a way to

0 commit comments

Comments
 (0)