Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P22 with wasmi reverted to 031 #1460

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
83 changes: 8 additions & 75 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = ["soroban-test-wasms/wasm-workspace"]
# code guarded by `unstable-*` features to make it enabled
# unconditionally.
version = "22.0.0"
rust-version = "1.79.0"
rust-version = "1.81.0"

[workspace.dependencies]
soroban-env-common = { version = "=22.0.0", path = "soroban-env-common", default-features = false }
Expand All @@ -41,10 +41,9 @@ default-features = false

[workspace.dependencies.wasmi]
package = "soroban-wasmi"
version = "=0.36.0-soroban.22.0.0"
version = "=0.31.1-soroban.20.0.1"
git = "https://github.com/stellar/wasmi"
rev = "122a74a7c491929e5ac9de876099154ef7c06d06"
features = ["no-hash-maps"]
rev = "0ed3f3dee30dc41ebe21972399e0a73a41944aa0"

# [patch."https://github.com/stellar/rs-stellar-xdr"]
# [patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ crate-git-revision = "0.0.6"
[dependencies]
soroban-env-macros = { workspace = true }
stellar-xdr = { workspace = true, default-features = false, features = [ "curr" ] }
wasmi = { workspace = true, optional = true, features = ["no-hash-maps"] }
wasmi = { workspace = true, optional = true }
wasmparser = { workspace = true, optional = true}
serde = { version = "1.0.192", features = ["derive"], optional = true }
static_assertions = "1.1.0"
Expand Down
27 changes: 11 additions & 16 deletions soroban-env-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@ impl From<wasmi::core::TrapCode> for Error {
#[cfg(feature = "wasmi")]
impl From<wasmi::errors::FuncError> for Error {
fn from(err: wasmi::errors::FuncError) -> Self {
(&err).into()
}
}

#[cfg(feature = "wasmi")]
impl From<&wasmi::errors::FuncError> for Error {
fn from(err: &wasmi::errors::FuncError) -> Self {
let ec = match err {
wasmi::errors::FuncError::ExportedFuncNotFound => ScErrorCode::MissingValue,
wasmi::errors::FuncError::MismatchingParameterType
Expand All @@ -227,20 +220,20 @@ impl From<wasmi::Error> for Error {
const INDEX_BOUND: Error =
Error::from_type_and_code(ScErrorType::WasmVm, ScErrorCode::IndexBounds);

match e.kind() {
wasmi::errors::ErrorKind::Memory(e) => match e {
match e {
wasmi::Error::Memory(e) => match e {
wasmi::errors::MemoryError::OutOfBoundsAllocation
| wasmi::errors::MemoryError::OutOfBoundsGrowth => return EXCEEDED_LIMIT,
wasmi::errors::MemoryError::OutOfBoundsAccess => return INDEX_BOUND,
_ => (),
},
wasmi::errors::ErrorKind::Table(e) => match e {
wasmi::Error::Table(e) => match e {
wasmi::errors::TableError::GrowOutOfBounds { .. } => return EXCEEDED_LIMIT,
wasmi::errors::TableError::AccessOutOfBounds { .. }
| wasmi::errors::TableError::CopyOutOfBounds => return INDEX_BOUND,
_ => (),
},
wasmi::errors::ErrorKind::Instantiation(e) => match e {
wasmi::Error::Instantiation(e) => match e {
wasmi::errors::InstantiationError::Memory(me) => match me {
wasmi::errors::MemoryError::OutOfBoundsAllocation
| wasmi::errors::MemoryError::OutOfBoundsGrowth => return EXCEEDED_LIMIT,
Expand All @@ -255,18 +248,20 @@ impl From<wasmi::Error> for Error {
},
_ => (),
},
wasmi::errors::ErrorKind::Fuel(e) => {
wasmi::Error::Store(e) => {
if let wasmi::errors::FuelError::OutOfFuel = e {
return EXCEEDED_LIMIT;
}
}
wasmi::errors::ErrorKind::TrapCode(code) => {
return (*code).into();
wasmi::Error::Trap(trap) => {
if let Some(code) = trap.trap_code() {
return code.into();
}
}
wasmi::errors::ErrorKind::Func(e) => {
wasmi::Error::Func(e) => {
return e.into();
}
wasmi::errors::ErrorKind::Global(e) => {
wasmi::Error::Global(e) => {
if matches!(e, wasmi::errors::GlobalError::TypeMismatch { .. }) {
return Error::from_type_and_code(
ScErrorType::WasmVm,
Expand Down
28 changes: 14 additions & 14 deletions soroban-env-common/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ impl_tryfroms_and_tryfromvals_delegating_to_valconvert!(Error);

#[cfg(feature = "wasmi")]
pub trait WasmiMarshal: Sized {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self>;
fn marshal_from_self(self) -> wasmi::Val;
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self>;
fn marshal_from_self(self) -> wasmi::Value;
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for Val {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
let v = Val::from_payload(i as u64);
if v.is_good() {
Some(v)
Expand All @@ -423,38 +423,38 @@ impl WasmiMarshal for Val {
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self.get_payload() as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self.get_payload() as i64)
}
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for u64 {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
Some(i as u64)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self as i64)
}
}

#[cfg(feature = "wasmi")]
impl WasmiMarshal for i64 {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
Some(i)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self)
}
}

Expand Down
12 changes: 6 additions & 6 deletions soroban-env-common/src/wrapper_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ macro_rules! impl_wrapper_wasmi_conversions {
// wasmi / VM argument support
#[cfg(feature = "wasmi")]
impl $crate::WasmiMarshal for $wrapper {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let Some(val) = $crate::Val::try_marshal_from_value(v) {
if <Self as $crate::val::ValConvert>::is_val_type(val) {
return Some(unsafe {
Expand All @@ -95,7 +95,7 @@ macro_rules! impl_wrapper_wasmi_conversions {
None
}

fn marshal_from_self(self) -> wasmi::Val {
fn marshal_from_self(self) -> wasmi::Value {
$crate::Val::marshal_from_self(self.to_val())
}
}
Expand Down Expand Up @@ -188,17 +188,17 @@ macro_rules! declare_wasmi_marshal_for_enum {
($ENUM:ident) => {
#[cfg(feature = "wasmi")]
impl $crate::WasmiMarshal for $ENUM {
fn try_marshal_from_value(v: wasmi::Val) -> Option<Self> {
if let wasmi::Val::I64(i) = v {
fn try_marshal_from_value(v: wasmi::Value) -> Option<Self> {
if let wasmi::Value::I64(i) = v {
use num_traits::FromPrimitive;
$ENUM::from_i64(i)
} else {
None
}
}

fn marshal_from_self(self) -> wasmi::Val {
wasmi::Val::I64(self as i64)
fn marshal_from_self(self) -> wasmi::Value {
wasmi::Value::I64(self as i64)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
version.workspace = true
readme = "../README.md"
edition = "2021"
rust-version = "1.79.0"
rust-version = "1.81.0"
build = "build.rs"

exclude = ["observations/"]
Expand Down
Loading