Skip to content

Commit

Permalink
Replace parity-wasm with wasmparser
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jul 24, 2023
1 parent 0e48309 commit 2d4aac7
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 145 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ cosmwasm-std = { path = "../std", version = "1.3.0", default-features = false }
cosmwasm-crypto = { path = "../crypto", version = "1.3.0" }
derivative = "2"
hex = "0.4"
parity-wasm = { version = "0.45", features = ["sign_ext"] }
schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
serde_json = "1.0.40"
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::filesystem::mkdir_p;
use crate::instance::{Instance, InstanceOptions};
use crate::modules::{CachedModule, FileSystemCache, InMemoryCache, PinnedMemoryCache};
use crate::size::Size;
use crate::static_analysis::{deserialize_wasm, has_ibc_entry_points};
use crate::static_analysis::{deserialize_exports, has_ibc_entry_points};
use crate::wasm_backend::{compile, make_store_with_engine};

const STATE_DIR: &str = "state";
Expand Down Expand Up @@ -244,7 +244,7 @@ where
pub fn analyze(&self, checksum: &Checksum) -> VmResult<AnalysisReport> {
// Here we could use a streaming deserializer to slightly improve performance. However, this way it is DRYer.
let wasm = self.load_wasm(checksum)?;
let module = deserialize_wasm(&wasm)?;
let module = deserialize_exports(&wasm)?;
Ok(AnalysisReport {
has_ibc_entry_points: has_ibc_entry_points(&module),
required_capabilities: required_capabilities_from_module(&module),
Expand Down
8 changes: 4 additions & 4 deletions packages/vm/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn capabilities_from_csv(csv: &str) -> HashSet<String> {

/// Implementation for check_wasm, based on static analysis of the bytecode.
/// This is used for code upload, to perform check before compiling the Wasm.
pub fn required_capabilities_from_module(module: &impl ExportInfo) -> HashSet<String> {
pub fn required_capabilities_from_module(module: impl ExportInfo) -> HashSet<String> {
module
.exported_function_names(Some(REQUIRES_PREFIX))
.into_iter()
Expand All @@ -33,7 +33,7 @@ pub fn required_capabilities_from_module(module: &impl ExportInfo) -> HashSet<St
#[cfg(test)]
mod tests {
use super::*;
use crate::static_analysis::deserialize_wasm;
use crate::static_analysis::deserialize_exports;

#[test]
fn capabilities_from_csv_works() {
Expand Down Expand Up @@ -73,7 +73,7 @@ mod tests {
)"#,
)
.unwrap();
let module = deserialize_wasm(&wasm).unwrap();
let module = deserialize_exports(&wasm).unwrap();

let required_capabilities = required_capabilities_from_module(&module);
assert_eq!(required_capabilities.len(), 3);
Expand All @@ -85,7 +85,7 @@ mod tests {
#[test]
fn required_capabilities_from_module_works_without_exports_section() {
let wasm = wat::parse_str(r#"(module)"#).unwrap();
let module = deserialize_wasm(&wasm).unwrap();
let module = deserialize_exports(&wasm).unwrap();
let required_capabilities = required_capabilities_from_module(&module);
assert_eq!(required_capabilities.len(), 0);
}
Expand Down
Loading

0 comments on commit 2d4aac7

Please sign in to comment.