Initial ChronoSeal release
This commit is contained in:
commit
a66debdece
48 files changed
+2362
No files matched your search
@@ -0,0 +1,33 @@
|
||||
use rand::Rng;
|
||||
|
||||
pub fn generate_random_program(len_range: std::ops::RangeInclusive<usize>) -> Vec<u8> {
|
||||
// Same logic as earlier, using shared::hashing for HASH if needed
|
||||
let mut rng = rand::thread_rng();
|
||||
let count = rng.gen_range(len_range);
|
||||
let mut ops = Vec::new();
|
||||
let mut depth: i32 = 0;
|
||||
for _ in 0..count {
|
||||
if depth < 2 {
|
||||
ops.push(0x00); // PUSH
|
||||
let val = rng.gen::<u32>();
|
||||
ops.extend_from_slice(&val.to_le_bytes());
|
||||
depth += 1;
|
||||
} else {
|
||||
let op = rng.gen_range(0..10);
|
||||
match op {
|
||||
0x00 => {
|
||||
ops.push(0x00);
|
||||
let val = rng.gen::<u32>();
|
||||
ops.extend_from_slice(&val.to_le_bytes());
|
||||
depth += 1;
|
||||
}
|
||||
0x01..=0x08 => { ops.push(op as u8); depth -= 1; }
|
||||
0x09 => { ops.push(0x09); depth = 1; }
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
ops
|
||||
}
|
||||
|
||||
// Server does not need to execute the program; client does.
|
||||
Reference in new issue
Block a user