You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you set the rust compiler to version 1.77.x, build the wasm (via wasm-pack or however you wish), and run the complile function from the browser it works. However, if you build this wasm with version 1.78.0 or nightly, the TransactionKernel assembler fails to compile the module and panics at the above mentioned function.
I've rewritten the function locally and the account code compiles successfully after. Here is the rewrite if it ends up being helpful:
pubfngroup_vector_elements_2<T,constN:usize>(source:Vec<T>) -> Vec<[T;N]>{assert_eq!(
source.len() % N,0,"source length must be divisible by {}, but was {}",N,
source.len());// Capacity of the new vectorlet capacity = source.len() / N;letmut result = Vec::with_capacity(capacity);// SAFETY: We ensure the source length is exactly divisible by N// Convert Vec<T> into Vec<[T; N]>unsafe{// Convert source into a raw pointer for further manipulationletmut source_ptr = source.as_ptr();
std::mem::forget(source);// Avoid destructor being calledfor _ in0..capacity {// Point to an array of N elements. We advance by N each iteration.let array_ptr = source_ptr as*const[T;N];// Copy the array. This avoids aliasing issues by not modifying source_ptr directly.let array = std::ptr::read(array_ptr);
result.push(array);
source_ptr = source_ptr.add(N);// Move the pointer by N elements}}
result
}
The text was updated successfully, but these errors were encountered:
Very interesting! Thank you for reporting this! I'm curious if the following modification would also fix the issue:
pubfngroup_vector_elements<T,constN:usize>(mutsource:Vec<T>) -> Vec<[T;N]>{assert_eq!(
source.len() % N,0,"source length must be divisible by {}, but was {}",N,
source.len());let len = source.len() / N;let cap = source.capacity() / N;// reduce the capacity of the vector to make sure it is a multiple of N
source.shrink_to(cap *N);// convert the vector to a pointer but make sure we don't deallocate the underlying memoryletmut v = mem::ManuallyDrop::new(source);let p = v.as_mut_ptr();// build a new vector from the same memory with new length and capacityunsafe{Vec::from_raw_parts(p as*mut[T;N], len, cap)}}
group_vector_elements
panics during account compilation for wasm built with rust nightly compiler or rust stable version 1.78.0
A simple example can be seen here: https://github.com/JohnDonavon/AssemblyWasm/blob/john-test/rust_lib/src/lib.rs
If you set the rust compiler to version 1.77.x, build the wasm (via wasm-pack or however you wish), and run the
complile
function from the browser it works. However, if you build this wasm with version 1.78.0 or nightly, the TransactionKernel assembler fails to compile the module and panics at the above mentioned function.I've rewritten the function locally and the account code compiles successfully after. Here is the rewrite if it ends up being helpful:
The text was updated successfully, but these errors were encountered: