Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dsl)!: add hash index to pedersen constraint #436

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
sirasistant marked this conversation as resolved.
Show resolved Hide resolved

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