diff --git a/basic_bootloader/src/lib.rs b/basic_bootloader/src/lib.rs index 1b7a8e717..4b1eea373 100644 --- a/basic_bootloader/src/lib.rs +++ b/basic_bootloader/src/lib.rs @@ -2,7 +2,6 @@ #![feature(allocator_api)] #![allow(incomplete_features)] #![feature(generic_const_exprs)] -#![feature(array_chunks)] #![feature(get_mut_unchecked)] #![feature(const_type_id)] #![feature(vec_push_within_capacity)] diff --git a/basic_system/src/lib.rs b/basic_system/src/lib.rs index 2ce2ebbe2..6d2c1c247 100644 --- a/basic_system/src/lib.rs +++ b/basic_system/src/lib.rs @@ -2,7 +2,6 @@ #![allow(incomplete_features)] #![feature(generic_const_exprs)] #![feature(allocator_api)] -#![feature(array_chunks)] #![feature(get_mut_unchecked)] #![feature(const_type_id)] #![feature(vec_push_within_capacity)] diff --git a/basic_system/src/system_functions/bn254_ecmul.rs b/basic_system/src/system_functions/bn254_ecmul.rs index 46e4cf429..eab77c1d3 100644 --- a/basic_system/src/system_functions/bn254_ecmul.rs +++ b/basic_system/src/system_functions/bn254_ecmul.rs @@ -54,7 +54,7 @@ fn bn254_ecmul_as_system_function_inner< *dst = *src; } - let mut it = buffer.array_chunks::<32>(); + let mut it = buffer.as_chunks::<32>().0.iter(); let serialized_result = unsafe { let x0 = it.next().unwrap_unchecked(); let y0 = it.next().unwrap_unchecked(); diff --git a/basic_system/src/system_functions/bn254_pairing_check.rs b/basic_system/src/system_functions/bn254_pairing_check.rs index 523179569..c1dccc7e6 100644 --- a/basic_system/src/system_functions/bn254_pairing_check.rs +++ b/basic_system/src/system_functions/bn254_pairing_check.rs @@ -85,7 +85,7 @@ fn bn254_pairing_check_inner( for (dst, src) in buffer.iter_mut().zip(&mut src_iter) { *dst = *src; } - let mut it = buffer.array_chunks::<32>(); + let mut it = buffer.as_chunks::<32>().0.iter(); unsafe { let mut g1_x = *it.next().unwrap_unchecked(); let mut g1_y = *it.next().unwrap_unchecked(); diff --git a/basic_system/src/system_functions/ecrecover.rs b/basic_system/src/system_functions/ecrecover.rs index 10a56f6f3..1b0b03063 100644 --- a/basic_system/src/system_functions/ecrecover.rs +++ b/basic_system/src/system_functions/ecrecover.rs @@ -52,7 +52,7 @@ fn ecrecover_as_system_function_inner< // follow https://github.com/ethereum/go-ethereum/blob/aadcb886753079d419f966a3bc990f708f8d1c3b/core/vm/contracts.go#L188 - let mut it = buffer.array_chunks::<32>(); + let mut it = buffer.as_chunks::<32>().0.iter(); let recovered_pubkey_bytes = unsafe { let digest = it.next().unwrap_unchecked(); let v = it.next().unwrap_unchecked(); diff --git a/basic_system/src/system_functions/p256_verify.rs b/basic_system/src/system_functions/p256_verify.rs index 1f5297519..bd0652752 100644 --- a/basic_system/src/system_functions/p256_verify.rs +++ b/basic_system/src/system_functions/p256_verify.rs @@ -70,7 +70,7 @@ fn p256_verify_as_system_function_inner< *dst = *src; } - let mut it = buffer.array_chunks::<32>(); + let mut it = buffer.as_chunks::<32>().0.iter(); let is_valid = unsafe { let digest = it.next().unwrap_unchecked(); let r = it.next().unwrap_unchecked(); diff --git a/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/commitment_and_proof_advice.rs b/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/commitment_and_proof_advice.rs index 2d1c57d88..ec3ce57a7 100644 --- a/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/commitment_and_proof_advice.rs +++ b/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/commitment_and_proof_advice.rs @@ -21,8 +21,8 @@ impl UsizeSerializable for KZGCommitmentAndProof { } else { #[allow(clippy::needless_return)] return ExactSizeChain::new( - self.commitment.array_chunks::<{ core::mem::size_of::() }>().map(|chunk| usize::from_le_bytes(*chunk)), - self.proof.array_chunks::<{ core::mem::size_of::() }>().map(|chunk| usize::from_le_bytes(*chunk)), + self.commitment.as_chunks::<{ core::mem::size_of::() }>().0.iter().map(|chunk| usize::from_le_bytes(*chunk)), + self.proof.as_chunks::<{ core::mem::size_of::() }>().0.iter().map(|chunk| usize::from_le_bytes(*chunk)), ); } ); diff --git a/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/polynomial_evaluation.rs b/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/polynomial_evaluation.rs index d6f180a76..10c695f68 100644 --- a/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/polynomial_evaluation.rs +++ b/basic_system/src/system_implementation/system/da_commitment_generator/blob_commitment_generator/polynomial_evaluation.rs @@ -16,8 +16,7 @@ pub fn evaluate_blob_polynomial(data: &[u8], x: &crypto::bls12_381::Fr) -> crypt [MaybeUninit::uninit(); ELEMENTS_PER_4844_BLOB]; let mut poly_iter = poly.iter_mut(); - let chunks = data.array_chunks::(); - let remainder = chunks.remainder(); + let (chunks, remainder) = data.as_chunks::(); for chunk in chunks { poly_iter .next() diff --git a/callable_oracles/src/hash_to_prime/common.rs b/callable_oracles/src/hash_to_prime/common.rs index cf97958a5..ce12aabc8 100644 --- a/callable_oracles/src/hash_to_prime/common.rs +++ b/callable_oracles/src/hash_to_prime/common.rs @@ -203,7 +203,7 @@ pub fn create_entropy(source: &[u8]) -> [u8; 64] { use crypto::blake2s::Blake2s256; assert!(MAX_ENTROPY_BYTES <= 64); let mut entropy = [0u8; 64]; - for (idx, dst) in entropy.array_chunks_mut::<32>().enumerate() { + for (idx, dst) in entropy.as_chunks_mut::<32>().0.iter_mut().enumerate() { let mut hasher = Blake2s256::new(); hasher.update(&(idx as u32).to_le_bytes()); hasher.update(&source); diff --git a/callable_oracles/src/lib.rs b/callable_oracles/src/lib.rs index bd63748d2..06775a92f 100644 --- a/callable_oracles/src/lib.rs +++ b/callable_oracles/src/lib.rs @@ -1,8 +1,6 @@ #![cfg_attr(all(not(feature = "evaluate"), not(test)), no_std)] #![allow(incomplete_features)] #![feature(generic_const_exprs)] -#![feature(array_chunks)] -#![feature(iter_array_chunks)] #![allow(clippy::new_without_default)] #![allow(clippy::needless_lifetimes)] #![allow(clippy::needless_borrow)] diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index f77607622..8ae998669 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(test), no_std)] -#![feature(array_chunks)] #![allow(static_mut_refs)] #![allow(clippy::uninit_assumed_init)] #![allow(clippy::new_without_default)] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7f4a02cdf..007954dc2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2025-05-23" +channel = "nightly-2026-01-22" diff --git a/supporting_crates/solidity_abi/src/impls/byte_ref.rs b/supporting_crates/solidity_abi/src/impls/byte_ref.rs index d17dd707f..1cf815d5c 100644 --- a/supporting_crates/solidity_abi/src/impls/byte_ref.rs +++ b/supporting_crates/solidity_abi/src/impls/byte_ref.rs @@ -58,14 +58,14 @@ impl<'a> SolidityCodableReflectionRef<'a> for BytesRef<'a> { if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, bytes_body) = local_tail.split_at_checked(32).ok_or(())?; @@ -87,14 +87,14 @@ impl<'a> SolidityCodableReflectionRefMut<'a> for BytesRefMut<'a> { if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_mut_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, bytes_body) = local_tail.split_at_mut_checked(32).ok_or(())?; diff --git a/supporting_crates/solidity_abi/src/impls/codable_array.rs b/supporting_crates/solidity_abi/src/impls/codable_array.rs index df38e3ad3..6e86d2e41 100644 --- a/supporting_crates/solidity_abi/src/impls/codable_array.rs +++ b/supporting_crates/solidity_abi/src/impls/codable_array.rs @@ -98,14 +98,14 @@ impl<'a, T: SolidityCodable + 'a, const N: usize> SolidityCodableReflectionRef<' return Err(()); } let array_source = if T::IS_DYNAMIC { - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, body) = local_tail.split_at_checked(32).ok_or(())?; @@ -142,14 +142,14 @@ impl<'a, T: SolidityCodable + 'a, const N: usize> SolidityCodableReflectionRefMu return Err(()); } let array_source = if T::IS_DYNAMIC { - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_mut_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, body) = local_tail.split_at_mut_checked(32).ok_or(())?; diff --git a/supporting_crates/solidity_abi/src/impls/codable_slice.rs b/supporting_crates/solidity_abi/src/impls/codable_slice.rs index b8e76df16..9547c6198 100644 --- a/supporting_crates/solidity_abi/src/impls/codable_slice.rs +++ b/supporting_crates/solidity_abi/src/impls/codable_slice.rs @@ -105,14 +105,14 @@ impl<'a, T: SolidityCodable + 'a> SolidityCodableReflectionRef<'a> for SliceRef< if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, body) = local_tail.split_at_checked(32).ok_or(())?; @@ -141,14 +141,14 @@ impl<'a, T: SolidityCodable + 'a> SolidityCodableReflectionRefMut<'a> for SliceR if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_mut_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, body) = local_tail.split_at_mut_checked(32).ok_or(())?; diff --git a/supporting_crates/solidity_abi/src/impls/string_ref.rs b/supporting_crates/solidity_abi/src/impls/string_ref.rs index 3b379263a..facfd68cd 100644 --- a/supporting_crates/solidity_abi/src/impls/string_ref.rs +++ b/supporting_crates/solidity_abi/src/impls/string_ref.rs @@ -37,14 +37,14 @@ impl<'a> SolidityCodableReflectionRef<'a> for SolidityStringRef<'a> { if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, bytes_body) = local_tail.split_at_checked(32).ok_or(())?; @@ -66,14 +66,14 @@ impl<'a> SolidityCodableReflectionRefMut<'a> for SolidityStringRefMut<'a> { if local_head.len() < 32 { return Err(()); } - let tail_offset = local_head.array_chunks::<32>().next().unwrap(); + let tail_offset = local_head.as_chunks::<32>().0.iter().next().unwrap(); let tail_offset = U256::from_be_bytes(*tail_offset); let tail_offset = u256_to_usize_checked(&tail_offset)?; let (_, local_tail) = source.split_at_mut_checked(tail_offset).ok_or(())?; if local_tail.len() < 32 { return Err(()); } - let len = local_tail.array_chunks::<32>().next().unwrap(); + let len = local_tail.as_chunks::<32>().0.iter().next().unwrap(); let len = U256::from_be_bytes(*len); let len = u256_to_usize_checked(&len)?; let (_, bytes_body) = local_tail.split_at_mut_checked(32).ok_or(())?; diff --git a/supporting_crates/solidity_abi/src/impls/uint_x.rs b/supporting_crates/solidity_abi/src/impls/uint_x.rs index 3eb3f17f0..38f687ecd 100644 --- a/supporting_crates/solidity_abi/src/impls/uint_x.rs +++ b/supporting_crates/solidity_abi/src/impls/uint_x.rs @@ -28,7 +28,7 @@ macro_rules! uint_impl { if local_head.len() < 32 { return Err(()); } - let source = local_head.array_chunks::<32>().next().unwrap(); + let source = local_head.as_chunks::<32>().0.iter().next().unwrap(); let new = Self { source }; *head_offset += 32; @@ -42,7 +42,7 @@ macro_rules! uint_impl { if local_head.len() < 32 { return Err(()); } - let source = local_head.array_chunks_mut::<32>().next().unwrap(); + let source = local_head.as_chunks_mut::<32>().0.iter_mut().next().unwrap(); let new = Self { source }; *head_offset += 32; @@ -137,7 +137,7 @@ impl<'a> SolidityCodableReflectionRef<'a> for AddressRef<'a> { if local_head.len() < 32 { return Err(()); } - let source = local_head.array_chunks::<32>().next().unwrap(); + let source = local_head.as_chunks::<32>().0.iter().next().unwrap(); let new = Self { source }; *head_offset += 32; @@ -151,7 +151,7 @@ impl<'a> SolidityCodableReflectionRefMut<'a> for AddressRefMut<'a> { if local_head.len() < 32 { return Err(()); } - let source = local_head.array_chunks_mut::<32>().next().unwrap(); + let source = local_head.as_chunks_mut::<32>().0.iter_mut().next().unwrap(); let new = Self { source }; *head_offset += 32; @@ -241,7 +241,7 @@ impl<'a> SolidityCodableReflectionRefWritable<'a> for AddressRefMut<'a> { // if local_head.len() < 32 { // return Err(()); // } -// let source = local_head.array_chunks::<32>().next().unwrap(); +// let source = local_head.as_chunks::<32>().0.iter().next().unwrap(); // let new = Self { source }; // *head_offset += 32; diff --git a/supporting_crates/solidity_abi/src/lib.rs b/supporting_crates/solidity_abi/src/lib.rs index 084bb3edc..f449815ad 100644 --- a/supporting_crates/solidity_abi/src/lib.rs +++ b/supporting_crates/solidity_abi/src/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(not(test), no_std)] #![allow(incomplete_features)] #![feature(generic_const_exprs)] -#![feature(array_chunks)] #![feature(allocator_api)] #![allow(clippy::result_unit_err)] #![allow(clippy::needless_lifetimes)] diff --git a/system_hooks/src/lib.rs b/system_hooks/src/lib.rs index 61b3b3217..154751e08 100644 --- a/system_hooks/src/lib.rs +++ b/system_hooks/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(target_arch = "riscv32", no_std)] #![feature(allocator_api)] -#![feature(array_chunks)] #![feature(get_mut_unchecked)] #![feature(const_type_id)] #![feature(vec_push_within_capacity)] diff --git a/tests/binary_checker/src/lib.rs b/tests/binary_checker/src/lib.rs index 9805beeeb..4e2061d3b 100644 --- a/tests/binary_checker/src/lib.rs +++ b/tests/binary_checker/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(array_chunks)] - #[cfg(test)] mod tests { use std::{io::Read, path::PathBuf, str::FromStr}; @@ -17,7 +15,9 @@ mod tests { assert!(binary.len() % 4 == 0); binary - .array_chunks() + .as_chunks() + .0 + .iter() .map(|el| u32::from_le_bytes(*el)) .collect() } diff --git a/tests/instances/eth_runner/src/main.rs b/tests/instances/eth_runner/src/main.rs index c8fb69df3..a08d1a942 100644 --- a/tests/instances/eth_runner/src/main.rs +++ b/tests/instances/eth_runner/src/main.rs @@ -1,4 +1,3 @@ -#![feature(slice_as_array)] #![recursion_limit = "1024"] use clap::{Parser, Subcommand}; diff --git a/tests/rig/src/chain.rs b/tests/rig/src/chain.rs index 30e5428e9..39c357811 100644 --- a/tests/rig/src/chain.rs +++ b/tests/rig/src/chain.rs @@ -850,7 +850,7 @@ fn run_prover(csr_reads: &[u32]) { let mut buffer = vec![]; file.read_to_end(&mut buffer).expect("must read the file"); let mut binary = vec![]; - for el in buffer.array_chunks::<4>() { + for el in buffer.as_chunks::<4>().0.iter() { binary.push(u32::from_le_bytes(*el)); } diff --git a/tests/rig/src/lib.rs b/tests/rig/src/lib.rs index ce5158c10..24ee61b43 100644 --- a/tests/rig/src/lib.rs +++ b/tests/rig/src/lib.rs @@ -1,7 +1,5 @@ #![allow(incomplete_features)] -#![feature(generic_const_exprs)] #![feature(allocator_api)] -#![feature(array_chunks)] //! //! This crate contains infrastructure to write ZKsync OS integration tests. //! It contains `Chain` - in memory chain state structure with methods to run blocks, change state diff --git a/tests/rig/src/utils.rs b/tests/rig/src/utils.rs index a16904701..a9a177723 100644 --- a/tests/rig/src/utils.rs +++ b/tests/rig/src/utils.rs @@ -4,6 +4,7 @@ use crate::chain::BlockContext; use crate::Chain; +use alloy::consensus::BlobTransactionSidecar; use alloy::consensus::SidecarBuilder; use alloy::consensus::SimpleCoder; use alloy::consensus::TxEip1559; @@ -320,7 +321,7 @@ pub fn calldata_for_forwarder(target: alloy::primitives::Address, input: &[u8]) /// * `[u8; 32]` - The versioned hash of the blob pub fn get_alloy_4844_blob_versioned_hash(data: &[u8]) -> [u8; 32] { // Create a blob sidecar using Alloy's SimpleCoder (handles encoding internally) - let blob_sidecar = SidecarBuilder::::from_slice(data) + let blob_sidecar: BlobTransactionSidecar = SidecarBuilder::::from_slice(data) .build() .unwrap(); diff --git a/zk_ee/src/common_structs/history_map/element_pool.rs b/zk_ee/src/common_structs/history_map/element_pool.rs index f7ee8616d..ac4729367 100644 --- a/zk_ee/src/common_structs/history_map/element_pool.rs +++ b/zk_ee/src/common_structs/history_map/element_pool.rs @@ -47,7 +47,7 @@ impl ElementPool { match self.head { None => { // Allocate - let raw = Box::into_raw(Box::new_in( + let (raw, _) = Box::into_raw_with_allocator(Box::new_in( HistoryRecord { touch_ss_id: snapshot_id, value, diff --git a/zk_ee/src/lib.rs b/zk_ee/src/lib.rs index 2dce9d60d..d47ea5b44 100644 --- a/zk_ee/src/lib.rs +++ b/zk_ee/src/lib.rs @@ -1,12 +1,8 @@ #![cfg_attr(not(feature = "serde"), no_std)] #![allow(incomplete_features)] -#![feature(generic_const_exprs)] -#![feature(const_type_id)] #![feature(allocator_api)] -#![feature(array_chunks)] #![feature(associated_type_defaults)] #![feature(get_mut_unchecked)] -#![feature(array_windows)] #![feature(vec_push_within_capacity)] #![feature(slice_from_ptr_range)] #![feature(never_type)] diff --git a/zk_ee/src/utils/aligned_buffer.rs b/zk_ee/src/utils/aligned_buffer.rs deleted file mode 100644 index f4950b2a4..000000000 --- a/zk_ee/src/utils/aligned_buffer.rs +++ /dev/null @@ -1,214 +0,0 @@ -use crate::utils::usize_rw::UsizeWriteable; - -use super::*; - -pub struct AlignedBuffer<'a, const N: usize> -where - Assert<{ is_proper_buffer_alignment(N) }>: IsTrue, -{ - inner: &'a mut [u8], -} - -pub const fn is_proper_buffer_alignment(alignment: usize) -> bool { - alignment.is_power_of_two() && alignment >= core::mem::size_of::() -} - -impl<'a, const N: usize> AlignedBuffer<'a, N> -where - Assert<{ is_proper_buffer_alignment(N) }>: IsTrue, -{ - pub fn new(dst: &'a mut [u8]) -> Self { - assert!(dst.as_ptr().is_aligned_to(N)); - assert!(dst.len() % N == 0); - - Self { inner: dst } - } -} - -impl<'a, const N: usize> AsRef<[u8]> for AlignedBuffer<'a, N> -where - Assert<{ is_proper_buffer_alignment(N) }>: IsTrue, -{ - fn as_ref(&self) -> &[u8] { - &*self.inner - } -} - -impl<'a, const N: usize> AsMut<[u8]> for AlignedBuffer<'a, N> -where - Assert<{ is_proper_buffer_alignment(N) }>: IsTrue, -{ - fn as_mut(&mut self) -> &mut [u8] { - self.inner - } -} - -pub const USIZE_ALIGNMENT: usize = core::mem::align_of::(); -pub const USIZE_SIZE: usize = core::mem::size_of::(); -pub const U64_SIZE: usize = core::mem::size_of::(); -pub const U64_ALIGNMENT: usize = core::mem::align_of::(); - -const _: () = const { - assert!(U64_ALIGNMENT >= USIZE_ALIGNMENT); - assert!(U64_SIZE >= USIZE_SIZE); -}; - -pub type U64AlignedBuffer<'a> = AlignedBuffer<'a, U64_ALIGNMENT>; - -pub struct AlignedBufferIterator<'a> { - pub(crate) start: *const usize, - pub(crate) end: *const usize, - pub(crate) _marker: core::marker::PhantomData<&'a ()>, -} - -impl<'a> U64AlignedBuffer<'a> { - pub const fn len_in_usize(&self) -> usize { - debug_assert!(self.inner.len() % USIZE_SIZE == 0); - self.inner.len() / USIZE_SIZE - } - - pub fn iter(&self) -> AlignedBufferIterator<'_> { - debug_assert!(self.inner.len() % USIZE_SIZE == 0); - debug_assert!(self.inner.as_ptr().is_aligned_to(USIZE_SIZE)); - let start = self.inner.as_ptr().cast(); - let end = self.inner.as_ptr_range().end.cast(); - // by constructor and checks we can cast the pointer to usize - AlignedBufferIterator { - start, - end, - _marker: core::marker::PhantomData, - } - } - - pub fn as_usize_slice(&self) -> &[usize] { - let (ptr, len) = (self.inner.as_ptr(), self.inner.len()); - let ptr = ptr.cast(); - let len = len / USIZE_SIZE; - - unsafe { core::slice::from_raw_parts(ptr, len) } - } - - pub fn as_usize_slice_mut(&mut self) -> &mut [usize] { - let (ptr, len) = (self.inner.as_mut_ptr(), self.inner.len()); - let ptr = ptr.cast(); - let len = len / USIZE_SIZE; - - unsafe { core::slice::from_raw_parts_mut(ptr, len) } - } -} - -impl<'a> AlignedBufferIterator<'a> { - pub const fn empty() -> Self { - Self { - start: core::ptr::null(), - end: core::ptr::null(), - _marker: core::marker::PhantomData, - } - } -} - -impl<'a> Iterator for AlignedBufferIterator<'a> { - type Item = usize; - fn next(&mut self) -> Option { - if self.start < self.end { - unsafe { - let item = self.start.read(); - self.start = self.start.add(1); - - Some(item) - } - } else { - None - } - } -} - -impl<'a> ExactSizeIterator for AlignedBufferIterator<'a> { - fn len(&self) -> usize { - if self.start >= self.end { - 0 - } else { - unsafe { self.end.offset_from_unsigned(self.start) } - } - } -} - -pub fn copy_bytes_to_usize_buffer(src: &[u8], dst: &mut impl UsizeWriteable) -> usize { - let mut it = src.array_chunks::(); - let mut written = it.len(); - for src in &mut it { - unsafe { - dst.write_usize(usize::from_le_bytes(*src)); - } - } - let remainder = it.remainder(); - if !remainder.is_empty() { - written += 1; - let mut buffer = 0usize.to_le_bytes(); - buffer[..remainder.len()].copy_from_slice(remainder); - unsafe { - dst.write_usize(usize::from_le_bytes(buffer)); - } - } - - written -} - -pub fn copy_bytes_iter_to_usize_buffer( - src: impl ExactSizeIterator, - dst: &mut impl UsizeWriteable, -) -> usize { - let mut it = src.array_chunks::(); - let mut written = it.len(); - for src in &mut it { - unsafe { - dst.write_usize(usize::from_ne_bytes(src)); - } - } - if let Some(remainder) = it.into_remainder() { - if remainder.len() > 0 { - written += 1; - let mut buffer = 0usize.to_ne_bytes(); - for (dst, src) in buffer.iter_mut().zip(remainder) { - *dst = src; - } - unsafe { - dst.write_usize(usize::from_le_bytes(buffer)); - } - } - } - - written -} - -pub fn copy_bytes_iter_to_usize_slice( - src: impl ExactSizeIterator, - dst: &mut [usize], -) -> usize { - let min_capacity = num_usize_words_for_u8_capacity(src.len()); - assert!(dst.len() >= min_capacity); - let mut it = src.array_chunks::(); - let mut written = it.len(); - // go unsafe - let mut dst = dst.as_mut_ptr(); - for src in &mut it { - unsafe { - dst.write(usize::from_ne_bytes(src)); - dst = dst.add(1); - } - } - if let Some(remainder) = it.into_remainder() { - if remainder.len() > 0 { - written += 1; - let mut buffer = 0usize.to_ne_bytes(); - for (dst, src) in buffer.iter_mut().zip(remainder) { - *dst = src; - } - unsafe { - dst.write(usize::from_ne_bytes(buffer)); - } - } - } - - written -} diff --git a/zk_ee/src/utils/aligned_vector.rs b/zk_ee/src/utils/aligned_vector.rs index 55359af78..65e8e3cfa 100644 --- a/zk_ee/src/utils/aligned_vector.rs +++ b/zk_ee/src/utils/aligned_vector.rs @@ -1,12 +1,10 @@ -use super::{ - copy_bytes_iter_to_usize_slice, - usize_rw::{AsUsizeWritable, SafeUsizeWritable, UsizeWriteable}, - USIZE_SIZE, -}; -use core::alloc::Allocator; +use crate::utils::usize_rw::{AsUsizeWritable, SafeUsizeWritable, UsizeWriteable}; + +use super::USIZE_SIZE; +use core::{alloc::Allocator, mem::MaybeUninit}; pub const fn num_usize_words_for_u8_capacity(u8_capacity: usize) -> usize { - let num_words = u8_capacity.next_multiple_of(USIZE_SIZE) / USIZE_SIZE; + let num_words = u8_capacity.div_ceil(USIZE_SIZE); // give it some slack to account for 64/32 bit architectures mismatch num_words.next_multiple_of(2) } @@ -34,6 +32,12 @@ pub struct UsizeAlignedByteBox { byte_capacity: usize, } +impl AsRef<[u8]> for UsizeAlignedByteBox { + fn as_ref(&self) -> &[u8] { + Self::as_slice(self) + } +} + impl UsizeAlignedByteBox { pub fn preallocated_in(byte_capacity: usize, allocator: A) -> Self { let num_usize_words = num_usize_words_for_u8_capacity(byte_capacity); @@ -56,13 +60,6 @@ impl UsizeAlignedByteBox { self.byte_capacity } - pub fn from_u8_iterator_in(src: impl ExactSizeIterator, allocator: A) -> Self { - let mut result = Self::preallocated_in(src.len(), allocator); - copy_bytes_iter_to_usize_slice(src, &mut result.inner); - - result - } - pub fn from_slice_in(src: &[u8], allocator: A) -> Self { let mut result = Self::preallocated_in(src.len(), allocator); // copy @@ -94,17 +91,19 @@ impl UsizeAlignedByteBox { } pub fn from_usize_iterator_in(src: impl ExactSizeIterator, allocator: A) -> Self { - let mut inner: alloc::boxed::Box<[usize], A> = - unsafe { alloc::boxed::Box::new_uninit_slice_in(src.len(), allocator).assume_init() }; - let mut dst = inner.as_mut_ptr(); - for word in src { - unsafe { - dst.write(word); - dst = dst.add(1); - } + let word_capacity = src.len(); + let mut inner: alloc::boxed::Box<[MaybeUninit], A> = + alloc::boxed::Box::new_uninit_slice_in(word_capacity, allocator); + // iterators will have same length by the contract + unsafe { + core::hint::assert_unchecked(src.len() == inner.len()); } - - let byte_capacity = inner.len() * USIZE_SIZE; + for (src, dst) in src.zip(inner.iter_mut()) { + dst.write(src); + } + // everything was initialized + let inner = unsafe { inner.assume_init() }; + let byte_capacity = word_capacity * USIZE_SIZE; Self { inner, @@ -112,25 +111,33 @@ impl UsizeAlignedByteBox { } } - pub fn truncated_to_byte_length(&mut self, byte_len: usize) { - assert!(byte_len <= self.byte_capacity); - self.byte_capacity = byte_len; - } - - pub fn into_pinned(self) -> UsizeAlignedPinnedByteBox - where - A: 'static, - { - let Self { - inner, - byte_capacity, - } = self; + pub fn from_init_fn_in( + buffer_size: usize, + init_fn: impl FnOnce(&mut [MaybeUninit]) -> usize, + allocator: A, + ) -> Self { + let mut inner: alloc::boxed::Box<[MaybeUninit], A> = + alloc::boxed::Box::new_uninit_slice_in(buffer_size, allocator); + let written_words = init_fn(&mut inner); + assert!(written_words <= buffer_size); // we do not want to truncate or realloc, but we will expose only written part below + let byte_capacity = written_words * USIZE_SIZE; // we only count initialized words for capacity purposes - UsizeAlignedPinnedByteBox { - inner: alloc::boxed::Box::into_pin(inner), + Self { + inner: unsafe { inner.assume_init() }, byte_capacity, } } + + #[track_caller] + pub fn truncated_to_byte_length(&mut self, byte_len: usize) { + assert!( + byte_len <= self.byte_capacity, + "trying to truncate to {} bytes, while capacity is just {} bytes", + byte_len, + self.byte_capacity + ); + self.byte_capacity = byte_len; + } } impl AsUsizeWritable for UsizeAlignedByteBox { @@ -179,21 +186,4 @@ impl<'a> SafeUsizeWritable for UsizeSliceWriter<'a> { fn len(&self) -> usize { unsafe { self.end.offset_from_unsigned(self.dst) } } -} - -#[derive(Clone, Debug)] -pub struct UsizeAlignedPinnedByteBox { - inner: core::pin::Pin>, - byte_capacity: usize, -} - -impl UsizeAlignedPinnedByteBox { - pub fn as_slice(&self) -> &[u8] { - debug_assert!(self.inner.len() * USIZE_SIZE >= self.byte_capacity); - unsafe { core::slice::from_raw_parts(self.inner.as_ptr().cast::(), self.byte_capacity) } - } - - pub fn len(&self) -> usize { - self.byte_capacity - } -} +} \ No newline at end of file diff --git a/zk_ee/src/utils/mod.rs b/zk_ee/src/utils/mod.rs index 13c44984f..1c9c96c18 100644 --- a/zk_ee/src/utils/mod.rs +++ b/zk_ee/src/utils/mod.rs @@ -1,4 +1,3 @@ -pub mod aligned_buffer; pub mod aligned_vector; pub mod bytes32; pub mod cheap_clone; @@ -10,9 +9,18 @@ pub mod type_assert; pub mod usize_rw; pub mod write_bytes; +pub const USIZE_ALIGNMENT: usize = core::mem::align_of::(); +pub const USIZE_SIZE: usize = core::mem::size_of::(); +pub const U64_SIZE: usize = core::mem::size_of::(); +pub const U64_ALIGNMENT: usize = core::mem::align_of::(); + +const _: () = const { + assert!(U64_ALIGNMENT >= USIZE_ALIGNMENT); + assert!(U64_SIZE >= USIZE_SIZE); +}; + use crypto::MiniDigest; -pub use self::aligned_buffer::*; pub use self::aligned_vector::*; pub use self::bytes32::*; pub use self::convenience::*; diff --git a/zksync_os/reproduce/Dockerfile b/zksync_os/reproduce/Dockerfile index b44a1a21f..931f588c2 100644 --- a/zksync_os/reproduce/Dockerfile +++ b/zksync_os/reproduce/Dockerfile @@ -27,7 +27,7 @@ ENV PATH=/opt/cargo/bin:$PATH RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates curl git build-essential libssl-dev pkg-config \ && rm -rf /var/lib/apt/lists/* -RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2025-05-24 --profile minimal +RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2026-01-22 --profile minimal RUN rustup target add riscv32i-unknown-none-elf \ && cargo install cargo-binutils --locked \ && rustup component add llvm-tools-preview diff --git a/zksync_os/rust-toolchain.toml b/zksync_os/rust-toolchain.toml index c94befe00..403a4a633 100644 --- a/zksync_os/rust-toolchain.toml +++ b/zksync_os/rust-toolchain.toml @@ -1,3 +1,3 @@ # If changed, also change reproduce/Dockerfile [toolchain] -channel = "nightly-2025-05-24" +channel = "nightly-2026-01-22"