From b01e79899ceeeb3d39f9531bbc09b39bf0149da8 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 8 Aug 2024 16:00:25 -0700 Subject: [PATCH] Strip out pre-p22-protocol-qualification code --- .github/workflows/rust.yml | 2 +- soroban-env-host/src/budget.rs | 24 ++----- soroban-env-host/src/e2e_testutils.rs | 12 +--- soroban-env-host/src/host.rs | 6 +- soroban-env-host/src/host/lifecycle.rs | 28 ++++---- soroban-env-host/src/test/bytes.rs | 7 +- soroban-env-host/src/test/crypto.rs | 6 -- soroban-env-host/src/test/e2e_tests.rs | 42 ++--------- soroban-env-host/src/test/hostile.rs | 68 +----------------- soroban-env-host/src/test/lifecycle.rs | 71 +------------------ .../src/test/lifetime_extension.rs | 10 --- soroban-env-host/src/test/map.rs | 11 +-- soroban-env-host/src/test/vec.rs | 7 +- soroban-env-host/src/testutils.rs | 10 ++- soroban-env-host/src/vm.rs | 4 +- soroban-env-host/src/vm/module_cache.rs | 3 - soroban-env-host/src/vm/parsed_module.rs | 16 ++--- soroban-env-host/tests/secp256r1_sig_ver.rs | 8 --- soroban-simulation/src/testutils.rs | 2 +- 19 files changed, 51 insertions(+), 286 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1b041716b..5ebc1d6b8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -73,7 +73,7 @@ jobs: strategy: matrix: rust: [msrv, latest] - test-protocol: [20, 21] + test-protocol: [22] sys: - os: ubuntu-latest target: wasm32-unknown-unknown diff --git a/soroban-env-host/src/budget.rs b/soroban-env-host/src/budget.rs index b91a8e154..4c6189b06 100644 --- a/soroban-env-host/src/budget.rs +++ b/soroban-env-host/src/budget.rs @@ -257,12 +257,6 @@ impl BudgetImpl { /// read on-chain from network configuration via [`from_configs`] above. impl Default for BudgetImpl { fn default() -> Self { - #[cfg(any(test, feature = "testutils"))] - let proto = Host::current_test_protocol(); - - #[cfg(not(any(test, feature = "testutils")))] - let proto = crate::meta::get_ledger_protocol_version(crate::meta::INTERFACE_VERSION); - let mut b = Self { cpu_insns: BudgetDimension::default(), mem_bytes: BudgetDimension::default(), @@ -347,13 +341,8 @@ impl Default for BudgetImpl { cpu.lin_term = ScaledU64(45405); } ContractCostType::VmCachedInstantiation => { - if proto < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - cpu.const_term = 451626; - cpu.lin_term = ScaledU64(45405); - } else { - cpu.const_term = 41142; - cpu.lin_term = ScaledU64(634); - } + cpu.const_term = 41142; + cpu.lin_term = ScaledU64(634); } ContractCostType::InvokeVmFunction => { cpu.const_term = 1948; @@ -544,13 +533,8 @@ impl Default for BudgetImpl { mem.lin_term = ScaledU64(5064); } ContractCostType::VmCachedInstantiation => { - if proto < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - mem.const_term = 130065; - mem.lin_term = ScaledU64(5064); - } else { - mem.const_term = 69472; - mem.lin_term = ScaledU64(1217); - } + mem.const_term = 69472; + mem.lin_term = ScaledU64(1217); } ContractCostType::InvokeVmFunction => { mem.const_term = 14; diff --git a/soroban-env-host/src/e2e_testutils.rs b/soroban-env-host/src/e2e_testutils.rs index 523cd484c..9b7641939 100644 --- a/soroban-env-host/src/e2e_testutils.rs +++ b/soroban-env-host/src/e2e_testutils.rs @@ -1,4 +1,3 @@ -use crate::vm::ModuleCache; use crate::vm::ParsedModule; use crate::xdr::{ AccountEntry, AccountEntryExt, AccountId, ContractCodeEntry, ContractDataDurability, @@ -65,10 +64,7 @@ pub fn wasm_entry_non_validated(wasm: &[u8]) -> LedgerEntry { /// The entry has the most 'up-to-date' contents possible (such as refined costs /// in protocol 21). pub fn wasm_entry(wasm: &[u8]) -> LedgerEntry { - wasm_entry_with_refined_contract_cost_inputs( - wasm, - e2e_test_protocol_version() >= ModuleCache::MIN_LEDGER_VERSION, - ) + wasm_entry_with_refined_contract_cost_inputs(wasm, true) } pub(crate) fn wasm_entry_with_refined_contract_cost_inputs( @@ -123,11 +119,7 @@ pub struct CreateContractData { impl CreateContractData { pub fn new(salt: [u8; 32], wasm: &[u8]) -> Self { - Self::new_with_refined_contract_cost_inputs( - salt, - wasm, - e2e_test_protocol_version() >= ModuleCache::MIN_LEDGER_VERSION, - ) + Self::new_with_refined_contract_cost_inputs(salt, wasm, true) } pub fn new_with_refined_contract_cost_inputs( salt: [u8; 32], diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index 5beeee605..12f728090 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -387,9 +387,7 @@ impl Host { } pub fn build_module_cache_if_needed(&self) -> Result<(), HostError> { - if self.get_ledger_protocol_version()? >= ModuleCache::MIN_LEDGER_VERSION - && self.try_borrow_module_cache()?.is_none() - { + if self.try_borrow_module_cache()?.is_none() { let cache = ModuleCache::new(self)?; let linker = cache.make_linker(self)?; *self.try_borrow_module_cache_mut()? = Some(cache); @@ -542,7 +540,7 @@ impl Host { &[proto.into()], )); } - if proto > meta::get_ledger_protocol_version(meta::INTERFACE_VERSION) { + if proto > meta::get_ledger_protocol_version(meta::INTERFACE_VERSION) { return Err(self.err( ScErrorType::Context, ScErrorCode::InternalError, diff --git a/soroban-env-host/src/host/lifecycle.rs b/soroban-env-host/src/host/lifecycle.rs index 6b1ec8fcc..8435afd73 100644 --- a/soroban-env-host/src/host/lifecycle.rs +++ b/soroban-env-host/src/host/lifecycle.rs @@ -183,19 +183,17 @@ impl Host { Hash(hash_bytes.metered_clone(self)?), wasm_bytes_m.as_slice(), )?; - if self.get_ledger_protocol_version()? >= super::ModuleCache::MIN_LEDGER_VERSION { - // At this point we do a secondary parse on what we've checked to be a valid - // module in order to extract a refined cost model, which we'll store in the - // code entry's ext field, for future parsing and instantiations. - _check_vm.module.cost_inputs.charge_for_parsing(self)?; - ext = crate::xdr::ContractCodeEntryExt::V1(crate::xdr::ContractCodeEntryV1 { - ext: ExtensionPoint::V0, - cost_inputs: crate::vm::ParsedModule::extract_refined_contract_cost_inputs( - self, - wasm_bytes_m.as_slice(), - )?, - }); - } + // At this point we do a secondary parse on what we've checked to be a valid + // module in order to extract a refined cost model, which we'll store in the + // code entry's ext field, for future parsing and instantiations. + _check_vm.module.cost_inputs.charge_for_parsing(self)?; + ext = crate::xdr::ContractCodeEntryExt::V1(crate::xdr::ContractCodeEntryV1 { + ext: ExtensionPoint::V0, + cost_inputs: crate::vm::ParsedModule::extract_refined_contract_cost_inputs( + self, + wasm_bytes_m.as_slice(), + )?, + }); } let hash_obj = self.add_host_object(self.scbytes_from_slice(hash_bytes.as_slice())?)?; @@ -213,9 +211,7 @@ impl Host { let mut should_put_contract = !storage.has_with_host(&code_key, self, None)?; // We may also, in the cache-supporting protocol, overwrite the contract if its ext field changed. - if !should_put_contract - && self.get_ledger_protocol_version()? >= super::ModuleCache::MIN_LEDGER_VERSION - { + if !should_put_contract { let entry = storage.get_with_host(&code_key, self, None)?; if let crate::xdr::LedgerEntryData::ContractCode(ContractCodeEntry { ext: old_ext, diff --git a/soroban-env-host/src/test/bytes.rs b/soroban-env-host/src/test/bytes.rs index c1528af09..95aa4626a 100644 --- a/soroban-env-host/src/test/bytes.rs +++ b/soroban-env-host/src/test/bytes.rs @@ -492,12 +492,7 @@ fn instantiate_oversized_bytes_from_linear_memory() -> Result<(), HostError> { ); // constructing a big bytes will cause budget limit exceeded error - let num_bytes: u32 = - if host.get_ledger_protocol_version()? < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - 480_000 - } else { - 8_000_000 - }; + let num_bytes: u32 = 8_000_000; let wasm_long = wasm::wasm_module_with_large_bytes_from_linear_memory(num_bytes, 7); host.clear_module_cache()?; host.budget_ref().reset_unlimited()?; diff --git a/soroban-env-host/src/test/crypto.rs b/soroban-env-host/src/test/crypto.rs index 349d9e547..b270c9d8a 100644 --- a/soroban-env-host/src/test/crypto.rs +++ b/soroban-env-host/src/test/crypto.rs @@ -255,16 +255,10 @@ fn recover_ecdsa_secp256k1_key_test() { .err().unwrap())); } -const PROTOCOL_SUPPORT_FOR_SECP256R1: u32 = 21; - #[test] fn test_secp256r1_signature_verification() -> Result<(), HostError> { let host = observe_host!(Host::test_host()); - if host.get_ledger_protocol_version()? < PROTOCOL_SUPPORT_FOR_SECP256R1 { - return Ok(()); - } - let verify_sig = |public_key: Vec, msg_digest: Vec, signature: Vec| diff --git a/soroban-env-host/src/test/e2e_tests.rs b/soroban-env-host/src/test/e2e_tests.rs index a11dc671c..a273d682d 100644 --- a/soroban-env-host/src/test/e2e_tests.rs +++ b/soroban-env-host/src/test/e2e_tests.rs @@ -1,7 +1,6 @@ use crate::builtin_contracts::testutils::AccountContractSigner; use crate::e2e_testutils::{account_entry, bytes_sc_val, upload_wasm_host_fn}; use crate::testutils::simple_account_sign_fn; -use crate::vm::ModuleCache; use crate::{ budget::Budget, builtin_contracts::testutils::TestSigner, @@ -649,12 +648,7 @@ fn test_wasm_upload_success_in_recording_mode() { }] ); assert!(res.auth.is_empty()); - let (expected_insns, expected_write_bytes) = - if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - (1767136, 684) - } else { - (1060474, 636) - }; + let (expected_insns, expected_write_bytes) = (1767136, 684); assert_eq!( res.resources, SorobanResources { @@ -692,11 +686,7 @@ fn test_wasm_upload_failure_in_recording_mode() { )); assert!(res.ledger_changes.is_empty()); assert!(res.auth.is_empty()); - let expected_instructions = if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - 1093647 - } else { - 1093647 - }; + let expected_instructions = 1093647; assert_eq!( res.resources, SorobanResources { @@ -1030,12 +1020,7 @@ fn test_create_contract_success_in_recording_mode() { ] ); assert_eq!(res.auth, vec![cd.auth_entry]); - let (expected_insns, expected_read_bytes) = - if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - (453719, 684) - } else { - (449458, 636) - }; + let (expected_insns, expected_read_bytes) = (453719, 684); assert_eq!( res.resources, SorobanResources { @@ -1097,12 +1082,7 @@ fn test_create_contract_success_in_recording_mode_with_enforced_auth() { ] ); assert_eq!(res.auth, vec![cd.auth_entry]); - let (expected_insns, expected_read_bytes) = - if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - (455160, 684) - } else { - (450899, 636) - }; + let (expected_insns, expected_read_bytes) = (455160, 684); assert_eq!( res.resources, SorobanResources { @@ -1531,12 +1511,7 @@ fn test_invoke_contract_with_storage_ops_success_in_recording_mode() { wasm_entry_change.clone() ] ); - let (expected_insns, expected_read_bytes) = - if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - (1431216, 3132) - } else { - (2221742, 3084) - }; + let (expected_insns, expected_read_bytes) = (1431216, 3132); assert_eq!( res.resources, SorobanResources { @@ -1599,12 +1574,7 @@ fn test_invoke_contract_with_storage_ops_success_in_recording_mode() { wasm_entry_change.clone() ] ); - let (expected_insns, expected_read_bytes) = - if ledger_info.protocol_version >= ModuleCache::MIN_LEDGER_VERSION { - (1543254, 3212) - } else { - (2333780, 3164) - }; + let (expected_insns, expected_read_bytes) = (1543254, 3212); assert_eq!( extend_res.resources, SorobanResources { diff --git a/soroban-env-host/src/test/hostile.rs b/soroban-env-host/src/test/hostile.rs index 422291e45..c8abf4339 100644 --- a/soroban-env-host/src/test/hostile.rs +++ b/soroban-env-host/src/test/hostile.rs @@ -528,11 +528,9 @@ fn excessive_logging() -> Result<(), HostError> { host.enable_debug()?; let contract_id_obj = host.register_test_contract_wasm(wasm.as_slice()); - if host.get_ledger_protocol_version()? >= crate::vm::ModuleCache::MIN_LEDGER_VERSION { - host.switch_to_enforcing_storage()?; - } + host.switch_to_enforcing_storage()?; - let expected_budget_p21 = expect![[r#" + let expected_budget = expect![[r#" ================================================================= Cpu limit: 2000000; used: 215305 Mem limit: 500000; used: 166764 @@ -587,68 +585,6 @@ fn excessive_logging() -> Result<(), HostError> { "#]]; - let expected_budget_p20 = expect![[r#" - ================================================================= - Cpu limit: 2000000; used: 522315 - Mem limit: 500000; used: 202391 - ================================================================= - CostType cpu_insns mem_bytes - WasmInsnExec 300 0 - MemAlloc 15750 67248 - MemCpy 2298 0 - MemCmp 696 0 - DispatchHostFunction 310 0 - VisitObject 244 0 - ValSer 0 0 - ValDeser 0 0 - ComputeSha256Hash 3738 0 - ComputeEd25519PubKey 0 0 - VerifyEd25519Sig 0 0 - VmInstantiation 497031 135129 - VmCachedInstantiation 0 0 - InvokeVmFunction 1948 14 - ComputeKeccak256Hash 0 0 - DecodeEcdsaCurve256Sig 0 0 - RecoverEcdsaSecp256k1Key 0 0 - Int256AddSub 0 0 - Int256Mul 0 0 - Int256Div 0 0 - Int256Pow 0 0 - Int256Shift 0 0 - ChaCha20DrawBytes 0 0 - ParseWasmInstructions 0 0 - ParseWasmFunctions 0 0 - ParseWasmGlobals 0 0 - ParseWasmTableEntries 0 0 - ParseWasmTypes 0 0 - ParseWasmDataSegments 0 0 - ParseWasmElemSegments 0 0 - ParseWasmImports 0 0 - ParseWasmExports 0 0 - ParseWasmDataSegmentBytes 0 0 - InstantiateWasmInstructions 0 0 - InstantiateWasmFunctions 0 0 - InstantiateWasmGlobals 0 0 - InstantiateWasmTableEntries 0 0 - InstantiateWasmTypes 0 0 - InstantiateWasmDataSegments 0 0 - InstantiateWasmElemSegments 0 0 - InstantiateWasmImports 0 0 - InstantiateWasmExports 0 0 - InstantiateWasmDataSegmentBytes 0 0 - Sec1DecodePointUncompressed 0 0 - VerifyEcdsaSecp256r1Sig 0 0 - ================================================================= - - "#]]; - - let expected_budget = - if host.get_ledger_protocol_version()? < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - expected_budget_p20 - } else { - expected_budget_p21 - }; - // moderate logging { host.clear_module_cache()?; diff --git a/soroban-env-host/src/test/lifecycle.rs b/soroban-env-host/src/test/lifecycle.rs index dc2cca079..3d003bbab 100644 --- a/soroban-env-host/src/test/lifecycle.rs +++ b/soroban-env-host/src/test/lifecycle.rs @@ -578,7 +578,6 @@ mod cap_54_55_56 { storage::{FootprintMap, StorageMap}, test::observe::ObservedHost, testutils::wasm::wasm_module_with_a_bit_of_everything, - vm::ModuleCache, xdr::{ ContractCostType::{self, *}, LedgerEntry, LedgerKey, @@ -587,8 +586,8 @@ mod cap_54_55_56 { }; use std::rc::Rc; - const V_NEW: u32 = ModuleCache::MIN_LEDGER_VERSION; - const V_OLD: u32 = V_NEW - 1; + const V_NEW: u32 = 22; + const V_OLD: u32 = 20; const NEW_COST_TYPES: &'static [ContractCostType] = &[ ParseWasmInstructions, ParseWasmFunctions, @@ -819,24 +818,6 @@ mod cap_54_55_56 { // region: CAP-0054 refined cost model - // Test that running on protocol vOld only charges the VmInstantiation cost - // type. - #[test] - fn test_v_old_only_charges_vm_instantiation() -> Result<(), HostError> { - let (budget, _storage) = upload_and_call( - "test_v_old_only_charges_vminstantiation_upload", - V_OLD, - "test_v_old_only_charges_vm_instantiation_call", - V_OLD, - )?; - assert_ne!(budget.get_tracker(VmInstantiation)?.cpu, 0); - assert_eq!(budget.get_tracker(VmCachedInstantiation)?.cpu, 0); - for ct in NEW_COST_TYPES { - assert_eq!(budget.get_tracker(*ct)?.cpu, 0); - } - Ok(()) - } - // Test that running on protocol vNew on a ContractCode LE that does not have // ContractCodeCostInputs charges the VmInstantiation and VmCachedInstantiation // cost types. @@ -894,37 +875,6 @@ mod cap_54_55_56 { Ok(()) } - // Test that running on protocol vOld does not add ContractCodeCostInputs to a - // newly uploaded ContractCode LE. - #[test] - fn test_v_old_no_contract_code_cost_inputs() -> Result<(), HostError> { - let entries = upload_and_get_contract_and_wasm_entries( - "test_v_old_no_contract_code_cost_inputs_upload", - V_OLD, - )?; - assert!(!code_entry_has_cost_inputs(&entries.wasm_entry)); - Ok(()) - } - - // Test that running on protocol vOld does not rewrite a ContractCode LE when it - // already exists. - #[test] - fn test_v_old_no_rewrite() -> Result<(), HostError> { - let entries = - upload_and_get_contract_and_wasm_entries("test_v_old_no_rewrite_upload", V_OLD)?; - // make a new storage map for a new run - let budget = Budget::default(); - let storage = entries.read_only_storage(&budget); - let host = observed_test_host_with_storage_and_budget( - "test_v_old_no_rewrite_call", - V_OLD, - storage, - budget, - )?; - host.upload_contract_wasm(wasm_module_with_a_bit_of_everything(V_OLD))?; - Ok(()) - } - // Test that running on protocol vNew does rewrite a ContractCode LE when it // already exists but doesn't yet have ContractCodeCostInputs. #[test] @@ -996,23 +946,6 @@ mod cap_54_55_56 { // region: CAP-0056 ModuleCache related tests - // Test that running on protocol vOld does not make a ModuleCache at all. - #[test] - fn test_v_old_no_module_cache() -> Result<(), HostError> { - let host = upload_and_make_host_for_next_ledger( - "test_v_old_no_module_cache_upload", - V_OLD, - "test_v_old_no_module_cache_check", - V_OLD, - )? - .0; - // force a module-cache build (this normally happens on first VM call) - host.build_module_cache_if_needed()?; - let module_cache = host.try_borrow_module_cache()?; - assert!(module_cache.is_none()); - Ok(()) - } - // Test that running on protocol vNew does add ModuleCache entries. #[test] fn test_v_new_module_cache() -> Result<(), HostError> { diff --git a/soroban-env-host/src/test/lifetime_extension.rs b/soroban-env-host/src/test/lifetime_extension.rs index 31d2fa0f9..f9ad4b048 100644 --- a/soroban-env-host/src/test/lifetime_extension.rs +++ b/soroban-env-host/src/test/lifetime_extension.rs @@ -51,8 +51,6 @@ impl InstanceCodeTest { mod separate_instance_code_extension { use super::*; - const PROTOCOL_SUPPORT_FOR_SEPARATE_EXTENSIONS: u32 = 21; - #[test] fn extend_only_instance() { let InstanceCodeTest { @@ -62,10 +60,6 @@ mod separate_instance_code_extension { .. } = InstanceCodeTest::setup(); - if host.get_ledger_protocol_version().unwrap() < PROTOCOL_SUPPORT_FOR_SEPARATE_EXTENSIONS { - return; - } - assert!(host .extend_contract_instance_ttl(contract_id, 5.into(), 5000.into()) .is_ok()); @@ -91,10 +85,6 @@ mod separate_instance_code_extension { .. } = InstanceCodeTest::setup(); - if host.get_ledger_protocol_version().unwrap() < PROTOCOL_SUPPORT_FOR_SEPARATE_EXTENSIONS { - return; - } - assert!(host .extend_contract_code_ttl(contract_id, 5.into(), 5000.into()) .is_ok()); diff --git a/soroban-env-host/src/test/map.rs b/soroban-env-host/src/test/map.rs index 84e6a308f..ebe6f0635 100644 --- a/soroban-env-host/src/test/map.rs +++ b/soroban-env-host/src/test/map.rs @@ -484,12 +484,7 @@ fn instantiate_oversized_map_from_linear_memory() -> Result<(), HostError> { ); // constructing a big map will cause budget limit exceeded error - let num_vals = - if host.get_ledger_protocol_version()? < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - 20_000 - } else { - 400_000 - }; + let num_vals = 400_000; let wasm_long = wasm::wasm_module_with_large_map_from_linear_memory(num_vals, U32Val::from(7).to_val()); host.clear_module_cache()?; @@ -503,9 +498,7 @@ fn instantiate_oversized_map_from_linear_memory() -> Result<(), HostError> { // with this test in feature=testutils mode (which turns on // feature=recording_mode implicitly). The easiest workaround is just to // switch to enforcing mode. - if host.get_ledger_protocol_version()? >= crate::vm::ModuleCache::MIN_LEDGER_VERSION { - host.switch_to_enforcing_storage()?; - } + host.switch_to_enforcing_storage()?; let res = host.call( contract_id_obj2, diff --git a/soroban-env-host/src/test/vec.rs b/soroban-env-host/src/test/vec.rs index 4fae1841f..6b2d73430 100644 --- a/soroban-env-host/src/test/vec.rs +++ b/soroban-env-host/src/test/vec.rs @@ -453,12 +453,7 @@ fn instantiate_oversized_vec_from_linear_memory() -> Result<(), HostError> { ); // constructing a big map will cause budget limit exceeded error - let num_vals = - if host.get_ledger_protocol_version()? < crate::vm::ModuleCache::MIN_LEDGER_VERSION { - 60_000 - } else { - 1_000_000 - }; + let num_vals = 1_000_000; let wasm_long = wasm::wasm_module_with_large_vector_from_linear_memory(num_vals, U32Val::from(7).to_val()); host.clear_module_cache()?; diff --git a/soroban-env-host/src/testutils.rs b/soroban-env-host/src/testutils.rs index 6f04cc39d..1f010a3e0 100644 --- a/soroban-env-host/src/testutils.rs +++ b/soroban-env-host/src/testutils.rs @@ -165,11 +165,12 @@ impl Host { pub fn current_test_protocol() -> u32 { use crate::meta::{get_ledger_protocol_version, INTERFACE_VERSION}; let max_supported_protocol = get_ledger_protocol_version(INTERFACE_VERSION); + let min_supported_protocol = crate::host::MIN_LEDGER_PROTOCOL_VERSION; if let Ok(vers) = std::env::var("TEST_PROTOCOL") { let test_protocol = vers.parse().expect("parsing TEST_PROTOCOL"); - if test_protocol <= max_supported_protocol { + if test_protocol >= min_supported_protocol && test_protocol <= max_supported_protocol { test_protocol - } else { + } else if test_protocol > max_supported_protocol { let next_advice = if cfg!(feature = "next") { "" } else { @@ -179,6 +180,11 @@ impl Host { "TEST_PROTOCOL={} is higher than the max supported protocol {}{}", test_protocol, max_supported_protocol, next_advice ); + } else { + panic!( + "TEST_PROTOCOL={} is lower than the min supported protocol {}", + test_protocol, min_supported_protocol + ); } } else { max_supported_protocol diff --git a/soroban-env-host/src/vm.rs b/soroban-env-host/src/vm.rs index e9d6579cf..186c1511a 100644 --- a/soroban-env-host/src/vm.rs +++ b/soroban-env-host/src/vm.rs @@ -361,9 +361,7 @@ impl Vm { cost_inputs: VersionedContractCodeCostInputs, cost_mode: ModuleParseCostMode, ) -> Result, HostError> { - if cost_mode == ModuleParseCostMode::PossiblyDeferredIfRecording - && host.get_ledger_protocol_version()? >= ModuleCache::MIN_LEDGER_VERSION - { + if cost_mode == ModuleParseCostMode::PossiblyDeferredIfRecording { if host.in_storage_recording_mode()? { return host.budget_ref().with_observable_shadow_mode(|| { ParsedModule::new_with_isolated_engine(host, wasm, cost_inputs) diff --git a/soroban-env-host/src/vm/module_cache.rs b/soroban-env-host/src/vm/module_cache.rs index a0582c121..65e3c8d19 100644 --- a/soroban-env-host/src/vm/module_cache.rs +++ b/soroban-env-host/src/vm/module_cache.rs @@ -23,9 +23,6 @@ pub struct ModuleCache { } impl ModuleCache { - // ModuleCache should not be active until protocol version 21. - pub const MIN_LEDGER_VERSION: u32 = 21; - pub fn new(host: &Host) -> Result { let config = get_wasmi_config(host.as_budget(), wasmi::CompilationMode::Lazy)?; let engine = Engine::new(&config); diff --git a/soroban-env-host/src/vm/parsed_module.rs b/soroban-env-host/src/vm/parsed_module.rs index 5aaea99ea..08d6ac906 100644 --- a/soroban-env-host/src/vm/parsed_module.rs +++ b/soroban-env-host/src/vm/parsed_module.rs @@ -8,7 +8,7 @@ use crate::{ use wasmi::{Engine, Module}; -use super::{ModuleCache, Vm}; +use super::Vm; use std::{collections::BTreeSet, io::Cursor, rc::Rc}; #[derive(Debug, Clone)] @@ -85,12 +85,10 @@ impl VersionedContractCodeCostInputs { // VmInstantiation cost type was repurposed to only cover the // cost of parsing, so we have to charge the "second half" cost // of instantiation separately here. - if _host.get_ledger_protocol_version()? >= ModuleCache::MIN_LEDGER_VERSION { - _host.charge_budget( - ContractCostType::VmCachedInstantiation, - Some(*wasm_bytes as u64), - )?; - } + _host.charge_budget( + ContractCostType::VmCachedInstantiation, + Some(*wasm_bytes as u64), + )?; } Self::V1(inputs) => { _host.charge_budget(ContractCostType::InstantiateWasmInstructions, None)?; @@ -188,9 +186,7 @@ impl ParsedModule { // parsing phase, so there is no DOS factor. We don't charge for // insertion/lookups, since they should be cheap and number of // operations on the set is limited. - if host.get_ledger_protocol_version()? >= ModuleCache::MIN_LEDGER_VERSION { - Vec::<(&str, &str)>::charge_bulk_init_cpy(symbols.len() as u64, host)?; - } + Vec::<(&str, &str)>::charge_bulk_init_cpy(symbols.len() as u64, host)?; callback(&symbols) } diff --git a/soroban-env-host/tests/secp256r1_sig_ver.rs b/soroban-env-host/tests/secp256r1_sig_ver.rs index 7fb5d4e48..b87b1f0f7 100644 --- a/soroban-env-host/tests/secp256r1_sig_ver.rs +++ b/soroban-env-host/tests/secp256r1_sig_ver.rs @@ -8,17 +8,12 @@ mod v21 { use soroban_env_common::EnvBase; use soroban_env_host::{budget::AsBudget, Env, Host, HostError}; - const PROTOCOL_SUPPORT_FOR_SECP256R1: u32 = 21; - // Test vectors copied from // https://csrc.nist.gov/groups/STM/cavp/documents/dss/186-3ecdsatestvectors.zip // `SigVer.rsp` section [P-256,SHA-256] #[test] fn test_secp256r1_sig_ver_with_sha256_on_msg() -> Result<(), HostError> { let host = Host::test_host(); - if host.get_ledger_protocol_version()? < PROTOCOL_SUPPORT_FOR_SECP256R1 { - return Ok(()); - } for test_vector in FIPS186_ECDSA_TEST_VECTORS { // reset the budget for each test case so they don't interfere host.as_budget().reset_default()?; @@ -202,9 +197,6 @@ mod v21 { let test_set = TestSet::load(EcdsaSecp256r1Sha256).unwrap(); let host = Host::test_host(); - if host.get_ledger_protocol_version()? < PROTOCOL_SUPPORT_FOR_SECP256R1 { - return Ok(()); - } for test_group in test_set.test_groups { let public_key = host.bytes_new_from_slice(&test_group.key.key).unwrap(); for test in test_group.tests { diff --git a/soroban-simulation/src/testutils.rs b/soroban-simulation/src/testutils.rs index cd1a3d0fa..bc9382d4a 100644 --- a/soroban-simulation/src/testutils.rs +++ b/soroban-simulation/src/testutils.rs @@ -20,7 +20,7 @@ use std::rc::Rc; /// the current ledger protocol and the next one. Thus, the code that /// depends on the certain behavior of the current version can be /// safely removed as soon as the current protocol has been bumped. -pub const CURRENT_PROTOCOL_VERSION: u32 = 20; +pub const CURRENT_PROTOCOL_VERSION: u32 = 22; pub struct MockSnapshotSource { map: BTreeMap, EntryWithLiveUntil>,