Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 57,
spec_version: 58,
impl_version: 59,
apis: RUNTIME_API_VERSIONS,
};
Expand Down
72 changes: 70 additions & 2 deletions srml/contract/src/wasm/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl<'a, Gas: 'a + As<u32> + Clone> ContractModule<'a, Gas> {
///
/// - 'call'
/// - 'deploy'
///
/// Any other exports are not allowed.
fn scan_exports(&self) -> Result<(), &'static str> {
let mut deploy_found = false;
let mut call_found = false;
Expand Down Expand Up @@ -147,7 +149,7 @@ impl<'a, Gas: 'a + As<u32> + Clone> ContractModule<'a, Gas> {
match export.field() {
"call" => call_found = true,
"deploy" => deploy_found = true,
_ => continue,
_ => return Err("unknown export: expecting only deploy and call functions"),
}

// Then check the export kind. "call" and "deploy" are
Expand Down Expand Up @@ -218,12 +220,19 @@ impl<'a, Gas: 'a + As<u32> + Clone> ContractModule<'a, Gas> {
}

let type_idx = match import.external() {
&External::Table(_) => return Err("Cannot import tables"),
&External::Global(_) => return Err("Cannot import globals"),
&External::Function(ref type_idx) => type_idx,
&External::Memory(ref memory_type) => {
if import.field() != "memory" {
return Err("Memory import must have the field name 'memory'")
}
if imported_mem_type.is_some() {
return Err("Multiple memory imports defined")
}
imported_mem_type = Some(memory_type);
continue;
}
_ => continue,
};

let Type::Function(ref func_ty) = types
Expand Down Expand Up @@ -447,6 +456,54 @@ mod tests {
"#,
Err("Maximum number of pages should not exceed the configured maximum.")
);

prepare_test!(field_name_not_memory,
r#"
(module
(import "env" "forgetit" (memory 1 1))

(func (export "call"))
(func (export "deploy"))
)
"#,
Err("Memory import must have the field name 'memory'")
);

prepare_test!(multiple_memory_imports,
r#"
(module
(import "env" "memory" (memory 1 1))
(import "env" "memory" (memory 1 1))

(func (export "call"))
(func (export "deploy"))
)
"#,
Err("Multiple memory imports defined")
);

prepare_test!(table_import,
r#"
(module
(import "env" "table" (table 1 anyfunc))

(func (export "call"))
(func (export "deploy"))
)
"#,
Err("Cannot import tables")
);

prepare_test!(global_import,
r#"
(module
(global $g (import "env" "global") (mut i32))
(func (export "call"))
(func (export "deploy"))
)
"#,
Err("Cannot import globals")
);
}

mod imports {
Expand Down Expand Up @@ -582,5 +639,16 @@ mod tests {
"#,
Err("entry point has wrong signature")
);

prepare_test!(unknown_exports,
r#"
(module
(func (export "call"))
(func (export "deploy"))
(func (export "whatevs"))
)
"#,
Err("unknown export: expecting only deploy and call functions")
);
}
}