This commit is contained in:
Dmitry Vagner 2022-10-12 10:06:34 -04:00
parent f83504b16e
commit d1bad81985
4 changed files with 28 additions and 2 deletions

View File

@ -33,6 +33,7 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/curve/secp256k1/moddiv.asm"),
include_str!("asm/exp.asm"),
include_str!("asm/halt.asm"),
include_str!("asm/fields/fp6mul.asm"),
include_str!("asm/main.asm"),
include_str!("asm/memory/core.asm"),
include_str!("asm/memory/memcpy.asm"),

View File

@ -1,4 +1,5 @@
%macro mul_Fp6
mul_Fp6:
DUP6
// stack: c0_, d1, c2_, d0, c0, d2_, c0_, d2, d1_, c1, c2, d0_, c1_
DUP12
@ -315,4 +316,5 @@
// stack: d2c0_ + d2_c0 + d0c2_ + d1c1_ + d1_c1 + d0_c2, 9d1c2_ + d1_c2 + d2c1_ + d2_c1 + d1c2 + d2c1 - d2_c1_ + d1_c2_ + d0c0 - d0_c0_, c0d1 + c1d0 + 9c2d2_ + c2_d2 - c2d2 - c2_d2_ - c0_d1_ + c1_d0_, c0d1_ + c0_d1 + c1d0_ + c1_d0 + 9c2d2 - c2_d2_ + c2d2_ + c2_d2, c0d2 + c1d1 + c2d0 - c0_d2_ + c1_d1_ + c2_d0_, 9d1c2 + d2c1 - d2_c1_ + d1_c2_ - d1c2_ + d1_c2 + d2c1_ + d2_c1 + c0d0_ + c0_d0
SWAP5
// stack: 9d1c2 + d2c1 - d2_c1_ + d1_c2_ - d1c2_ + d1_c2 + d2c1_ + d2_c1 + c0d0_ + c0_d0, 9d1c2_ + d1_c2 + d2c1_ + d2_c1 + d1c2 + d2c1 - d2_c1_ + d1_c2_ + d0c0 - d0_c0_, c0d1 + c1d0 + 9c2d2_ + c2_d2 - c2d2 - c2_d2_ - c0_d1_ + c1_d0_, c0d1_ + c0_d1 + c1d0_ + c1_d0 + 9c2d2 - c2_d2_ + c2d2_ + c2_d2, c0d2 + c1d1 + c2d0 - c0_d2_ + c1_d1_ + c2_d0_, d2c0_ + d2_c0 + d0c2_ + d1c1_ + d1_c1 + d0_c2
%endmacro
%jump(0xdeadbeef)

View File

@ -0,0 +1,22 @@
use anyhow::Result;
use ethereum_types::U256;
use crate::cpu::kernel::aggregator::combined_kernel;
use crate::cpu::kernel::interpreter::run_with_kernel;
#[test]
fn test_field() -> Result<()> {
let kernel = combined_kernel();
let initial_offset = kernel.global_labels["mul_Fp6"];
let initial_stack: Vec<U256> = vec![0, 0, 3, 1, 0, 1, 0, 1, 0, 1, 0, 0].iter().map(|&x| U256::from(x as u32)).collect();
let final_stack: Vec<U256> = run_with_kernel(&kernel, initial_offset, initial_stack)?
.stack()
.to_vec();
let expected: Vec<U256> = vec![2, 12, -1, 1, 3, 0].iter().map(|&x| U256::from(x as u32)).collect();
assert_eq!(final_stack, expected);
Ok(())
}

View File

@ -3,6 +3,7 @@ mod curve_ops;
mod ecrecover;
mod exp;
mod hash;
mod fields;
mod mpt;
mod packing;
mod ripemd;