Adjustments to APIs in sinsemilla::chip and sinsemilla::message.

This commit is contained in:
therealyingtong 2021-06-21 23:27:13 +08:00
parent c43c91b796
commit 6fdee71667
2 changed files with 18 additions and 16 deletions

View File

@ -60,13 +60,19 @@ pub struct SinsemillaConfig {
lambda_2: Column<Advice>,
/// The lookup table where $(\mathsf{idx}, x_p, y_p)$ are loaded for the $2^K$
/// generators of the Sinsemilla hash.
generator_table: GeneratorTableConfig,
pub(super) generator_table: GeneratorTableConfig,
/// Fixed column shared by the whole circuit. This is used to load the
/// x-coordinate of the domain $Q$, which is then constrained to equal the
/// initial $x_a$.
constants: Column<Fixed>,
/// Permutation over all advice columns and the `constants` fixed column.
perm: Permutation,
// Permutation over all advice columns and the `constants` fixed column.
pub(super) perm: Permutation,
}
impl SinsemillaConfig {
pub fn advices(&self) -> [Column<Advice>; 5] {
[self.bits, self.lambda_1, self.lambda_2, self.x_a, self.x_p]
}
}
#[derive(Eq, PartialEq, Clone, Debug)]

View File

@ -34,25 +34,17 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize, const MAX_WORDS: usize> std::
/// cannot exceed the base field's `NUM_BITS`.
#[derive(Copy, Clone, Debug)]
pub struct MessagePiece<F: FieldExt, const K: usize> {
cell: Cell,
field_elem: Option<F>,
cell_value: CellValue<F>,
/// The number of K-bit words in this message piece.
num_words: usize,
}
#[allow(clippy::from_over_into)]
impl<F: FieldExt + PrimeFieldBits, const K: usize> Into<CellValue<F>> for MessagePiece<F, K> {
fn into(self) -> CellValue<F> {
CellValue::new(self.cell(), self.field_elem())
}
}
impl<F: FieldExt + PrimeFieldBits, const K: usize> MessagePiece<F, K> {
pub fn new(cell: Cell, field_elem: Option<F>, num_words: usize) -> Self {
assert!(num_words * K < F::NUM_BITS as usize);
let cell_value = CellValue::new(cell, field_elem);
Self {
cell,
field_elem,
cell_value,
num_words,
}
}
@ -62,10 +54,14 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize> MessagePiece<F, K> {
}
pub fn cell(&self) -> Cell {
self.cell
self.cell_value.cell()
}
pub fn field_elem(&self) -> Option<F> {
self.field_elem
self.cell_value.value()
}
pub fn cell_value(&self) -> CellValue<F> {
self.cell_value
}
}