Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
374 changes: 277 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ edition = "2021"
version = "0.7.2"

[workspace.dependencies]
agave-feature-set = "3.0.10"
agave-precompiles = "3.0.10"
agave-syscalls = "~3.0.10"
agave-feature-set = "3.1.0"
agave-precompiles = "3.1.0"
agave-syscalls = "3.1.0"
bincode = "1.3.3"
bs58 = "0.5.1"
chrono = "0.4.42"
Expand Down Expand Up @@ -55,9 +55,9 @@ serde_yaml = "0.9.34"
serial_test = "2.0"
solana-account = "3.2.0"
solana-account-info = "3.0"
solana-bpf-loader-program = "3.0.10"
solana-bpf-loader-program = "3.1.0"
solana-clock = "3.0"
solana-compute-budget = "3.0.10"
solana-compute-budget = "3.1.0"
solana-cpi = "3.0"
solana-ed25519-program = "3.0"
solana-epoch-rewards = "3.0"
Expand All @@ -68,7 +68,7 @@ solana-instruction-error = { version = "2.0", features = ["serde"] }
solana-keccak-hasher = { version = "3.0", features = ["sha3"] }
solana-loader-v3-interface = "6.1.0"
solana-loader-v4-interface = "3.1.0"
solana-loader-v4-program = "3.0.10"
solana-loader-v4-program = "3.1.0"
solana-logger = "3.0"
solana-native-token = "3.0"
solana-precompile-error = "3.0"
Expand All @@ -83,15 +83,15 @@ solana-secp256k1-program = "3.0"
solana-secp256r1-program = "3.0"
solana-slot-hashes = "3.0"
solana-stake-interface = "2.0.1"
solana-stake-program = "3.0.10"
solana-svm-callback = "3.0.10"
solana-svm-log-collector = "3.0.10"
solana-svm-timings = "3.0.10"
solana-stake-program = "3.1.0"
solana-svm-callback = "3.1.0"
solana-svm-log-collector = "3.1.0"
solana-svm-timings = "3.1.0"
solana-system-interface = "2.0"
solana-system-program = "3.0.10"
solana-system-program = "3.1.0"
solana-sysvar = "3.0"
solana-sysvar-id = "3.0"
solana-transaction-context = "~3.0.10"
solana-transaction-context = "3.1.0"
spl-associated-token-account-interface = "2.0.0"
spl-token-interface = "2.0.0"
thiserror = "1.0.64"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ clippy-fix:
@cargo +$(NIGHTLY_TOOLCHAIN) clippy --all --all-features --all-targets --fix --allow-dirty --allow-staged -- -D warnings

check-features:
@cargo hack check --feature-powerset --no-dev-deps
@cargo hack --feature-powerset --no-dev-deps check

