Skip to content

Commit

Permalink
Remove vnext test wasms (#1181)
Browse files Browse the repository at this point in the history
### What

Remove vnext test wasms to allow core to test multiple protocol
versions. This only works at the moment because V20 test wasms are
compatible with V21, but this may not be the case in the future. At some
point we may need test wasms organized by protocol version (not just
curr vs vnext).
  • Loading branch information
sisuresh committed Nov 7, 2023
1 parent f799245 commit 4f4a7f3
Show file tree
Hide file tree
Showing 27 changed files with 46 additions and 79 deletions.
2 changes: 1 addition & 1 deletion soroban-env-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pretty_assertions = "1.4.0"

[features]
testutils = ["soroban-env-common/testutils", "soroban-synth-wasm/testutils", "recording_auth"]
next = ["soroban-env-common/next", "soroban-test-wasms/next", "soroban-synth-wasm/next", "soroban-bench-utils/next"]
next = ["soroban-env-common/next", "soroban-synth-wasm/next", "soroban-bench-utils/next"]
tracy = ["dep:tracy-client", "soroban-env-common/tracy"]
recording_auth = []

Expand Down
15 changes: 14 additions & 1 deletion soroban-env-host/src/test/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn get_contract_wasm_ref(host: &Host, contract_id: Hash) -> Hash {
LedgerEntryData::ContractData(e) => match &e.val {
ScVal::ContractInstance(i) => match &i.executable {
ContractExecutable::Wasm(h) => Ok(h.clone()),
_ => panic!("expectecd Wasm executable"),
_ => panic!("expected Wasm executable"),
},
_ => panic!("expected ContractInstance"),
},
Expand Down Expand Up @@ -412,3 +412,16 @@ fn test_create_contract_from_source_account_recording_auth() {
}]
);
}

#[test]
fn test_invalid_contract() {
let host = Host::test_host_with_recording_footprint();

let bytes = [0u8, 32];

assert!(host
.invoke_function(HostFunction::UploadContractWasm(
bytes.to_vec().try_into().unwrap(),
))
.is_err());
}
42 changes: 29 additions & 13 deletions soroban-env-host/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::{xdr::Hash, Host, Symbol, Val};
use fuel_refillable::FuelRefillable;
use func_info::HOST_FUNCTIONS;
use soroban_env_common::{
meta::{self, get_ledger_protocol_version, get_pre_release_version},
meta::{self, get_ledger_protocol_version},
xdr::{
DepthLimitedRead, ReadXdr, ScEnvMetaEntry, ScErrorCode, ScErrorType,
DEFAULT_XDR_RW_DEPTH_LIMIT,
Expand Down Expand Up @@ -96,12 +96,22 @@ impl Vm {
}
};

let got_pre = get_pre_release_version(interface_version);
// Not used when "next" is enabled
#[cfg(not(feature = "next"))]
let got_pre = meta::get_pre_release_version(interface_version);

let got_proto = get_ledger_protocol_version(interface_version);

if got_proto < want_proto {
// Old protocols are finalized, we only support contracts
// with similarly finalized (zero) prerelease numbers.
//
// Note that we only enable this check if the "next" feature isn't enabled
// because a "next" stellar-core can still run a "curr" test using non-finalized
// test wasms. The "next" feature isn't safe for production and is meant to
// simulate the protocol version after the one currently supported in
// stellar-core, so bypassing this check for "next" is safe.
#[cfg(not(feature = "next"))]
if got_pre != 0 {
return Err(err!(
host,
Expand All @@ -111,17 +121,23 @@ impl Vm {
));
}
} else if got_proto == want_proto {
// Current protocol might have a nonzero prerelease number; we will
// allow it only if it matches the current prerelease exactly.
let want_pre = get_pre_release_version(meta::INTERFACE_VERSION);
if want_pre != got_pre {
return Err(err!(
host,
(ScErrorType::WasmVm, ScErrorCode::InvalidInput),
"contract pre-release number for current protocol does not match host",
got_pre,
want_pre
));
// Relax this check as well for the "next" feature to allow for flexibility while testing.
// stellar-core can pass in an older protocol version, in which case the pre-release version
// will not match up with the "next" feature (The "next" pre-release version is always 1).
#[cfg(not(feature = "next"))]
{
// Current protocol might have a nonzero prerelease number; we will
// allow it only if it matches the current prerelease exactly.
let want_pre = meta::get_pre_release_version(meta::INTERFACE_VERSION);
if want_pre != got_pre {
return Err(err!(
host,
(ScErrorType::WasmVm, ScErrorCode::InvalidInput),
"contract pre-release number for current protocol does not match host",
got_pre,
want_pre
));
}
}
} else {
// Future protocols we don't allow. It might be nice (in the sense
Expand Down
5 changes: 1 addition & 4 deletions soroban-test-wasms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ version.workspace = true
description = "crate full of precompiled test WASM binaries for soroban -- for use in other tests, do not publish"
edition = "2021"
publish = false
rust-version = "1.71"

[features]
next = []
rust-version = "1.71"
48 changes: 0 additions & 48 deletions soroban-test-wasms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
//! documentation purpopses without having to worry about breaking tests in
//! the host here.

#[cfg(not(feature = "next"))]
pub use curr::*;

#[cfg(not(feature = "next"))]
mod curr {
pub const ADD_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_add_i32.wasm").as_slice();
Expand Down Expand Up @@ -86,49 +84,3 @@ mod curr {
pub const SAC_REENTRY_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/sac_reentry_account.wasm").as_slice();
}

#[cfg(feature = "next")]
pub use next::*;

#[cfg(feature = "next")]
mod next {
pub const ADD_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_add_i32.wasm").as_slice();
pub const ADD_F32: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_add_f32.wasm").as_slice();
pub const ALLOC: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_alloc.wasm").as_slice();
pub const CREATE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_create_contract.wasm").as_slice();
pub const CONTRACT_STORAGE: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_contract_data.wasm").as_slice();
pub const LINEAR_MEMORY: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_linear_memory.wasm").as_slice();
pub const VEC: &[u8] = include_bytes!("../wasm-workspace/opt/next/example_vec.wasm").as_slice();
pub const INVOKE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_invoke_contract.wasm").as_slice();
pub const HOSTILE: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_hostile.wasm").as_slice();
pub const FIB: &[u8] = include_bytes!("../wasm-workspace/opt/next/example_fib.wasm").as_slice();
pub const FANNKUCH: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_fannkuch.wasm").as_slice();
pub const COMPLEX: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_complex.wasm").as_slice();
pub const SIMPLE_ACCOUNT_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_simple_account.wasm").as_slice();
pub const AUTH_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/auth_test_contract.wasm").as_slice();
pub const UPDATEABLE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/example_updateable_contract.wasm").as_slice();
pub const DELEGATED_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/test_delegated_account.wasm").as_slice();
pub const ERR: &[u8] = include_bytes!("../wasm-workspace/opt/next/example_err.wasm").as_slice();
pub const WRITE_BYTES: &[u8] =
include_bytes!("../wasm-workspace/opt/next/soroban_write_upgrade_bytes_contract.wasm")
.as_slice();
pub const CONDITIONAL_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/test_conditional_account.wasm").as_slice();

pub const SAC_REENTRY_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/next/sac_reentry_account.wasm").as_slice();
}
13 changes: 1 addition & 12 deletions soroban-test-wasms/wasm-workspace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,4 @@ regenerate-test-wasms:
for i in target/wasm32-unknown-unknown/release/*.wasm ; do \
wasm-opt -Oz "$$i" -o "opt/curr/$$(basename $$i)"; \
ls -l "opt/curr/$$(basename $$i)"; \
done
cargo clean
cargo +nightly build \
--target wasm32-unknown-unknown \
--release \
--features next \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort
for i in target/wasm32-unknown-unknown/release/*.wasm ; do \
wasm-opt -Oz "$$i" -o "opt/next/$$(basename $$i)"; \
ls -l "opt/next/$$(basename $$i)"; \
done
done
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4f4a7f3

Please sign in to comment.