poseidon: Return CellValue from squeeze()

This commit is contained in:
therealyingtong 2021-11-19 00:04:27 -05:00
parent de37248749
commit 0417e233c3
3 changed files with 7 additions and 13 deletions

View File

@ -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.

View File

@ -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)?;

View File

@ -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)
},
)
}