Skip to content

Commit

Permalink
Mina-poseidon: add regtest absorbing identity
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Jan 7, 2025
1 parent a340c95 commit 3e4eacc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions poseidon/src/sponge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub trait FqSponge<Fq: Field, G, Fr> {
fn absorb_fq(&mut self, x: &[Fq]);

/// Absorbs a base field point, that is a pair of `Fq` elements.
/// In the case of the point to infinity, the values `(0, 0)` are absorbed.
fn absorb_g(&mut self, g: &[G]);

/// Absorbs an element of the scalar field `Fr` --- it is done
Expand Down
25 changes: 24 additions & 1 deletion poseidon/tests/poseidon_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ark_ec::AffineRepr;
use ark_ff::{Field, UniformRand};
use mina_curves::pasta::{Fp, Fq, PallasParameters, VestaParameters};
use mina_curves::pasta::{Fp, Fq, Pallas, PallasParameters, Vesta, VestaParameters};
use mina_poseidon::{
constants::{PlonkSpongeConstantsKimchi, PlonkSpongeConstantsLegacy},
pasta::{fp_kimchi, fp_legacy, fq_kimchi},
Expand Down Expand Up @@ -136,3 +137,25 @@ fn test_poseidon_pallas_kimchi_challenge_is_squeezed_to_128_bits() {
let two_128 = Fq::from(2).pow([128]);
assert!(challenge < two_128);
}

#[test]
fn test_poseidon_pallas_absorb_point_to_infinity() {
let mut sponge = DefaultFqSponge::<PallasParameters, PlonkSpongeConstantsKimchi>::new(
fp_kimchi::static_params(),
);
let point = Pallas::zero();
sponge.absorb_g(&[point]);
let exp_output = [Fp::from(0); 3];
assert_eq!(sponge.sponge.state, exp_output);
}

#[test]
fn test_poseidon_vesta_absorb_point_to_infinity() {
let mut sponge = DefaultFqSponge::<VestaParameters, PlonkSpongeConstantsKimchi>::new(
fq_kimchi::static_params(),
);
let point = Vesta::zero();
sponge.absorb_g(&[point]);
let exp_output = [Fq::from(0); 3];
assert_eq!(sponge.sponge.state, exp_output);
}

0 comments on commit 3e4eacc

Please sign in to comment.