Skip to content

Commit

Permalink
feat: sys rand + hashmap random keys fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas authored and mattstam committed Jul 22, 2024
1 parent 5cf79c7 commit 3e7462e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/std/src/sys/zkvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
buf: *const u8,
count: u32,
);
pub fn sys_rand(recv_buf: *mut u32, words: usize);
pub fn sys_rand(recv_buf: *mut u8, words: usize);
pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
pub fn sys_log(msg_ptr: *const u8, len: usize);
pub fn sys_cycle_count() -> usize;
Expand Down
9 changes: 8 additions & 1 deletion library/std/src/sys/zkvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,12 @@ pub fn abort_internal() -> ! {
}

pub fn hashmap_random_keys() -> (u64, u64) {
(1, 2)
let mut buf = [0u8; 16];
unsafe {
abi::sys_rand(buf.as_mut_ptr(), buf.len());
};

let a = u64::from_le_bytes(buf[0..8].try_into().unwrap());
let b = u64::from_le_bytes(buf[8..16].try_into().unwrap());
(a, b)
}

0 comments on commit 3e7462e

Please sign in to comment.