Skip to content

Commit 0a16dfe

Browse files
committed
feat: sys rand + hashmap random keys fix
1 parent 295b693 commit 0a16dfe

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

library/std/src/sys/zkvm/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
buf: *const u8,
3535
count: u32,
3636
);
37-
pub fn sys_rand(recv_buf: *mut u32, words: usize);
37+
pub fn sys_rand(recv_buf: *mut u8, words: usize);
3838
pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
3939
pub fn sys_log(msg_ptr: *const u8, len: usize);
4040
pub fn sys_cycle_count() -> usize;

library/std/src/sys/zkvm/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,12 @@ pub fn abort_internal() -> ! {
8585
}
8686

8787
pub fn hashmap_random_keys() -> (u64, u64) {
88-
(1, 2)
88+
let mut buf = [0u8; 16];
89+
unsafe {
90+
abi::sys_rand(buf.as_mut_ptr(), buf.len());
91+
};
92+
93+
let a = u64::from_le_bytes(buf[0..8].try_into().unwrap());
94+
let b = u64::from_le_bytes(buf[8..16].try_into().unwrap());
95+
(a, b)
8996
}

0 commit comments

Comments
 (0)