diff --git a/soroban-env-host/benches/common/cost_types/vm_ops.rs b/soroban-env-host/benches/common/cost_types/vm_ops.rs
index a71c9db84..ae0c32d50 100644
--- a/soroban-env-host/benches/common/cost_types/vm_ops.rs
+++ b/soroban-env-host/benches/common/cost_types/vm_ops.rs
@@ -6,7 +6,6 @@ use soroban_env_host::{
vm::{ParsedModule, VersionedContractCodeCostInputs},
xdr, Host,
};
-use std::rc::Rc;
// Protocol 20 coarse cost model.
pub(crate) struct VmInstantiationMeasure;
@@ -40,10 +39,9 @@ macro_rules! impl_measurement_for_instantiation_cost_type {
.unwrap(),
)
}
- let module = Rc::new(
+ let module =
ParsedModule::new_with_isolated_engine(_host, &wasm, cost_inputs.clone())
- .unwrap(),
- );
+ .unwrap();
VmInstantiationSample {
id: Some(id),
wasm,
diff --git a/soroban-env-host/benches/worst_case_linear_models.rs b/soroban-env-host/benches/worst_case_linear_models.rs
index 87a5f188f..3f0effd26 100644
--- a/soroban-env-host/benches/worst_case_linear_models.rs
+++ b/soroban-env-host/benches/worst_case_linear_models.rs
@@ -217,6 +217,7 @@ fn write_budget_params_code(
ty,
);
}
+ #[cfg(not(feature = "next"))]
ContractCostType::VmCachedInstantiation => {
println!(
"
@@ -230,7 +231,7 @@ fn write_budget_params_code(
cpu.const_term, cpu.lin_term
),
None => println!(
- "ContractCostType::VmCachedInstantiation => !todo()"
+ "ContractCostType::VmCachedInstantiation => todo!()"
),
}
}
@@ -239,7 +240,7 @@ fn write_budget_params_code(
"ContractCostType::{:?} => {{ cpu.const_term = {}; cpu.lin_term = {:?}; }}",
ty, cpu.const_term, cpu.lin_term
),
- None => println!("ContractCostType::VmCachedInstantiation => !todo()"),
+ None => println!("ContractCostType::{:?} => todo!()", ty),
},
}
}
@@ -292,6 +293,7 @@ fn write_budget_params_code(
ty
)
}
+ #[cfg(not(feature = "next"))]
ContractCostType::VmCachedInstantiation => {
println!(
"
@@ -305,7 +307,7 @@ fn write_budget_params_code(
mem.const_term, mem.lin_term
),
None => println!(
- "ContractCostType::VmCachedInstantiation => !todo()"
+ "ContractCostType::VmCachedInstantiation => todo!()"
),
}
}
@@ -314,7 +316,7 @@ fn write_budget_params_code(
"ContractCostType::{:?} => {{ mem.const_term = {}; mem.lin_term = {:?}; }}",
ty, mem.const_term, mem.lin_term
),
- None => println!("ContractCostType::VmCachedInstantiation => !todo()"),
+ None => println!("ContractCostType::{:?} => todo!()", ty),
},
}
}
diff --git a/soroban-env-host/src/budget.rs b/soroban-env-host/src/budget.rs
index 8b3e1ddbb..ec0c30bfb 100644
--- a/soroban-env-host/src/budget.rs
+++ b/soroban-env-host/src/budget.rs
@@ -365,10 +365,16 @@ impl Default for BudgetImpl {
cpu.const_term = 451626;
cpu.lin_term = ScaledU64(45405);
}
+ #[cfg(not(feature = "next"))]
ContractCostType::VmCachedInstantiation => {
cpu.const_term = 451626;
cpu.lin_term = ScaledU64(45405);
}
+ #[cfg(feature = "next")]
+ ContractCostType::VmCachedInstantiation => {
+ cpu.const_term = 41142;
+ cpu.lin_term = ScaledU64(634);
+ }
ContractCostType::InvokeVmFunction => {
cpu.const_term = 1948;
cpu.lin_term = ScaledU64(0);
@@ -412,73 +418,73 @@ impl Default for BudgetImpl {
#[cfg(feature = "next")]
ContractCostType::ParseWasmInstructions => {
- cpu.const_term = 72736;
- cpu.lin_term = ScaledU64(25420);
+ cpu.const_term = 73077;
+ cpu.lin_term = ScaledU64(25410);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmFunctions => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(536688);
+ cpu.lin_term = ScaledU64(540752);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmGlobals => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(176902);
+ cpu.lin_term = ScaledU64(176363);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmTableEntries => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(29639);
+ cpu.lin_term = ScaledU64(29989);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmTypes => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(1048891);
+ cpu.lin_term = ScaledU64(1061449);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmDataSegments => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(236970);
+ cpu.lin_term = ScaledU64(237336);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmElemSegments => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(317249);
+ cpu.lin_term = ScaledU64(328476);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmImports => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(694667);
+ cpu.lin_term = ScaledU64(701845);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmExports => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(427037);
+ cpu.lin_term = ScaledU64(429383);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmDataSegmentBytes => {
- cpu.const_term = 66075;
+ cpu.const_term = 0;
cpu.lin_term = ScaledU64(28);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmInstructions => {
- cpu.const_term = 25059;
+ cpu.const_term = 43030;
cpu.lin_term = ScaledU64(0);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmFunctions => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(7503);
+ cpu.lin_term = ScaledU64(7556);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmGlobals => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(10761);
+ cpu.lin_term = ScaledU64(10711);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmTableEntries => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(3211);
+ cpu.lin_term = ScaledU64(3300);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmTypes => {
@@ -488,26 +494,26 @@ impl Default for BudgetImpl {
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmDataSegments => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(16370);
+ cpu.lin_term = ScaledU64(23038);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmElemSegments => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(28309);
+ cpu.lin_term = ScaledU64(42488);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmImports => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(683461);
+ cpu.lin_term = ScaledU64(828974);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmExports => {
cpu.const_term = 0;
- cpu.lin_term = ScaledU64(297065);
+ cpu.lin_term = ScaledU64(297100);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmDataSegmentBytes => {
- cpu.const_term = 25191;
+ cpu.const_term = 0;
cpu.lin_term = ScaledU64(14);
}
}
@@ -569,10 +575,16 @@ impl Default for BudgetImpl {
mem.const_term = 130065;
mem.lin_term = ScaledU64(5064);
}
+ #[cfg(not(feature = "next"))]
ContractCostType::VmCachedInstantiation => {
mem.const_term = 130065;
mem.lin_term = ScaledU64(5064);
}
+ #[cfg(feature = "next")]
+ ContractCostType::VmCachedInstantiation => {
+ mem.const_term = 69472;
+ mem.lin_term = ScaledU64(1217);
+ }
ContractCostType::InvokeVmFunction => {
mem.const_term = 14;
mem.lin_term = ScaledU64(0);
@@ -652,7 +664,7 @@ impl Default for BudgetImpl {
#[cfg(feature = "next")]
ContractCostType::ParseWasmImports => {
mem.const_term = 0;
- mem.lin_term = ScaledU64(102890);
+ mem.lin_term = ScaledU64(103229);
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmExports => {
@@ -661,13 +673,12 @@ impl Default for BudgetImpl {
}
#[cfg(feature = "next")]
ContractCostType::ParseWasmDataSegmentBytes => {
- mem.const_term = 17580;
+ mem.const_term = 0;
mem.lin_term = ScaledU64(257);
}
-
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmInstructions => {
- mem.const_term = 70192;
+ mem.const_term = 70704;
mem.lin_term = ScaledU64(0);
}
#[cfg(feature = "next")]
@@ -703,7 +714,7 @@ impl Default for BudgetImpl {
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmImports => {
mem.const_term = 0;
- mem.lin_term = ScaledU64(77273);
+ mem.lin_term = ScaledU64(97637);
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmExports => {
@@ -712,7 +723,7 @@ impl Default for BudgetImpl {
}
#[cfg(feature = "next")]
ContractCostType::InstantiateWasmDataSegmentBytes => {
- mem.const_term = 69256;
+ mem.const_term = 0;
mem.lin_term = ScaledU64(126);
}
}
diff --git a/soroban-env-host/src/cost_runner/cost_types/vm_ops.rs b/soroban-env-host/src/cost_runner/cost_types/vm_ops.rs
index b21d02c0e..aa6648fcd 100644
--- a/soroban-env-host/src/cost_runner/cost_types/vm_ops.rs
+++ b/soroban-env-host/src/cost_runner/cost_types/vm_ops.rs
@@ -83,7 +83,7 @@ mod v21 {
_iter: u64,
sample: Self::SampleType,
) -> Self::RecycledType {
- let module = black_box(Rc::new(
+ let module = black_box(
ParsedModule::new(
host,
sample.module.module.engine(),
@@ -91,7 +91,7 @@ mod v21 {
sample.module.cost_inputs.clone(),
)
.unwrap(),
- ));
+ );
(Some(module), sample.wasm)
}
diff --git a/soroban-env-host/src/e2e_testutils.rs b/soroban-env-host/src/e2e_testutils.rs
index ef749f57e..a1a83e70d 100644
--- a/soroban-env-host/src/e2e_testutils.rs
+++ b/soroban-env-host/src/e2e_testutils.rs
@@ -58,6 +58,21 @@ pub fn wasm_entry(wasm: &[u8]) -> LedgerEntry {
}))
}
+#[cfg(feature = "next")]
+pub fn wasm_entry_with_refined_contract_cost_inputs(wasm: &[u8]) -> LedgerEntry {
+ use crate::xdr::ContractCodeEntryV1;
+ let host = crate::Host::default();
+ ledger_entry(LedgerEntryData::ContractCode(ContractCodeEntry {
+ ext: ContractCodeEntryExt::V1(ContractCodeEntryV1 {
+ ext: ExtensionPoint::V0,
+ cost_inputs: crate::vm::ParsedModule::extract_refined_contract_cost_inputs(&host, wasm)
+ .unwrap(),
+ }),
+ hash: get_wasm_hash(wasm).try_into().unwrap(),
+ code: wasm.try_into().unwrap(),
+ }))
+}
+
pub fn default_ledger_info() -> LedgerInfo {
LedgerInfo {
protocol_version: 20,
@@ -84,6 +99,13 @@ pub struct CreateContractData {
impl CreateContractData {
pub fn new(salt: [u8; 32], wasm: &[u8]) -> Self {
+ Self::new_with_refined_contract_cost_inputs(salt, wasm, false)
+ }
+ pub fn new_with_refined_contract_cost_inputs(
+ salt: [u8; 32],
+ wasm: &[u8],
+ _refined_cost_inputs: bool,
+ ) -> Self {
let deployer = get_account_id([123; 32]);
let contract_id_preimage = get_contract_id_preimage(&deployer, &salt);
@@ -114,10 +136,20 @@ impl CreateContractData {
}),
}));
+ #[cfg(not(feature = "next"))]
+ let wasm_entry = wasm_entry(wasm);
+
+ #[cfg(feature = "next")]
+ let wasm_entry = if _refined_cost_inputs {
+ wasm_entry_with_refined_contract_cost_inputs(wasm)
+ } else {
+ wasm_entry(wasm)
+ };
+
Self {
deployer,
wasm_key: get_wasm_key(wasm),
- wasm_entry: wasm_entry(wasm),
+ wasm_entry,
contract_key,
contract_entry,
contract_address,
diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs
index d89447827..8dbb4df7e 100644
--- a/soroban-env-host/src/host.rs
+++ b/soroban-env-host/src/host.rs
@@ -81,6 +81,7 @@ pub struct CoverageScoreboard {
#[derive(Clone, Default)]
struct HostImpl {
module_cache: RefCell