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