diff --git a/Cargo.toml b/Cargo.toml index 06e87351..5a5d337f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ members = [ edition = "2021" license = "Apache-2.0" repository = "https://github.com/anza-xyz/pinocchio" -rust-version = "1.79" +rust-version = "1.84" [workspace.dependencies] five8_const = "0.1.4" @@ -28,12 +28,12 @@ regex = "1" syn = "1.0" [workspace.metadata.cli] -solana = "2.2.0" +solana = "2.3.0" [workspace.metadata.toolchains] build = "1.84.1" -format = "nightly-2024-11-22" -lint = "nightly-2024-11-22" +format = "nightly-2025-02-16" +lint = "nightly-2025-02-16" test = "1.84.1" [workspace.metadata.release] diff --git a/sdk/pinocchio/src/account_info.rs b/sdk/pinocchio/src/account_info.rs index 8ba2499e..d1c20cd5 100644 --- a/sdk/pinocchio/src/account_info.rs +++ b/sdk/pinocchio/src/account_info.rs @@ -63,7 +63,7 @@ pub(crate) struct Account { /// - `7 6 5 4 3 2 1 0` /// - `. x x x . . . .`: number of immutable borrows that can still be /// allocated, for the lamports field. Ranges from 7 (`111`) to - /// 0 (`000`). + /// 0 (`000`). /// /// * data mutable borrow flag /// - `7 6 5 4 3 2 1 0` diff --git a/sdk/pinocchio/src/entrypoint/mod.rs b/sdk/pinocchio/src/entrypoint/mod.rs index 6422566f..4f81d25e 100644 --- a/sdk/pinocchio/src/entrypoint/mod.rs +++ b/sdk/pinocchio/src/entrypoint/mod.rs @@ -13,6 +13,7 @@ pub use alloc::BumpAllocator; use core::{ cmp::min, mem::{size_of, MaybeUninit}, + ptr::with_exposed_provenance_mut, slice::from_raw_parts, }; @@ -195,9 +196,14 @@ macro_rules! program_entrypoint { /// Align a pointer to the BPF alignment of [`u128`]. macro_rules! align_pointer { ($ptr:ident) => { - // integer-to-pointer cast: the resulting pointer will have the same provenance as - // the original pointer and it follows the alignment requirement for the input. - (($ptr as usize + (BPF_ALIGN_OF_U128 - 1)) & !(BPF_ALIGN_OF_U128 - 1)) as *mut u8 + // Integer-to-pointer cast: first compute the aligned address as a `usize`, + // since this is more CU-efficient than using `ptr::align_offset()` or the + // strict provenance API (e.g., `ptr::with_addr()`). Then cast the result + // back to a pointer. The resulting pointer is guaranteed to be valid + // becauseit follows the layout serialized by the runtime. + with_exposed_provenance_mut( + ($ptr.expose_provenance() + (BPF_ALIGN_OF_U128 - 1)) & !(BPF_ALIGN_OF_U128 - 1), + ) }; } diff --git a/sdk/pinocchio/src/sysvars/slot_hashes/test.rs b/sdk/pinocchio/src/sysvars/slot_hashes/test.rs index 269c3c47..80e7fb33 100644 --- a/sdk/pinocchio/src/sysvars/slot_hashes/test.rs +++ b/sdk/pinocchio/src/sysvars/slot_hashes/test.rs @@ -416,7 +416,7 @@ fn test_from_account_info_constructor() { unsafe { let header_size = core::mem::size_of::(); let total_size = header_size + data.len(); - let word_len = (total_size + 7) / 8; + let word_len = total_size.div_ceil(8); aligned_backing = std::vec![0u64; word_len]; let base_ptr = aligned_backing.as_mut_ptr() as *mut u8; diff --git a/sdk/pinocchio/src/sysvars/slot_hashes/test_utils.rs b/sdk/pinocchio/src/sysvars/slot_hashes/test_utils.rs index f8753e30..203f1199 100644 --- a/sdk/pinocchio/src/sysvars/slot_hashes/test_utils.rs +++ b/sdk/pinocchio/src/sysvars/slot_hashes/test_utils.rs @@ -123,7 +123,7 @@ pub unsafe fn make_account_info( ) -> (AccountInfo, Vec) { let hdr_size = mem::size_of::(); let total = hdr_size + data.len(); - let words = (total + 7) / 8; + let words = total.div_ceil(8); let mut backing: Vec = std::vec![0u64; words]; assert!( mem::align_of::() >= mem::align_of::(),