Skip to content

Commit

Permalink
Merge pull request #4350 from Fraser999/revert-types-change
Browse files Browse the repository at this point in the history
Revert types change and bump versions
  • Loading branch information
Fraser999 authored Oct 18, 2023
2 parents 273d309 + ced9145 commit 53dd338
Show file tree
Hide file tree
Showing 39 changed files with 249 additions and 259 deletions.
244 changes: 118 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@ lto = true
[profile.bench]
codegen-units = 1
lto = true

[patch.crates-io]
parity-wasm = { git = "https://github.com/casper-network/casper-wasm.git", branch = "casper-0.45.0" }
11 changes: 10 additions & 1 deletion execution_engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Security: in case of vulnerabilities)


## [Unreleased]

## 6.0.0

### Changed
* Default value for `max_stack_height` is increased to 500.
* Replaced usage of `parity-wasm` and `wasmi` with Casper forks `casper-wasm` and `casper-wasmi` respectively.

### Fixed
* Fix incorrect handling of unbonding purses for validators that were also evicted in that era.
* Fix issue with one-time code used for migrating data to support redelegations.

### Security
* Fix unbounded memory allocation issue while parsing Wasm.



Expand Down
12 changes: 6 additions & 6 deletions execution_engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casper-execution-engine"
version = "5.0.0" # when updating, also update 'html_root_url' in lib.rs
version = "6.0.0" # when updating, also update 'html_root_url' in lib.rs
authors = ["Henry Till <henrytill@gmail.com>", "Ed Hastings <ed@casperlabs.io>"]
edition = "2018"
description = "CasperLabs execution engine crates."
Expand All @@ -15,12 +15,14 @@ anyhow = "1.0.33"
base16 = "0.2.1"
bincode = "1.3.1"
casper-hashing = { version = "2.0.0", path = "../hashing" }
casper-types = { version = "4.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema"] }
casper-wasm-utils = "2.0.0"
casper-types = { version = "3.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema"] }
casper-wasm = { version = "0.46.0", default-features = false }
casper-wasm-utils = "3.0.0"
casper-wasmi = "0.13.2"
datasize = "0.2.4"
either = "1.8.1"
hex_fmt = "0.3.0"
hex-buffer-serde = "0.2.1"
hex_fmt = "0.3.0"
hostname = "0.3.0"
humantime = "2"
itertools = "0.10.0"
Expand All @@ -34,7 +36,6 @@ num-rational = { version = "0.4.0", features = ["serde"] }
num-traits = "0.2.10"
num_cpus = "1"
once_cell = "1.5.2"
parity-wasm = { version = "0.45.0", default-features = false }
proptest = { version = "1.0.0", optional = true }
rand = "0.8.3"
rand_chacha = "0.3.0"
Expand All @@ -47,7 +48,6 @@ thiserror = "1.0.18"
tracing = "0.1.18"
uint = "0.9.0"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
wasmi = "0.13.2"

