mirror of https://github.com/zcash/halo2.git
poseidon: Return CellValue from squeeze()
This commit is contained in:
parent
de37248749
commit
0417e233c3
|
@ -488,12 +488,10 @@ impl plonk::Circuit<pallas::Base> for Circuit {
|
|||
layouter.namespace(|| "Poseidon init"),
|
||||
ConstantLength::<2>,
|
||||
)?;
|
||||
let poseidon_output = poseidon_hasher.hash(
|
||||
poseidon_hasher.hash(
|
||||
layouter.namespace(|| "Poseidon hash (nk, rho_old)"),
|
||||
poseidon_message,
|
||||
)?;
|
||||
let poseidon_output: CellValue<pallas::Base> = poseidon_output.inner().into();
|
||||
poseidon_output
|
||||
)?
|
||||
};
|
||||
|
||||
// Add hash output to psi.
|
||||
|
|
|
@ -20,7 +20,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>>;
|
||||
type Word: Copy + fmt::Debug + From<CellValue<F>> + Into<CellValue<F>>;
|
||||
|
||||
/// Applies the Poseidon permutation to the given state.
|
||||
fn permute(
|
||||
|
@ -182,10 +182,7 @@ impl<
|
|||
}
|
||||
|
||||
/// Squeezes an element from the sponge.
|
||||
pub fn squeeze(
|
||||
&mut self,
|
||||
mut layouter: impl Layouter<F>,
|
||||
) -> Result<Word<F, PoseidonChip, S, T, RATE>, Error> {
|
||||
pub fn squeeze(&mut self, mut layouter: impl Layouter<F>) -> Result<CellValue<F>, Error> {
|
||||
loop {
|
||||
match self.sponge {
|
||||
Sponge::Absorbing(ref input) => {
|
||||
|
@ -200,7 +197,7 @@ impl<
|
|||
Sponge::Squeezing(ref mut output) => {
|
||||
for entry in output.iter_mut() {
|
||||
if let Some(inner) = entry.take() {
|
||||
return Ok(Word { inner });
|
||||
return Ok(inner.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +250,7 @@ impl<
|
|||
mut self,
|
||||
mut layouter: impl Layouter<F>,
|
||||
message: [CellValue<F>; L],
|
||||
) -> Result<Word<F, PoseidonChip, S, T, RATE>, Error> {
|
||||
) -> Result<CellValue<F>, Error> {
|
||||
for (i, value) in array::IntoIter::new(message).enumerate() {
|
||||
self.duplex
|
||||
.absorb(layouter.namespace(|| format!("absorb_{}", i)), value)?;
|
||||
|
|
|
@ -821,8 +821,7 @@ mod tests {
|
|||
0,
|
||||
|| self.output.ok_or(Error::SynthesisError),
|
||||
)?;
|
||||
let word: StateWord<_> = output.inner;
|
||||
region.constrain_equal(word.var, expected_var)
|
||||
region.constrain_equal(output.cell(), expected_var)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue