bls method

This commit is contained in:
Dmitry Vagner 2023-03-27 21:10:23 -07:00
parent 5783a3745e
commit 3b95e01390
2 changed files with 8 additions and 4 deletions

View File

@ -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]

View File

@ -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<BLS381> for Standard {