fixed multiplication

This commit is contained in:
Dmitry Vagner 2023-02-28 18:34:22 -08:00
parent bde5c557a6
commit ab32f03b10
3 changed files with 19 additions and 2 deletions

View File

@ -93,8 +93,8 @@ impl Mul for Fp {
fn mul(self, other: Self) -> Self {
let b256: U512 = U512([0, 0, 0, 0, 1, 0, 0, 0]);
// x1, y1 are at most (q-1) // 2^256 < 2^125
let (x0, x1) = self.val.div_mod(b256);
let (y0, y1) = other.val.div_mod(b256);
let (x1, x0) = self.val.div_mod(b256);
let (y1, y0) = other.val.div_mod(b256);
let z00 = Fp {
val: x0.saturating_mul(y0) % BLS_BASE,

View File

@ -0,0 +1,16 @@
use crate::bls381_arithmetic::Fp;
use rand::Rng;
#[test]
fn test_bls_mul() -> Result<(),()> {
let mut rng = rand::thread_rng();
let f: Fp = rng.gen::<Fp>();
let g: Fp = rng.gen::<Fp>();
let fg = f*g;
println!("{:#?}", f);
println!("{:#?}", g);
println!("{:#?}", fg);
Ok(())
}

View File

@ -1,5 +1,6 @@
mod account_code;
mod balance;
mod bls381;
mod bn254;
mod core;
mod ecc;