Skip to content

Commit

Permalink
test-validator: Verify program ELFs
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto committed Dec 20, 2024
1 parent ee31e31 commit d4c3e11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-accounts-db = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-cli-output = { workspace = true }
solana-compute-budget = { workspace = true }
solana-core = { workspace = true }
Expand All @@ -31,6 +32,7 @@ solana-rpc = { workspace = true }
solana-rpc-client = { workspace = true }
solana-rpc-client-api = { workspace = true }
solana-runtime = { workspace = true }
solana-sbpf = { workspace = true }
solana-sdk = { workspace = true, features = ["openssl-vendored"] }
solana-streamer = { workspace = true }
solana-tpu-client = { workspace = true }
Expand Down
19 changes: 19 additions & 0 deletions test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
utils::create_accounts_run_and_snapshot_dirs,
},
solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1,
solana_cli_output::CliAccount,
solana_compute_budget::compute_budget::ComputeBudget,
solana_core::{
Expand All @@ -30,6 +31,7 @@ use {
create_new_tmp_ledger,
},
solana_net_utils::PortRange,
solana_program_test::InvokeContext,
solana_rpc::{rpc::JsonRpcConfig, rpc_pubsub_service::PubSubConfig},
solana_rpc_client::{nonblocking, rpc_client::RpcClient},
solana_rpc_client_api::request::MAX_MULTIPLE_ACCOUNTS,
Expand All @@ -39,6 +41,7 @@ use {
runtime_config::RuntimeConfig,
snapshot_config::SnapshotConfig,
},
solana_sbpf::{elf::Executable, verifier::RequisiteVerifier},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
bpf_loader_upgradeable::UpgradeableLoaderState,
Expand Down Expand Up @@ -790,12 +793,28 @@ impl TestValidator {
let validator_stake_lamports = sol_to_lamports(1_000_000.);
let mint_lamports = sol_to_lamports(500_000_000.);

let program_runtime_environment = create_program_runtime_environment_v1(
// TODO: Apply the configured feature set rather than the default
&FeatureSet::default(),
&ComputeBudget::default(),
true,
false,
)?;
let program_runtime_environment = Arc::new(program_runtime_environment);

let mut accounts = config.accounts.clone();
for (address, account) in solana_program_test::programs::spl_programs(&config.rent) {
accounts.entry(address).or_insert(account);
}
for upgradeable_program in &config.upgradeable_programs {
let data = solana_program_test::read_file(&upgradeable_program.program_path);
let executable =
Executable::<InvokeContext>::from_elf(&data, program_runtime_environment.clone())
.map_err(|err| format!("ELF error: {err}"))?;
executable
.verify::<RequisiteVerifier>()
.map_err(|err| format!("ELF error: {err}"))?;

let (programdata_address, _) = Pubkey::find_program_address(
&[upgradeable_program.program_id.as_ref()],
&upgradeable_program.loader,
Expand Down

0 comments on commit d4c3e11

Please sign in to comment.