Skip to content

Commit 86e64d9

Browse files
committed
Fix two TODOs
1 parent 0501080 commit 86e64d9

File tree

8 files changed

+53
-28
lines changed

8 files changed

+53
-28
lines changed

ceno_cli/src/commands/common_args/ceno.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ impl CenoOptions {
307307
self,
308308
compilation_options,
309309
elf_path,
310-
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
310+
Checkpoint::PrepVerify, // TODO: when whir and babybear is ready
311311
)
312312
}
313313
(PcsKind::Whir, FieldType::BabyBear) => {
314314
prove_inner::<BabyBearExt4, Whir<BabyBearExt4, WhirDefaultSpec>, P>(
315315
self,
316316
compilation_options,
317317
elf_path,
318-
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
318+
Checkpoint::PrepVerify, // TODO: when whir and babybear is ready
319319
)
320320
}
321321
}

ceno_emul/src/syscalls/sha256.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub fn sha_extend(w: &mut [u32]) {
3838
.wrapping_add(s0)
3939
.wrapping_add(w[i - 7])
4040
.wrapping_add(s1);
41-
// TODO: why doesn't sp1 use wrapping_add?
4241
}
4342
}
4443

ceno_rt/src/lib.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use getrandom::{Error, register_custom_getrandom};
66
use core::arch::{asm, global_asm};
77
use std::{
88
alloc::{Layout, alloc_zeroed},
9-
ptr::null,
9+
ptr,
10+
sync::atomic::{AtomicU32, Ordering},
1011
};
1112

1213
#[cfg(target_arch = "riscv32")]
@@ -37,7 +38,7 @@ pub extern "C" fn sys_alloc_words(nwords: usize) -> *mut u32 {
3738
#[unsafe(no_mangle)]
3839
#[linkage = "weak"]
3940
pub extern "C" fn sys_getenv(_name: *const u8) -> *const u8 {
40-
null()
41+
ptr::null()
4142
}
4243

4344
/// Generates random bytes.
@@ -49,26 +50,37 @@ pub extern "C" fn sys_getenv(_name: *const u8) -> *const u8 {
4950
#[unsafe(no_mangle)]
5051
#[linkage = "weak"]
5152
pub unsafe extern "C" fn sys_rand(recv_buf: *mut u8, words: usize) {
52-
unsafe fn step() -> u32 {
53-
static mut X: u32 = 0xae569764;
54-
// We are stealing Borland Delphi's random number generator.
55-
// The random numbers here are only good enough to make eg
56-
// HashMap work.
53+
// We are stealing Borland Delphi's random number generator.
54+
// The random numbers here are only good enough to make eg
55+
// HashMap work.
56+
fn step() -> u32 {
57+
static X: AtomicU32 = AtomicU32::new(0xae569764);
58+
let rslt = X.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |x| {
59+
Some(x.wrapping_mul(134775813).wrapping_add(1))
60+
});
61+
match rslt {
62+
Ok(el) => el,
63+
Err(err) => err,
64+
}
65+
}
66+
let mut idx = 0;
67+
let steps = words / 4;
68+
let rest = words % 4;
69+
for _ in 0..steps {
70+
let bytes = step().to_le_bytes();
71+
// SAFETY: Up to the caller
5772
unsafe {
58-
X = X.wrapping_mul(134775813) + 1;
59-
X
73+
ptr::copy_nonoverlapping(bytes.as_ptr(), recv_buf.add(idx), 4);
6074
}
75+
idx = idx.wrapping_add(4);
6176
}
62-
// TODO(Matthias): this is a bit inefficient,
63-
// we could fill whole u32 words at a time.
64-
// But it's just for testing.
65-
for i in 0..words {
77+
let [a, b, c, _] = step().to_le_bytes();
78+
for (_, el) in (0..rest).zip([a, b, c]) {
79+
// SAFETY: Up to the caller
6680
unsafe {
67-
let element = recv_buf.add(i);
68-
// The lower bits ain't really random, so might as well take
69-
// the higher order ones, if we are only using 8 bits.
70-
*element = step().to_le_bytes()[3];
81+
*recv_buf.add(idx) = el;
7182
}
83+
idx = idx.wrapping_add(1);
7284
}
7385
}
7486

@@ -153,3 +165,17 @@ unsafe extern "C" {
153165
// The address of this variable is the start of the stack (growing downwards).
154166
static _stack_start: u8;
155167
}
168+
169+
#[cfg(test)]
170+
mod tests {
171+
use crate::sys_rand;
172+
173+
#[test]
174+
fn fills_with_random_bytes() {
175+
let mut buf = [0u8; 65];
176+
unsafe {
177+
sys_rand(buf.as_mut_ptr(), buf.len());
178+
}
179+
assert_ne!(buf, [0u8; 65]);
180+
}
181+
}

ceno_zkvm/src/bin/e2e.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ fn main() {
284284
max_steps,
285285
args.proof_file,
286286
args.vk_file,
287-
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
287+
Checkpoint::PrepVerify, // TODO: when whir and babybear is ready
288288
)
289289
}
290290
(PcsKind::Whir, FieldType::BabyBear) => {
@@ -299,7 +299,7 @@ fn main() {
299299
max_steps,
300300
args.proof_file,
301301
args.vk_file,
302-
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
302+
Checkpoint::PrepVerify, // TODO: when whir and babybear is ready
303303
)
304304
}
305305
};

ceno_zkvm/src/instructions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait Instruction<E: ExtensionField> {
106106
num_structural_witin: usize,
107107
steps: Vec<StepRecord>,
108108
) -> Result<(RMMCollections<E::BaseField>, Multiplicity<u64>), ZKVMError> {
109-
// FIXME selector is the only structural witness
109+
// TODO: selector is the only structural witness
110110
// this is workaround, as call `construct_circuit` will not initialized selector
111111
// we can remove this one all opcode unittest migrate to call `build_gkr_iop_circuit`
112112
assert!(num_structural_witin == 0 || num_structural_witin == 1);

ceno_zkvm/src/scheme/prover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<
254254
evaluations.push(opcode_proof.wits_in_evals.clone());
255255
chip_proofs.insert(index, opcode_proof);
256256
} else {
257-
// FIXME: PROGRAM table circuit is not guaranteed to have 2^n instances
257+
// TODO: PROGRAM table circuit is not guaranteed to have 2^n instances
258258
input.num_instances = 1 << input.log2_num_instances();
259259
let (mut table_proof, pi_in_evals, input_opening_point) = self
260260
.create_chip_proof(circuit_name, pk, input, &mut transcript, &challenges)?;
@@ -266,7 +266,7 @@ impl<
266266
]
267267
.concat(),
268268
);
269-
// FIXME: PROGRAM table circuit is not guaranteed to have 2^n instances
269+
// TODO: PROGRAM table circuit is not guaranteed to have 2^n instances
270270
table_proof.num_instances = num_instances;
271271
chip_proofs.insert(index, table_proof);
272272
for (idx, eval) in pi_in_evals {

gkr_iop/src/gkr/layer/cpu/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub(crate) fn prove_rotation<E: ExtensionField, PCS: PolynomialCommitmentScheme<
302302
)
303303
.collect_vec();
304304
exit_span!(span);
305-
// TODO FIXME: we pick a random point from output point, does it sound?
305+
// TODO: we pick a random point from output point, does it sound?
306306
let builder = VirtualPolynomialsBuilder::new_with_mles(
307307
num_threads,
308308
max_num_variables,

gkr_iop/src/gkr/layer_constraint_system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// TODO FIXME LayerConstrainSystem is deprecated
1+
/// TODO: LayerConstrainSystem is deprecated
22
use std::{cmp::Ordering, collections::BTreeMap};
33

44
use crate::{
@@ -134,7 +134,7 @@ impl<E: ExtensionField> LayerConstraintSystem<E> {
134134
assert!(size <= 16);
135135
let rlc_record = rlc_chip_record(
136136
vec![
137-
// TODO FIXME layer constrain system is deprecated
137+
// TODO: layer constrain system is deprecated
138138
E::BaseField::from_canonical_u64(LookupTable::Dynamic as u64).expr(),
139139
value.clone(),
140140
],

0 commit comments

Comments
 (0)