franklin_crypto/plonk/circuit/
tables.rsuse crate::bellman::pairing::Engine;
use crate::bellman::pairing::ff::{BitIterator, Field, PrimeField, PrimeFieldRepr};
use crate::bellman::SynthesisError;
use crate::bellman::plonk::better_better_cs::cs::{
ArithmeticTerm, Coefficient, ConstraintSystem, Gate, GateInternal, LinearCombinationOfTerms, MainGate, MainGateTerm, PlonkConstraintSystemParams, PlonkCsWidth4WithNextStepParams,
PolynomialInConstraint, PolynomialMultiplicativeTerm, TimeDilation, TrivialAssembly, Variable, Width4MainGateWithDNext,
};
use crate::bellman::plonk::better_better_cs::data_structures::PolyIdentifier;
use crate::bellman::plonk::better_better_cs::lookup_tables::*;
use super::bigint_new::*;
use super::*;
use crate::plonk::circuit::Assignment;
use crate::plonk::circuit::allocated_num::{AllocatedNum, Num};
use crate::plonk::circuit::linear_combination::LinearCombination;
use crate::plonk::circuit::simple_term::Term;
pub use crate::bellman::plonk::better_better_cs::lookup_tables::RANGE_CHECK_SINGLE_APPLICATION_TABLE_NAME;
const DEFAULT_RANGE_TABLE_NAME_PREFIX: &'static str = "Range check table over 3 columns for";
pub fn inscribe_default_range_table_for_bit_width_over_first_three_columns<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS, width: usize) -> Result<(), SynthesisError> {
let over = vec![PolyIdentifier::VariablesPolynomial(0), PolyIdentifier::VariablesPolynomial(1), PolyIdentifier::VariablesPolynomial(2)];
let table = LookupTableApplication::new_range_table_of_width_3(width, over)?;
cs.add_table(table)?;
Ok(())
}
pub fn inscribe_combined_bitwise_ops_and_range_table<E, CS>(cs: &mut CS, width: usize) -> Result<(), SynthesisError>
where
E: Engine,
CS: ConstraintSystem<E>,
{
let over = vec![PolyIdentifier::VariablesPolynomial(0), PolyIdentifier::VariablesPolynomial(1), PolyIdentifier::VariablesPolynomial(2)];
use crate::plonk::circuit::bigint_new::*;
let name = BITWISE_LOGICAL_OPS_TABLE_NAME;
let table = LookupTableApplication::new(name, CombinedBitwiseLogicRangeTable::new(&name, width), over.clone(), None, true);
cs.add_table(table)?;
Ok(())
}
pub fn inscribe_range_table_for_bit_width_over_first_three_columns<E: Engine, CS: ConstraintSystem<E>>(cs: &mut CS, width: usize) -> Result<String, SynthesisError> {
assert!(width > 0);
let generator = move || format!("{} {} bits over A/B/C", DEFAULT_RANGE_TABLE_NAME_PREFIX, width);
let name = (&generator)();
if let Ok(..) = cs.get_table(&name) {
return Ok(name);
}
let table_internal = RangeCheckTableOverOneColumnOfWidth3::new(width);
let over = vec![PolyIdentifier::VariablesPolynomial(0), PolyIdentifier::VariablesPolynomial(1), PolyIdentifier::VariablesPolynomial(2)];
let name_generator = Box::new(generator) as Box<dyn Fn() -> String + Send + Sync>;
let application = LookupTableApplication::new("Range check table", table_internal, over, Some(name_generator), true);
cs.add_table(application)?;
Ok(name)
}
pub fn get_name_for_range_table_for_bit_width_over_first_three_columns(width: usize) -> String {
assert!(width > 0);
format!("{} {} bits over A/B/C", DEFAULT_RANGE_TABLE_NAME_PREFIX, width)
}