From ab32f03b107fdfef64a231fae53c7df0aa253cd4 Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Tue, 28 Feb 2023 18:34:22 -0800 Subject: [PATCH] fixed multiplication --- evm/src/bls381_arithmetic.rs | 4 ++-- evm/src/cpu/kernel/tests/bls381.rs | 16 ++++++++++++++++ evm/src/cpu/kernel/tests/mod.rs | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 evm/src/cpu/kernel/tests/bls381.rs diff --git a/evm/src/bls381_arithmetic.rs b/evm/src/bls381_arithmetic.rs index 88e27596..f25bce79 100644 --- a/evm/src/bls381_arithmetic.rs +++ b/evm/src/bls381_arithmetic.rs @@ -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, diff --git a/evm/src/cpu/kernel/tests/bls381.rs b/evm/src/cpu/kernel/tests/bls381.rs new file mode 100644 index 00000000..8b56abf1 --- /dev/null +++ b/evm/src/cpu/kernel/tests/bls381.rs @@ -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::(); + let g: Fp = rng.gen::(); + let fg = f*g; + + println!("{:#?}", f); + println!("{:#?}", g); + println!("{:#?}", fg); + + Ok(()) +} \ No newline at end of file diff --git a/evm/src/cpu/kernel/tests/mod.rs b/evm/src/cpu/kernel/tests/mod.rs index aab8298d..a0452d34 100644 --- a/evm/src/cpu/kernel/tests/mod.rs +++ b/evm/src/cpu/kernel/tests/mod.rs @@ -1,5 +1,6 @@ mod account_code; mod balance; +mod bls381; mod bn254; mod core; mod ecc;