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

Function test_ubigint_to_be_bits_toaltstack

bitvm/src/bigint/bits.rs:459–509  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

457
458 #[test]
459 fn test_ubigint_to_be_bits_toaltstack() {
460 let mut prng = ChaCha20Rng::seed_from_u64(0);
461
462 for _ in 0..10 {
463 let a: BigUint = prng.sample(RandomBits::new(U254::N_BITS as u64));
464
465 let mut bits = vec![];
466 let mut cur = a.clone();
467 for _ in 0..U254::N_BITS {
468 bits.push(if cur.bit(0) { 1 } else { 0 });
469 cur.shr_assign(1);
470 }
471
472 let script = script! {
473 { U254::push_u32_le(&a.to_u32_digits()) }
474 { U254::convert_to_be_bits_toaltstack() }
475 for i in 0..U254::N_BITS {
476 OP_FROMALTSTACK
477 { bits[i as usize] }
478 OP_EQUALVERIFY
479 }
480 OP_TRUE
481 };
482
483 run(script);
484 }
485
486 for _ in 0..10 {
487 let a: BigUint = prng.sample(RandomBits::new(U64::N_BITS as u64));
488
489 let mut bits = vec![];
490 let mut cur = a.clone();
491 for _ in 0..U64::N_BITS {
492 bits.push(if cur.bit(0) { 1 } else { 0 });
493 cur.shr_assign(1);
494 }
495
496 let script = script! {
497 { U64::push_u32_le(&a.to_u32_digits()) }
498 { U64::convert_to_be_bits_toaltstack() }
499 for i in 0..U64::N_BITS {
500 OP_FROMALTSTACK
501 { bits[i as usize] }
502 OP_EQUALVERIFY
503 }
504 OP_TRUE
505 };
506
507 run(script);
508 }
509 }
510
511 #[test]
512 fn test_ubigint_to_le_bits_toaltstack() {

Callers

nothing calls this directly

Calls 3

runFunction · 0.85
cloneMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected