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

Function sha256_stack

bitvm/src/hash/sha256_u4_stack.rs:291–725  ·  view source on GitHub ↗
(
    stack: &mut StackTracker,
    num_bytes: u32,
    use_add_table: bool,
    use_full_xor: bool,
)

Source from the content-addressed store, hash-verified

289}
290
291pub fn sha256_stack(
292 stack: &mut StackTracker,
293 num_bytes: u32,
294 use_add_table: bool,
295 use_full_xor: bool,
296) -> Script {
297 // up to 55 is one block and always supports add table
298 // probably up to 68 bytes I can afford to load the add tables for the first chunk (but have I would have to unload it)
299
300 let (mut padding_scripts, chunks) = double_padding(num_bytes);
301 let mut bytes_per_chunk: Vec<u32> = Vec::new();
302 let mut bytes_remaining = num_bytes;
303 while bytes_remaining > 0 {
304 if bytes_remaining > 64 {
305 bytes_per_chunk.push(64);
306 bytes_remaining -= 64;
307 } else {
308 bytes_per_chunk.push(bytes_remaining);
309 bytes_remaining = 0;
310 }
311 }
312 if bytes_per_chunk.len() < chunks as usize {
313 bytes_per_chunk.push(0);
314 }
315 //println!("{:?}", bytes_per_chunk);
316 //println!("{:?}", padding_scripts);
317
318 let scheduling_64 = scheduling_64_padding();
319
320 let mut message = (0..num_bytes * 2)
321 .map(|i| stack.define(1, &format!("message[{}]", i)))
322 .collect::<Vec<StackVariable>>();
323
324 let (modulo, quotient) = match use_add_table {
325 true => (
326 u4_push_modulo_table_stack(stack),
327 u4_push_quotient_table_stack(stack),
328 ),
329 false => (StackVariable::null(), StackVariable::null()),
330 };
331
332 stack.set_breakpoint("init");
333
334 let shift_tables = u4_push_shift_tables_stack(stack);
335
336 let (lookup, xor_table) = if use_full_xor {
337 (
338 u4_push_full_lookup_table_stack(stack),
339 u4_push_full_xor_table_stack(stack),
340 )
341 } else {
342 (
343 u4_push_half_lookup_table_0_based_stack(stack),
344 u4_push_half_xor_table_stack(stack),
345 )
346 };
347
348 let mut varmap: HashMap<char, [StackVariable; 8]> = HashMap::new();

Callers 4

test_sizes_tmpFunction · 0.85
test_shatempFunction · 0.85
test_sha256Function · 0.85
test_genesis_blockFunction · 0.85

Tested by 4

test_sizes_tmpFunction · 0.68
test_shatempFunction · 0.68
test_sha256Function · 0.68
test_genesis_blockFunction · 0.68