build:
@$(MAKE) build-test-programs
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fixture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ prost = { workspace = true }
serde = { workspace = true, features = ["derive"] }
solana-account = { workspace = true }
solana-clock = { workspace = true }
solana-compute-budget = { workspace = true }
solana-compute-budget = { workspace = true, features = ["agave-unstable-api"] }
solana-epoch-rewards = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-hash = { workspace = true }
Expand Down
32 changes: 19 additions & 13 deletions fuzz/fixture/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ impl From<ProtoContext> for Context {
let feature_set: FeatureSet = value.feature_set.map(Into::into).unwrap_or_default();
let simd_0268_active =
feature_set.is_active(&agave_feature_set::raise_cpi_nesting_limit_to_8::id());
let simd_0339_active =
feature_set.is_active(&agave_feature_set::increase_cpi_account_info_limit::id());

let compute_budget = value
.compute_budget
.map(Into::into)
.unwrap_or_else(|| ComputeBudget::new_with_defaults(simd_0268_active));
let compute_budget = value.compute_budget.map(Into::into).unwrap_or_else(|| {
ComputeBudget::new_with_defaults(simd_0268_active, simd_0339_active)
});

Self {
compute_budget,
Expand Down Expand Up @@ -151,12 +152,15 @@ mod tests {
ComputeBudget as ProtoComputeBudget, FeatureSet as ProtoFeatureSet,
InstrContext as ProtoContext,
},
solana_pubkey::Pubkey,
};

fn proto_feature_set_with(feature_id: solana_pubkey::Pubkey) -> ProtoFeatureSet {
let discr = u64::from_le_bytes(feature_id.to_bytes()[0..8].try_into().unwrap());
fn proto_feature_set_with(features: &[Pubkey]) -> ProtoFeatureSet {
ProtoFeatureSet {
features: vec![discr],
features: features
.iter()
.map(|id| u64::from_le_bytes(id.to_bytes()[0..8].try_into().unwrap()))
.collect(),
}
}

Expand All @@ -175,20 +179,21 @@ mod tests {
#[test]
fn test_defaults_use_feature_flag_when_active() {
let mut proto = empty_proto_context();
proto.feature_set = Some(proto_feature_set_with(
proto.feature_set = Some(proto_feature_set_with(&[
agave_feature_set::raise_cpi_nesting_limit_to_8::id(),
));
agave_feature_set::increase_cpi_account_info_limit::id(),
]));

let ctx: Context = proto.into();
let expected = ComputeBudget::new_with_defaults(true);
let expected = ComputeBudget::new_with_defaults(true, true);
assert_eq!(ctx.compute_budget, expected);
}

#[test]
fn test_defaults_use_feature_flag_when_inactive() {
let proto = empty_proto_context();
let ctx: Context = proto.into();
let expected = ComputeBudget::new_with_defaults(false);
let expected = ComputeBudget::new_with_defaults(false, false);
assert_eq!(ctx.compute_budget, expected);
}

Expand All @@ -202,9 +207,10 @@ mod tests {
proto.compute_budget = Some(cb);

// Whether the feature is present or not should not affect passthrough
proto.feature_set = Some(proto_feature_set_with(
proto.feature_set = Some(proto_feature_set_with(&[
agave_feature_set::raise_cpi_nesting_limit_to_8::id(),
));
agave_feature_set::increase_cpi_account_info_limit::id(),
]));

let ctx: Context = proto.into();
assert_eq!(ctx.compute_budget.compute_unit_limit, 12345);
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fixture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
fn test_consistent_hashing() {
const ITERATIONS: usize = 1000;

let compute_budget = ComputeBudget::new_with_defaults(true);
let compute_budget = ComputeBudget::new_with_defaults(true, true);

let feature_set = FeatureSet::all_enabled();
let sysvars = Sysvars::default();
Expand Down
12 changes: 6 additions & 6 deletions harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ serde = [
]

[dependencies]
agave-feature-set = { workspace = true }
agave-precompiles = { workspace = true, optional = true }
agave-feature-set = { workspace = true, features = ["agave-unstable-api"] }
agave-precompiles = { workspace = true, features = ["agave-unstable-api"], optional = true }
agave-syscalls = { workspace = true }
bincode = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
Expand All @@ -44,17 +44,17 @@ mollusk-svm-fuzz-fs = { workspace = true, optional = true }
mollusk-svm-keys = { workspace = true }
mollusk-svm-result = { workspace = true }
solana-account = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-bpf-loader-program = { workspace = true, features = ["agave-unstable-api"] }
solana-clock = { workspace = true }
solana-compute-budget = { workspace = true }
solana-compute-budget = { workspace = true, features = ["agave-unstable-api"] }
solana-epoch-rewards = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-instruction-error = { workspace = true, features = ["serde"] }
solana-loader-v3-interface = { workspace = true, features = ["serde"] }
solana-loader-v4-interface = { workspace = true }
solana-loader-v4-program = { workspace = true, optional = true }
solana-loader-v4-program = { workspace = true, features = ["agave-unstable-api"], optional = true }
solana-logger = { workspace = true }
solana-precompile-error = { workspace = true }
solana-program-error = { workspace = true }
Expand All @@ -68,7 +68,7 @@ solana-stake-program = { workspace = true, optional = true }
solana-svm-callback = { workspace = true }
solana-svm-log-collector = { workspace = true }
solana-svm-timings = { workspace = true }
solana-system-program = { workspace = true }
solana-system-program = { workspace = true, features = ["agave-unstable-api"] }
solana-sysvar = { workspace = true }
solana-sysvar-id = { workspace = true }
solana-transaction-context = { workspace = true, features = ["dev-context-only-utils"] }
Expand Down
6 changes: 3 additions & 3 deletions harness/src/compile_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use {
},
keys::KeyMap,
},
solana_account::{Account, WritableAccount},
solana_account::{Account, AccountSharedData, WritableAccount},
solana_instruction::Instruction,
solana_pubkey::Pubkey,
solana_transaction_context::{InstructionAccount, TransactionAccount},
solana_transaction_context::InstructionAccount,
};

pub struct CompiledAccounts {
pub program_id_index: u16,
pub instruction_accounts: Vec<InstructionAccount>,
pub transaction_accounts: Vec<TransactionAccount>,
pub transaction_accounts: Vec<(Pubkey, AccountSharedData)>,
}

pub fn compile_accounts<'a>(
Expand Down
2 changes: 1 addition & 1 deletion harness/src/fuzz/firedancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) fn parse_fixture_context(context: &FuzzContext) -> ParsedFixtureConte

let compute_budget = ComputeBudget {
compute_unit_limit: *compute_units_available,
..ComputeBudget::new_with_defaults(true)
..ComputeBudget::new_with_defaults(true, true)
};

let accounts = accounts
Expand Down
51 changes: 40 additions & 11 deletions harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,25 @@ use {
program::ProgramCache, sysvar::Sysvars,
},
agave_feature_set::FeatureSet,
agave_syscalls::{
create_program_runtime_environment_v1, create_program_runtime_environment_v2,
},
mollusk_svm_error::error::{MolluskError, MolluskPanic},
mollusk_svm_result::{Check, CheckContext, Config, InstructionResult},
solana_account::{Account, AccountSharedData},
solana_account::{Account, AccountSharedData, ReadableAccount},
solana_compute_budget::compute_budget::ComputeBudget,
solana_hash::Hash,
solana_instruction::{AccountMeta, Instruction},
solana_program_runtime::invoke_context::{EnvironmentConfig, InvokeContext},
solana_program_runtime::{
invoke_context::{EnvironmentConfig, InvokeContext},
loaded_programs::ProgramRuntimeEnvironments,
},
solana_pubkey::Pubkey,
solana_svm_callback::InvokeContextCallback,
solana_svm_log_collector::LogCollector,
solana_svm_timings::ExecuteTimings,
solana_transaction_context::{InstructionAccount, TransactionContext},
std::{cell::RefCell, collections::HashSet, iter::once, rc::Rc},
std::{cell::RefCell, collections::HashSet, iter::once, rc::Rc, sync::Arc},
};

pub(crate) const DEFAULT_LOADER_KEY: Pubkey = solana_sdk_ids::bpf_loader_upgradeable::id();
Expand Down Expand Up @@ -537,7 +543,7 @@ impl Default for Mollusk {
solana_runtime::message_processor=debug,\
solana_runtime::system_instruction_processor=trace",
);
let compute_budget = ComputeBudget::new_with_defaults(true);
let compute_budget = ComputeBudget::new_with_defaults(true, true);

#[cfg(feature = "fuzz")]
let feature_set = {
Expand Down Expand Up @@ -713,8 +719,26 @@ impl Mollusk {
epoch_stake: &self.epoch_stake,
feature_set: &self.feature_set,
};
let execution_budget = self.compute_budget.to_budget();
let runtime_features = self.feature_set.runtime_features();
let sysvar_cache = self.sysvars.setup_sysvar_cache(accounts);

let program_runtime_environments = ProgramRuntimeEnvironments {
program_runtime_v1: Arc::new(
create_program_runtime_environment_v1(
&runtime_features,
&execution_budget,
/* reject_deployment_of_broken_elfs */ false,
/* debugging_features */ false,
)
.unwrap(),
),
program_runtime_v2: Arc::new(create_program_runtime_environment_v2(
&execution_budget,
/* debugging_features */ false,
)),
};

let mut invoke_context = InvokeContext::new(
&mut transaction_context,
&mut program_cache,
Expand All @@ -723,6 +747,8 @@ impl Mollusk {
/* blockhash_lamports_per_signature */ 5000, // The default value
&callback,
&runtime_features,
&program_runtime_environments,
&program_runtime_environments,
&sysvar_cache,
),
self.logger.clone(),
Expand All @@ -736,7 +762,7 @@ impl Mollusk {
.configure_next_instruction_for_tests(
program_id_index,
instruction_accounts.clone(),
&instruction.data,
instruction.data.clone(),
)
.expect("failed to configure next instruction");

Expand Down Expand Up @@ -774,12 +800,15 @@ impl Mollusk {
transaction_context
.find_index_of_account(pubkey)
.map(|index| {
let resulting_account = transaction_context
.accounts()
.try_borrow(index)
.unwrap()
.clone()
.into();
let account_ref =
transaction_context.accounts().try_borrow(index).unwrap();
let resulting_account = Account {
lamports: account_ref.lamports(),
data: account_ref.data().to_vec(),
owner: *account_ref.owner(),
executable: account_ref.executable(),
rent_epoch: account_ref.rent_epoch(),
};
(*pubkey, resulting_account)
})
.unwrap_or((*pubkey, account.clone()))
Expand Down
8 changes: 1 addition & 7 deletions harness/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct ProgramCache {
entries_cache: Rc<RefCell<HashMap<Pubkey, Pubkey>>>,
// The function registry (syscalls) to use for verifying and loading
// program ELFs.
pub program_runtime_environment: BuiltinProgram<InvokeContext<'static>>,
pub program_runtime_environment: BuiltinProgram<InvokeContext<'static, 'static>>,
}

impl ProgramCache {
Expand Down Expand Up @@ -232,12 +232,6 @@ static BUILTINS: &[Builtin] = &[
name: "solana_loader_v4_program",
entrypoint: solana_loader_v4_program::Entrypoint::vm,
},
#[cfg(feature = "all-builtins")]
Builtin {
program_id: solana_sdk_ids::stake::id(),
name: "solana_stake_program",
entrypoint: solana_stake_program::stake_instruction::Entrypoint::vm,
},
/* ... */
];

Expand Down
6 changes: 3 additions & 3 deletions harness/tests/bpf_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn test_transfer() {
],
&[
Check::success(),
Check::compute_units(2534),
Check::compute_units(2480),
Check::account(&payer)
.lamports(payer_lamports - transfer_amount)
.build(),
Expand Down Expand Up @@ -256,7 +256,7 @@ fn test_close_account() {
],
&[
Check::success(),
Check::compute_units(2609),
Check::compute_units(2555),
Check::account(&key)
.closed() // The rest is unnecessary, just testing.
.data(&[])
Expand Down Expand Up @@ -376,7 +376,7 @@ fn test_cpi() {
],
&[
Check::success(),
Check::compute_units(2371),
Check::compute_units(2317),
Check::account(&key)
.data(data)
.lamports(lamports)
Expand Down
Loading