mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 06:13:07 +00:00
works
This commit is contained in:
parent
1f0776281e
commit
7dda0effec
@ -12,9 +12,9 @@ use crate::extension_tower::{FieldExt, Fp12, Fp2, Fp6, Stack, BN254};
|
||||
use crate::memory::segments::Segment::BnPairing;
|
||||
|
||||
fn run_bn_mul_fp6(f: Fp6<BN254>, g: Fp6<BN254>, label: &str) -> Fp6<BN254> {
|
||||
let mut stack = f.to_stack();
|
||||
let mut stack = f.to_stack().to_vec();
|
||||
if label == "mul_fp254_6" {
|
||||
stack.extend(g.to_stack());
|
||||
stack.extend(g.to_stack().to_vec());
|
||||
}
|
||||
stack.push(U256::from(0xdeadbeefu32));
|
||||
let setup = InterpreterMemoryInitialization {
|
||||
@ -61,7 +61,7 @@ fn run_bn_mul_fp12(f: Fp12<BN254>, g: Fp12<BN254>, label: &str) -> Fp12<BN254> {
|
||||
label: label.to_string(),
|
||||
stack,
|
||||
segment: BnPairing,
|
||||
memory: vec![(in0, f.to_stack()), (in1, g.to_stack())],
|
||||
memory: vec![(in0, f.to_stack().to_vec()), (in1, g.to_stack().to_vec())],
|
||||
};
|
||||
let interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output = interpreter.extract_kernel_memory(BnPairing, out..out + 12);
|
||||
@ -89,7 +89,7 @@ fn test_bn_mul_fp12() -> Result<()> {
|
||||
fn run_bn_frob_fp6(n: usize, f: Fp6<BN254>) -> Fp6<BN254> {
|
||||
let setup = InterpreterMemoryInitialization {
|
||||
label: format!("test_frob_fp254_6_{}", n),
|
||||
stack: f.to_stack(),
|
||||
stack: f.to_stack().to_vec(),
|
||||
segment: BnPairing,
|
||||
memory: vec![],
|
||||
};
|
||||
@ -115,7 +115,7 @@ fn run_bn_frob_fp12(n: usize, f: Fp12<BN254>) -> Fp12<BN254> {
|
||||
label: format!("test_frob_fp254_12_{}", n),
|
||||
stack: vec![U256::from(ptr)],
|
||||
segment: BnPairing,
|
||||
memory: vec![(ptr, f.to_stack())],
|
||||
memory: vec![(ptr, f.to_stack().to_vec())],
|
||||
};
|
||||
let interpeter: Interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output: Vec<U256> = interpeter.extract_kernel_memory(BnPairing, ptr..ptr + 12);
|
||||
@ -144,7 +144,7 @@ fn test_bn_inv_fp12() -> Result<()> {
|
||||
label: "inv_fp254_12".to_string(),
|
||||
stack: vec![U256::from(ptr), U256::from(inv), U256::from(0xdeadbeefu32)],
|
||||
segment: BnPairing,
|
||||
memory: vec![(ptr, f.to_stack())],
|
||||
memory: vec![(ptr, f.to_stack().to_vec())],
|
||||
};
|
||||
let interpreter: Interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output: Vec<U256> = interpreter.extract_kernel_memory(BnPairing, inv..inv + 12);
|
||||
@ -165,12 +165,12 @@ fn test_bn_final_exponentiation() -> Result<()> {
|
||||
label: "bn254_invariant_exponent".to_string(),
|
||||
stack: vec![U256::from(ptr), U256::from(0xdeadbeefu32)],
|
||||
segment: BnPairing,
|
||||
memory: vec![(ptr, f.to_stack())],
|
||||
memory: vec![(ptr, f.to_stack().to_vec())],
|
||||
};
|
||||
|
||||
let interpreter: Interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output: Vec<U256> = interpreter.extract_kernel_memory(BnPairing, ptr..ptr + 12);
|
||||
let expected: Vec<U256> = invariant_exponent(f).to_stack();
|
||||
let expected: Vec<U256> = invariant_exponent(f).to_stack().to_vec();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
|
||||
@ -250,7 +250,7 @@ fn test_bn_miller_loop() -> Result<()> {
|
||||
};
|
||||
let interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output: Vec<U256> = interpreter.extract_kernel_memory(BnPairing, out..out + 12);
|
||||
let expected = miller_loop(CURVE_GENERATOR, TWISTED_GENERATOR).to_stack();
|
||||
let expected = miller_loop(CURVE_GENERATOR, TWISTED_GENERATOR).to_stack().to_vec();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
|
||||
@ -278,7 +278,7 @@ fn test_bn_tate_pairing() -> Result<()> {
|
||||
};
|
||||
let interpreter = run_interpreter_with_memory(setup).unwrap();
|
||||
let output: Vec<U256> = interpreter.extract_kernel_memory(BnPairing, out..out + 12);
|
||||
let expected = tate(CURVE_GENERATOR, TWISTED_GENERATOR).to_stack();
|
||||
let expected = tate(CURVE_GENERATOR, TWISTED_GENERATOR).to_stack().to_vec();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
use std::mem::transmute;
|
||||
use std::ops::{Add, Div, Mul, Neg, Sub};
|
||||
|
||||
use ethereum_types::{U256, U512};
|
||||
use plonky2::field::types::Field;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
use rand::Rng;
|
||||
|
||||
@ -1251,61 +1249,63 @@ impl<T: FieldExt + Stack> Stack for Fp2<T> {
|
||||
}
|
||||
|
||||
fn from_stack(stack: &[U256]) -> Fp2<T> {
|
||||
let re = T::from_stack(&stack[0..2]);
|
||||
let im = T::from_stack(&stack[2..4]);
|
||||
let field_size = T::SIZE;
|
||||
let re = T::from_stack(&stack[0..field_size]);
|
||||
let im = T::from_stack(&stack[field_size..2*field_size]);
|
||||
Fp2 { re, im }
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T> Stack for Fp6<T>
|
||||
// where
|
||||
// T: FieldExt,
|
||||
// Fp2<T>: Adj,
|
||||
// Fp2<T>: Stack,
|
||||
// {
|
||||
// const SIZE: usize = 3 * Fp2::<T>::SIZE;
|
||||
impl<T> Stack for Fp6<T>
|
||||
where
|
||||
T: FieldExt,
|
||||
Fp2<T>: Adj,
|
||||
Fp2<T>: Stack,
|
||||
{
|
||||
const SIZE: usize = 3 * Fp2::<T>::SIZE;
|
||||
|
||||
// fn to_stack(&self) -> &[U256] {
|
||||
// let t0 = self.t0.to_stack();
|
||||
// let t1 = self.t1.to_stack();
|
||||
// let t2 = self.t2.to_stack();
|
||||
fn to_stack(&self) -> &[U256] {
|
||||
let t0 = self.t0.to_stack();
|
||||
let t1 = self.t1.to_stack();
|
||||
let t2 = self.t2.to_stack();
|
||||
|
||||
// let mut combined: Vec<U256> = Vec::new();
|
||||
// combined.extend_from_slice(t0);
|
||||
// combined.extend_from_slice(t1);
|
||||
// combined.extend_from_slice(t2);
|
||||
// Box::leak(combined.into_boxed_slice())
|
||||
// }
|
||||
let mut combined: Vec<U256> = Vec::new();
|
||||
combined.extend_from_slice(t0);
|
||||
combined.extend_from_slice(t1);
|
||||
combined.extend_from_slice(t2);
|
||||
Box::leak(combined.into_boxed_slice())
|
||||
}
|
||||
|
||||
// fn from_stack(stack: &[U256]) -> Self {
|
||||
// let f = [
|
||||
// T::from_stack(&stack[0..2]),
|
||||
// T::from_stack(&stack[2..4]),
|
||||
// T::from_stack(&stack[4..6]),
|
||||
// ];
|
||||
// f.copy_from_slice(stack);
|
||||
// unsafe { transmute(f) }
|
||||
// }
|
||||
// }
|
||||
fn from_stack(stack: &[U256]) -> Self {
|
||||
let field_size = Fp2::<T>::SIZE;
|
||||
let t0 = Fp2::<T>::from_stack(&stack[0..field_size]);
|
||||
let t1 = Fp2::<T>::from_stack(&stack[field_size..2*field_size]);
|
||||
let t2 = Fp2::<T>::from_stack(&stack[2*field_size..3*field_size]);
|
||||
Fp6 { t0, t1, t2 }
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T> Stack for Fp12<T>
|
||||
// where
|
||||
// T: FieldExt,
|
||||
// Fp2<T>: Adj,
|
||||
// Fp6<T>: Stack,{
|
||||
// const SIZE: usize = 2 * Fp6::<T>::SIZE;
|
||||
impl<T> Stack for Fp12<T>
|
||||
where
|
||||
T: FieldExt,
|
||||
Fp2<T>: Adj,
|
||||
Fp6<T>: Stack,{
|
||||
const SIZE: usize = 2 * Fp6::<T>::SIZE;
|
||||
|
||||
// fn to_stack(&self) -> &[U256] {
|
||||
// let z0 = self.z0.to_stack();
|
||||
// let z1 = self.z1.to_stack();
|
||||
fn to_stack(&self) -> &[U256] {
|
||||
let z0 = self.z0.to_stack();
|
||||
let z1 = self.z1.to_stack();
|
||||
|
||||
// let mut combined: Vec<U256> = Vec::new();
|
||||
// combined.extend_from_slice(z0);
|
||||
// combined.extend_from_slice(z1);
|
||||
// Box::leak(combined.into_boxed_slice())
|
||||
// }
|
||||
let mut combined: Vec<U256> = Vec::new();
|
||||
combined.extend_from_slice(z0);
|
||||
combined.extend_from_slice(z1);
|
||||
Box::leak(combined.into_boxed_slice())
|
||||
}
|
||||
|
||||
// fn from_stack(stack: &[U256]) -> Self {
|
||||
// let f = [T::from_stack(&stack[0..6]), T::from_stack(&stack[6..12])];
|
||||
// }
|
||||
// }
|
||||
fn from_stack(stack: &[U256]) -> Self {
|
||||
let field_size = Fp6::<T>::SIZE;
|
||||
let z0 = Fp6::<T>::from_stack(&stack[0..field_size]);
|
||||
let z1 = Fp6::<T>::from_stack(&stack[field_size..2*field_size]);
|
||||
Fp12 { z0, z1 }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user