From 3b95e0139062b594045b1541ca70910eb841e10d Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Mon, 27 Mar 2023 21:10:23 -0700 Subject: [PATCH] bls method --- evm/src/cpu/kernel/tests/bls381.rs | 5 +---- evm/src/extension_tower.rs | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/evm/src/cpu/kernel/tests/bls381.rs b/evm/src/cpu/kernel/tests/bls381.rs index afd22a14..b8315b6f 100644 --- a/evm/src/cpu/kernel/tests/bls381.rs +++ b/evm/src/cpu/kernel/tests/bls381.rs @@ -1,5 +1,4 @@ use anyhow::Result; -use ethereum_types::U512; use rand::Rng; use crate::cpu::kernel::interpreter::{ @@ -19,9 +18,7 @@ fn run_and_return_bls(label: String, x: BLS381, y: BLS381) -> BLS381 { }; let interpreter = run_interpreter_with_memory(setup).unwrap(); let output = interpreter.stack(); - BLS381 { - val: U512::from(output[1]) + (U512::from(output[0]) << 256), - } + BLS381::from_limbs(output[0], output[1]) } #[test] diff --git a/evm/src/extension_tower.rs b/evm/src/extension_tower.rs index ddcfe254..72a1106c 100644 --- a/evm/src/extension_tower.rs +++ b/evm/src/extension_tower.rs @@ -144,6 +144,13 @@ impl BLS381 { pub fn hi(self) -> U256 { U256(self.val.0[4..].try_into().unwrap()) } + + pub fn from_limbs(hi: U256, lo: U256) -> BLS381 { + let mut val = [0u64; 8]; + val[..4].copy_from_slice(&lo.0); + val[4..].copy_from_slice(&hi.0); + BLS381 { val: U512(val) } + } } impl Distribution for Standard {