Skip to content

Commit

Permalink
Strip out pre-p22-protocol-qualification code
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Aug 8, 2024
1 parent 4259da6 commit b01e798
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 4 additions & 20 deletions soroban-env-host/src/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions soroban-env-host/src/e2e_testutils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::vm::ModuleCache;
use crate::vm::ParsedModule;
use crate::xdr::{
AccountEntry, AccountEntryExt, AccountId, ContractCodeEntry, ContractDataDurability,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 12 additions & 16 deletions soroban-env-host/src/host/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?)?;
Expand All @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions soroban-env-host/src/test/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
6 changes: 0 additions & 6 deletions soroban-env-host/src/test/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
msg_digest: Vec<u8>,
signature: Vec<u8>|
Expand Down
42 changes: 6 additions & 36 deletions soroban-env-host/src/test/e2e_tests.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
68 changes: 2 additions & 66 deletions soroban-env-host/src/test/hostile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()?;
Expand Down
Loading

0 comments on commit b01e798

Please sign in to comment.