diff --git a/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index f503481ce7..82905710dd 100644 --- a/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -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 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 to_compress(data, data + length); diff --git a/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index 59b4ef6c40..85454d2256 100644 --- a/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -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); } \ No newline at end of file diff --git a/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp b/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp index d272a3a8ed..f31b7b1a4d 100644 --- a/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp @@ -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::commit(scalars); + auto point = stdlib::pedersen_plookup_commitment::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); diff --git a/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp b/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp index 3144359b2f..e966f0a20b 100644 --- a/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp @@ -7,6 +7,8 @@ namespace acir_format { // P = xG + bH struct PedersenConstraint { std::vector scalars; + uint32_t hash_index; + uint32_t result_x; uint32_t result_y; @@ -19,6 +21,7 @@ template 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); } @@ -27,6 +30,7 @@ template 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); }