diff --git a/examples/wallet/core-logic/src/lib.rs b/examples/wallet/core-logic/src/lib.rs index 3a2f279a9..793d81219 100644 --- a/examples/wallet/core-logic/src/lib.rs +++ b/examples/wallet/core-logic/src/lib.rs @@ -4,6 +4,7 @@ extern crate alloc; use mozak_sdk::common::types::{Poseidon2Hash, ProgramIdentifier, StateObject}; use rkyv::rancor::{Failure, Panic, Strategy}; +use rkyv::util::AlignedVec; use rkyv::{Archive, Deserialize, Serialize}; /// A generic private key used by the wallet. @@ -60,7 +61,9 @@ pub struct TokenObject { impl From for TokenObject { fn from(value: StateObject) -> Self { - let archived = rkyv::access::(&value.data[..]).unwrap(); + let mut aligned_data = AlignedVec::with_capacity(value.data.len()); + aligned_data.extend_from_slice(&value.data); + let archived = rkyv::access::(&aligned_data).unwrap(); let token_object: TokenObject = archived .deserialize(Strategy::<_, Panic>::wrap(&mut ())) .unwrap(); diff --git a/examples/wallet/native/src/main.rs b/examples/wallet/native/src/main.rs index 5a8b7b7f7..7988271c0 100644 --- a/examples/wallet/native/src/main.rs +++ b/examples/wallet/native/src/main.rs @@ -21,19 +21,21 @@ use mozak_sdk::common::types::ProgramIdentifier; use wallet_core_logic::{dispatch, BlackBox, MethodArgs, PrivateKey, PublicKey, TokenObject}; fn main() { - let wallet_program = ProgramIdentifier::new_from_rand_seed(1); let remitter_program = ProgramIdentifier::new_from_rand_seed(2); let remittee_program = ProgramIdentifier::new_from_rand_seed(3); - let private_key = PrivateKey::new_from_rand_seed(4); - let public_key = PublicKey(mozak_sdk::native::poseidon::poseidon2_hash_no_pad( - &private_key.0, + let remitter_private_key = PrivateKey::new_from_rand_seed(4); + let remitter_public_key = PublicKey(mozak_sdk::native::poseidon::poseidon2_hash_no_pad( + &remitter_private_key.0, )); mozak_sdk::add_identity(remitter_program); // Manual override for `IdentityStack` - let _ = mozak_sdk::write(&mozak_sdk::InputTapeType::PrivateTape, &private_key.0[..]); + let _ = mozak_sdk::write( + &mozak_sdk::InputTapeType::PrivateTape, + &remitter_private_key.0[..], + ); mozak_sdk::rm_identity(); // Manual override for `IdentityStack` let token_object = TokenObject { - pub_key: public_key.clone(), + pub_key: remitter_public_key.clone(), amount: 10.into(), }; @@ -44,8 +46,8 @@ fn main() { }; mozak_sdk::call_send( - wallet_program, - MethodArgs::ApproveSignature(public_key, black_box.clone()), + remitter_program, + MethodArgs::ApproveSignature(remitter_public_key, black_box.clone()), dispatch, ); diff --git a/sdk/src/common/system.rs b/sdk/src/common/system.rs index 448a2561c..73a2898e3 100644 --- a/sdk/src/common/system.rs +++ b/sdk/src/common/system.rs @@ -8,6 +8,7 @@ use { call_tape_read, event_tape_read, ioread_private, ioread_public, self_prog_id_tape_read, }, rkyv::rancor::{Panic, Strategy}, + rkyv::util::AlignedVec, std::collections::BTreeSet, }; #[cfg(not(target_os = "mozakvm"))] @@ -102,7 +103,10 @@ fn populate_call_tape(self_prog_id: ProgramIdentifier) -> CallTapeType { let mut len_bytes = [0; 4]; call_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])); + let buf: &'static mut AlignedVec = Box::leak(Box::new(AlignedVec::with_capacity(len))); + unsafe { + buf.set_len(len); + } call_tape_read(buf); let archived_cpc_messages = rkyv::access::, Panic>(buf).unwrap(); @@ -139,7 +143,10 @@ fn populate_event_tape(self_prog_id: ProgramIdentifier) -> EventTapeType { 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])); + let buf: &'static mut AlignedVec = Box::leak(Box::new(AlignedVec::with_capacity(len))); + unsafe { + buf.set_len(len); + } event_tape_read(buf); let canonical_ordered_temporal_hints =