diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 9bd667b09..8cde0c52e 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -23,9 +23,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "array-concat" @@ -138,9 +138,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "funty" @@ -221,9 +221,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "log" @@ -398,9 +398,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] @@ -523,9 +523,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -543,9 +543,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", @@ -586,9 +586,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" -version = "2.0.61" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", diff --git a/examples/inputtape/core-logic/Cargo.toml b/examples/inputtape/core-logic/Cargo.toml index 57420f512..8b221da2f 100644 --- a/examples/inputtape/core-logic/Cargo.toml +++ b/examples/inputtape/core-logic/Cargo.toml @@ -5,5 +5,5 @@ version = "0.1.0" [dependencies] mozak-sdk = { path = "../../../sdk" } -rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc"] } +rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc", "bytecheck"] } rkyv_derive = "=0.8.0-alpha.1" diff --git a/examples/inputtape/core-logic/src/lib.rs b/examples/inputtape/core-logic/src/lib.rs index 1e2f98a2f..a59ad30a0 100644 --- a/examples/inputtape/core-logic/src/lib.rs +++ b/examples/inputtape/core-logic/src/lib.rs @@ -5,12 +5,14 @@ use rkyv::{Archive, Deserialize, Serialize}; #[derive(Archive, Deserialize, Serialize, PartialEq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub enum MethodArgs { RawTapesTest, } #[derive(Archive, Default, Deserialize, Serialize, PartialEq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub enum MethodReturns { #[default] Noop, diff --git a/examples/token/core-logic/src/lib.rs b/examples/token/core-logic/src/lib.rs index 8b1004c09..2d14cb569 100644 --- a/examples/token/core-logic/src/lib.rs +++ b/examples/token/core-logic/src/lib.rs @@ -7,6 +7,7 @@ use rkyv::{Archive, Deserialize, Serialize}; #[derive(Archive, Deserialize, Serialize, PartialEq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub enum MethodArgs { // Mint, // Burn, @@ -22,6 +23,7 @@ pub enum MethodArgs { #[derive(Archive, Default, Deserialize, Serialize, PartialEq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub enum MethodReturns { // TODO: Remove later #[default] diff --git a/examples/token/mozakvm/Cargo.toml b/examples/token/mozakvm/Cargo.toml index d2e77d042..904d74821 100644 --- a/examples/token/mozakvm/Cargo.toml +++ b/examples/token/mozakvm/Cargo.toml @@ -6,7 +6,7 @@ version = "0.1.0" [dependencies] mozak-sdk = { path = "../../../sdk" } -rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc"] } +rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc", "bytecheck"] } rkyv_derive = "=0.8.0-alpha.1" token-core-logic = { path = "../core-logic" } wallet-core-logic = { path = "../../wallet/core-logic" } @@ -17,4 +17,4 @@ std = [] # The following is read by `run_examples.py` [package.metadata.mozak] example_dependents = ["wallet"] -example_program_id = "MZK-b10da48cea4c09676b8e0efcd806941465060736032bb898420d0863dca72538" +example_program_id = "MZK-63236d3b0bc73b9cb18ab2aacbbcf741b84d0560e00172374ddfcffea7b409cc" diff --git a/examples/wallet/core-logic/Cargo.toml b/examples/wallet/core-logic/Cargo.toml index 2c0a799ec..9490dcb18 100644 --- a/examples/wallet/core-logic/Cargo.toml +++ b/examples/wallet/core-logic/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" [dependencies] mozak-sdk = { path = "../../../sdk" } -rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc"] } +rkyv = { version = "=0.8.0-alpha.1", default-features = false, features = ["pointer_width_32", "alloc", "bytecheck"] } rkyv_derive = "=0.8.0-alpha.1" [target.'cfg(not(target_os="mozakvm"))'.dependencies] diff --git a/examples/wallet/core-logic/src/lib.rs b/examples/wallet/core-logic/src/lib.rs index 8c3a3cb3b..3a2f279a9 100644 --- a/examples/wallet/core-logic/src/lib.rs +++ b/examples/wallet/core-logic/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; use mozak_sdk::common::types::{Poseidon2Hash, ProgramIdentifier, StateObject}; -use rkyv::rancor::{Panic, Strategy}; +use rkyv::rancor::{Failure, Panic, Strategy}; use rkyv::{Archive, Deserialize, Serialize}; /// A generic private key used by the wallet. @@ -15,6 +15,7 @@ pub struct PrivateKey(pub [u8; 32]); /// a poseidon2 hash. #[derive(Archive, Deserialize, Serialize, PartialEq, Eq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub struct PublicKey(pub Poseidon2Hash); impl From<[u8; 32]> for PrivateKey { @@ -38,6 +39,7 @@ impl PrivateKey { /// `TokenObject`. #[derive(Archive, Deserialize, Serialize, PartialEq, Eq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub struct Amount(u64); impl From for Amount { @@ -47,6 +49,7 @@ impl From for Amount { /// A token object is represented in the `data` section of a `StateObject`, and /// contains information about the token that is being used in a program. #[derive(Archive, Deserialize, Serialize, PartialEq, Eq, Clone)] +#[archive(check_bytes)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] pub struct TokenObject { /// The public key that is the economic owner of this `TokenObject`. @@ -57,7 +60,7 @@ pub struct TokenObject { impl From for TokenObject { fn from(value: StateObject) -> Self { - let archived = unsafe { rkyv::access_unchecked::(&value.data[..]) }; + let archived = rkyv::access::(&value.data[..]).unwrap(); let token_object: TokenObject = archived .deserialize(Strategy::<_, Panic>::wrap(&mut ())) .unwrap(); @@ -73,6 +76,7 @@ impl From for TokenObject { /// differentiate between transactions. #[derive(Archive, Deserialize, Serialize, PartialEq, Eq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub struct BlackBox { pub remitter_program: ProgramIdentifier, pub remittee_program: ProgramIdentifier, @@ -95,11 +99,13 @@ impl BlackBox { #[derive(Archive, Deserialize, Serialize, PartialEq, Eq, Clone)] #[cfg_attr(not(target_os = "mozakvm"), derive(Debug))] +#[archive(check_bytes)] pub enum MethodArgs { ApproveSignature(PublicKey, BlackBox), } #[derive(Archive, Debug, Deserialize, Serialize, PartialEq, Eq, Clone)] +#[archive(check_bytes)] pub enum MethodReturns { ApproveSignature(()), } diff --git a/examples/wallet/mozakvm/Cargo.lock b/examples/wallet/mozakvm/Cargo.lock index cd5540bd6..d2b962a8f 100644 --- a/examples/wallet/mozakvm/Cargo.lock +++ b/examples/wallet/mozakvm/Cargo.lock @@ -29,8 +29,9 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "array-concat" -version = "0.5.2" -source = "git+https://github.com/Daniel-Aaron-Bloom/array-concat.git#c929d49bc0f3c5f7e25d87fb940ece830e87e8da" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b4d2c47ea522f4135657904891e533727daca3d2d852f29f5e4cc50960c77c" [[package]] name = "array-init" diff --git a/sdk/Cargo.lock b/sdk/Cargo.lock index 94e948330..ce5d30c1e 100644 --- a/sdk/Cargo.lock +++ b/sdk/Cargo.lock @@ -23,9 +23,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "array-concat" @@ -138,9 +138,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "funty" @@ -204,9 +204,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "log" @@ -381,9 +381,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] @@ -506,9 +506,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -526,9 +526,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", @@ -569,9 +569,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" -version = "2.0.61" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", diff --git a/sdk/src/common/system.rs b/sdk/src/common/system.rs index c771a3974..448a2561c 100644 --- a/sdk/src/common/system.rs +++ b/sdk/src/common/system.rs @@ -1,6 +1,4 @@ use once_cell::unsync::Lazy; -use rkyv::rancor::{Panic, Strategy}; -use rkyv::Deserialize; #[cfg(target_os = "mozakvm")] use { crate::common::merkle::merkleize, @@ -9,12 +7,15 @@ use { crate::core::ecall::{ call_tape_read, event_tape_read, ioread_private, ioread_public, self_prog_id_tape_read, }, + rkyv::rancor::{Panic, Strategy}, std::collections::BTreeSet, }; #[cfg(not(target_os = "mozakvm"))] use {core::cell::RefCell, std::rc::Rc}; -use crate::common::traits::{Call, CallArgument, CallReturn, EventEmit}; +use crate::common::traits::{ + ArchivedCallArgument, ArchivedCallReturn, Call, CallArgument, CallReturn, EventEmit, +}; use crate::common::types::{ CallTapeType, Event, EventTapeType, PrivateInputTapeType, ProgramIdentifier, PublicInputTapeType, SystemTape, @@ -104,7 +105,7 @@ fn populate_call_tape(self_prog_id: ProgramIdentifier) -> CallTapeType { let buf: &'static mut Vec = Box::leak(Box::new(vec![0; len])); call_tape_read(buf); - let archived_cpc_messages = unsafe { rkyv::access_unchecked::>(buf) }; + let archived_cpc_messages = rkyv::access::, Panic>(buf).unwrap(); let cast_list: Vec = archived_cpc_messages .iter() @@ -136,12 +137,13 @@ fn populate_call_tape(self_prog_id: ProgramIdentifier) -> CallTapeType { fn populate_event_tape(self_prog_id: ProgramIdentifier) -> EventTapeType { let mut len_bytes = [0; 4]; event_tape_read(&mut len_bytes); + let len: usize = u32::from_le_bytes(len_bytes).try_into().unwrap(); let buf: &'static mut Vec = Box::leak(Box::new(vec![0; len])); event_tape_read(buf); let canonical_ordered_temporal_hints = - unsafe { rkyv::access_unchecked::>(buf) }; + rkyv::access::, Panic>(buf).unwrap(); EventTapeType { self_prog_id, reader: Some(canonical_ordered_temporal_hints), @@ -167,8 +169,8 @@ pub fn call_receive() -> Option<(ProgramIdentifier, A, R)> where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>, { + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn, { unsafe { SYSTEM_TAPE.call_tape.receive() } } @@ -184,8 +186,8 @@ pub fn call_send( where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>, { + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn, { unsafe { SYSTEM_TAPE .call_tape diff --git a/sdk/src/common/traits.rs b/sdk/src/common/traits.rs index 3bc0c67d2..681787f56 100644 --- a/sdk/src/common/traits.rs +++ b/sdk/src/common/traits.rs @@ -1,7 +1,9 @@ -use rkyv::rancor::{Panic, Strategy}; +use rkyv::bytecheck::CheckBytes; +use rkyv::rancor::{Failure, Panic, Strategy}; use rkyv::ser::allocator::{AllocationTracker, GlobalAllocator}; use rkyv::ser::{AllocSerializer, Composite}; use rkyv::util::AlignedVec; +use rkyv::validation::validators::DefaultValidator; use rkyv::{Archive, Deserialize, Serialize}; use crate::common::types::{Event, ProgramIdentifier}; @@ -10,6 +12,11 @@ pub trait RkyvSerializable = rkyv::Serialize< Strategy, Panic>, Panic>, > + Serialize, Panic>>; pub trait CallArgument = Sized + RkyvSerializable; +pub trait ArchivedCallArgument = + Deserialize> + CheckBytes>; +pub trait ArchivedCallReturn = + Deserialize> + CheckBytes>; + pub trait CallReturn = ?Sized + Clone + Default + RkyvSerializable + Archive; /// A data struct that is aware of it's own ID @@ -35,8 +42,8 @@ pub trait Call: SelfIdentify { where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>; + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn; /// `receive` emulates a function call directed towards the /// program, presents back with a three tuple of the form @@ -49,8 +56,8 @@ pub trait Call: SelfIdentify { where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>; + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn; } /// `EventEmit` trait provides method `emit` to use the underlying diff --git a/sdk/src/common/types/event.rs b/sdk/src/common/types/event.rs index 1b6079b06..790c30971 100644 --- a/sdk/src/common/types/event.rs +++ b/sdk/src/common/types/event.rs @@ -21,6 +21,7 @@ use crate::native::poseidon::poseidon2_hash_no_pad; derive(Debug, serde::Serialize, serde::Deserialize) )] #[allow(clippy::module_name_repetitions)] +#[archive(check_bytes)] #[repr(u8)] pub enum EventType { Write = 0, @@ -63,6 +64,7 @@ pub struct Event { not(target_os = "mozakvm"), derive(Debug, serde::Serialize, serde::Deserialize) )] +#[archive(check_bytes)] #[allow(clippy::module_name_repetitions)] #[allow(clippy::unsafe_derive_deserialize)] pub struct CanonicalEvent { @@ -115,4 +117,5 @@ impl CanonicalEvent { not(target_os = "mozakvm"), derive(Debug, serde::Serialize, serde::Deserialize) )] +#[archive(check_bytes)] pub struct CanonicalOrderedTemporalHints(pub CanonicalEvent, pub u32); diff --git a/sdk/src/common/types/raw_message.rs b/sdk/src/common/types/raw_message.rs index 3a019f461..3db845a8d 100644 --- a/sdk/src/common/types/raw_message.rs +++ b/sdk/src/common/types/raw_message.rs @@ -5,11 +5,11 @@ use serde_hex::{SerHexSeq, StrictPfx}; #[derive( Default, Clone, Hash, PartialEq, PartialOrd, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, )] -#[archive(check_bytes)] #[cfg_attr( not(target_os = "mozakvm"), derive(serde::Serialize, serde::Deserialize) )] +#[archive(check_bytes)] #[archive_attr(derive(Debug))] pub struct RawMessage( #[cfg_attr(not(target_os = "mozakvm"), serde(with = "SerHexSeq::"))] pub Vec, diff --git a/sdk/src/common/types/state_address.rs b/sdk/src/common/types/state_address.rs index 83fe02a41..89e341938 100644 --- a/sdk/src/common/types/state_address.rs +++ b/sdk/src/common/types/state_address.rs @@ -20,6 +20,7 @@ pub const STATE_TREE_DEPTH: usize = 8; not(target_os = "mozakvm"), derive(serde::Serialize, serde::Deserialize) )] +#[archive(check_bytes)] pub struct StateAddress( #[cfg_attr(not(target_os = "mozakvm"), serde(with = "SerHex::"))] pub [u8; STATE_TREE_DEPTH], diff --git a/sdk/src/common/types/state_object.rs b/sdk/src/common/types/state_object.rs index 91a879dc9..372fd7049 100644 --- a/sdk/src/common/types/state_object.rs +++ b/sdk/src/common/types/state_object.rs @@ -8,6 +8,7 @@ use serde_hex::{SerHexSeq, StrictPfx}; not(target_os = "mozakvm"), derive(serde::Serialize, serde::Deserialize) )] +#[archive(check_bytes)] pub struct StateObject { pub address: super::StateAddress, pub constraint_owner: super::ProgramIdentifier, diff --git a/sdk/src/mozakvm/calltape.rs b/sdk/src/mozakvm/calltape.rs index e1d175ad0..fd833794b 100644 --- a/sdk/src/mozakvm/calltape.rs +++ b/sdk/src/mozakvm/calltape.rs @@ -1,7 +1,9 @@ -use rkyv::rancor::{Panic, Strategy}; +use rkyv::rancor::{Failure, Panic, Strategy}; use rkyv::{Archive, Deserialize}; -use crate::common::traits::{Call, CallArgument, CallReturn, SelfIdentify}; +use crate::common::traits::{ + ArchivedCallArgument, ArchivedCallReturn, Call, CallArgument, CallReturn, SelfIdentify, +}; use crate::common::types::{CrossProgramCall, ProgramIdentifier}; /// Represents the `CallTape` under `mozak-vm` @@ -36,8 +38,9 @@ impl Call for CallTape { where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>, { + + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn, { // Ensure we aren't validating past the length of the event tape assert!(self.index < self.reader.as_ref().unwrap().len()); @@ -52,7 +55,7 @@ impl Call for CallTape { assert!(self.is_casted_actor(&recipient_program)); // Deserialize the `arguments` seen on the tape, and assert - let zcd_args = unsafe { rkyv::access_unchecked::(&cpcmsg.argument.0[..]) }; + let zcd_args = rkyv::access::(&cpcmsg.argument.0[..]).unwrap(); let deserialized_args = <::Archived as Deserialize>>::deserialize( zcd_args, @@ -67,7 +70,7 @@ impl Call for CallTape { // Return the claimed return value as seen on the tape // It remains that specific program's prerogative to ensure // that the return value used here is according to expectation - let zcd_ret = unsafe { rkyv::access_unchecked::(&cpcmsg.return_.0[..]) }; + let zcd_ret = rkyv::access::(&cpcmsg.return_.0[..]).unwrap(); <::Archived as Deserialize>>::deserialize( zcd_ret, Strategy::wrap(&mut ()), @@ -80,8 +83,8 @@ impl Call for CallTape { where A: CallArgument + PartialEq, R: CallReturn, - ::Archived: Deserialize>, - ::Archived: Deserialize>, { + ::Archived: ArchivedCallArgument, + ::Archived: ArchivedCallReturn, { // Loop until we completely traverse the call tape in the // worst case. Hopefully, we see a message directed towards us // before the end @@ -115,11 +118,11 @@ impl Call for CallTape { assert!(self.is_casted_actor(&caller)); let archived_args = - unsafe { rkyv::access_unchecked::(zcd_cpcmsg.argument.0.as_slice()) }; + rkyv::access::(zcd_cpcmsg.argument.0.as_slice()).unwrap(); let args: A = archived_args.deserialize(Strategy::wrap(&mut ())).unwrap(); let archived_ret = - unsafe { rkyv::access_unchecked::(zcd_cpcmsg.return_.0.as_slice()) }; + rkyv::access::(zcd_cpcmsg.return_.0.as_slice()).unwrap(); let ret: R = archived_ret.deserialize(Strategy::wrap(&mut ())).unwrap(); return Some((caller, args, ret));