MCPcopy Create free account
hub / github.com/BitVM/BitVM / init_state

Function init_state

bitvm/src/hash/blake3_utils.rs:436–468  ·  view source on GitHub ↗

Initializes the internal state, uses the same variable names as the paper

(
    stack: &mut StackTracker,
    chaining: bool,
    counter: u32,
    block_len: u32,
    flags: u32,
)

Source from the content-addressed store, hash-verified

434
435/// Initializes the internal state, uses the same variable names as the paper
436fn init_state(
437 stack: &mut StackTracker,
438 chaining: bool,
439 counter: u32,
440 block_len: u32,
441 flags: u32,
442) -> HashMap<u8, StackVariable> {
443 let mut state = Vec::new();
444
445 if chaining {
446 for i in 0..8 {
447 state.push(stack.from_altstack_joined(8, &format!("prev-hash[{}]", i)));
448 }
449 } else {
450 for u32 in IV {
451 state.push(stack.number_u32(u32));
452 }
453 }
454 for u32 in &IV[0..4] {
455 state.push(stack.number_u32(*u32));
456 }
457 state.push(stack.number_u32(counter));
458 state.push(stack.number_u32(0));
459 state.push(stack.number_u32(block_len));
460 state.push(stack.number_u32(flags));
461
462 let mut state_map = HashMap::new();
463 for (i, s) in state.iter().enumerate() {
464 state_map.insert(i as u8, *s);
465 stack.rename(*s, &format!("state_{}", i));
466 }
467 state_map
468}
469
470/// Applies the blake3 compression function to the given 512 bit message, consumes everything and leaves only the final value
471#[allow(clippy::too_many_arguments)]

Callers 1

compressFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected