Skip to content
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
62 changes: 31 additions & 31 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,10 @@ polkadot-subsystem-bench = { path = "polkadot/node/subsystem-bench" }
polkadot-test-client = { path = "polkadot/node/test/client" }
polkadot-test-runtime = { path = "polkadot/runtime/test-runtime" }
polkadot-test-service = { path = "polkadot/node/test/service" }
polkavm = { version = "0.31.0", default-features = false }
polkavm-common = { version = "0.31.0", default-features = false }
polkavm-derive = "0.31.0"
polkavm-linker = "0.31.0"
polkavm = { version = "0.33.0", default-features = false }
polkavm-common = { version = "0.33.0", default-features = false }
polkavm-derive = "0.33.0"
polkavm-linker = "0.33.0"
portpicker = { version = "0.1.1" }
pretty_assertions = { version = "1.3.0" }
primitive-types = { version = "0.13.1", default-features = false, features = [
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_11650.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
title: Update PolkaVM to latest version (0.31 → 0.33)

doc:
- audience: [Runtime Dev, Node Dev]
description: |
Updates all PolkaVM dependencies from 0.31.0 to 0.33.0.

crates:
- name: sp-wasm-interface
bump: major
- name: sc-executor-common
bump: major
- name: sc-executor-polkavm
bump: minor
- name: sc-executor-wasmtime
bump: patch
- name: pallet-revive
bump: major
13 changes: 11 additions & 2 deletions substrate/client/executor/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub enum WasmError {
#[error("Failure to erase the wasm memory: {0}")]
ErasingFailed(String),

#[error("Wasm code failed validation.")]
InvalidModule,
#[error("Code failed validation: {0}")]
InvalidModule(String),

#[error("Wasm code could not be deserialized.")]
CantDeserializeWasm,
Expand Down Expand Up @@ -162,6 +162,15 @@ impl From<polkavm::Error> for WasmError {
}
}

impl From<polkavm::CompileError> for WasmError {
fn from(error: polkavm::CompileError) -> Self {
match error {
polkavm::CompileError::ValidationFailed(msg) => WasmError::InvalidModule(msg),
polkavm::CompileError::Error(err) => WasmError::Other(err.to_string()),
}
}
}

impl From<polkavm::Error> for Error {
fn from(error: polkavm::Error) -> Self {
Error::Other(error.to_string())
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/executor/polkavm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct Context<'r, 'a>(&'r mut polkavm::Caller<'a, ()>);

impl<'r, 'a> FunctionContext for Context<'r, 'a> {
fn read_memory_into(
&self,
&mut self,
address: Pointer<u8>,
dest: &mut [u8],
) -> sp_wasm_interface::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/executor/wasmtime/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> HostContext<'a> {

impl<'a> sp_wasm_interface::FunctionContext for HostContext<'a> {
fn read_memory_into(
&self,
&mut self,
address: Pointer<u8>,
dest: &mut [u8],
) -> sp_wasm_interface::Result<()> {
Expand Down
24 changes: 12 additions & 12 deletions substrate/frame/revive/src/vm/pvm.rs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revive does not use the pvm version from the main Cargo.toml. So those changes here should not be necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revive does not use the pvm version from the main Cargo.toml

Seems like that has changed?

polkavm = { workspace = true }
polkavm-common = { workspace = true, features = ["alloc"] }

Copy link
Copy Markdown
Contributor Author

@s0me0ne-unkn0wn s0me0ne-unkn0wn Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I even approved it 🙃 #11096

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I didn't know that. We kept it separate when pvm was still breaking semantics with new versions. I guess its fine to sync it now.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait Memory<T: Config> {
/// Returns `Err` if one of the following conditions occurs:
///
/// - requested buffer is not within the bounds of the sandbox memory.
fn read_into_buf(&self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError>;
fn read_into_buf(&mut self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError>;

/// Write the given buffer to the designated location in the sandbox memory.
///
Expand Down Expand Up @@ -86,40 +86,40 @@ pub trait Memory<T: Config> {
/// Returns `Err` if one of the following conditions occurs:
///
/// - requested buffer is not within the bounds of the sandbox memory.
fn read(&self, ptr: u32, len: u32) -> Result<Vec<u8>, DispatchError> {
fn read(&mut self, ptr: u32, len: u32) -> Result<Vec<u8>, DispatchError> {
let mut buf = vec![0u8; len as usize];
self.read_into_buf(ptr, buf.as_mut_slice())?;
Ok(buf)
}

/// Same as `read` but reads into a fixed size buffer.
fn read_array<const N: usize>(&self, ptr: u32) -> Result<[u8; N], DispatchError> {
fn read_array<const N: usize>(&mut self, ptr: u32) -> Result<[u8; N], DispatchError> {
let mut buf = [0u8; N];
self.read_into_buf(ptr, &mut buf)?;
Ok(buf)
}

/// Read a `u32` from the sandbox memory.
fn read_u32(&self, ptr: u32) -> Result<u32, DispatchError> {
fn read_u32(&mut self, ptr: u32) -> Result<u32, DispatchError> {
let buf: [u8; 4] = self.read_array(ptr)?;
Ok(u32::from_le_bytes(buf))
}

/// Read a `U256` from the sandbox memory.
fn read_u256(&self, ptr: u32) -> Result<U256, DispatchError> {
fn read_u256(&mut self, ptr: u32) -> Result<U256, DispatchError> {
let buf: [u8; 32] = self.read_array(ptr)?;
Ok(U256::from_little_endian(&buf))
}

/// Read a `H160` from the sandbox memory.
fn read_h160(&self, ptr: u32) -> Result<H160, DispatchError> {
fn read_h160(&mut self, ptr: u32) -> Result<H160, DispatchError> {
let mut buf = H160::default();
self.read_into_buf(ptr, buf.as_bytes_mut())?;
Ok(buf)
}

/// Read a `H256` from the sandbox memory.
fn read_h256(&self, ptr: u32) -> Result<H256, DispatchError> {
fn read_h256(&mut self, ptr: u32) -> Result<H256, DispatchError> {
let mut code_hash = H256::default();
self.read_into_buf(ptr, code_hash.as_bytes_mut())?;
Ok(code_hash)
Expand All @@ -146,7 +146,7 @@ pub trait PolkaVmInstance<T: Config>: Memory<T> {
// in the streaming implementation while it could fail with a segfault in the copy implementation.
#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> Memory<T> for [u8] {
fn read_into_buf(&self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError> {
fn read_into_buf(&mut self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError> {
let ptr = ptr as usize;
let bound_checked =
self.get(ptr..ptr + buf.len()).ok_or_else(|| Error::<T>::OutOfBounds)?;
Expand All @@ -170,7 +170,7 @@ impl<T: Config> Memory<T> for [u8] {
}

impl<T: Config> Memory<T> for polkavm::RawInstance {
fn read_into_buf(&self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError> {
fn read_into_buf(&mut self, ptr: u32, buf: &mut [u8]) -> Result<(), DispatchError> {
self.read_memory_into(ptr, buf)
.map(|_| ())
.map_err(|_| Error::<T>::OutOfBounds.into())
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'a, E: Ext, M: ?Sized + Memory<E::T>> Runtime<'a, E, M> {
Ok(())
}

fn decode_key(&self, memory: &M, key_ptr: u32, key_len: u32) -> Result<Key, TrapReason> {
fn decode_key(&self, memory: &mut M, key_ptr: u32, key_len: u32) -> Result<Key, TrapReason> {
let res = match key_len {
SENTINEL => {
let mut buffer = [0u8; 32];
Expand All @@ -476,7 +476,7 @@ impl<'a, E: Ext, M: ?Sized + Memory<E::T>> Runtime<'a, E, M> {

fn set_storage(
&mut self,
memory: &M,
memory: &mut M,
flags: u32,
key_ptr: u32,
key_len: u32,
Expand Down Expand Up @@ -521,7 +521,7 @@ impl<'a, E: Ext, M: ?Sized + Memory<E::T>> Runtime<'a, E, M> {

fn clear_storage(
&mut self,
memory: &M,
memory: &mut M,
flags: u32,
key_ptr: u32,
key_len: u32,
Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/wasm-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ impl PartialEq for dyn Function {
/// Context used by `Function` to interact with the allocator and the memory of the wasm instance.
pub trait FunctionContext {
/// Read memory from `address` into a vector.
fn read_memory(&self, address: Pointer<u8>, size: WordSize) -> Result<Vec<u8>> {
fn read_memory(&mut self, address: Pointer<u8>, size: WordSize) -> Result<Vec<u8>> {
let mut vec = vec![0; size as usize];
self.read_memory_into(address, &mut vec)?;
Ok(vec)
}
/// Read memory into the given `dest` buffer from `address`.
fn read_memory_into(&self, address: Pointer<u8>, dest: &mut [u8]) -> Result<()>;
fn read_memory_into(&mut self, address: Pointer<u8>, dest: &mut [u8]) -> Result<()>;
/// Write the given data at `address` into the memory.
fn write_memory(&mut self, address: Pointer<u8>, data: &[u8]) -> Result<()>;
/// Allocate a memory instance of `size` bytes.
Expand Down
Loading