Skip to content

Commit e650ade

Browse files
authored
Merge pull request #5318 from igor-casper/core-81
[VM2] Replace safe transmute with borsh
2 parents 98c12ed + 1fb4bbf commit e650ade

File tree

12 files changed

+142
-116
lines changed

12 files changed

+142
-116
lines changed

Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

executor/wasm_common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ casper-contract-sdk-sys = { version = "0.1.3", path = "../../smart_contracts/sdk
1616
num-derive = { workspace = true }
1717
num-traits = { workspace = true }
1818
thiserror = "2"
19-
safe-transmute = "0.11"
19+
2020

2121
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
2222
serde = { version = "1", features = ["derive"] }

executor/wasm_common/src/env_info.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

executor/wasm_common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A crate that shares common types and utilities between the Wasm executor and the Wasm interface.
22
pub mod chain_utils;
33
pub mod entry_point;
4-
pub mod env_info;
4+
55
pub mod error;
66
pub mod flags;
77
pub mod keyspace;

executor/wasm_host/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ either = "1.15"
2626
num-derive = { workspace = true }
2727
num-traits = { workspace = true }
2828
parking_lot = "0.12"
29-
safe-transmute = "0.11"
3029
thiserror = "2"
3130
tracing = "0.1"

executor/wasm_host/src/abi.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
use safe_transmute::TriviallyTransmutable;
1+
use borsh::BorshSerialize;
22

3+
#[derive(Copy, Clone, Debug, PartialEq, BorshSerialize)]
34
#[repr(C)]
4-
#[derive(Copy, Clone, Debug, PartialEq)]
55
pub(crate) struct ReadInfo {
66
/// Allocated pointer.
7-
pub(crate) data: u32,
7+
pub(crate) data_ptr: u32,
88
/// Size in bytes.
99
pub(crate) data_size: u32,
1010
}
1111

12-
unsafe impl TriviallyTransmutable for ReadInfo {}
13-
1412
#[repr(C)]
15-
#[derive(Copy, Clone, Debug, PartialEq)]
13+
#[derive(Copy, Clone, Debug, PartialEq, BorshSerialize)]
1614

1715
pub(crate) struct CreateResult {
1816
pub(crate) package_address: [u8; 32],
1917
}
2018

21-
unsafe impl TriviallyTransmutable for CreateResult {}
19+
const _: () = assert!(
20+
std::mem::size_of::<CreateResult>() == 32,
21+
"CreateResult must be 32 bytes"
22+
);
23+
24+
#[derive(Clone, Copy, BorshSerialize, Debug, PartialEq)]
25+
#[repr(C)]
26+
pub struct EnvInfo {
27+
pub block_time: u64,
28+
pub transferred_value: u64,
29+
pub caller_addr: [u8; 32],
30+
pub caller_kind: u32,
31+
pub callee_addr: [u8; 32],
32+
pub callee_kind: u32,
33+
pub protocol_version_major: u32,
34+
pub protocol_version_minor: u32,
35+
pub protocol_version_patch: u32,
36+
pub parent_block_hash: [u8; 32],
37+
pub block_height: u64,
38+
}

0 commit comments

Comments
 (0)