2021-05-19 15:57:28 -07:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
use std::ops::Range;
|
|
|
|
|
|
2021-06-08 10:58:03 +02:00
|
|
|
use crate::field::extension_field::algebra::ExtensionAlgebra;
|
2021-06-08 11:30:39 +02:00
|
|
|
use crate::field::extension_field::target::{ExtensionAlgebraTarget, ExtensionTarget};
|
2021-07-22 14:00:55 +02:00
|
|
|
use crate::field::extension_field::{Extendable, FieldExtension};
|
2021-02-09 21:25:21 -08:00
|
|
|
use crate::field::field::Field;
|
2021-07-21 08:26:19 -07:00
|
|
|
use crate::proof::{Hash, HashTarget};
|
2021-02-09 21:25:21 -08:00
|
|
|
|
2021-06-24 14:11:47 +02:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
2021-05-30 13:25:53 -07:00
|
|
|
pub struct EvaluationVars<'a, F: Extendable<D>, const D: usize> {
|
|
|
|
|
pub(crate) local_constants: &'a [F::Extension],
|
|
|
|
|
pub(crate) local_wires: &'a [F::Extension],
|
2021-07-21 08:26:19 -07:00
|
|
|
pub(crate) public_inputs_hash: &'a Hash<F>,
|
2021-05-30 13:25:53 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-24 14:11:47 +02:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
2021-05-30 13:25:53 -07:00
|
|
|
pub struct EvaluationVarsBase<'a, F: Field> {
|
2021-02-09 21:25:21 -08:00
|
|
|
pub(crate) local_constants: &'a [F],
|
2021-03-18 12:44:45 -07:00
|
|
|
pub(crate) local_wires: &'a [F],
|
2021-07-21 08:26:19 -07:00
|
|
|
pub(crate) public_inputs_hash: &'a Hash<F>,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
|
|
|
|
|
2021-05-30 13:25:53 -07:00
|
|
|
impl<'a, F: Extendable<D>, const D: usize> EvaluationVars<'a, F, D> {
|
2021-06-08 10:58:03 +02:00
|
|
|
pub fn get_local_ext_algebra(
|
2021-05-30 13:25:53 -07:00
|
|
|
&self,
|
|
|
|
|
wire_range: Range<usize>,
|
2021-06-08 10:58:03 +02:00
|
|
|
) -> ExtensionAlgebra<F::Extension, D> {
|
2021-05-19 15:57:28 -07:00
|
|
|
debug_assert_eq!(wire_range.len(), D);
|
|
|
|
|
let arr = self.local_wires[wire_range].try_into().unwrap();
|
2021-06-08 10:58:03 +02:00
|
|
|
ExtensionAlgebra::from_basefield_array(arr)
|
2021-05-19 15:57:28 -07:00
|
|
|
}
|
2021-06-23 16:06:30 +02:00
|
|
|
|
|
|
|
|
pub fn remove_prefix(&mut self, prefix: &[bool]) {
|
|
|
|
|
self.local_constants = &self.local_constants[prefix.len()..];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, F: Field> EvaluationVarsBase<'a, F> {
|
2021-07-22 14:00:55 +02:00
|
|
|
pub fn get_local_ext<const D: usize>(&self, wire_range: Range<usize>) -> F::Extension
|
|
|
|
|
where
|
|
|
|
|
F: Extendable<D>,
|
|
|
|
|
{
|
|
|
|
|
debug_assert_eq!(wire_range.len(), D);
|
|
|
|
|
let arr = self.local_wires[wire_range].try_into().unwrap();
|
|
|
|
|
F::Extension::from_basefield_array(arr)
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 16:06:30 +02:00
|
|
|
pub fn remove_prefix(&mut self, prefix: &[bool]) {
|
|
|
|
|
self.local_constants = &self.local_constants[prefix.len()..];
|
|
|
|
|
}
|
2021-05-19 15:57:28 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:25:28 +02:00
|
|
|
impl<'a, const D: usize> EvaluationTargets<'a, D> {
|
|
|
|
|
pub fn remove_prefix(&mut self, prefix: &[bool]) {
|
|
|
|
|
self.local_constants = &self.local_constants[prefix.len()..];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 19:15:39 -07:00
|
|
|
#[derive(Copy, Clone)]
|
2021-05-30 13:25:53 -07:00
|
|
|
pub struct EvaluationTargets<'a, const D: usize> {
|
|
|
|
|
pub(crate) local_constants: &'a [ExtensionTarget<D>],
|
|
|
|
|
pub(crate) local_wires: &'a [ExtensionTarget<D>],
|
2021-07-21 08:26:19 -07:00
|
|
|
pub(crate) public_inputs_hash: &'a HashTarget,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
2021-05-24 17:31:55 +02:00
|
|
|
|
2021-05-30 13:25:53 -07:00
|
|
|
impl<'a, const D: usize> EvaluationTargets<'a, D> {
|
2021-06-08 11:30:39 +02:00
|
|
|
pub fn get_local_ext_algebra(&self, wire_range: Range<usize>) -> ExtensionAlgebraTarget<D> {
|
2021-05-24 17:31:55 +02:00
|
|
|
debug_assert_eq!(wire_range.len(), D);
|
|
|
|
|
let arr = self.local_wires[wire_range].try_into().unwrap();
|
2021-06-08 11:30:39 +02:00
|
|
|
ExtensionAlgebraTarget(arr)
|
2021-05-24 17:31:55 +02:00
|
|
|
}
|
|
|
|
|
}
|