Skip to content

Commit

Permalink
Merge pull request #713 from CosmWasm/bump_interface_version
Browse files Browse the repository at this point in the history
Bump interface version and rebuild testing contract
  • Loading branch information
webmaster128 authored Jan 13, 2021
2 parents cdeabd0 + 4496238 commit 2b7eef9
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to
performance. Also, remove `memory_limit` from `InstanceOptions`, and define it
instead at `Cache` level (same memory limit for all cached instances).
([#697])
- cosmwasm-vm: Bump required marker export `cosmwasm_vm_version_4` to
`interface_version_5`.

[#696]: https://github.com/CosmWasm/cosmwasm/issues/696
[#697]: https://github.com/CosmWasm/cosmwasm/issues/697
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ macro_rules! create_entry_points {

$crate::create_entry_points!(@migration; $contract, $migration);

// Other C externs like cosmwasm_vm_version_4, allocate, deallocate are available
// Other C externs like interface_version_5, allocate, deallocate are available
// automatically because we `use cosmwasm_std`.
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/std/src/exports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! exports exposes the public wasm API
//!
//! cosmwasm_vm_version_4, allocate and deallocate turn into Wasm exports
//! interface_version_5, allocate and deallocate turn into Wasm exports
//! as soon as cosmwasm_std is `use`d in the contract, even privately.
//!
//! do_init and do_wrapper should be wrapped with a extern "C" entry point
Expand Down Expand Up @@ -29,11 +29,11 @@ extern "C" fn requires_staking() -> () {}
#[no_mangle]
extern "C" fn requires_stargate() -> () {}

/// cosmwasm_vm_version_* exports mark which Wasm VM interface level this contract is compiled for.
/// interface_version_* exports mark which Wasm VM interface level this contract is compiled for.
/// They can be checked by cosmwasm_vm.
/// Update this whenever the Wasm VM interface breaks.
#[no_mangle]
extern "C" fn cosmwasm_vm_version_4() -> () {}
extern "C" fn interface_version_5() -> () {}

/// allocate reserves the given number of bytes in wasm memory and returns a pointer
/// to a Region defining this data. This space is managed by the calling process
Expand Down
3 changes: 2 additions & 1 deletion packages/vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ compatibility list:

| cosmwasm-vm | Supported interface versions | cosmwasm-std |
| ----------- | ---------------------------- | ------------ |
| 0.14 | `interface_version_5` | 0.14 |
| 0.13 | `cosmwasm_vm_version_4` | 0.11-0.13 |
| 0.12 | `cosmwasm_vm_version_4` | 0.11-0.13 |
| 0.11 | `cosmwasm_vm_version_4` | 0.11-0.13 |
Expand All @@ -39,7 +40,7 @@ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="devcontract_cache_hackatom",target=/code/contracts/hackatom/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.10.5 ./contracts/hackatom \
&& cp artifacts/hackatom.wasm packages/vm/testdata/contract_0.12.wasm
&& cp artifacts/hackatom.wasm packages/vm/testdata/hackatom_0.14.wasm
```

## Testing
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
// Cache
const MEMORY_CACHE_SIZE: Size = Size::mebi(200);

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

fn bench_instance(c: &mut Criterion) {
let mut group = c.benchmark_group("Instance");
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {
};
const TESTING_MEMORY_CACHE_SIZE: Size = Size::mebi(200);

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

fn default_features() -> HashSet<String> {
features_from_csv("staking")
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mod tests {
use crate::testing::{mock_env, mock_info, mock_instance};
use cosmwasm_std::{coins, Empty};

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

#[test]
fn call_init_works() {
Expand Down
16 changes: 8 additions & 8 deletions packages/vm/src/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SUPPORTED_IMPORTS: &[&str] = &[
/// Other optional exports exist, e.g. "query" and "migrate".
/// This is unlikely to change much, must be frozen at 1.0 to avoid breaking existing contracts
const REQUIRED_EXPORTS: &[&str] = &[
"cosmwasm_vm_version_4",
"interface_version_5",
"init",
"handle",
"allocate",
Expand Down Expand Up @@ -164,9 +164,9 @@ mod tests {
use parity_wasm::elements::Internal;
use std::iter::FromIterator;

static CONTRACT_0_6: &[u8] = include_bytes!("../testdata/contract_0.6.wasm");
static CONTRACT_0_7: &[u8] = include_bytes!("../testdata/contract_0.7.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT_0_6: &[u8] = include_bytes!("../testdata/hackatom_0.6.wasm");
static CONTRACT_0_7: &[u8] = include_bytes!("../testdata/hackatom_0.7.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
static CORRUPTED: &[u8] = include_bytes!("../testdata/corrupted.wasm");

fn default_features() -> HashSet<String> {
Expand Down Expand Up @@ -228,15 +228,15 @@ mod tests {
fn check_wasm_old_contract() {
match check_wasm(CONTRACT_0_7, &default_features()) {
Err(VmError::StaticValidationErr { msg, .. }) => assert!(msg.starts_with(
"Wasm contract doesn't have required export: \"cosmwasm_vm_version_4\""
"Wasm contract doesn't have required export: \"interface_version_5\""
)),
Err(e) => panic!("Unexpected error {:?}", e),
Ok(_) => panic!("This must not succeeed"),
};

match check_wasm(CONTRACT_0_6, &default_features()) {
Err(VmError::StaticValidationErr { msg, .. }) => assert!(msg.starts_with(
"Wasm contract doesn't have required export: \"cosmwasm_vm_version_4\""
"Wasm contract doesn't have required export: \"interface_version_5\""
)),
Err(e) => panic!("Unexpected error {:?}", e),
Ok(_) => panic!("This must not succeeed"),
Expand Down Expand Up @@ -350,7 +350,7 @@ mod tests {
match check_wasm_exports(&module) {
Err(VmError::StaticValidationErr { msg, .. }) => {
assert!(msg.starts_with(
"Wasm contract doesn't have required export: \"cosmwasm_vm_version_4\""
"Wasm contract doesn't have required export: \"interface_version_5\""
));
}
Err(e) => panic!("Unexpected error {:?}", e),
Expand All @@ -364,7 +364,7 @@ mod tests {
match check_wasm_exports(&module) {
Err(VmError::StaticValidationErr { msg, .. }) => {
assert!(msg.starts_with(
"Wasm contract doesn't have required export: \"cosmwasm_vm_version_4\""
"Wasm contract doesn't have required export: \"interface_version_5\""
));
}
Err(e) => panic!("Unexpected error {:?}", e),
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ mod tests {
};
use wasmer::{imports, Function, Instance as WasmerInstance};

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

// shorthands for function generics below
type MA = MockApi;
Expand Down Expand Up @@ -630,7 +630,7 @@ mod tests {
let (env, _instance) = make_instance(TESTING_GAS_LIMIT);
leave_default_data(&env);

env.call_function0("cosmwasm_vm_version_4", &[]).unwrap();
env.call_function0("interface_version_5", &[]).unwrap();
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ mod tests {
use crate::testing::{MockApi, MockQuerier, MockStorage};
use crate::wasm_backend::compile_and_use;

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

// shorthands for function generics below
type MA = MockApi;
Expand Down
18 changes: 9 additions & 9 deletions packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mod tests {
const KIB: usize = 1024;
const MIB: usize = 1024 * 1024;
const DEFAULT_QUERY_GAS_LIMIT: u64 = 300_000;
static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

#[test]
fn required_features_works() {
Expand Down Expand Up @@ -348,7 +348,7 @@ mod tests {
let instance = mock_instance(&CONTRACT, &[]);

instance
.call_function0("cosmwasm_vm_version_4", &[])
.call_function0("interface_version_5", &[])
.expect("error calling function");
}

Expand Down Expand Up @@ -491,7 +491,7 @@ mod tests {
(type (func))
(func (type 0) nop)
(export "cosmwasm_vm_version_4" (func 0))
(export "interface_version_5" (func 0))
(export "init" (func 0))
(export "handle" (func 0))
(export "allocate" (func 0))
Expand All @@ -510,7 +510,7 @@ mod tests {
(type (func))
(func (type 0) nop)
(export "cosmwasm_vm_version_4" (func 0))
(export "interface_version_5" (func 0))
(export "init" (func 0))
(export "handle" (func 0))
(export "allocate" (func 0))
Expand Down Expand Up @@ -565,7 +565,7 @@ mod tests {

let report2 = instance.create_gas_report();
assert_eq!(report2.used_externally, 146);
assert_eq!(report2.used_internally, 67318);
assert_eq!(report2.used_internally, 67147);
assert_eq!(report2.limit, LIMIT);
assert_eq!(
report2.remaining,
Expand Down Expand Up @@ -749,7 +749,7 @@ mod singlepass_tests {
use crate::calls::{call_handle, call_init, call_query};
use crate::testing::{mock_env, mock_info, mock_instance, mock_instance_with_gas_limit};

static CONTRACT: &[u8] = include_bytes!("../testdata/contract.wasm");
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");

#[test]
fn contract_deducts_gas_init() {
Expand All @@ -764,7 +764,7 @@ mod singlepass_tests {
.unwrap();

let init_used = orig_gas - instance.get_gas_left();
assert_eq!(init_used, 67464);
assert_eq!(init_used, 67293);
}

#[test]
Expand All @@ -787,7 +787,7 @@ mod singlepass_tests {
.unwrap();

let handle_used = gas_before_handle - instance.get_gas_left();
assert_eq!(handle_used, 194543);
assert_eq!(handle_used, 191869);
}

#[test]
Expand Down Expand Up @@ -821,6 +821,6 @@ mod singlepass_tests {
assert_eq!(answer.as_slice(), b"{\"verifier\":\"verifies\"}");

let query_used = gas_before_query - instance.get_gas_left();
assert_eq!(query_used, 52471);
assert_eq!(query_used, 52424);
}
}
1 change: 0 additions & 1 deletion packages/vm/testdata/contract.wasm

This file was deleted.

1 change: 1 addition & 0 deletions packages/vm/testdata/hackatom.wasm
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added packages/vm/testdata/hackatom_0.14.wasm
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2b7eef9

Please sign in to comment.