[dev-dependencies]
assert_matches = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/engine_state/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum Error {
WasmPreprocessing(#[from] wasm_prep::PreprocessingError),
/// WASM serialization error.
#[error("Wasm serialization error: {0:?}")]
WasmSerialization(#[from] parity_wasm::SerializationError),
WasmSerialization(#[from] casper_wasm::SerializationError),
/// Contract execution error.
#[error(transparent)]
Exec(execution::Error),
Expand Down
8 changes: 4 additions & 4 deletions execution_engine/src/core/execution/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Execution error and supporting code.
use parity_wasm::elements;
use casper_wasm::elements;
use thiserror::Error;

use casper_types::{
Expand Down Expand Up @@ -197,10 +197,10 @@ impl Error {
}
}

impl wasmi::HostError for Error {}
impl casper_wasmi::HostError for Error {}

impl From<wasmi::Error> for Error {
fn from(error: wasmi::Error) -> Self {
impl From<casper_wasmi::Error> for Error {
fn from(error: casper_wasmi::Error) -> Self {
match error
.as_host_error()
.and_then(|host_error| host_error.downcast_ref::<Error>())
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/resolvers/memory_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module contains resolver of a memory section of the WASM code.
use wasmi::MemoryRef;
use casper_wasmi::MemoryRef;

use super::error::ResolverError;

Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod memory_resolver;
pub(crate) mod v1_function_index;
mod v1_resolver;

use wasmi::ModuleImportResolver;
use casper_wasmi::ModuleImportResolver;

use casper_types::ProtocolVersion;

Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/resolvers/v1_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::cell::RefCell;

use wasmi::{
use casper_wasmi::{
memory_units::Pages, Error as InterpreterError, FuncInstance, FuncRef, MemoryDescriptor,
MemoryInstance, MemoryRef, ModuleImportResolver, Signature, ValueType,
};
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/runtime/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasmi::{FromValue, RuntimeArgs, Trap};
use casper_wasmi::{FromValue, RuntimeArgs, Trap};

pub(crate) trait Args
where
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/runtime/externals.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::BTreeSet, convert::TryFrom};

use wasmi::{Externals, RuntimeArgs, RuntimeValue, Trap};
use casper_wasmi::{Externals, RuntimeArgs, RuntimeValue, Trap};

use casper_types::{
account::AccountHash,
Expand Down
10 changes: 5 additions & 5 deletions execution_engine/src/core/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::{
iter::FromIterator,
};

use parity_wasm::elements::Module;
use casper_wasm::elements::Module;
use casper_wasmi::{MemoryRef, Trap, TrapCode};
use tracing::error;
use wasmi::{MemoryRef, Trap, TrapCode};

use casper_types::{
account::{Account, AccountHash, ActionType, Weight},
Expand Down Expand Up @@ -205,14 +205,14 @@ where
self.try_get_memory()?
.with_direct_access(|buffer| {
let end = offset.checked_add(size).ok_or_else(|| {
wasmi::Error::Memory(format!(
casper_wasmi::Error::Memory(format!(
"trying to access memory block of size {} from offset {}",
size, offset
))
})?;

if end > buffer.len() {
return Err(wasmi::Error::Memory(format!(
return Err(casper_wasmi::Error::Memory(format!(
"trying to access region [{}..{}] in memory [0..{}]",
offset,
end,
Expand Down Expand Up @@ -1367,7 +1367,7 @@ where
None => return Err(Error::KeyNotFound(context_key)),
};

parity_wasm::deserialize_buffer(contract_wasm.bytes())?
casper_wasm::deserialize_buffer(contract_wasm.bytes())?
};

let context = self.context.new_from_self(
Expand Down
6 changes: 3 additions & 3 deletions execution_engine/src/core/runtime/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use parity_wasm::elements::Module;
use wasmi::{ImportsBuilder, MemoryRef, ModuleInstance, ModuleRef};
use casper_wasm::elements::Module;
use casper_wasmi::{ImportsBuilder, MemoryRef, ModuleInstance, ModuleRef};

use casper_types::{
contracts::NamedKeys, AccessRights, CLType, CLValue, Key, ProtocolVersion, PublicKey,
Expand Down Expand Up @@ -30,7 +30,7 @@ pub(super) fn instance_and_memory(
protocol_version: ProtocolVersion,
wasm_config: &WasmConfig,
) -> Result<(ModuleRef, MemoryRef), Error> {
let module = wasmi::Module::from_parity_wasm_module(parity_module)?;
let module = casper_wasmi::Module::from_casper_wasm_module(parity_module)?;
let resolver = resolvers::create_module_resolver(protocol_version, wasm_config)?;
let mut imports = ImportsBuilder::new();
imports.push_resolver("env", &resolver);
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The engine which executes smart contracts on the Casper network.

#![doc(html_root_url = "https://docs.rs/casper-execution-engine/5.0.0")]
#![doc(html_root_url = "https://docs.rs/casper-execution-engine/6.0.0")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Favicon_RGB_50px.png",
html_logo_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png",
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/shared/opcode_costs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Support for Wasm opcode costs.
use std::{convert::TryInto, num::NonZeroU32};

use casper_wasm::elements::Instruction;
use casper_wasm_utils::rules::{MemoryGrowCost, Rules};
use datasize::DataSize;
use parity_wasm::elements::Instruction;
use rand::{distributions::Standard, prelude::*, Rng};
use serde::{Deserialize, Serialize};

Expand Down
20 changes: 10 additions & 10 deletions execution_engine/src/shared/wasm_prep.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Preprocessing of Wasm modules.
use casper_wasm_utils::{self, stack_height};
use parity_wasm::elements::{
use casper_wasm::elements::{
self, External, Instruction, Internal, MemorySection, Module, Section, TableType, Type,
};
use casper_wasm_utils::{self, stack_height};
use thiserror::Error;

use super::wasm_config::WasmConfig;
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn preprocess(

/// Returns a parity Module from the given bytes without making modifications or checking limits.
pub fn deserialize(module_bytes: &[u8]) -> Result<Module, PreprocessingError> {
parity_wasm::deserialize_buffer::<Module>(module_bytes).map_err(Into::into)
casper_wasm::deserialize_buffer::<Module>(module_bytes).map_err(Into::into)
}

/// Creates new wasm module from entry points.
Expand All @@ -431,15 +431,15 @@ pub fn get_module_from_entry_points(
Some(missing_name) => Err(execution::Error::FunctionNotFound(missing_name)),
None => {
casper_wasm_utils::optimize(&mut module, entry_point_names)?;
parity_wasm::serialize(module).map_err(execution::Error::ParityWasm)
casper_wasm::serialize(module).map_err(execution::Error::ParityWasm)
}
}
}

#[cfg(test)]
mod tests {
use casper_types::contracts::DEFAULT_ENTRY_POINT_NAME;
use parity_wasm::{
use casper_wasm::{
builder,
elements::{CodeSection, Instructions},
};
Expand Down Expand Up @@ -484,7 +484,7 @@ mod tests {
.memory()
.build()
.build();
let module_bytes = parity_wasm::serialize(module).expect("should serialize");
let module_bytes = casper_wasm::serialize(module).expect("should serialize");
let error = preprocess(WasmConfig::default(), &module_bytes)
.expect_err("should fail with an error");
assert!(
Expand Down Expand Up @@ -523,7 +523,7 @@ mod tests {
.memory()
.build()
.build();
let module_bytes = parity_wasm::serialize(module).expect("should serialize");
let module_bytes = casper_wasm::serialize(module).expect("should serialize");
let error = preprocess(WasmConfig::default(), &module_bytes)
.expect_err("should fail with an error");
assert!(
Expand Down Expand Up @@ -559,7 +559,7 @@ mod tests {
.memory()
.build()
.build();
let module_bytes = parity_wasm::serialize(module).expect("should serialize");
let module_bytes = casper_wasm::serialize(module).expect("should serialize");
let error = preprocess(WasmConfig::default(), &module_bytes)
.expect_err("should fail with an error");
assert!(
Expand All @@ -580,7 +580,7 @@ mod tests {
.memory()
.build()
.build();
let module_bytes = parity_wasm::serialize(module).expect("should serialize");
let module_bytes = casper_wasm::serialize(module).expect("should serialize");

let error = preprocess(WasmConfig::default(), &module_bytes)
.expect_err("should fail with an error");
Expand All @@ -603,7 +603,7 @@ mod tests {
.memory()
.build()
.build();
let module_bytes = parity_wasm::serialize(module).expect("should serialize");
let module_bytes = casper_wasm::serialize(module).expect("should serialize");
let error = preprocess(WasmConfig::default(), &module_bytes)
.expect_err("should fail with an error");
assert!(
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/storage/error/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Error {
CommitError(#[from] CommitError),
}

impl wasmi::HostError for Error {}
impl casper_wasmi::HostError for Error {}

impl From<bytesrepr::Error> for Error {
fn from(error: bytesrepr::Error) -> Self {
Expand Down
8 changes: 8 additions & 0 deletions execution_engine_testing/test_support/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ All notable changes to this project will be documented in this file. The format



## 6.0.0

### Changed
* Update `casper-execution-engine` dependency.
* Handle evict items in the `WasmTestBuilder` when advancing eras or calling `step`.



## 5.0.0

### Added
Expand Down
8 changes: 4 additions & 4 deletions execution_engine_testing/test_support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casper-engine-test-support"
version = "5.0.0" # when updating, also update 'html_root_url' in lib.rs
version = "6.0.0" # when updating, also update 'html_root_url' in lib.rs
authors = ["Fraser Hutchison <fraser@casperlabs.io>"]
edition = "2018"
description = "Library to support testing of Wasm smart contracts for use on the Casper network."
Expand All @@ -11,9 +11,9 @@ repository = "https://github.com/CasperLabs/casper-node/tree/master/execution_en
license = "Apache-2.0"

[dependencies]
casper-execution-engine = { version = "5.0.0", path = "../../execution_engine", features = ["test-support"] }
casper-execution-engine = { version = "6.0.0", path = "../../execution_engine", features = ["test-support"] }
casper-hashing = { version = "2.0.0", path = "../../hashing" }
casper-types = { version = "4.0.0", path = "../../types" }
casper-types = { version = "3.0.0", path = "../../types" }
humantime = "2"
filesize = "0.2.0"
lmdb-rkv = "0.14"
Expand All @@ -27,7 +27,7 @@ toml = "0.5.6"
tempfile = "3.4.0"

[dev-dependencies]
casper-types = { version = "4.0.0", path = "../../types", features = ["std"] }
casper-types = { version = "3.0.0", path = "../../types", features = ["std"] }
version-sync = "0.9.3"

[features]
Expand Down
2 changes: 1 addition & 1 deletion execution_engine_testing/test_support/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A library to support testing of Wasm smart contracts for use on the Casper Platform.

#![doc(html_root_url = "https://docs.rs/casper-engine-test-support/5.0.0")]
#![doc(html_root_url = "https://docs.rs/casper-engine-test-support/6.0.0")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Favicon_RGB_50px.png",
html_logo_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png",
Expand Down
2 changes: 1 addition & 1 deletion execution_engine_testing/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ casper-engine-test-support = { path = "../test_support", features = ["test-suppo
casper-execution-engine = { path = "../../execution_engine", features = ["test-support"] }
casper-hashing = { path = "../../hashing" }
casper-types = { path = "../../types", features = ["datasize", "json-schema"] }
casper-wasm = "0.46.0"
clap = "2"
fs_extra = "1.2.0"
log = "0.4.8"
parity-wasm = "0.45.0"
rand = "0.8.3"
serde = "1"
serde_json = "1"
Expand Down
4 changes: 2 additions & 2 deletions execution_engine_testing/tests/src/test/gas_counter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use assert_matches::assert_matches;
use parity_wasm::{
use casper_wasm::{
builder,
elements::{BlockType, Instruction, Instructions},
};
Expand Down Expand Up @@ -33,7 +33,7 @@ fn make_session_code_with(instructions: Vec<Instruction>) -> Vec<u8> {
.memory()
.build()
.build();
parity_wasm::serialize(module).expect("should serialize")
casper_wasm::serialize(module).expect("should serialize")
}

#[ignore]
Expand Down
Loading

0 comments on commit 53dd338

Please sign in to comment.