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

Function test_sub

bitvm/src/bn254/fr.rs:87–112  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85
86 #[test]
87 fn test_sub() {
88 println!("Fr.sub: {} bytes", Fr::sub(0, 1).len());
89
90 let m = BigUint::from_str_radix(Fr::MODULUS, 16).unwrap();
91
92 let mut prng = ChaCha20Rng::seed_from_u64(0);
93
94 for _ in 0..100 {
95 let a: BigUint = prng.sample(RandomBits::new(254));
96 let b: BigUint = prng.sample(RandomBits::new(254));
97
98 let a = a.rem(&m);
99 let b = b.rem(&m);
100 let c: BigUint = a.clone().add(&m).sub(b.clone()).rem(&m);
101
102 let script = script! {
103 { Fr::push_u32_le(&a.to_u32_digits()) }
104 { Fr::push_u32_le(&b.to_u32_digits()) }
105 { Fr::sub(1, 0) }
106 { Fr::push_u32_le(&c.to_u32_digits()) }
107 { Fr::equalverify(1, 0) }
108 OP_TRUE
109 };
110 run(script);
111 }
112 }
113
114 #[test]
115 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