Skip to content

Instantly share code, notes, and snippets.

@RajeshRk18
Created October 1, 2023 21:48
Show Gist options
  • Save RajeshRk18/c83fe189b734d20489b5ce098ca2a9ed to your computer and use it in GitHub Desktop.
Save RajeshRk18/c83fe189b734d20489b5ce098ca2a9ed to your computer and use it in GitHub Desktop.
use libsecp256k1::curve::Scalar;
fn main() {
let limbs: [u32; 8] = [23, 4, 55, 6, 7, 2, 4, 1];
let (mut b, ptr) = {
let a = Scalar(limbs);
println!("Creation Address: {:?}", a.0.as_ptr());
(a, a.0.as_ptr()) // a gets copied and returned
};
println!("Value before dropping: {:?}", b.0);
b.clear();
let val_at_returned_memory = unsafe {
core::slice::from_raw_parts(b.0.as_ptr(), 8)
};
println!("Value at Returned Address: {:?}", val_at_returned_memory); // Zeroed
let val_at_dropped_memory = unsafe {
core::slice::from_raw_parts(ptr, 8)
};
println!("Value at Creation Address: {:?}", val_at_dropped_memory); // value still in memory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment