Skip to content

Commit e4ada64

Browse files
committed
fix comments
1 parent 873491e commit e4ada64

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

crypto/crypto/src/merkle_tree/merkle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ where
255255
/// Merkle tree
256256
pub fn get_proof_by_pos(&self, pos: usize) -> Option<Proof<B::Node>> {
257257
// A root only tree (from `from_root`) has no nodes to walk. Callers must
258-
// gather paths from the device resident copy instead. Catch the misuse
259-
// early in debug builds rather than returning a misleading None.
260-
debug_assert!(
258+
// gather paths from the device resident copy instead. Fail loudly in all
259+
// builds rather than returning a misleading empty path.
260+
assert!(
261261
!self.nodes.is_empty(),
262262
"get_proof_by_pos called on a root-only MerkleTree (no nodes)"
263263
);

crypto/math-cuda/src/merkle.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,11 @@ pub fn gather_merkle_paths_dev(
378378
Ok(host)
379379
}
380380

381-
/// Row-pair Keccak leaf + Merkle tree build for R2 composition-polynomial
382-
/// commit. `parts_interleaved` is `num_parts` slices, each holding an ext3
383-
/// LDE column interleaved as `[a0,a1,a2, b0,b1,b2, ...]` of length `3*lde_size`.
384-
///
385-
/// Returns `(2*(lde_size/2) - 1) * 32` bytes of tree nodes in the standard
386-
/// layout (root at byte offset 0, leaves in the tail).
387-
/// Build the composition Merkle tree on device. Leaves hash row pairs, so
381+
/// Build the composition Merkle tree on device. `parts_interleaved` is
382+
/// `num_parts` slices, each an ext3 LDE column interleaved as
383+
/// `[a0,a1,a2, b0,b1,b2, ...]` of length `3*lde_size`. Leaves hash row pairs, so
388384
/// `num_leaves = lde_size / 2`. Returns the device node buffer, the leaf count,
389-
/// and the stream it was built on. Shared by the host copy and device keep
390-
/// wrappers below.
385+
/// and the stream it was built on. Used by the device keep wrapper below.
391386
fn build_comp_poly_tree_nodes_dev(
392387
parts_interleaved: &[&[u64]],
393388
) -> Result<(CudaSlice<u8>, usize, Arc<CudaStream>)> {

crypto/stark/src/gpu_lde.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,12 @@ pub(crate) fn gather_proofs_dev(
14461446
if positions.is_empty() {
14471447
return Some(Vec::new());
14481448
}
1449+
// Positions index an LDE that `assert_u32_domain` keeps within u32; guard the
1450+
// cast so any future relaxation fails loudly instead of wrapping silently.
1451+
debug_assert!(
1452+
positions.iter().all(|&p| p <= u32::MAX as usize),
1453+
"gather_proofs_dev: position exceeds u32 range"
1454+
);
14491455
let positions_u32: Vec<u32> = positions.iter().map(|&p| p as u32).collect();
14501456
let bytes = math_cuda::merkle::gather_merkle_paths_dev(
14511457
&tree.nodes,
@@ -1698,8 +1704,17 @@ where
16981704
// The GPU FRI commit sets `gpu_tree` on every layer as a group; the CPU
16991705
// commit sets none. Host trees fall back to the host walk. When the layers
17001706
// are device resident the host trees are root only, so the gather below must
1701-
// succeed (a failure is a hard abort, not a silent walk).
1702-
if fri_layers[0].gpu_tree.is_none() {
1707+
// succeed (a failure is a hard abort, not a silent walk). The residency is
1708+
// all or nothing; assert it so a future partial-build can never route a
1709+
// root-only layer through the host walk and ship empty proofs.
1710+
let first_resident = fri_layers[0].gpu_tree.is_some();
1711+
debug_assert!(
1712+
fri_layers
1713+
.iter()
1714+
.all(|l| l.gpu_tree.is_some() == first_resident),
1715+
"FRI layer residency must be all or nothing"
1716+
);
1717+
if !first_resident {
17031718
return None;
17041719
}
17051720
let stream = math_cuda::device::backend()

0 commit comments

Comments
 (0)