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

Function test_sub

bitvm/src/bn254/fq.rs:869–894  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

867
868 #[test]
869 fn test_sub() {
870 println!("Fq.sub: {} bytes", Fq::sub(0, 1).len());
871
872 let m = BigUint::from_str_radix(Fq::MODULUS, 16).unwrap();
873
874 let mut prng = ChaCha20Rng::seed_from_u64(0);
875
876 for _ in 0..100 {
877 let a: BigUint = prng.sample(RandomBits::new(254));
878 let b: BigUint = prng.sample(RandomBits::new(254));
879
880 let a = a.rem(&m);
881 let b = b.rem(&m);
882 let c: BigUint = a.clone().add(&m).sub(b.clone()).rem(&m);
883
884 let script = script! {
885 { Fq::push_u32_le(&a.to_u32_digits()) }
886 { Fq::push_u32_le(&b.to_u32_digits()) }
887 { Fq::sub(1, 0) }
888 { Fq::push_u32_le(&c.to_u32_digits()) }
889 { Fq::equalverify(1, 0) }
890 OP_TRUE
891 };
892 run(script);
893 }
894 }
895
896 #[test]
897 fn test_double() {

Callers

nothing calls this directly

Calls 4

runFunction · 0.85
cloneMethod · 0.80
subMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected