Index Mathematics Conjectures nbv lettuce Widgets

oraccle_squeeze

stdlib/oraccle/oraccle_squeeze.nbv

oraccle_squeeze(let mut pending_elements)

No description.

Calls
calloc, copy_into, extend_to, milli/poseidon/poseidon_milli_config, slice_from_start
Precompiles
assert_eq!, assert_lt!, chunks_flat_map!, clone!, concat!, div_ceil!, if_lt!, len!, loop!, poseidon_milli_state!, println!
Used by
oraccle/oraccle_sample_uniform, oraccle/oraccle_sample_uniform_vec

Source

(let mut pending_elements)

(
  static INPUT_LEN,
  static OUTPUT_LEN,
  static _,
  static _,
  static _,
  static _,
  static _ 
) = poseidon_milli_config()

static T = INPUT_LEN + OUTPUT_LEN

static pending_len = len! pending_elements
# must have some pending state elements
assert_lt! 0, pending_len
println! "oraccle squeezing", pending_len, "elements"

# ingest all state elements and collapse
# to a single output by repeatedly hashing outputs

# permutation must be compressing
assert_lt! OUTPUT_LEN, INPUT_LEN

let mut out = chunks_flat_map! pending_elements, INPUT_LEN, chunk {
  let state = concat! calloc(OUTPUT_LEN), extend_to(INPUT_LEN, chunk)
  let out = poseidon_milli_state! OUTPUT_LEN, INPUT_LEN, state
  slice_from_start(out, OUTPUT_LEN)
}
static mut last_len = len! out
loop! T, i {
  if_lt! OUTPUT_LEN, last_len {
    let next_out = chunks_flat_map! slice_from_start((clone! out), last_len), INPUT_LEN, chunk {
      let state = concat! calloc(OUTPUT_LEN), extend_to(INPUT_LEN, chunk)
      let v = poseidon_milli_state! OUTPUT_LEN, INPUT_LEN, state
      slice_from_start(v, OUTPUT_LEN)
    }
    last_len = len! next_out
    out = copy_into(next_out, out, 0)
  }
}

assert_eq! (div_ceil! pending_len, INPUT_LEN) * OUTPUT_LEN, len! out

let entropy = slice_from_start(out, OUTPUT_LEN)
let state = clone! entropy

(state, entropy)