Skip to content

Commit 581514d

Browse files
TomAFrenchRumata888
authored andcommitted
chore: delete poseidon2 from bn254_blackbox_solver (#8741)
This is no longer needed post #8740
1 parent 6c0f4ca commit 581514d

File tree

2 files changed

+1
-88
lines changed

2 files changed

+1
-88
lines changed

noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ mod schnorr;
1313
use ark_ec::AffineRepr;
1414
pub use embedded_curve_ops::{embedded_curve_add, multi_scalar_mul};
1515
pub use generator::generators::derive_generators;
16-
pub use poseidon2::{
17-
field_from_hex, poseidon2_permutation, poseidon_hash, Poseidon2Config, Poseidon2Sponge,
18-
POSEIDON2_CONFIG,
19-
};
16+
pub use poseidon2::{field_from_hex, poseidon2_permutation, Poseidon2Config, POSEIDON2_CONFIG};
2017

2118
// Temporary hack, this ensure that we always use a bn254 field here
2219
// without polluting the feature flags of the `acir_field` crate.

noir/noir-repo/acvm-repo/bn254_blackbox_solver/src/poseidon2.rs

-84
Original file line numberDiff line numberDiff line change
@@ -543,75 +543,6 @@ impl<'a> Poseidon2<'a> {
543543
}
544544
}
545545

546-
/// Performs a poseidon hash with a sponge construction equivalent to the one in poseidon2.nr
547-
pub fn poseidon_hash(inputs: &[FieldElement]) -> Result<FieldElement, BlackBoxResolutionError> {
548-
let two_pow_64 = 18446744073709551616_u128.into();
549-
let iv = FieldElement::from(inputs.len()) * two_pow_64;
550-
let mut sponge = Poseidon2Sponge::new(iv, 3);
551-
for input in inputs.iter() {
552-
sponge.absorb(*input)?;
553-
}
554-
sponge.squeeze()
555-
}
556-
557-
pub struct Poseidon2Sponge<'a> {
558-
rate: usize,
559-
poseidon: Poseidon2<'a>,
560-
squeezed: bool,
561-
cache: Vec<FieldElement>,
562-
state: Vec<FieldElement>,
563-
}
564-
565-
impl<'a> Poseidon2Sponge<'a> {
566-
pub fn new(iv: FieldElement, rate: usize) -> Poseidon2Sponge<'a> {
567-
let mut result = Poseidon2Sponge {
568-
cache: Vec::with_capacity(rate),
569-
state: vec![FieldElement::zero(); rate + 1],
570-
squeezed: false,
571-
rate,
572-
poseidon: Poseidon2::new(),
573-
};
574-
result.state[rate] = iv;
575-
result
576-
}
577-
578-
fn perform_duplex(&mut self) -> Result<(), BlackBoxResolutionError> {
579-
// zero-pad the cache
580-
for _ in self.cache.len()..self.rate {
581-
self.cache.push(FieldElement::zero());
582-
}
583-
// add the cache into sponge state
584-
for i in 0..self.rate {
585-
self.state[i] += self.cache[i];
586-
}
587-
self.state = self.poseidon.permutation(&self.state, 4)?;
588-
Ok(())
589-
}
590-
591-
pub fn absorb(&mut self, input: FieldElement) -> Result<(), BlackBoxResolutionError> {
592-
assert!(!self.squeezed);
593-
if self.cache.len() == self.rate {
594-
// If we're absorbing, and the cache is full, apply the sponge permutation to compress the cache
595-
self.perform_duplex()?;
596-
self.cache = vec![input];
597-
} else {
598-
// If we're absorbing, and the cache is not full, add the input into the cache
599-
self.cache.push(input);
600-
}
601-
Ok(())
602-
}
603-
604-
pub fn squeeze(&mut self) -> Result<FieldElement, BlackBoxResolutionError> {
605-
assert!(!self.squeezed);
606-
// If we're in absorb mode, apply sponge permutation to compress the cache.
607-
self.perform_duplex()?;
608-
self.squeezed = true;
609-
610-
// Pop one item off the top of the permutation and return it.
611-
Ok(self.state[0])
612-
}
613-
}
614-
615546
#[cfg(test)]
616547
mod test {
617548
use acir::AcirField;
@@ -631,19 +562,4 @@ mod test {
631562
];
632563
assert_eq!(result, expected_result);
633564
}
634-
635-
#[test]
636-
fn hash_smoke_test() {
637-
let fields = [
638-
FieldElement::from(1u128),
639-
FieldElement::from(2u128),
640-
FieldElement::from(3u128),
641-
FieldElement::from(4u128),
642-
];
643-
let result = super::poseidon_hash(&fields).expect("should hash successfully");
644-
assert_eq!(
645-
result,
646-
field_from_hex("130bf204a32cac1f0ace56c78b731aa3809f06df2731ebcf6b3464a15788b1b9"),
647-
);
648-
}
649565
}

0 commit comments

Comments
 (0)