Skip to content

Commit b584fd7

Browse files
committed
remove use pf pedersen in various test contracts etc
remove use from merkle infra fix noir contracts failure update snap one more
1 parent d339734 commit b584fd7

File tree

30 files changed

+521
-632
lines changed

30 files changed

+521
-632
lines changed

barretenberg/cpp/src/barretenberg/benchmark/merkle_tree_bench/merkle_tree.bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static std::vector<fr> VALUES = []() {
2828
void hash(State& state) noexcept
2929
{
3030
for (auto _ : state) {
31-
hash_pair_native({ 0, 0, 0, 0 }, { 1, 1, 1, 1 });
31+
PedersenHashPolicy::hash_pair({ 0, 0, 0, 0 }, { 1, 1, 1, 1 });
3232
}
3333
}
3434
BENCHMARK(hash)->MinTime(5);

barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash.hpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
// =====================
66

77
#pragma once
8-
#include "barretenberg/common/assert.hpp"
9-
#include "barretenberg/common/net.hpp"
10-
#include "barretenberg/crypto/blake2s/blake2s.hpp"
11-
#include "barretenberg/crypto/pedersen_commitment/pedersen.hpp"
128
#include "barretenberg/crypto/pedersen_hash/pedersen.hpp"
139
#include "barretenberg/crypto/poseidon2/poseidon2.hpp"
14-
#include "barretenberg/numeric/bitop/pow.hpp"
1510
#include <vector>
1611

1712
namespace bb::crypto::merkle_tree {
@@ -35,53 +30,4 @@ struct Poseidon2HashPolicy {
3530
static fr zero_hash() { return fr::zero(); }
3631
};
3732

38-
inline bb::fr hash_pair_native(bb::fr const& lhs, bb::fr const& rhs)
39-
{
40-
return crypto::pedersen_hash::hash({ lhs, rhs }); // uses lookup tables
41-
}
42-
43-
inline bb::fr hash_native(std::vector<bb::fr> const& inputs)
44-
{
45-
return crypto::pedersen_hash::hash(inputs); // uses lookup tables
46-
}
47-
48-
/**
49-
* Computes the root of a tree with leaves given as the vector `input`.
50-
*
51-
* @param input: vector of leaf values.
52-
* @returns root as field
53-
*/
54-
inline bb::fr compute_tree_root_native(std::vector<bb::fr> const& input)
55-
{
56-
BB_ASSERT(numeric::is_power_of_two(input.size()), "Check if the input vector size is a power of 2.");
57-
auto layer = input;
58-
while (layer.size() > 1) {
59-
std::vector<bb::fr> next_layer(layer.size() / 2);
60-
for (size_t i = 0; i < next_layer.size(); ++i) {
61-
next_layer[i] = crypto::pedersen_hash::hash({ layer[i * 2], layer[i * 2 + 1] });
62-
}
63-
layer = std::move(next_layer);
64-
}
65-
66-
return layer[0];
67-
}
68-
69-
// TODO write test
70-
inline std::vector<bb::fr> compute_tree_native(std::vector<bb::fr> const& input)
71-
{
72-
BB_ASSERT(numeric::is_power_of_two(input.size()), "Check if the input vector size is a power of 2.");
73-
auto layer = input;
74-
std::vector<bb::fr> tree(input);
75-
while (layer.size() > 1) {
76-
std::vector<bb::fr> next_layer(layer.size() / 2);
77-
for (size_t i = 0; i < next_layer.size(); ++i) {
78-
next_layer[i] = crypto::pedersen_hash::hash({ layer[i * 2], layer[i * 2 + 1] });
79-
tree.push_back(next_layer[i]);
80-
}
81-
layer = std::move(next_layer);
82-
}
83-
84-
return tree;
85-
}
86-
8733
} // namespace bb::crypto::merkle_tree

barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash_path.hpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ using fr_hash_path = std::vector<std::pair<fr, fr>>;
1616
using fr_sibling_path = std::vector<fr>;
1717
template <typename Ctx> using hash_path = std::vector<std::pair<bb::stdlib::field_t<Ctx>, bb::stdlib::field_t<Ctx>>>;
1818

19-
inline fr_hash_path get_new_hash_path(fr_hash_path const& old_path, uint128_t index, fr const& value)
20-
{
21-
fr_hash_path path = old_path;
22-
fr current = value;
23-
for (size_t i = 0; i < old_path.size(); ++i) {
24-
bool path_bit = static_cast<bool>(index & 0x1);
25-
if (path_bit) {
26-
path[i].second = current;
27-
} else {
28-
path[i].first = current;
29-
}
30-
current = hash_pair_native(path[i].first, path[i].second);
31-
index /= 2;
32-
}
33-
return path;
34-
}
35-
3619
inline fr_hash_path get_random_hash_path(size_t const& tree_depth)
3720
{
3821
fr_hash_path path;
@@ -52,20 +35,6 @@ template <typename Ctx> inline hash_path<Ctx> create_witness_hash_path(Ctx& ctx,
5235
return result;
5336
}
5437

55-
inline fr get_hash_path_root(fr_hash_path const& input)
56-
{
57-
return hash_pair_native(input[input.size() - 1].first, input[input.size() - 1].second);
58-
}
59-
60-
inline fr zero_hash_at_height(size_t height)
61-
{
62-
auto current = fr(0);
63-
for (size_t i = 0; i < height; ++i) {
64-
current = hash_pair_native(current, current);
65-
}
66-
return current;
67-
}
68-
6938
} // namespace bb::crypto::merkle_tree
7039

7140
// We add to std namespace as fr_hash_path is actually a std::vector, and this is the only way

barretenberg/cpp/src/barretenberg/crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool check_hash_path(const fr& root,
3232
for (size_t i = 0; i < depth_; ++i) {
3333
fr left = (index & 1) ? path[i].first : current;
3434
fr right = (index & 1) ? current : path[i].second;
35-
current = hash_pair_native(left, right);
35+
current = HashPolicy::hash_pair(left, right);
3636
index >>= 1;
3737
}
3838
return current == root;

boxes/boxes/vanilla/contracts/src/main.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub contract PrivateVoting {
1616
storage::storage,
1717
};
1818
use dep::aztec::state_vars::{Map, PublicImmutable, PublicMutable};
19-
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Hash, ToField}};
19+
use dep::aztec::protocol_types::{address::AztecAddress, hash::poseidon2_hash, traits::{Hash, ToField}};
2020

