Skip to main content

slice

Function slice 

Source
pub fn slice(
    b: &CircuitBuilder,
    len_input: Wire,
    len_slice: Wire,
    input: &[Wire],
    offset: Wire,
    max_n_words: usize,
) -> Vec<Wire>
Expand description

Extracts a slice from an input byte array and returns it as a vector of packed 64-bit words.

Returns the bytes from input starting at offset for len_slice bytes, packed into max_n_words little-endian 64-bit words. Bytes past len_slice are not constrained — they hold whatever raw bytes happen to follow in input (and may be nonzero garbage). Callers that need to compare against an expected slice should use assert_slice_eq, which masks the comparison to the first len_slice bytes.

§Limitations

All size and offset values must fit within 32 bits. Specifically:

  • len_input must be < 2^32
  • len_slice must be < 2^32
  • offset must be < 2^32
  • offset + len_slice must be < 2^32

These limitations are enforced by the circuit constraints.

§Arguments

  • b - Circuit builder
  • len_input - Actual input size in bytes
  • len_slice - Actual slice size in bytes
  • input - Input array packed as words (8 bytes per word)
  • offset - Byte offset where slice starts
  • max_n_words - Number of output wires; the maximum slice length in bytes is max_n_words * 8

§Returns

A Vec<Wire> of length max_n_words containing the extracted slice bytes packed in little-endian order. Bytes past len_slice are unconstrained garbage; use assert_slice_eq for comparisons that should ignore them.

§Panics

  • If input.len() * 8 > u32::MAX
  • If max_n_words * 8 > u32::MAX