Skip to content

Commit

Permalink
Merge pull request privacy-scaling-explorations#37 from input-output-…
Browse files Browse the repository at this point in the history
…hk/fixes/address-pr-4-comments

Address comments in PR #4
  • Loading branch information
iquerejeta authored Dec 15, 2023
2 parents 6c816a0 + d569b21 commit aceeb4e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions halo2_proofs/src/poseidon/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ impl DuplexPhase {
/// <https://hackmd.io/bHgsH6mMStCVibM_wYvb2w>.
fn encode(&self) -> u32 {
match *self {
Self::Absorb(length) => (1 << 31) | length,
Self::Absorb(length) => {
assert!(length < (1 << 31), "length must be less than 2^31");
(1 << 31) | length
}
Self::Squeeze(length) => length,
}
}
Expand Down Expand Up @@ -191,7 +194,7 @@ impl<const L: usize> DuplexPattern<L> {
.chain(std::iter::once(separator))
.collect::<Vec<F>>()
.try_into()
.unwrap(); // This `unwrap` should never fail, since the vector contains `L_PLUS_ONE` elements.
.expect("vector should be of length `L_PLUS_ONE`");
let hash = Hash::<F, S, ConstantLength<L_PLUS_ONE>, WIDTH, RATE>::init();
hash.hash(input)
}
Expand Down Expand Up @@ -410,9 +413,7 @@ impl<
DuplexPhase::Absorb(0),
);
}
for value in message.into_iter() {
sponge.absorb(value);
}
message.into_iter().for_each(|value| sponge.absorb(value));
self.intra_phase_count += N;
self
}
Expand Down Expand Up @@ -457,7 +458,7 @@ impl<
assert!(N < (1 << 31), "`N` must be less than 2^31");
}
match self.state {
DuplexState::Absorbing(mut absorb) => {
DuplexState::Absorbing(mut sponge) => {
if check {
D::pattern().assert_valid_squeeze_pattern(
self.phase_count,
Expand All @@ -466,15 +467,15 @@ impl<
DuplexPhase::Absorb(0),
);
}
for padding in D::padding(self.intra_phase_count) {
absorb.absorb(padding);
}
self.state = DuplexState::Squeezing(absorb.finish_absorbing());
D::padding(self.intra_phase_count)
.into_iter()
.for_each(|padding| sponge.absorb(padding));
self.state = DuplexState::Squeezing(sponge.finish_absorbing());
self.intra_phase_count = 0;
self.phase_count += 1;
self.squeeze_internal::<N>(check)
}
DuplexState::Squeezing(ref mut squeeze) => {
DuplexState::Squeezing(ref mut sponge) => {
if check {
D::pattern().assert_valid_squeeze_pattern(
self.phase_count,
Expand All @@ -484,10 +485,10 @@ impl<
);
}
let output = (0..N)
.map(|_| squeeze.squeeze())
.map(|_| sponge.squeeze())
.collect::<Vec<F>>()
.try_into()
.unwrap();
.expect("vector should be of length `N`");
self.intra_phase_count += N;
(output, self)
}
Expand Down

0 comments on commit aceeb4e

Please sign in to comment.