|
1 | | -use super::poseidon2; |
| 1 | +use super::{poseidon, poseidon2}; |
2 | 2 |
|
3 | 3 | /// This calls the bb.js Poseidon2 implementation |
4 | 4 | #[oracle(getPoseidon2Hash)] |
5 | | -unconstrained fn poseidon2_hash_oracle(input: [Field; 10]) -> Field {} |
| 5 | +unconstrained fn get_poseidon2_hash(input: [Field], message_size: u32) -> Field {} |
6 | 6 |
|
7 | | -unconstrained fn get_poseidon2_hash(input: [Field; 10]) -> Field { |
8 | | - poseidon2_hash_oracle(input) |
| 7 | +/// This calls the poseidon-lite Poseidon implementation |
| 8 | +#[oracle(getPoseidonHash)] |
| 9 | +unconstrained fn get_poseidon_hash(input: [Field], message_size: u32) -> Field {} |
| 10 | + |
| 11 | +#[test] |
| 12 | +unconstrained fn test_poseidon2(input: [Field; 20]) { |
| 13 | + for i in 0..=20 { |
| 14 | + // get hash from Noir implementation |
| 15 | + let temp_size = i % (input.len() + 1); |
| 16 | + let noir_hash = poseidon2::Poseidon2::hash(input, temp_size); |
| 17 | + |
| 18 | + // get hash from bb.js via oracle |
| 19 | + let bb_hash = get_poseidon2_hash(input, temp_size); |
| 20 | + |
| 21 | + assert_eq(noir_hash, bb_hash); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +// Poseidon (original) oracle tests |
| 26 | + |
| 27 | +#[test] |
| 28 | +unconstrained fn test_poseidon_hash_1(input: [Field; 1]) { |
| 29 | + let noir_hash = poseidon::bn254::hash_1(input); |
| 30 | + let oracle_hash = get_poseidon_hash(input, 1); |
| 31 | + assert_eq(noir_hash, oracle_hash); |
| 32 | +} |
| 33 | + |
| 34 | +#[test] |
| 35 | +unconstrained fn test_poseidon_hash_2(input: [Field; 2]) { |
| 36 | + let noir_hash = poseidon::bn254::hash_2(input); |
| 37 | + let oracle_hash = get_poseidon_hash(input, 2); |
| 38 | + assert_eq(noir_hash, oracle_hash); |
9 | 39 | } |
10 | 40 |
|
11 | 41 | #[test] |
12 | | -unconstrained fn test_poseidon2(input: [Field; 10]) { |
13 | | - // get hash from Noir implementation |
14 | | - let noir_hash = poseidon2::Poseidon2::hash(input, input.len()); |
| 42 | +unconstrained fn test_poseidon_hash_3(input: [Field; 3]) { |
| 43 | + let noir_hash = poseidon::bn254::hash_3(input); |
| 44 | + let oracle_hash = get_poseidon_hash(input, 3); |
| 45 | + assert_eq(noir_hash, oracle_hash); |
| 46 | +} |
15 | 47 |
|
16 | | - // get hash from bb.js via oracle |
17 | | - let bb_hash = get_poseidon2_hash(input); |
| 48 | +#[test] |
| 49 | +unconstrained fn test_poseidon_hash_4(input: [Field; 4]) { |
| 50 | + let noir_hash = poseidon::bn254::hash_4(input); |
| 51 | + let oracle_hash = get_poseidon_hash(input, 4); |
| 52 | + assert_eq(noir_hash, oracle_hash); |
| 53 | +} |
| 54 | + |
| 55 | +#[test] |
| 56 | +unconstrained fn test_poseidon_hash_5(input: [Field; 5]) { |
| 57 | + let noir_hash = poseidon::bn254::hash_5(input); |
| 58 | + let oracle_hash = get_poseidon_hash(input, 5); |
| 59 | + assert_eq(noir_hash, oracle_hash); |
| 60 | +} |
| 61 | + |
| 62 | +#[test] |
| 63 | +unconstrained fn test_poseidon_hash_6(input: [Field; 6]) { |
| 64 | + let noir_hash = poseidon::bn254::hash_6(input); |
| 65 | + let oracle_hash = get_poseidon_hash(input, 6); |
| 66 | + assert_eq(noir_hash, oracle_hash); |
| 67 | +} |
| 68 | + |
| 69 | +#[test] |
| 70 | +unconstrained fn test_poseidon_hash_7(input: [Field; 7]) { |
| 71 | + let noir_hash = poseidon::bn254::hash_7(input); |
| 72 | + let oracle_hash = get_poseidon_hash(input, 7); |
| 73 | + assert_eq(noir_hash, oracle_hash); |
| 74 | +} |
18 | 75 |
|
19 | | - assert_eq(noir_hash, bb_hash); |
| 76 | +#[test] |
| 77 | +unconstrained fn test_poseidon_hash_8(input: [Field; 8]) { |
| 78 | + let noir_hash = poseidon::bn254::hash_8(input); |
| 79 | + let oracle_hash = get_poseidon_hash(input, 8); |
| 80 | + assert_eq(noir_hash, oracle_hash); |
| 81 | +} |
| 82 | + |
| 83 | +#[test] |
| 84 | +unconstrained fn test_poseidon_hash_9(input: [Field; 9]) { |
| 85 | + let noir_hash = poseidon::bn254::hash_9(input); |
| 86 | + let oracle_hash = get_poseidon_hash(input, 9); |
| 87 | + assert_eq(noir_hash, oracle_hash); |
| 88 | +} |
| 89 | + |
| 90 | +#[test] |
| 91 | +unconstrained fn test_poseidon_hash_10(input: [Field; 10]) { |
| 92 | + let noir_hash = poseidon::bn254::hash_10(input); |
| 93 | + let oracle_hash = get_poseidon_hash(input, 10); |
| 94 | + assert_eq(noir_hash, oracle_hash); |
| 95 | +} |
| 96 | + |
| 97 | +#[test] |
| 98 | +unconstrained fn test_poseidon_hash_11(input: [Field; 11]) { |
| 99 | + let noir_hash = poseidon::bn254::hash_11(input); |
| 100 | + let oracle_hash = get_poseidon_hash(input, 11); |
| 101 | + assert_eq(noir_hash, oracle_hash); |
| 102 | +} |
| 103 | + |
| 104 | +#[test] |
| 105 | +unconstrained fn test_poseidon_hash_12(input: [Field; 12]) { |
| 106 | + let noir_hash = poseidon::bn254::hash_12(input); |
| 107 | + let oracle_hash = get_poseidon_hash(input, 12); |
| 108 | + assert_eq(noir_hash, oracle_hash); |
| 109 | +} |
| 110 | + |
| 111 | +#[test] |
| 112 | +unconstrained fn test_poseidon_hash_13(input: [Field; 13]) { |
| 113 | + let noir_hash = poseidon::bn254::hash_13(input); |
| 114 | + let oracle_hash = get_poseidon_hash(input, 13); |
| 115 | + assert_eq(noir_hash, oracle_hash); |
| 116 | +} |
| 117 | + |
| 118 | +#[test] |
| 119 | +unconstrained fn test_poseidon_hash_14(input: [Field; 14]) { |
| 120 | + let noir_hash = poseidon::bn254::hash_14(input); |
| 121 | + let oracle_hash = get_poseidon_hash(input, 14); |
| 122 | + assert_eq(noir_hash, oracle_hash); |
| 123 | +} |
| 124 | + |
| 125 | +#[test] |
| 126 | +unconstrained fn test_poseidon_hash_15(input: [Field; 15]) { |
| 127 | + let noir_hash = poseidon::bn254::hash_15(input); |
| 128 | + let oracle_hash = get_poseidon_hash(input, 15); |
| 129 | + assert_eq(noir_hash, oracle_hash); |
20 | 130 | } |
0 commit comments