diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 6b3d91e9e85183..8eb8868dc44a1d 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -30,7 +30,7 @@ use solana_sdk::{ bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, clock::Clock, - entrypoint::SUCCESS, + entrypoint::{HEAP_LENGTH, SUCCESS}, feature_set::{add_missing_program_error_mappings, upgradeable_close_instruction}, ic_logger_msg, ic_msg, instruction::InstructionError, @@ -142,10 +142,6 @@ fn check_loader_id(id: &Pubkey) -> bool { || bpf_loader_upgradeable::check_id(id) } -/// Default program heap size, allocators -/// are expected to enforce this -const DEFAULT_HEAP_SIZE: usize = 32 * 1024; - /// Create the BPF virtual machine pub fn create_vm<'a>( loader_id: &'a Pubkey, @@ -153,7 +149,11 @@ pub fn create_vm<'a>( parameter_bytes: &mut [u8], invoke_context: &'a mut dyn InvokeContext, ) -> Result, EbpfError> { - let heap = AlignedMemory::new_with_size(DEFAULT_HEAP_SIZE, HOST_ALIGN); + let bpf_compute_budget = invoke_context.get_bpf_compute_budget(); + let heap = AlignedMemory::new_with_size( + bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH), + HOST_ALIGN, + ); let heap_region = MemoryRegion::new_from_slice(heap.as_slice(), MM_HEAP_START, 0, true); let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?; syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6b4cbb3dda4f13..b674f83bf9f35b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -27,6 +27,7 @@ pub mod loader_utils; pub mod log_collector; pub mod message_processor; mod native_loader; +pub mod neon_evm_program; pub mod non_circulating_supply; mod pubkey_bins; mod read_only_accounts_cache; diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 08ceebcb8e733f..ce01e8ff133b6e 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -9,7 +9,9 @@ use solana_sdk::{ account::{AccountSharedData, ReadableAccount, WritableAccount}, account_utils::StateMut, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, - feature_set::{instructions_sysvar_enabled, updated_verify_policy, FeatureSet}, + feature_set::{ + instructions_sysvar_enabled, neon_evm_compute_budget, updated_verify_policy, FeatureSet, + }, ic_logger_msg, ic_msg, instruction::{CompiledInstruction, Instruction, InstructionError}, keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount}, @@ -1151,6 +1153,16 @@ impl MessageProcessor { } let program_id = instruction.program_id(&message.account_keys); + + let mut bpf_compute_budget = bpf_compute_budget; + if feature_set.is_active(&neon_evm_compute_budget::id()) + && *program_id == crate::neon_evm_program::id() + { + // Bump the compute budget for neon_evm + bpf_compute_budget.max_units = 500_000; + bpf_compute_budget.heap_size = Some(256 * 1024); + } + let mut invoke_context = ThisInvokeContext::new( program_id, rent_collector.rent, diff --git a/runtime/src/neon_evm_program.rs b/runtime/src/neon_evm_program.rs new file mode 100644 index 00000000000000..6816f04e4ffc98 --- /dev/null +++ b/runtime/src/neon_evm_program.rs @@ -0,0 +1 @@ +solana_sdk::declare_id!("NeonEVM111111111111111111111111111111111111"); diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index e0dca9d860fd1e..d22457b9eab5f1 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -163,6 +163,10 @@ pub mod updated_verify_policy { solana_sdk::declare_id!("k15tVxtkgsmo7dy6iJ56N5hBCxuQAtqRgYwoTDuwbia"); } +pub mod neon_evm_compute_budget { + solana_sdk::declare_id!("GLrVvDPkQi5PMYUrsYWT9doZhSHr1BVZXqj5DbFps3rS"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: HashMap = [ @@ -203,6 +207,7 @@ lazy_static! { (deterministic_shred_seed_enabled::id(), "deterministic shred seed"), (vote_stake_checked_instructions::id(), "vote/state program checked instructions #18345"), (updated_verify_policy::id(), "Update verify policy"), + (neon_evm_compute_budget::id(), "bump neon_evm's compute budget"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter() diff --git a/sdk/src/process_instruction.rs b/sdk/src/process_instruction.rs index ff0781c654f433..33b0ea3a329e47 100644 --- a/sdk/src/process_instruction.rs +++ b/sdk/src/process_instruction.rs @@ -181,6 +181,8 @@ pub struct BpfComputeBudget { pub sysvar_base_cost: u64, /// Number of compute units consumed to call secp256k1_recover pub secp256k1_recover_cost: u64, + /// Optional program heap region size, if `None` then loader default + pub heap_size: Option, } impl Default for BpfComputeBudget { fn default() -> Self { @@ -205,6 +207,7 @@ impl BpfComputeBudget { cpi_bytes_per_unit: 250, // ~50MB at 200,000 units sysvar_base_cost: 100, secp256k1_recover_cost: 25_000, + heap_size: None, } } }