From 0278b7312517fbf5f717962490b40f51fb37ac07 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 23 Dec 2024 12:24:30 +0700 Subject: [PATCH 01/15] refactor(ethexe): remove to_vec and transmute from ethexe --- ethexe/processor/src/common.rs | 16 +++++++++++++ ethexe/processor/src/host/api/lazy_pages.rs | 23 +++++++++++-------- ethexe/processor/src/host/api/mod.rs | 6 +++-- ethexe/processor/src/host/api/sandbox.rs | 7 ++++-- ethexe/processor/src/host/mod.rs | 4 ++-- ethexe/runtime/src/wasm/api/mod.rs | 2 +- ethexe/runtime/src/wasm/interface/database.rs | 2 +- ethexe/runtime/src/wasm/interface/mod.rs | 2 +- 8 files changed, 44 insertions(+), 18 deletions(-) diff --git a/ethexe/processor/src/common.rs b/ethexe/processor/src/common.rs index 8104947737b..9c94177819e 100644 --- a/ethexe/processor/src/common.rs +++ b/ethexe/processor/src/common.rs @@ -31,3 +31,19 @@ pub enum LocalOutcome { Transition(StateTransition), } + +pub fn unpack_i64(x: i64) -> (i32, i32) { + let high = (x >> 32) as i32; + let low = (x & 0xFFFFFFFF) as i32; + + (high, low) +} + +pub fn pack_i64(high: i32, low: i32) -> i64 { + // Convert high to i64 and shift left by 32 bits + let high = (high as i64) << 32; + // Convert low to i64 (no shift needed) + let low = low as i64; + + high | low +} diff --git a/ethexe/processor/src/host/api/lazy_pages.rs b/ethexe/processor/src/host/api/lazy_pages.rs index d6f8b122edd..5ae7ec3bde7 100644 --- a/ethexe/processor/src/host/api/lazy_pages.rs +++ b/ethexe/processor/src/host/api/lazy_pages.rs @@ -127,19 +127,24 @@ fn pre_process_memory_accesses( let memory = MemoryWrap(caller.data().memory()); - let reads = memory.slice_by_val(&caller, reads).to_vec(); + let reads = memory.slice_by_val(&caller, reads); - let writes = memory.slice_by_val(&caller, writes).to_vec(); + let writes = memory.slice_by_val(&caller, writes); // 8 len bytes of u64 counter. // TODO: why gas_bytes is &mut [u8; 8] and not &mut u64 (?). - let gas_bytes = memory - .slice_mut(&mut caller, gas_bytes as usize, 8) - .try_into() - .unwrap(); - - let res = lazy_pages_detail::pre_process_memory_accesses(&reads, &writes, gas_bytes) as i32; - + // read gas_bytes into `mut` variable because `pre_process_memory_accesses` updates + // it, then write updated slice to memory. Can't use `slice_mut` here without using `.to_vec()` + // on `writes` and `reads`. + let ptr = gas_bytes; + let mut gas_bytes: [u8; 8] = memory.slice(&caller, ptr as usize, 8).try_into().unwrap(); + + let res = + lazy_pages_detail::pre_process_memory_accesses(&reads, &writes, &mut gas_bytes) as i32; + + memory + .slice_mut(&mut caller, ptr as usize, 8) + .copy_from_slice(&gas_bytes); log::trace!(target: "host_call", "pre_process_memory_accesses(..) -> {res:?}"); res diff --git a/ethexe/processor/src/host/api/mod.rs b/ethexe/processor/src/host/api/mod.rs index d3b09ea6a11..9537ab9ed32 100644 --- a/ethexe/processor/src/host/api/mod.rs +++ b/ethexe/processor/src/host/api/mod.rs @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::common::{pack_i64, unpack_i64}; + use super::context::HostContext; use parity_scale_codec::{Decode, Encode}; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, StoreData}; @@ -58,7 +60,7 @@ impl MemoryWrap { store: impl Into>, ptr_len: i64, ) -> &'a [u8] { - let [ptr, len]: [i32; 2] = unsafe { mem::transmute(ptr_len) }; + let (ptr, len) = unpack_i64(ptr_len); self.slice(store, ptr as usize, len as usize) } @@ -119,7 +121,7 @@ pub fn allocate_and_write_raw( memory.write(&mut caller, ptr as usize, data).unwrap(); - let res = unsafe { mem::transmute::<[i32; 2], i64>([ptr, len as i32]) }; + let res = pack_i64(ptr, len as i32); (caller, res) } diff --git a/ethexe/processor/src/host/api/sandbox.rs b/ethexe/processor/src/host/api/sandbox.rs index fb82bfb5d60..94f9c0b6229 100644 --- a/ethexe/processor/src/host/api/sandbox.rs +++ b/ethexe/processor/src/host/api/sandbox.rs @@ -18,7 +18,10 @@ // TODO (breathx): remove cloning of slices from wasm memory. -use crate::host::{api::MemoryWrap, context::HostContext}; +use crate::{ + common::pack_i64, + host::{api::MemoryWrap, context::HostContext}, +}; use anyhow::Result; use core::mem; use gear_runtime_interface::{sandbox_detail, Instantiate}; @@ -102,7 +105,7 @@ fn get_global_val(caller: Caller<'_, StoreData>, instance_idx: i32, name: i64) - memory.write(&mut caller, ptr as usize, &res).unwrap(); - let res = unsafe { mem::transmute::<[i32; 2], i64>([ptr, res_len]) }; + let res = pack_i64(ptr, res_len); log::trace!(target: "host_call", "get_global_val(..) -> {res:?}"); diff --git a/ethexe/processor/src/host/mod.rs b/ethexe/processor/src/host/mod.rs index 7e2411508d5..0fc786ade9a 100644 --- a/ethexe/processor/src/host/mod.rs +++ b/ethexe/processor/src/host/mod.rs @@ -25,7 +25,7 @@ use sp_allocator::{AllocationStats, FreeingBumpHeapAllocator}; use sp_wasm_interface::{HostState, IntoValue, MemoryWrapper, StoreData}; use std::{mem, sync::Arc}; -use crate::Database; +use crate::{common::unpack_i64, Database}; pub mod api; pub mod runtime; @@ -200,7 +200,7 @@ impl InstanceWrapper { } fn get_call_output(&mut self, ptr_len: i64) -> Result { - let [ptr, len]: [i32; 2] = unsafe { mem::transmute(ptr_len) }; + let (ptr, len) = unpack_i64(ptr_len); // TODO: check range. let memory = self.memory()?; diff --git a/ethexe/runtime/src/wasm/api/mod.rs b/ethexe/runtime/src/wasm/api/mod.rs index decffaaff5f..f19f99647b0 100644 --- a/ethexe/runtime/src/wasm/api/mod.rs +++ b/ethexe/runtime/src/wasm/api/mod.rs @@ -74,5 +74,5 @@ fn return_val(val: impl Encode) -> i64 { let len = encoded.len() as i32; let ptr = Box::leak(Box::new(encoded)).as_ptr() as i32; - unsafe { core::mem::transmute([ptr, len]) } + (ptr as i64) << 32 | len as i64 } diff --git a/ethexe/runtime/src/wasm/interface/database.rs b/ethexe/runtime/src/wasm/interface/database.rs index a506fcd8d4a..93da0b8132b 100644 --- a/ethexe/runtime/src/wasm/interface/database.rs +++ b/ethexe/runtime/src/wasm/interface/database.rs @@ -43,7 +43,7 @@ pub fn read_raw(hash: &H256) -> Option<&[u8]> { let ptr_len = sys::ext_database_read_by_hash_version_1(hash.as_ptr() as _); (ptr_len != 0).then(|| { - let [ptr, len]: [i32; 2] = mem::transmute(ptr_len); + let (ptr, len) = ((ptr_len >> 32) as i32, (ptr_len & 0xFFFFFFFF) as i32); slice::from_raw_parts(ptr as _, len as usize) }) } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index 5c9d7ce426a..ec9593079a5 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -32,7 +32,7 @@ pub(crate) mod utils { let ptr = slice.as_ptr() as i32; let len = slice.len() as i32; - unsafe { core::mem::transmute([ptr, len]) } + (ptr as i64) << 32 | len as i64 } } From 09e923d20953eb4ce72a66d345b053ac122cab91 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 23 Dec 2024 12:34:59 +0700 Subject: [PATCH 02/15] remove unused import --- ethexe/runtime/src/wasm/interface/database.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethexe/runtime/src/wasm/interface/database.rs b/ethexe/runtime/src/wasm/interface/database.rs index 93da0b8132b..fb862fd2de6 100644 --- a/ethexe/runtime/src/wasm/interface/database.rs +++ b/ethexe/runtime/src/wasm/interface/database.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::wasm::interface; -use core::{mem, slice}; +use core::slice; use gprimitives::H256; use parity_scale_codec::{Decode, Encode, Error as CodecError}; From 6868cd14014a9a4bc333d8340a4940255df7f03a Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 23 Dec 2024 13:08:34 +0700 Subject: [PATCH 03/15] clippy --- ethexe/processor/src/host/api/lazy_pages.rs | 2 +- ethexe/processor/src/host/api/mod.rs | 1 - ethexe/processor/src/host/api/sandbox.rs | 1 - ethexe/processor/src/host/mod.rs | 5 ++--- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ethexe/processor/src/host/api/lazy_pages.rs b/ethexe/processor/src/host/api/lazy_pages.rs index 5ae7ec3bde7..db514baf3d0 100644 --- a/ethexe/processor/src/host/api/lazy_pages.rs +++ b/ethexe/processor/src/host/api/lazy_pages.rs @@ -140,7 +140,7 @@ fn pre_process_memory_accesses( let mut gas_bytes: [u8; 8] = memory.slice(&caller, ptr as usize, 8).try_into().unwrap(); let res = - lazy_pages_detail::pre_process_memory_accesses(&reads, &writes, &mut gas_bytes) as i32; + lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_bytes) as i32; memory .slice_mut(&mut caller, ptr as usize, 8) diff --git a/ethexe/processor/src/host/api/mod.rs b/ethexe/processor/src/host/api/mod.rs index 9537ab9ed32..aa0d730046b 100644 --- a/ethexe/processor/src/host/api/mod.rs +++ b/ethexe/processor/src/host/api/mod.rs @@ -21,7 +21,6 @@ use crate::common::{pack_i64, unpack_i64}; use super::context::HostContext; use parity_scale_codec::{Decode, Encode}; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, StoreData}; -use std::mem; use wasmtime::{Caller, Memory, StoreContext, StoreContextMut}; pub mod allocator; diff --git a/ethexe/processor/src/host/api/sandbox.rs b/ethexe/processor/src/host/api/sandbox.rs index 94f9c0b6229..6db4fad6060 100644 --- a/ethexe/processor/src/host/api/sandbox.rs +++ b/ethexe/processor/src/host/api/sandbox.rs @@ -23,7 +23,6 @@ use crate::{ host::{api::MemoryWrap, context::HostContext}, }; use anyhow::Result; -use core::mem; use gear_runtime_interface::{sandbox_detail, Instantiate}; use parity_scale_codec::Encode; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, Pointer, StoreData}; diff --git a/ethexe/processor/src/host/mod.rs b/ethexe/processor/src/host/mod.rs index 0fc786ade9a..ede0a90a3bb 100644 --- a/ethexe/processor/src/host/mod.rs +++ b/ethexe/processor/src/host/mod.rs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::{common::unpack_i64, Database}; use anyhow::{anyhow, Result}; use core_processor::common::JournalNote; use gear_core::{code::InstrumentedCode, ids::ProgramId}; @@ -23,9 +24,7 @@ use gprimitives::{CodeId, H256}; use parity_scale_codec::{Decode, Encode}; use sp_allocator::{AllocationStats, FreeingBumpHeapAllocator}; use sp_wasm_interface::{HostState, IntoValue, MemoryWrapper, StoreData}; -use std::{mem, sync::Arc}; - -use crate::{common::unpack_i64, Database}; +use std::sync::Arc; pub mod api; pub mod runtime; From a1b54dc310d91ae246cf7d036a6704f944293f74 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 23 Dec 2024 13:14:50 +0700 Subject: [PATCH 04/15] fmt --- ethexe/processor/src/host/api/lazy_pages.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethexe/processor/src/host/api/lazy_pages.rs b/ethexe/processor/src/host/api/lazy_pages.rs index db514baf3d0..d00a4004fb6 100644 --- a/ethexe/processor/src/host/api/lazy_pages.rs +++ b/ethexe/processor/src/host/api/lazy_pages.rs @@ -139,8 +139,7 @@ fn pre_process_memory_accesses( let ptr = gas_bytes; let mut gas_bytes: [u8; 8] = memory.slice(&caller, ptr as usize, 8).try_into().unwrap(); - let res = - lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_bytes) as i32; + let res = lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_bytes) as i32; memory .slice_mut(&mut caller, ptr as usize, 8) From 80b81d72bef0a060e87136859b4f78e94f94e924 Mon Sep 17 00:00:00 2001 From: playX18 Date: Tue, 24 Dec 2024 18:22:19 +0700 Subject: [PATCH 05/15] more correct handling of packing/unpacking i64 --- ethexe/processor/src/common.rs | 15 +++++---------- ethexe/runtime/src/wasm/api/mod.rs | 2 +- ethexe/runtime/src/wasm/interface/mod.rs | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/ethexe/processor/src/common.rs b/ethexe/processor/src/common.rs index 9c94177819e..316536ee92d 100644 --- a/ethexe/processor/src/common.rs +++ b/ethexe/processor/src/common.rs @@ -32,18 +32,13 @@ pub enum LocalOutcome { Transition(StateTransition), } -pub fn unpack_i64(x: i64) -> (i32, i32) { - let high = (x >> 32) as i32; - let low = (x & 0xFFFFFFFF) as i32; - +pub fn unpack_i64(packed: i64) -> (i32, i32) { + let high = (packed >> 32) as i32; // Shift right and cast + let low = (packed & 0xFFFFFFFF) as i32; // Mask and cast (high, low) } pub fn pack_i64(high: i32, low: i32) -> i64 { - // Convert high to i64 and shift left by 32 bits - let high = (high as i64) << 32; - // Convert low to i64 (no shift needed) - let low = low as i64; - - high | low + ((high as i64) << 32) | (low as i64 & 0xFFFFFFFF) } + diff --git a/ethexe/runtime/src/wasm/api/mod.rs b/ethexe/runtime/src/wasm/api/mod.rs index f19f99647b0..a44d24d2bdf 100644 --- a/ethexe/runtime/src/wasm/api/mod.rs +++ b/ethexe/runtime/src/wasm/api/mod.rs @@ -74,5 +74,5 @@ fn return_val(val: impl Encode) -> i64 { let len = encoded.len() as i32; let ptr = Box::leak(Box::new(encoded)).as_ptr() as i32; - (ptr as i64) << 32 | len as i64 + ((ptr as i64) << 32) | (len as i64 & 0xFFFFFFFF) } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index ec9593079a5..cd3201a8295 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -32,7 +32,7 @@ pub(crate) mod utils { let ptr = slice.as_ptr() as i32; let len = slice.len() as i32; - (ptr as i64) << 32 | len as i64 + ((ptr as i64) << 32) | (len as i64 & 0xFFFFFFFF) } } From 192d892dc5fdb62d3e7b929871f1b4223c6aaa38 Mon Sep 17 00:00:00 2001 From: playX18 Date: Tue, 24 Dec 2024 18:40:01 +0700 Subject: [PATCH 06/15] pass u64 to `pre_process_memory_accesses` --- ethexe/processor/src/common.rs | 1 - ethexe/processor/src/host/api/lazy_pages.rs | 16 ++++++++++------ runtime-interface/src/lib.rs | 14 ++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ethexe/processor/src/common.rs b/ethexe/processor/src/common.rs index 316536ee92d..8c48e86c7ef 100644 --- a/ethexe/processor/src/common.rs +++ b/ethexe/processor/src/common.rs @@ -41,4 +41,3 @@ pub fn unpack_i64(packed: i64) -> (i32, i32) { pub fn pack_i64(high: i32, low: i32) -> i64 { ((high as i64) << 32) | (low as i64 & 0xFFFFFFFF) } - diff --git a/ethexe/processor/src/host/api/lazy_pages.rs b/ethexe/processor/src/host/api/lazy_pages.rs index d00a4004fb6..9a7f9cbf508 100644 --- a/ethexe/processor/src/host/api/lazy_pages.rs +++ b/ethexe/processor/src/host/api/lazy_pages.rs @@ -132,18 +132,22 @@ fn pre_process_memory_accesses( let writes = memory.slice_by_val(&caller, writes); // 8 len bytes of u64 counter. - // TODO: why gas_bytes is &mut [u8; 8] and not &mut u64 (?). // read gas_bytes into `mut` variable because `pre_process_memory_accesses` updates // it, then write updated slice to memory. Can't use `slice_mut` here without using `.to_vec()` // on `writes` and `reads`. - let ptr = gas_bytes; - let mut gas_bytes: [u8; 8] = memory.slice(&caller, ptr as usize, 8).try_into().unwrap(); + let mut gas_counter: u64 = u64::from_le_bytes( + memory + .slice(&caller, gas_bytes as usize, 8) + .try_into() + .unwrap(), + ); - let res = lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_bytes) as i32; + let res = + lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_counter) as i32; memory - .slice_mut(&mut caller, ptr as usize, 8) - .copy_from_slice(&gas_bytes); + .slice_mut(&mut caller, gas_bytes as usize, 8) + .copy_from_slice(&gas_counter.to_le_bytes()); log::trace!(target: "host_call", "pre_process_memory_accesses(..) -> {res:?}"); res diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index 4eb02cc090c..683f9709810 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -23,7 +23,6 @@ extern crate alloc; -use byteorder::{ByteOrder, LittleEndian}; use codec::{Decode, Encode}; use gear_core::{ gas::GasLeft, @@ -153,7 +152,10 @@ pub enum ProcessAccessErrorVer1 { pub trait GearRI { #[version(2)] fn pre_process_memory_accesses(reads: &[u8], writes: &[u8], gas_bytes: &mut [u8; 8]) -> u8 { - lazy_pages_detail::pre_process_memory_accesses(reads, writes, gas_bytes) + let mut gas_counter = u64::from_le_bytes(*gas_bytes); + let res = lazy_pages_detail::pre_process_memory_accesses(reads, writes, &mut gas_counter); + gas_bytes.copy_from_slice(&gas_counter.to_le_bytes()); + res } fn lazy_pages_status() -> (Status,) { @@ -224,7 +226,7 @@ pub trait GearRI { pub mod lazy_pages_detail { use super::*; - pub fn pre_process_memory_accesses(reads: &[u8], writes: &[u8], gas_bytes: &mut [u8; 8]) -> u8 { + pub fn pre_process_memory_accesses(reads: &[u8], writes: &[u8], gas_counter: &mut u64) -> u8 { let mem_interval_size = size_of::(); let reads_len = reads.len(); let writes_len = writes.len(); @@ -234,19 +236,15 @@ pub mod lazy_pages_detail { let mut writes_intervals = Vec::with_capacity(writes_len / mem_interval_size); deserialize_mem_intervals(writes, &mut writes_intervals); - let mut gas_counter = LittleEndian::read_u64(gas_bytes); - let res = match gear_lazy_pages::pre_process_memory_accesses( &reads_intervals, &writes_intervals, - &mut gas_counter, + gas_counter, ) { Ok(_) => 0, Err(err) => err.into(), }; - LittleEndian::write_u64(gas_bytes, gas_counter); - res } From 15b54dc6b87cb147ae6f05db316c1ce72ed31f9b Mon Sep 17 00:00:00 2001 From: playX18 Date: Tue, 24 Dec 2024 18:58:55 +0700 Subject: [PATCH 07/15] clippy fix --- runtime-interface/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index 683f9709810..b9af8f0013f 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -236,16 +236,14 @@ pub mod lazy_pages_detail { let mut writes_intervals = Vec::with_capacity(writes_len / mem_interval_size); deserialize_mem_intervals(writes, &mut writes_intervals); - let res = match gear_lazy_pages::pre_process_memory_accesses( + match gear_lazy_pages::pre_process_memory_accesses( &reads_intervals, &writes_intervals, gas_counter, ) { Ok(_) => 0, Err(err) => err.into(), - }; - - res + } } pub fn lazy_pages_status() -> (Status,) { From d269bdd76f991fdf46cf9197f5f587cc30e891e2 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 13 Jan 2025 12:52:05 +0700 Subject: [PATCH 08/15] attempt to fix bit ops --- ethexe/common/src/lib.rs | 14 ++++++++++++++ ethexe/processor/src/common.rs | 10 ---------- ethexe/processor/src/host/api/mod.rs | 7 +++---- ethexe/processor/src/host/api/sandbox.rs | 10 ++++------ ethexe/processor/src/host/mod.rs | 5 +++-- ethexe/runtime/src/wasm/api/mod.rs | 5 ++++- ethexe/runtime/src/wasm/interface/mod.rs | 10 ++++++---- sandbox/sandbox/src/host_executor.rs | 6 ++++-- 8 files changed, 38 insertions(+), 29 deletions(-) diff --git a/ethexe/common/src/lib.rs b/ethexe/common/src/lib.rs index c70780b10cf..dd9a4101d1c 100644 --- a/ethexe/common/src/lib.rs +++ b/ethexe/common/src/lib.rs @@ -34,3 +34,17 @@ pub const fn u64_into_uint48_be_bytes_lossy(val: u64) -> [u8; 6] { [b1, b2, b3, b4, b5, b6] } + +pub const fn pack_u32_to_i64(low: u32, high: u32) -> i64 { + let mut result = 0u64; + result |= (high as u64) << 32; + result |= low as u64; + result as i64 +} + +pub const fn unpack_i64_to_u32(val: i64) -> (u32, u32) { + let val = val as u64; + let high = (val >> 32) as u32; + let low = val as u32; + (low, high) +} diff --git a/ethexe/processor/src/common.rs b/ethexe/processor/src/common.rs index 8c48e86c7ef..8104947737b 100644 --- a/ethexe/processor/src/common.rs +++ b/ethexe/processor/src/common.rs @@ -31,13 +31,3 @@ pub enum LocalOutcome { Transition(StateTransition), } - -pub fn unpack_i64(packed: i64) -> (i32, i32) { - let high = (packed >> 32) as i32; // Shift right and cast - let low = (packed & 0xFFFFFFFF) as i32; // Mask and cast - (high, low) -} - -pub fn pack_i64(high: i32, low: i32) -> i64 { - ((high as i64) << 32) | (low as i64 & 0xFFFFFFFF) -} diff --git a/ethexe/processor/src/host/api/mod.rs b/ethexe/processor/src/host/api/mod.rs index aa0d730046b..27bcaf6f547 100644 --- a/ethexe/processor/src/host/api/mod.rs +++ b/ethexe/processor/src/host/api/mod.rs @@ -16,9 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::common::{pack_i64, unpack_i64}; - use super::context::HostContext; +use ethexe_common::{pack_u32_to_i64, unpack_i64_to_u32}; use parity_scale_codec::{Decode, Encode}; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, StoreData}; use wasmtime::{Caller, Memory, StoreContext, StoreContextMut}; @@ -59,7 +58,7 @@ impl MemoryWrap { store: impl Into>, ptr_len: i64, ) -> &'a [u8] { - let (ptr, len) = unpack_i64(ptr_len); + let (ptr, len) = unpack_i64_to_u32(ptr_len); self.slice(store, ptr as usize, len as usize) } @@ -120,7 +119,7 @@ pub fn allocate_and_write_raw( memory.write(&mut caller, ptr as usize, data).unwrap(); - let res = pack_i64(ptr, len as i32); + let res = pack_u32_to_i64(ptr as u32, len as u32); (caller, res) } diff --git a/ethexe/processor/src/host/api/sandbox.rs b/ethexe/processor/src/host/api/sandbox.rs index 6db4fad6060..edfaf8ae11a 100644 --- a/ethexe/processor/src/host/api/sandbox.rs +++ b/ethexe/processor/src/host/api/sandbox.rs @@ -18,11 +18,9 @@ // TODO (breathx): remove cloning of slices from wasm memory. -use crate::{ - common::pack_i64, - host::{api::MemoryWrap, context::HostContext}, -}; +use crate::host::{api::MemoryWrap, context::HostContext}; use anyhow::Result; +use ethexe_common::pack_u32_to_i64; use gear_runtime_interface::{sandbox_detail, Instantiate}; use parity_scale_codec::Encode; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, Pointer, StoreData}; @@ -89,7 +87,7 @@ fn get_global_val(caller: Caller<'_, StoreData>, instance_idx: i32, name: i64) - let res = sandbox_detail::get_global_val(&mut host_context, instance_idx as u32, name); let res = res.encode(); - let res_len = res.len() as i32; + let res_len = res.len() as u32; let ptr = host_context .allocate_memory(res_len as u32) @@ -104,7 +102,7 @@ fn get_global_val(caller: Caller<'_, StoreData>, instance_idx: i32, name: i64) - memory.write(&mut caller, ptr as usize, &res).unwrap(); - let res = pack_i64(ptr, res_len); + let res = pack_u32_to_i64(ptr as u32, res_len); log::trace!(target: "host_call", "get_global_val(..) -> {res:?}"); diff --git a/ethexe/processor/src/host/mod.rs b/ethexe/processor/src/host/mod.rs index ede0a90a3bb..7a60469d6f3 100644 --- a/ethexe/processor/src/host/mod.rs +++ b/ethexe/processor/src/host/mod.rs @@ -16,9 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{common::unpack_i64, Database}; +use crate::Database; use anyhow::{anyhow, Result}; use core_processor::common::JournalNote; +use ethexe_common::unpack_i64_to_u32; use gear_core::{code::InstrumentedCode, ids::ProgramId}; use gprimitives::{CodeId, H256}; use parity_scale_codec::{Decode, Encode}; @@ -199,7 +200,7 @@ impl InstanceWrapper { } fn get_call_output(&mut self, ptr_len: i64) -> Result { - let (ptr, len) = unpack_i64(ptr_len); + let (ptr, len) = unpack_i64_to_u32(ptr_len); // TODO: check range. let memory = self.memory()?; diff --git a/ethexe/runtime/src/wasm/api/mod.rs b/ethexe/runtime/src/wasm/api/mod.rs index a44d24d2bdf..86b8c5e4015 100644 --- a/ethexe/runtime/src/wasm/api/mod.rs +++ b/ethexe/runtime/src/wasm/api/mod.rs @@ -74,5 +74,8 @@ fn return_val(val: impl Encode) -> i64 { let len = encoded.len() as i32; let ptr = Box::leak(Box::new(encoded)).as_ptr() as i32; - ((ptr as i64) << 32) | (len as i64 & 0xFFFFFFFF) + let mut result = 0u64; + result |= (ptr as u32 as u64) << 32; + result |= len as u64; + result as i64 } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index cd3201a8295..ae3098d3bca 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -29,10 +29,12 @@ pub(crate) mod utils { pub fn repr_ri_slice(slice: impl AsRef<[u8]>) -> i64 { let slice = slice.as_ref(); - let ptr = slice.as_ptr() as i32; - let len = slice.len() as i32; - - ((ptr as i64) << 32) | (len as i64 & 0xFFFFFFFF) + let ptr = slice.as_ptr() as u32; + let len = slice.len() as u32; + let mut result = 0u64; + result |= (ptr as u64) << 32; + result |= len as u64; + result as i64 } } diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index a05be46ca7a..19ef36c1f5d 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -306,8 +306,10 @@ extern "C" fn dispatch_thunk( let result_ptr = result.as_ptr() as u64; let result_len = result.len() as u64; mem::forget(result); - - (result_ptr << 32) | result_len + let mut result = 0u64; + result |= result_ptr << 32; + result |= result_len; + result } } From 713b613256ad0a0721176412c000b14abf570ac3 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 13 Jan 2025 13:25:17 +0700 Subject: [PATCH 09/15] fix #2: ptr is low bits, len is high bits --- ethexe/runtime/src/wasm/api/mod.rs | 4 ++-- ethexe/runtime/src/wasm/interface/database.rs | 2 +- ethexe/runtime/src/wasm/interface/mod.rs | 4 ++-- sandbox/host/src/sandbox/wasmer_backend.rs | 4 ++-- sandbox/host/src/sandbox/wasmi_backend.rs | 4 ++-- sandbox/sandbox/src/host_executor.rs | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ethexe/runtime/src/wasm/api/mod.rs b/ethexe/runtime/src/wasm/api/mod.rs index 86b8c5e4015..7910bef451b 100644 --- a/ethexe/runtime/src/wasm/api/mod.rs +++ b/ethexe/runtime/src/wasm/api/mod.rs @@ -75,7 +75,7 @@ fn return_val(val: impl Encode) -> i64 { let ptr = Box::leak(Box::new(encoded)).as_ptr() as i32; let mut result = 0u64; - result |= (ptr as u32 as u64) << 32; - result |= len as u64; + result |= (len as u32 as u64) << 32; + result |= ptr as u64; result as i64 } diff --git a/ethexe/runtime/src/wasm/interface/database.rs b/ethexe/runtime/src/wasm/interface/database.rs index fb862fd2de6..e057108b4a2 100644 --- a/ethexe/runtime/src/wasm/interface/database.rs +++ b/ethexe/runtime/src/wasm/interface/database.rs @@ -43,7 +43,7 @@ pub fn read_raw(hash: &H256) -> Option<&[u8]> { let ptr_len = sys::ext_database_read_by_hash_version_1(hash.as_ptr() as _); (ptr_len != 0).then(|| { - let (ptr, len) = ((ptr_len >> 32) as i32, (ptr_len & 0xFFFFFFFF) as i32); + let (len, ptr) = ((ptr_len >> 32) as i32, (ptr_len & 0xFFFFFFFF) as i32); slice::from_raw_parts(ptr as _, len as usize) }) } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index ae3098d3bca..b06c63d0b86 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -32,8 +32,8 @@ pub(crate) mod utils { let ptr = slice.as_ptr() as u32; let len = slice.len() as u32; let mut result = 0u64; - result |= (ptr as u64) << 32; - result |= len as u64; + result |= (len as u64) << 32; + result |= ptr as u64; result as i64 } } diff --git a/sandbox/host/src/sandbox/wasmer_backend.rs b/sandbox/host/src/sandbox/wasmer_backend.rs index 98a662af860..b5fbc70587d 100644 --- a/sandbox/host/src/sandbox/wasmer_backend.rs +++ b/sandbox/host/src/sandbox/wasmer_backend.rs @@ -345,8 +345,8 @@ fn dispatch_common( let (serialized_result_val_ptr, serialized_result_val_len) = { // Cast to u64 to use zero-extension. let v = serialized_result as u64; - let ptr = (v >> 32) as u32; - let len = (v & 0xFFFFFFFF) as u32; + let len = (v >> 32) as u32; + let ptr = (v & 0xFFFFFFFF) as u32; (Pointer::new(ptr), len) }; diff --git a/sandbox/host/src/sandbox/wasmi_backend.rs b/sandbox/host/src/sandbox/wasmi_backend.rs index b0c1d142756..233ef903968 100644 --- a/sandbox/host/src/sandbox/wasmi_backend.rs +++ b/sandbox/host/src/sandbox/wasmi_backend.rs @@ -511,8 +511,8 @@ fn dispatch_common( let (serialized_result_val_ptr, serialized_result_val_len) = { // Cast to u64 to use zero-extension. let v = serialized_result as u64; - let ptr = (v >> 32) as u32; - let len = (v & 0xFFFFFFFF) as u32; + let len = (v >> 32) as u32; + let ptr = (v & 0xFFFFFFFF) as u32; (Pointer::new(ptr), len) }; diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index 19ef36c1f5d..a0777ecbcb7 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -307,8 +307,8 @@ extern "C" fn dispatch_thunk( let result_len = result.len() as u64; mem::forget(result); let mut result = 0u64; - result |= result_ptr << 32; - result |= result_len; + result |= result_len << 32; + result |= result_ptr; result } } From 0f5621dfd060a3bfcbfe4ce61772f5f4992cb813 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 13 Jan 2025 15:11:42 +0700 Subject: [PATCH 10/15] move unpack and pack functions to ethexe/runtime/common --- ethexe/common/src/lib.rs | 14 -------------- ethexe/processor/src/host/api/mod.rs | 2 +- ethexe/processor/src/host/api/sandbox.rs | 2 +- ethexe/processor/src/host/mod.rs | 2 +- ethexe/runtime/common/src/lib.rs | 14 ++++++++++++++ ethexe/runtime/src/wasm/api/mod.rs | 6 ++---- ethexe/runtime/src/wasm/interface/mod.rs | 6 ++---- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/ethexe/common/src/lib.rs b/ethexe/common/src/lib.rs index dd9a4101d1c..c70780b10cf 100644 --- a/ethexe/common/src/lib.rs +++ b/ethexe/common/src/lib.rs @@ -34,17 +34,3 @@ pub const fn u64_into_uint48_be_bytes_lossy(val: u64) -> [u8; 6] { [b1, b2, b3, b4, b5, b6] } - -pub const fn pack_u32_to_i64(low: u32, high: u32) -> i64 { - let mut result = 0u64; - result |= (high as u64) << 32; - result |= low as u64; - result as i64 -} - -pub const fn unpack_i64_to_u32(val: i64) -> (u32, u32) { - let val = val as u64; - let high = (val >> 32) as u32; - let low = val as u32; - (low, high) -} diff --git a/ethexe/processor/src/host/api/mod.rs b/ethexe/processor/src/host/api/mod.rs index 27bcaf6f547..e1e77a20e40 100644 --- a/ethexe/processor/src/host/api/mod.rs +++ b/ethexe/processor/src/host/api/mod.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use super::context::HostContext; -use ethexe_common::{pack_u32_to_i64, unpack_i64_to_u32}; +use ethexe_runtime_common::{pack_u32_to_i64, unpack_i64_to_u32}; use parity_scale_codec::{Decode, Encode}; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, StoreData}; use wasmtime::{Caller, Memory, StoreContext, StoreContextMut}; diff --git a/ethexe/processor/src/host/api/sandbox.rs b/ethexe/processor/src/host/api/sandbox.rs index edfaf8ae11a..607156f3d6b 100644 --- a/ethexe/processor/src/host/api/sandbox.rs +++ b/ethexe/processor/src/host/api/sandbox.rs @@ -20,7 +20,7 @@ use crate::host::{api::MemoryWrap, context::HostContext}; use anyhow::Result; -use ethexe_common::pack_u32_to_i64; +use ethexe_runtime_common::pack_u32_to_i64; use gear_runtime_interface::{sandbox_detail, Instantiate}; use parity_scale_codec::Encode; use sp_wasm_interface::{FunctionContext as _, IntoValue as _, Pointer, StoreData}; diff --git a/ethexe/processor/src/host/mod.rs b/ethexe/processor/src/host/mod.rs index 7a60469d6f3..4c130e7ab1a 100644 --- a/ethexe/processor/src/host/mod.rs +++ b/ethexe/processor/src/host/mod.rs @@ -19,7 +19,7 @@ use crate::Database; use anyhow::{anyhow, Result}; use core_processor::common::JournalNote; -use ethexe_common::unpack_i64_to_u32; +use ethexe_runtime_common::unpack_i64_to_u32; use gear_core::{code::InstrumentedCode, ids::ProgramId}; use gprimitives::{CodeId, H256}; use parity_scale_codec::{Decode, Encode}; diff --git a/ethexe/runtime/common/src/lib.rs b/ethexe/runtime/common/src/lib.rs index 1fb2f1f483e..661015edc3a 100644 --- a/ethexe/runtime/common/src/lib.rs +++ b/ethexe/runtime/common/src/lib.rs @@ -270,3 +270,17 @@ where core_processor::process::>(&block_config, execution_context, random_data) .unwrap_or_else(|err| unreachable!("{err}")) } + +pub const fn pack_u32_to_i64(low: u32, high: u32) -> i64 { + let mut result = 0u64; + result |= (high as u64) << 32; + result |= low as u64; + result as i64 +} + +pub const fn unpack_i64_to_u32(val: i64) -> (u32, u32) { + let val = val as u64; + let high = (val >> 32) as u32; + let low = val as u32; + (low, high) +} diff --git a/ethexe/runtime/src/wasm/api/mod.rs b/ethexe/runtime/src/wasm/api/mod.rs index 1a410265551..d2358ffff3d 100644 --- a/ethexe/runtime/src/wasm/api/mod.rs +++ b/ethexe/runtime/src/wasm/api/mod.rs @@ -17,6 +17,7 @@ // along with this program. If not, see . use alloc::{boxed::Box, vec::Vec}; +use ethexe_runtime_common::pack_u32_to_i64; use parity_scale_codec::{Decode, Encode}; mod instrument; @@ -74,8 +75,5 @@ fn return_val(val: impl Encode) -> i64 { let len = encoded.len() as i32; let ptr = Box::leak(Box::new(encoded)).as_ptr() as i32; - let mut result = 0u64; - result |= (len as u32 as u64) << 32; - result |= ptr as u64; - result as i64 + pack_u32_to_i64(ptr as u32, len as u32) } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index 1aaaa80ffae..9866ec7e6d1 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -26,15 +26,13 @@ pub(crate) mod database_ri; pub(crate) mod logging_ri; pub(crate) mod utils { + use ethexe_runtime_common::pack_u32_to_i64; pub fn repr_ri_slice(slice: impl AsRef<[u8]>) -> i64 { let slice = slice.as_ref(); let ptr = slice.as_ptr() as u32; let len = slice.len() as u32; - let mut result = 0u64; - result |= (len as u64) << 32; - result |= ptr as u64; - result as i64 + pack_u32_to_i64(ptr, len) } } From 3f299cd30d098ecc2b1fefb65667362031dd5592 Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 13 Jan 2025 18:01:38 +0700 Subject: [PATCH 11/15] use old way of constructing result in host_executor --- sandbox/sandbox/src/host_executor.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index a0777ecbcb7..9302c7a87f5 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -306,10 +306,8 @@ extern "C" fn dispatch_thunk( let result_ptr = result.as_ptr() as u64; let result_len = result.len() as u64; mem::forget(result); - let mut result = 0u64; - result |= result_len << 32; - result |= result_ptr; - result + + (result_len << 32) | result_ptr } } From 50e9e9b899f155e8d63a309132bfbca31eeaa31b Mon Sep 17 00:00:00 2001 From: playX18 Date: Mon, 13 Jan 2025 18:02:00 +0700 Subject: [PATCH 12/15] use unpack_i64_to_u32 in read_raw; fmt --- ethexe/runtime/src/wasm/interface/database.rs | 3 ++- ethexe/runtime/src/wasm/interface/mod.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ethexe/runtime/src/wasm/interface/database.rs b/ethexe/runtime/src/wasm/interface/database.rs index e057108b4a2..1e5c074a497 100644 --- a/ethexe/runtime/src/wasm/interface/database.rs +++ b/ethexe/runtime/src/wasm/interface/database.rs @@ -18,6 +18,7 @@ use crate::wasm::interface; use core::slice; +use ethexe_runtime_common::unpack_i64_to_u32; use gprimitives::H256; use parity_scale_codec::{Decode, Encode, Error as CodecError}; @@ -43,7 +44,7 @@ pub fn read_raw(hash: &H256) -> Option<&[u8]> { let ptr_len = sys::ext_database_read_by_hash_version_1(hash.as_ptr() as _); (ptr_len != 0).then(|| { - let (len, ptr) = ((ptr_len >> 32) as i32, (ptr_len & 0xFFFFFFFF) as i32); + let (ptr, len) = unpack_i64_to_u32(ptr_len); slice::from_raw_parts(ptr as _, len as usize) }) } diff --git a/ethexe/runtime/src/wasm/interface/mod.rs b/ethexe/runtime/src/wasm/interface/mod.rs index 9866ec7e6d1..1b6bfeadcff 100644 --- a/ethexe/runtime/src/wasm/interface/mod.rs +++ b/ethexe/runtime/src/wasm/interface/mod.rs @@ -27,6 +27,7 @@ pub(crate) mod logging_ri; pub(crate) mod utils { use ethexe_runtime_common::pack_u32_to_i64; + pub fn repr_ri_slice(slice: impl AsRef<[u8]>) -> i64 { let slice = slice.as_ref(); From 37d774f439211985f20ea6973d0743285f879eea Mon Sep 17 00:00:00 2001 From: playX18 Date: Tue, 14 Jan 2025 10:51:36 +0700 Subject: [PATCH 13/15] remove match from pre_process_memory_accesses --- runtime-interface/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index b9af8f0013f..53f5d2831e1 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -236,14 +236,13 @@ pub mod lazy_pages_detail { let mut writes_intervals = Vec::with_capacity(writes_len / mem_interval_size); deserialize_mem_intervals(writes, &mut writes_intervals); - match gear_lazy_pages::pre_process_memory_accesses( + gear_lazy_pages::pre_process_memory_accesses( &reads_intervals, &writes_intervals, gas_counter, - ) { - Ok(_) => 0, - Err(err) => err.into(), - } + ) + .map(|_| 0) + .unwrap_or_else(|err| err.into()) } pub fn lazy_pages_status() -> (Status,) { From ee7da48a1861bb8cd3c68d5ddc3dec9ad70392b5 Mon Sep 17 00:00:00 2001 From: playX18 Date: Wed, 15 Jan 2025 10:05:35 +0700 Subject: [PATCH 14/15] change from BE to LE --- ethexe/runtime/common/src/lib.rs | 4 ++-- sandbox/host/src/sandbox/wasmer_backend.rs | 4 ++-- sandbox/host/src/sandbox/wasmi_backend.rs | 4 ++-- sandbox/sandbox/src/host_executor.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ethexe/runtime/common/src/lib.rs b/ethexe/runtime/common/src/lib.rs index 661015edc3a..a4a2d089c84 100644 --- a/ethexe/runtime/common/src/lib.rs +++ b/ethexe/runtime/common/src/lib.rs @@ -271,7 +271,7 @@ where .unwrap_or_else(|err| unreachable!("{err}")) } -pub const fn pack_u32_to_i64(low: u32, high: u32) -> i64 { +pub const fn pack_u32_to_i64(high: u32, low: u32) -> i64 { let mut result = 0u64; result |= (high as u64) << 32; result |= low as u64; @@ -282,5 +282,5 @@ pub const fn unpack_i64_to_u32(val: i64) -> (u32, u32) { let val = val as u64; let high = (val >> 32) as u32; let low = val as u32; - (low, high) + (high, low) } diff --git a/sandbox/host/src/sandbox/wasmer_backend.rs b/sandbox/host/src/sandbox/wasmer_backend.rs index 50313793f63..fae54a75dae 100644 --- a/sandbox/host/src/sandbox/wasmer_backend.rs +++ b/sandbox/host/src/sandbox/wasmer_backend.rs @@ -345,8 +345,8 @@ fn dispatch_common( let (serialized_result_val_ptr, serialized_result_val_len) = { // Cast to u64 to use zero-extension. let v = serialized_result as u64; - let len = (v >> 32) as u32; - let ptr = (v & 0xFFFFFFFF) as u32; + let ptr = (v >> 32) as u32; + let len = (v & 0xFFFFFFFF) as u32; (Pointer::new(ptr), len) }; diff --git a/sandbox/host/src/sandbox/wasmi_backend.rs b/sandbox/host/src/sandbox/wasmi_backend.rs index 233ef903968..b0c1d142756 100644 --- a/sandbox/host/src/sandbox/wasmi_backend.rs +++ b/sandbox/host/src/sandbox/wasmi_backend.rs @@ -511,8 +511,8 @@ fn dispatch_common( let (serialized_result_val_ptr, serialized_result_val_len) = { // Cast to u64 to use zero-extension. let v = serialized_result as u64; - let len = (v >> 32) as u32; - let ptr = (v & 0xFFFFFFFF) as u32; + let ptr = (v >> 32) as u32; + let len = (v & 0xFFFFFFFF) as u32; (Pointer::new(ptr), len) }; diff --git a/sandbox/sandbox/src/host_executor.rs b/sandbox/sandbox/src/host_executor.rs index 9302c7a87f5..a05be46ca7a 100644 --- a/sandbox/sandbox/src/host_executor.rs +++ b/sandbox/sandbox/src/host_executor.rs @@ -307,7 +307,7 @@ extern "C" fn dispatch_thunk( let result_len = result.len() as u64; mem::forget(result); - (result_len << 32) | result_ptr + (result_ptr << 32) | result_len } } From d7913af055772d22e6a366088281b4cd1474e84f Mon Sep 17 00:00:00 2001 From: playX18 Date: Wed, 15 Jan 2025 15:27:12 +0700 Subject: [PATCH 15/15] fix parameter ordering --- ethexe/runtime/common/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethexe/runtime/common/src/lib.rs b/ethexe/runtime/common/src/lib.rs index a4a2d089c84..661015edc3a 100644 --- a/ethexe/runtime/common/src/lib.rs +++ b/ethexe/runtime/common/src/lib.rs @@ -271,7 +271,7 @@ where .unwrap_or_else(|err| unreachable!("{err}")) } -pub const fn pack_u32_to_i64(high: u32, low: u32) -> i64 { +pub const fn pack_u32_to_i64(low: u32, high: u32) -> i64 { let mut result = 0u64; result |= (high as u64) << 32; result |= low as u64; @@ -282,5 +282,5 @@ pub const fn unpack_i64_to_u32(val: i64) -> (u32, u32) { let val = val as u64; let high = (val >> 32) as u32; let low = val as u32; - (high, low) + (low, high) }