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

Function test_add

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

Source from the content-addressed store, hash-verified

57
58 #[test]
59 fn test_add() {
60 println!("Fr.add: {} bytes", Fr::add(0, 1).len());
61
62 let m = BigUint::from_str_radix(Fr::MODULUS, 16).unwrap();
63
64 let mut prng = ChaCha20Rng::seed_from_u64(0);
65
66 for _ in 0..100 {
67 let a: BigUint = prng.sample(RandomBits::new(254));
68 let b: BigUint = prng.sample(RandomBits::new(254));
69
70 let a = a.rem(&m);
71 let b = b.rem(&m);
72 let c: BigUint = a.clone().add(b.clone()).rem(&m);
73
74 let script = script! {
75 { Fr::push_u32_le(&a.to_u32_digits()) }
76 { Fr::push_u32_le(&b.to_u32_digits()) }
77 { Fr::add(1, 0) }
78 { Fr::push_u32_le(&c.to_u32_digits()) }
79 { Fr::equalverify(1, 0) }
80 OP_TRUE
81 };
82 run(script);
83 }
84 }
85
86 #[test]
87 fn test_sub() {

Callers

nothing calls this directly

Calls 3

runFunction · 0.85
cloneMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected