MCPcopy Create free account
hub / github.com/argumentcomputer/ix / tree_partition

Function tree_partition

zisk/host/src/main.rs:706–727  ·  view source on GitHub ↗

Partition `n` items into chunks of at most `arity` each, avoiding any chunk of size exactly 1 (which would make agg-of-1 a no-op). When the trailing remainder is 1, it's merged into the previous chunk so the smallest chunk produced is size 2. Returns half-open `(start, end)` index ranges.

(n: usize, arity: usize)

Source from the content-addressed store, hash-verified

704
705/// The canonical subject root a leaf guest commits for a chunk that certifies
706/// `cover` (its `covered()` target addresses): `merkle_root_canonical` over the
707/// addresses, exactly as the guest computes it. Used host-side to re-derive the
708/// expected per-child subject *from the env* (not from the proof) so the final
709/// aggregate's committed subject can be checked against the env it should cover.
710fn subject_of_cover(cover: &[[u8; 32]]) -> ix_common::address::Address {
711 use ix_common::address::Address;
712 let leaves: Vec<Address> = cover
713 .iter()
714 .map(|b| Address::from_slice(b).expect("cover address"))
715 .collect();
716 ixon::merkle::merkle_root_canonical(&leaves)
717 .unwrap_or_else(ixon::merkle::zero_address)
718}
719
720/// Partition `n` items into chunks of at most `arity` each, avoiding
721/// any chunk of size exactly 1 (which would make agg-of-1 a no-op).
722/// When the trailing remainder is 1, it's merged into the previous
723/// chunk so the smallest chunk produced is size 2. Returns half-open
724/// `(start, end)` index ranges.
725fn tree_partition(n: usize, arity: usize) -> Vec<(usize, usize)> {
726 if n <= arity {
727 return vec![(0, n)];
728 }
729 let mut ranges: Vec<(usize, usize)> = Vec::new();
730 let mut i = 0;

Callers 1

mainFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected