Skip to content

Commit

Permalink
feat(dsl)!: add hash index to pedersen constraint (#436)
Browse files Browse the repository at this point in the history
* feat(noir): add hash index to pedersen constraint

* feat: added pedesen with hash_index in header
  • Loading branch information
sirasistant authored May 30, 2023
1 parent e916f0e commit e0b8804
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t*
write(output, pedersen_hash);
}

WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer,
uint8_t* output,
uint32_t hash_index)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash =
crypto::pedersen_commitment::lookup::commit_native(to_compress, hash_index);

write(output, pedersen_hash);
}

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r)
{
std::vector<uint8_t> to_compress(data, data + length);
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer

WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output);
WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output);
WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer,
uint8_t* output,
uint32_t hash_index);

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r);
}
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/pedersen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void create_pedersen_constraint(Composer& composer, const PedersenConstraint& in
}

// TODO: Does Noir need additive homomorphic Pedersen hash? If so, using plookup version won't help.
auto point = stdlib::pedersen_plookup_commitment<Composer>::commit(scalars);
auto point = stdlib::pedersen_plookup_commitment<Composer>::commit(scalars, input.hash_index);

composer.assert_equal(point.x.witness_index, input.result_x);
composer.assert_equal(point.y.witness_index, input.result_y);
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/barretenberg/dsl/acir_format/pedersen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace acir_format {
// P = xG + bH
struct PedersenConstraint {
std::vector<uint32_t> scalars;
uint32_t hash_index;

uint32_t result_x;
uint32_t result_y;

Expand All @@ -19,6 +21,7 @@ template <typename B> inline void read(B& buf, PedersenConstraint& constraint)
{
using serialize::read;
read(buf, constraint.scalars);
read(buf, constraint.hash_index);
read(buf, constraint.result_x);
read(buf, constraint.result_y);
}
Expand All @@ -27,6 +30,7 @@ template <typename B> inline void write(B& buf, PedersenConstraint const& constr
{
using serialize::write;
write(buf, constraint.scalars);
write(buf, constraint.hash_index);
write(buf, constraint.result_x);
write(buf, constraint.result_y);
}
Expand Down

0 comments on commit e0b8804

Please sign in to comment.