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: Pedersen hash in acir format #2990

Merged
merged 20 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
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
Next Next commit
feat: add pedersen hash in acir_format
sirasistant committed Oct 24, 2023

Verified

This commit was signed with the committer’s verified signature.
Sonicadvance1 Ryan Houdek
commit a84de081cc4e31204d6db2cf9723c8ad90d7375a
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "acir_format.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/dsl/acir_format/pedersen.hpp"

namespace acir_format {

@@ -83,6 +84,10 @@ void build_constraints(Builder& builder, acir_format const& constraint_system, b
create_pedersen_constraint(builder, constraint);
}

for (const auto& constraint : constraint_system.pedersen_hash_constraints) {
create_pedersen_hash_constraint(builder, constraint);
}

// Add fixed base scalar mul constraints
for (const auto& constraint : constraint_system.fixed_base_scalar_mul_constraints) {
create_fixed_base_constraint(builder, constraint);
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ struct acir_format {
std::vector<KeccakConstraint> keccak_constraints;
std::vector<KeccakVarConstraint> keccak_var_constraints;
std::vector<PedersenConstraint> pedersen_constraints;
std::vector<PedersenHashConstraint> pedersen_hash_constraints;
std::vector<HashToFieldConstraint> hash_to_field_constraints;
std::vector<FixedBaseScalarMul> fixed_base_scalar_mul_constraints;
std::vector<RecursionConstraint> recursion_constraints;
@@ -58,6 +59,7 @@ struct acir_format {
keccak_constraints,
keccak_var_constraints,
pedersen_constraints,
pedersen_hash_constraints,
hash_to_field_constraints,
fixed_base_scalar_mul_constraints,
recursion_constraints,
15 changes: 15 additions & 0 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp
Original file line number Diff line number Diff line change
@@ -20,4 +20,19 @@ void create_pedersen_constraint(Builder& builder, const PedersenConstraint& inpu
builder.assert_equal(point.y.witness_index, input.result_y);
}

void create_pedersen_hash_constraint(Builder& builder, const PedersenHashConstraint& input)
{
std::vector<field_ct> scalars;

for (const auto& scalar : input.scalars) {
// convert input indices to field_ct
field_ct scalar_as_field = field_ct::from_witness_index(&builder, scalar);
scalars.push_back(scalar_as_field);
}

auto result = stdlib::pedersen_hash<Builder>::hash(scalars, input.hash_index);

builder.assert_equal(result.witness_index, input.result);
}

} // namespace acir_format
10 changes: 10 additions & 0 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,17 @@ struct PedersenConstraint {
friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default;
};

struct PedersenHashConstraint {
std::vector<uint32_t> scalars;
uint32_t hash_index;

uint32_t result;

friend bool operator==(PedersenHashConstraint const& lhs, PedersenHashConstraint const& rhs) = default;
};

void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input);
void create_pedersen_hash_constraint(Builder& builder, const PedersenHashConstraint& input);

template <typename B> inline void read(B& buf, PedersenConstraint& constraint)
{