This commit is contained in:
Dmitry Vagner 2023-04-19 13:19:06 -07:00
parent ca3a7f8ab3
commit 21a1a98a7d

View File

@ -102,13 +102,15 @@ fn test_mul_fp12() -> Result<()> {
Ok(())
}
fn setup_frob_fp6_test(f: Fp6<BN254>, n: usize) -> InterpreterMemoryInitialization {
InterpreterMemoryInitialization {
label: String::from("test_frob_fp254_6_") + &(n.to_string()),
fn run_frob_fp6_test(f: Fp6<BN254>, n: usize) -> Vec<U256> {
let setup = InterpreterMemoryInitialization {
label: format!("test_frob_fp254_6_{}", n),
stack: f.on_stack(),
segment: BnPairing,
memory: vec![],
}
};
let interpreter = run_interpreter_with_memory(setup).unwrap();
extract_stack(interpreter)
}
#[test]
@ -116,35 +118,34 @@ fn test_frob_fp6() -> Result<()> {
let mut rng = rand::thread_rng();
let f: Fp6<BN254> = rng.gen::<Fp6<BN254>>();
for n in 1..4 {
let setup_frob = setup_frob_fp6_test(f, n);
let intrptr_frob: Interpreter = run_interpreter_with_memory(setup_frob).unwrap();
let out_frob: Vec<U256> = extract_stack(intrptr_frob);
let exp_frob: Vec<U256> = f.frob(n).on_stack();
assert_eq!(out_frob, exp_frob);
let output: Vec<U256> = run_frob_fp6_test(f, n);
let expected: Vec<U256> = f.frob(n).on_stack();
assert_eq!(output, expected);
}
Ok(())
}
fn setup_frob_fp12_test(ptr: usize, f: Fp12<BN254>, n: usize) -> InterpreterMemoryInitialization {
InterpreterMemoryInitialization {
label: String::from("test_frob_fp254_12_") + &(n.to_string()),
fn run_frob_fp12_test(f: Fp12<BN254>, n: usize) -> Vec<U256> {
let ptr: usize = 200;
let setup = InterpreterMemoryInitialization {
label: format!("test_frob_fp254_12_{}", n),
stack: vec![U256::from(ptr)],
segment: BnPairing,
memory: vec![(ptr, f.on_stack())],
}
};
let interpreter = run_interpreter_with_memory(setup).unwrap();
interpreter.extract_kernel_memory(BnPairing, ptr..ptr + 12)
}
#[test]
fn test_frob_fp12() -> Result<()> {
let ptr: usize = 200;
let mut rng = rand::thread_rng();
let f: Fp12<BN254> = rng.gen::<Fp12<BN254>>();
for n in [1, 2, 3, 6] {
let setup_frob = setup_frob_fp12_test(ptr, f, n);
let intrptr_frob: Interpreter = run_interpreter_with_memory(setup_frob).unwrap();
let out_frob: Vec<U256> = intrptr_frob.extract_kernel_memory(BnPairing, ptr..ptr + 12);
let exp_frob: Vec<U256> = f.frob(n).on_stack();
assert_eq!(out_frob, exp_frob);
let output = run_frob_fp12_test(f, n);
let expected: Vec<U256> = f.frob(n).on_stack();
assert_eq!(output, expected);
}
Ok(())
}