Skip to content

Commit

Permalink
Implement Wasm validation for known issues/markers (use-ink#171)
Browse files Browse the repository at this point in the history
* Implement Wasm validation for known issues/markers

* Add test for invalid panic import

* Add prefix to error markers

* Add test for ink! codegen error marker

* Implement improved linker error protocol

* Move validation into its own module

* Migrate tests to new linker error protocol

* Fix merge

* Improve code structure

* Fix formatting

* Improve code structure

* Remove mod indirection

* Replace `contains` with `starts_with`

* Add note regarding equivalent ink! type necessity

* Throw an error on invalid import function

* Add sunny day test

* Do not panic if no import section is found

* Update error message on decoding error
  • Loading branch information
Michael Müller authored Feb 11, 2021
1 parent 7ff7dbe commit 4f7356b
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ zip = { version = "0.5.8", default-features = false }
pwasm-utils = "0.17.0"
parity-wasm = "0.42.1"
cargo_metadata = "0.12.3"
codec = { package = "parity-scale-codec", version = "2.0.0" }
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
which = "4.0.2"
colored = "2.0.0"
toml = "0.5.8"
Expand All @@ -41,6 +41,7 @@ serde_json = "1.0.62"
tempfile = "3.2.0"
url = { version = "2.2.0", features = ["serde"] }
binaryen = { version = "0.12.0", optional = true }
impl-serde = "0.3.1"

# dependencies for optional extrinsics feature
async-std = { version = "1.9.0", optional = true }
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{io, process::Command};

use crate::{
crate_metadata::CrateMetadata,
maybe_println, util,
maybe_println, util, validate_wasm,
workspace::{ManifestPath, Profile, Workspace},
BuildArtifacts, BuildResult, UnstableFlags, UnstableOptions, VerbosityFlags,
};
Expand Down Expand Up @@ -252,6 +252,8 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> {
ensure_maximum_memory_pages(&mut module, MAX_MEMORY_PAGES)?;
strip_custom_sections(&mut module);

validate_wasm::validate_import_section(&module)?;

parity_wasm::serialize_to_file(&crate_metadata.dest_wasm, module)?;
Ok(())
}
Expand Down Expand Up @@ -436,7 +438,7 @@ pub(crate) fn execute_with_crate_metadata(

#[cfg(feature = "test-ci-only")]
#[cfg(test)]
mod tests {
mod tests_ci_only {
use crate::{cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags};

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
mod cmd;
mod crate_metadata;
mod util;
mod validate_wasm;
mod workspace;

use self::workspace::ManifestPath;
Expand Down
Loading

0 comments on commit 4f7356b

Please sign in to comment.