mirror of https://github.com/zcash/halo2.git
circuit: Remove `Copy` impl from `poseidon::pow5::StateWord`
We will be making it a newtype around `halo2::circuit::AssignedCell`, which does not impl `Copy`.
This commit is contained in:
parent
e99fc92e4b
commit
5cb838f1a2
|
@ -1,6 +1,7 @@
|
||||||
//! Gadget and chips for the Poseidon algebraic hash function.
|
//! Gadget and chips for the Poseidon algebraic hash function.
|
||||||
|
|
||||||
use std::array;
|
use std::array;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use halo2::{
|
use halo2::{
|
||||||
|
@ -20,7 +21,7 @@ pub trait PoseidonInstructions<F: FieldExt, S: Spec<F, T, RATE>, const T: usize,
|
||||||
Chip<F>
|
Chip<F>
|
||||||
{
|
{
|
||||||
/// Variable representing the word over which the Poseidon permutation operates.
|
/// Variable representing the word over which the Poseidon permutation operates.
|
||||||
type Word: Copy + fmt::Debug + From<CellValue<F>> + Into<CellValue<F>>;
|
type Word: Clone + fmt::Debug + From<CellValue<F>> + Into<CellValue<F>>;
|
||||||
|
|
||||||
/// Applies the Poseidon permutation to the given state.
|
/// Applies the Poseidon permutation to the given state.
|
||||||
fn permute(
|
fn permute(
|
||||||
|
@ -82,7 +83,7 @@ impl<
|
||||||
{
|
{
|
||||||
/// The word contained in this gadget.
|
/// The word contained in this gadget.
|
||||||
pub fn inner(&self) -> PoseidonChip::Word {
|
pub fn inner(&self) -> PoseidonChip::Word {
|
||||||
self.inner
|
self.inner.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`Word`] gadget from the inner word.
|
/// Construct a [`Word`] gadget from the inner word.
|
||||||
|
@ -144,7 +145,13 @@ impl<
|
||||||
chip.initial_state(&mut layouter, &domain)
|
chip.initial_state(&mut layouter, &domain)
|
||||||
.map(|state| Duplex {
|
.map(|state| Duplex {
|
||||||
chip,
|
chip,
|
||||||
sponge: Sponge::Absorbing([None; RATE]),
|
sponge: Sponge::Absorbing(
|
||||||
|
(0..RATE)
|
||||||
|
.map(|_| None)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
state,
|
state,
|
||||||
domain,
|
domain,
|
||||||
})
|
})
|
||||||
|
@ -205,7 +212,13 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
// We've already squeezed out all available elements
|
// We've already squeezed out all available elements
|
||||||
self.sponge = Sponge::Absorbing([None; RATE]);
|
self.sponge = Sponge::Absorbing(
|
||||||
|
(0..RATE)
|
||||||
|
.map(|_| None)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ impl<F: FieldExt, S: Spec<F, WIDTH, RATE>, const WIDTH: usize, const RATE: usize
|
||||||
|
|
||||||
// Load the input and padding into this region.
|
// Load the input and padding into this region.
|
||||||
let load_input_word = |i: usize| {
|
let load_input_word = |i: usize| {
|
||||||
let (constraint_var, value) = match (input[i], padding_values[i]) {
|
let (constraint_var, value) = match (input[i].clone(), padding_values[i]) {
|
||||||
(Some(word), None) => (word.var, word.value),
|
(Some(word), None) => (word.var, word.value),
|
||||||
(None, Some(padding_value)) => {
|
(None, Some(padding_value)) => {
|
||||||
let padding_var = region.assign_fixed(
|
let padding_var = region.assign_fixed(
|
||||||
|
@ -395,7 +395,7 @@ impl<F: FieldExt, S: Spec<F, WIDTH, RATE>, const WIDTH: usize, const RATE: usize
|
||||||
fn get_output(state: &State<Self::Word, WIDTH>) -> SpongeState<Self::Word, RATE> {
|
fn get_output(state: &State<Self::Word, WIDTH>) -> SpongeState<Self::Word, RATE> {
|
||||||
state[..RATE]
|
state[..RATE]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|word| Some(*word))
|
.map(|word| Some(word.clone()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -403,7 +403,7 @@ impl<F: FieldExt, S: Spec<F, WIDTH, RATE>, const WIDTH: usize, const RATE: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A word in the Poseidon state.
|
/// A word in the Poseidon state.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct StateWord<F: FieldExt> {
|
pub struct StateWord<F: FieldExt> {
|
||||||
var: Cell,
|
var: Cell,
|
||||||
value: Option<F>,
|
value: Option<F>,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! The Poseidon algebraic hash function.
|
//! The Poseidon algebraic hash function.
|
||||||
|
|
||||||
use std::array;
|
use std::array;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -147,9 +148,13 @@ pub(crate) enum Sponge<F, const RATE: usize> {
|
||||||
Squeezing(SpongeState<F, RATE>),
|
Squeezing(SpongeState<F, RATE>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Copy, const RATE: usize> Sponge<F, RATE> {
|
impl<F: fmt::Debug, const RATE: usize> Sponge<F, RATE> {
|
||||||
pub(crate) fn absorb(val: F) -> Self {
|
pub(crate) fn absorb(val: F) -> Self {
|
||||||
let mut input = [None; RATE];
|
let mut input: [Option<F>; RATE] = (0..RATE)
|
||||||
|
.map(|_| None)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.try_into()
|
||||||
|
.unwrap();
|
||||||
input[0] = Some(val);
|
input[0] = Some(val);
|
||||||
Sponge::Absorbing(input)
|
Sponge::Absorbing(input)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue