Poseidon(x,y)=z for BN254 scalar field
Below we show Noir and Cairo code computing the same hash.
use std::hash::poseidon;
fn main(x: Field, y: pub Field) {
let x1 = [x, y];
let z = poseidon::bn254::hash_2(x1);
assert(z == 7853200120776062878684798364095072458815029376092732009249414926327459813530);
}
#[test]
fn test_main() {
main(1, 2);
// Uncomment to make test fail
// main(1, 1);
}
use garaga::hashes::poseidon_hash_2_bn254;
fn test_poseidon_bn254() {
let x: u384 = u384 { limb0: 1, limb1: 0, limb2: 0, limb3: 0 };
let y: u384 = u384 { limb0: 2, limb1: 0, limb2: 0, limb3: 0 };
let z: u384 =
7853200120776062878684798364095072458815029376092732009249414926327459813530_u256
.into();
assert_eq!(poseidon_hash_2_bn254(x, y), z);
}