mirror of https://github.com/zcash/orchard.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.
|
||||
|
||||
use std::array;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
|
||||
use halo2::{
|
||||
|
@ -20,7 +21,7 @@ pub trait PoseidonInstructions<F: FieldExt, S: Spec<F, T, RATE>, const T: usize,
|
|||
Chip<F>
|
||||
{
|
||||
/// 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.
|
||||
fn permute(
|
||||
|
@ -82,7 +83,7 @@ impl<
|
|||
{
|
||||
/// The word contained in this gadget.
|
||||
pub fn inner(&self) -> PoseidonChip::Word {
|
||||
self.inner
|
||||
self.inner.clone()
|
||||
}
|
||||
|
||||
/// Construct a [`Word`] gadget from the inner word.
|
||||
|
@ -144,7 +145,13 @@ impl<
|
|||
chip.initial_state(&mut layouter, &domain)
|
||||
.map(|state| Duplex {
|
||||
chip,
|
||||
sponge: Sponge::Absorbing([None; RATE]),
|
||||
sponge: Sponge::Absorbing(
|
||||
(0..RATE)
|
||||
.map(|_| None)
|
||||
.collect::<Vec<_>>()
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
),
|
||||
state,
|
||||
domain,
|
||||
})
|
||||
|
@ -205,7 +212,13 @@ impl<
|
|||
}
|
||||
|
||||
// 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.
|
||||
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),
|
||||
(None, Some(padding_value)) => {
|
||||
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> {
|
||||
state[..RATE]
|
||||
.iter()
|
||||
.map(|word| Some(*word))
|
||||
.map(|word| Some(word.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
.try_into()
|
||||
.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.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StateWord<F: FieldExt> {
|
||||
var: Cell,
|
||||
value: Option<F>,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! The Poseidon algebraic hash function.
|
||||
|
||||
use std::array;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::marker::PhantomData;
|
||||
|
@ -147,9 +148,13 @@ pub(crate) enum Sponge<F, const RATE: usize> {
|
|||
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 {
|
||||
let mut input = [None; RATE];
|
||||
let mut input: [Option<F>; RATE] = (0..RATE)
|
||||
.map(|_| None)
|
||||
.collect::<Vec<_>>()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
input[0] = Some(val);
|
||||
Sponge::Absorbing(input)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue