Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InstantiateWasmImports which was broken by protocol-version gating #1429

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions soroban-env-host/benches/common/cost_types/wasm_insn_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,21 @@ pub fn wasm_module_with_n_globals(n: usize) -> Vec<u8> {

pub fn wasm_module_with_n_imports(n: usize) -> Vec<u8> {
let mut me = ModEmitter::default().add_bench_import();
let names = Vm::get_all_host_functions();
for (module, name, arity) in names.iter().take(n) {
let names = Vm::get_all_host_functions_with_supported_protocol_range();
for (module, name, arity, min_proto, max_proto) in names.iter().take(n) {
if *module == "t" {
continue;
}
if let Some(proto) = min_proto {
if *proto > 20 {
continue;
}
}
if let Some(proto) = max_proto {
if *proto < 20 {
continue;
}
}
me.import_func(module, name, Arity(*arity));
}
me.add_bench_export().finish()
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/benches/common/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rand::{rngs::StdRng, RngCore};
use soroban_env_host::{budget::AsBudget, meta, Host, LedgerInfo, Val, I256};
use soroban_env_host::{budget::AsBudget, Host, LedgerInfo, Val, I256};

pub(crate) fn test_host() -> Host {
let host = Host::default();
Expand Down
9 changes: 9 additions & 0 deletions soroban-env-host/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ impl Vm {
.collect()
}

#[cfg(feature = "testutils")]
pub fn get_all_host_functions_with_supported_protocol_range(
) -> Vec<(&'static str, &'static str, u32, Option<u32>, Option<u32>)> {
HOST_FUNCTIONS
.iter()
.map(|hf| (hf.mod_str, hf.fn_str, hf.arity, hf.min_proto, hf.max_proto))
.collect()
}

/// Instantiates a VM given the arguments provided in [`Self::new`],
/// or [`Self::new_from_module_cache`]
fn instantiate(
Expand Down
Loading