2121
#[storage]
2222
struct Storage<Context> {
@@ -39,7 +39,7 @@ pub contract PrivateVoting {
3939
let msg_sender_npk_m_hash = get_public_keys(self.msg_sender()).npk_m.hash();
4040

4141
let secret = self.context.request_nsk_app(msg_sender_npk_m_hash); // get secret key of caller of function
42-
let nullifier = std::hash::pedersen_hash([self.msg_sender().to_field(), secret]); // derive nullifier from sender and secret
42+
let nullifier = poseidon2_hash([self.msg_sender().to_field(), secret]); // derive nullifier from sender and secret
4343
self.context.push_nullifier(nullifier);
4444
self.enqueue_self.add_to_tally_public(candidate);
4545
}

noir-projects/aztec-nr/aztec/src/hash.nr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@ use dep::protocol_types::{
77
DOM_SEP__PUBLIC_CALLDATA, DOM_SEP__SECRET_HASH, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS,
88
},
99
hash::{poseidon2_hash_subarray, poseidon2_hash_with_separator, sha256_to_field},
10-
point::Point,
1110
traits::ToField,
1211
};
1312

14-
pub use dep::protocol_types::hash::{compute_siloed_nullifier, pedersen_hash};
15-
16-
pub fn pedersen_commitment<let N: u32>(inputs: [Field; N], hash_index: u32) -> Point {
17-
std::hash::pedersen_commitment_with_separator(inputs, hash_index)
18-
}
13+
pub use dep::protocol_types::hash::compute_siloed_nullifier;
1914

2015
pub fn compute_secret_hash(secret: Field) -> Field {
2116
poseidon2_hash_with_separator([secret], DOM_SEP__SECRET_HASH)

noir-projects/noir-contracts/contracts/app/card_game_contract/src/main.nr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use dep::aztec::macros::aztec;
55

66
#[aztec]
77
pub contract CardGame {
8-
use dep::aztec::{hash::pedersen_hash, state_vars::{Map, PublicMutable}};
98
use dep::aztec::protocol_types::address::AztecAddress;
9+
use dep::aztec::protocol_types::hash::poseidon2_hash;
10+
use dep::aztec::state_vars::{Map, PublicMutable};
1011

1112
use dep::aztec::note::constants::MAX_NOTES_PER_PAGE;
1213

@@ -103,7 +104,7 @@ pub contract CardGame {
103104

104105
let mut collection = self.storage.collections;
105106
let _inserted_cards = collection.add_cards(cards, player);
106-
self.enqueue_self.on_cards_claimed(game, player, pedersen_hash(cards_fields, 0));
107+
self.enqueue_self.on_cards_claimed(game, player, poseidon2_hash(cards_fields));
107108
}
108109

109110
#[external("public")]
@@ -117,7 +118,7 @@ pub contract CardGame {
117118

118119
assert_eq(
119120
cards_hash,
120-
pedersen_hash(game_data.rounds_cards.map(|card: Card| card.to_field()), 0),
121+
poseidon2_hash(game_data.rounds_cards.map(|card: Card| card.to_field())),
121122
);
122123

123124
let winner = game_data.winner();

noir-projects/noir-contracts/contracts/app/lending_contract/src/helpers.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dep::aztec::hash::pedersen_hash;
1+
use dep::aztec::protocol_types::hash::poseidon2_hash;
22
use std::ops::{Add, Sub};
33

44
// Utility used to easily get a "id" for a private user that sits in the same
@@ -8,7 +8,7 @@ pub fn compute_identifier(secret: Field, on_behalf_of: Field, this: Field) -> Fi
88
// EITHER secret OR on_behalf_of MUST be set. But not both
99
assert(!((secret == 0) as bool & (on_behalf_of == 0) as bool));
1010
if (secret != 0) {
11-
pedersen_hash([this, secret], 0)
11+
poseidon2_hash([this, secret])
1212
} else {
1313
on_behalf_of
1414
}

noir-projects/noir-contracts/contracts/test/test_contract/src/main.nr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ pub contract Test {
3636
},
3737
// Event related
3838
messages::message_delivery::MessageDelivery,
39-
// Hashing
40-
hash::pedersen_hash,
4139
// History and inclusion proofs
4240
history::note_inclusion::ProveNoteInclusion,
4341
// Key management
@@ -51,6 +49,7 @@ pub contract Test {
5149
// Contract instance management
5250
publish_contract_instance::publish_contract_instance_for_public_execution,
5351
};
52+
use std::hash::pedersen_hash_with_separator;
5453
use std::meta::derive;
5554
use token_portal_content_hash_lib::get_mint_to_private_content_hash;
5655

@@ -427,7 +426,7 @@ pub contract Test {
427426
}
428427

429428
fn get_commitment(self) -> Field {
430-
pedersen_hash([self.amount, self.secret_hash], 0)
429+
pedersen_hash_with_separator([self.amount, self.secret_hash], 0)
431430
}
432431
}
433432

noir-projects/noir-protocol-circuits/crates/types/src/hash.nr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@ pub fn accumulate_sha256(v0: Field, v1: Field) -> Field {
218218
sha256_to_field(hash_input_flattened)
219219
}
220220

221-
// TODO: remove this. The protocol doesn't need it.
222-
#[inline_always]
223-
pub fn pedersen_hash<let N: u32>(inputs: [Field; N], hash_index: u32) -> Field {
224-
std::hash::pedersen_hash_with_separator(inputs, hash_index)
225-
}
226-
227221
pub fn poseidon2_hash<let N: u32>(inputs: [Field; N]) -> Field {
228222
poseidon::poseidon2::Poseidon2::hash(inputs, N)
229223
}

0 commit comments

Comments
 (0)