| 839 | |
| 840 | #[test] |
| 841 | fn test_add() { |
| 842 | println!("Fq.add: {} bytes", Fq::add(0, 1).len()); |
| 843 | |
| 844 | let m = BigUint::from_str_radix(Fq::MODULUS, 16).unwrap(); |
| 845 | |
| 846 | let mut prng = ChaCha20Rng::seed_from_u64(0); |
| 847 | |
| 848 | for _ in 0..100 { |
| 849 | let a: BigUint = prng.sample(RandomBits::new(254)); |
| 850 | let b: BigUint = prng.sample(RandomBits::new(254)); |
| 851 | |
| 852 | let a = a.rem(&m); |
| 853 | let b = b.rem(&m); |
| 854 | let c: BigUint = a.clone().add(b.clone()).rem(&m); |
| 855 | |
| 856 | let script = script! { |
| 857 | { Fq::push_u32_le(&a.to_u32_digits()) } |
| 858 | { Fq::push_u32_le(&b.to_u32_digits()) } |
| 859 | { Fq::add(1, 0) } |
| 860 | { Fq::push_u32_le(&c.to_u32_digits()) } |
| 861 | { Fq::equalverify(1, 0) } |
| 862 | OP_TRUE |
| 863 | }; |
| 864 | run(script); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | #[test] |
| 869 | fn test_sub() { |