From a84de081cc4e31204d6db2cf9723c8ad90d7375a Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 10:07:49 +0000 Subject: [PATCH 01/15] feat: add pedersen hash in acir_format --- .../barretenberg/dsl/acir_format/acir_format.cpp | 5 +++++ .../barretenberg/dsl/acir_format/acir_format.hpp | 2 ++ .../src/barretenberg/dsl/acir_format/pedersen.cpp | 15 +++++++++++++++ .../src/barretenberg/dsl/acir_format/pedersen.hpp | 10 ++++++++++ 4 files changed, 32 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 59b5192a645..6d94ba7b766 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -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); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 0889bd2b4e2..15f2ecbcdd8 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -34,6 +34,7 @@ struct acir_format { std::vector keccak_constraints; std::vector keccak_var_constraints; std::vector pedersen_constraints; + std::vector pedersen_hash_constraints; std::vector hash_to_field_constraints; std::vector fixed_base_scalar_mul_constraints; std::vector 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, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp index 16a3dcebe7f..73aad6b94de 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp @@ -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 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::hash(scalars, input.hash_index); + + builder.assert_equal(result.witness_index, input.result); +} + } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp index e70b418d4f5..9605c75472b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp @@ -15,7 +15,17 @@ struct PedersenConstraint { friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default; }; +struct PedersenHashConstraint { + std::vector 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 inline void read(B& buf, PedersenConstraint& constraint) { From 02f641c62443bebc925e960001c4172979d89571 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 10:22:39 +0000 Subject: [PATCH 02/15] feat: added deserialization of pedersen hash --- .../acir_format/acir_to_constraint_buf.hpp | 6 + .../dsl/acir_format/serde/acir.hpp | 135 ++++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index ef84daaabb1..523d8245e92 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -129,6 +129,12 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci .result_x = arg.outputs[0].value, .result_y = arg.outputs[1].value, }); + } else if constexpr (std::is_same_v) { + af.pedersen_hash_constraints.push_back(PedersenHashConstraint{ + .scalars = map(arg.inputs, [](auto& e) { return e.witness.value; }), + .hash_index = arg.domain_separator, + .result = arg.output.value, + }); } else if constexpr (std::is_same_v) { af.hash_to_field_constraints.push_back(HashToFieldConstraint{ .inputs = map(arg.inputs, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index e59f786ce66..ae238935030 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -92,6 +92,16 @@ struct BlackBoxFuncCall { static Pedersen bincodeDeserialize(std::vector); }; + struct PedersenHash { + std::vector inputs; + uint32_t domain_separator; + Circuit::Witness output; + + friend bool operator==(const PedersenHash&, const PedersenHash&); + std::vector bincodeSerialize() const; + static PedersenHash bincodeDeserialize(std::vector); + }; + struct HashToField128Security { std::vector inputs; Circuit::Witness output; @@ -174,6 +184,7 @@ struct BlackBoxFuncCall { Blake2s, SchnorrVerify, Pedersen, + PedersenHash, HashToField128Security, EcdsaSecp256k1, EcdsaSecp256r1, @@ -467,6 +478,16 @@ struct BlackBoxOp { static Pedersen bincodeDeserialize(std::vector); }; + struct PedersenHash { + Circuit::HeapVector inputs; + Circuit::RegisterIndex domain_separator; + Circuit::RegisterIndex output; + + friend bool operator==(const PedersenHash&, const PedersenHash&); + std::vector bincodeSerialize() const; + static PedersenHash bincodeDeserialize(std::vector); + }; + struct FixedBaseScalarMul { Circuit::RegisterIndex low; Circuit::RegisterIndex high; @@ -2157,6 +2178,63 @@ Circuit::BlackBoxFuncCall::Pedersen serde::Deserializable BlackBoxFuncCall::PedersenHash::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxFuncCall::PedersenHash BlackBoxFuncCall::PedersenHash::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize( + const Circuit::BlackBoxFuncCall::PedersenHash& obj, Serializer& serializer) +{ + serde::Serializable::serialize(obj.inputs, serializer); + serde::Serializable::serialize(obj.domain_separator, serializer); + serde::Serializable::serialize(obj.output, serializer); +} + +template <> +template +Circuit::BlackBoxFuncCall::PedersenHash serde::Deserializable::deserialize( + Deserializer& deserializer) +{ + Circuit::BlackBoxFuncCall::PedersenHash obj; + obj.inputs = serde::Deserializable::deserialize(deserializer); + obj.domain_separator = serde::Deserializable::deserialize(deserializer); + obj.output = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + inline bool operator==(const BlackBoxFuncCall::HashToField128Security& lhs, const BlackBoxFuncCall::HashToField128Security& rhs) { @@ -3105,6 +3183,63 @@ Circuit::BlackBoxOp::Pedersen serde::Deserializable BlackBoxOp::PedersenHash::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxOp::PedersenHash BlackBoxOp::PedersenHash::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize(const Circuit::BlackBoxOp::PedersenHash& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.inputs, serializer); + serde::Serializable::serialize(obj.domain_separator, serializer); + serde::Serializable::serialize(obj.output, serializer); +} + +template <> +template +Circuit::BlackBoxOp::PedersenHash serde::Deserializable::deserialize( + Deserializer& deserializer) +{ + Circuit::BlackBoxOp::PedersenHash obj; + obj.inputs = serde::Deserializable::deserialize(deserializer); + obj.domain_separator = serde::Deserializable::deserialize(deserializer); + obj.output = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + inline bool operator==(const BlackBoxOp::FixedBaseScalarMul& lhs, const BlackBoxOp::FixedBaseScalarMul& rhs) { if (!(lhs.low == rhs.low)) { From 9316d63cd36f6e4ca2cc6238cea67757e907fe72 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 12:51:23 +0000 Subject: [PATCH 03/15] test: test against the pedersen hash branch --- barretenberg/acir_tests/run_acir_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index a7c59f98dd4..f75efcef24d 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -eu BIN=${BIN:-../cpp/build/bin/bb} FLOW=${FLOW:-prove_and_verify} CRS_PATH=~/.bb-crs -BRANCH=kw/mv/new-pedersen +BRANCH=arv/pedersen_hash VERBOSE=${VERBOSE:-} NAMED_TEST=${1:-} @@ -41,7 +41,7 @@ fi cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member merkle_insert simple_shield pedersen_check schnorr) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member) function test() { cd $1 From 6ec5b1c0f5a07af97b57f0c1561c32ee67faa214 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 13:06:45 +0000 Subject: [PATCH 04/15] fix: fixed throw to throw or abort --- .../cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index ae238935030..f4c480f9d28 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -2204,7 +2204,7 @@ inline BlackBoxFuncCall::PedersenHash BlackBoxFuncCall::PedersenHash::bincodeDes auto deserializer = serde::BincodeDeserializer(input); auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { - throw serde::deserialization_error("Some input bytes were not read"); + throw_or_abort("Some input bytes were not read"); } return value; } @@ -3209,7 +3209,7 @@ inline BlackBoxOp::PedersenHash BlackBoxOp::PedersenHash::bincodeDeserialize(std auto deserializer = serde::BincodeDeserializer(input); auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { - throw serde::deserialization_error("Some input bytes were not read"); + throw_or_abort("Some input bytes were not read"); } return value; } From 37895820a9d5b645e2d9ad07875d7ea0790230ca Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 13:41:19 +0000 Subject: [PATCH 05/15] Empty commit From 558e6fdcc14cb7d508718f483bc2c11338a22915 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 13:56:34 +0000 Subject: [PATCH 06/15] skip two failing tests --- barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index f75efcef24d..aa344c8ecd9 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -41,7 +41,7 @@ fi cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul double_verify_proof) function test() { cd $1 From 6e177f2465f62d3dd270847a770bfdd2de56c41f Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 14:08:20 +0000 Subject: [PATCH 07/15] test: fixed constructors for tests --- .../src/barretenberg/dsl/acir_format/acir_format.test.cpp | 5 +++++ .../barretenberg/dsl/acir_format/block_constraint.test.cpp | 1 + .../barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp | 3 +++ .../barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp | 4 ++++ .../dsl/acir_format/recursion_constraint.test.cpp | 2 ++ 5 files changed, 15 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 171d203ffef..b0711582deb 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -40,6 +40,7 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -146,6 +147,7 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -210,6 +212,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -297,6 +300,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -403,6 +407,7 @@ TEST_F(AcirFormatTests, TestVarKeccak) .keccak_constraints = {}, .keccak_var_constraints = { keccak }, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index 02e8a841911..37c7aa784f2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -121,6 +121,7 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index 4dfc0dad44f..57576bd763f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -100,6 +100,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -140,6 +141,7 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -175,6 +177,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index affb7e25c75..01adec035f0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -134,6 +134,7 @@ TEST(ECDSASecp256r1, test_hardcoded) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -175,6 +176,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -214,6 +216,7 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -248,6 +251,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 775c862b2e2..550bd180cc3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -93,6 +93,7 @@ Builder create_inner_circuit() .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, @@ -219,6 +220,7 @@ Builder create_outer_circuit(std::vector& inner_circuits) .keccak_constraints = {}, .keccak_var_constraints = {}, .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, .hash_to_field_constraints = {}, .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = recursion_constraints, From 770f7e377e9c370f1a37c82bd53ec580f8dbadf0 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 14:36:42 +0000 Subject: [PATCH 08/15] Empty commit From 6e28a16042c1c9f1040f3efb4cd9719e3f363dda Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 14:38:23 +0000 Subject: [PATCH 09/15] fix: re enable double verify --- barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index aa344c8ecd9..2c723192693 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -41,7 +41,7 @@ fi cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul double_verify_proof) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul) function test() { cd $1 From f0bc9bbae5e8bc0d52b7027fb060a8ee0f20c8d9 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 14:38:24 +0000 Subject: [PATCH 10/15] don't ignore double_verify --- barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index aa344c8ecd9..2c723192693 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -41,7 +41,7 @@ fi cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul double_verify_proof) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul) function test() { cd $1 From 0e28a9927784d637c945fdc1279e82e1f065ae3a Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 14:46:52 +0000 Subject: [PATCH 11/15] fix: added missing variant --- barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index f4c480f9d28..20cfb17c9ee 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -506,6 +506,7 @@ struct BlackBoxOp { EcdsaSecp256r1, SchnorrVerify, Pedersen, + PedersenHash, FixedBaseScalarMul> value; From 168bd773955422c17e88ab0f2b0211149863460c Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 14:48:47 +0000 Subject: [PATCH 12/15] test: re enable brillig test --- barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index 2c723192693..f75efcef24d 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -41,7 +41,7 @@ fi cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member brillig_scalar_mul) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member) function test() { cd $1 From 5fac638cad000e50aae531bf0b099806eef5f6b0 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Tue, 24 Oct 2023 15:10:51 +0000 Subject: [PATCH 13/15] feat: add pedersen_hash opcode supported --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 +- barretenberg/ts/src/info.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 169dc6a10f4..19d4fac408a 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -300,7 +300,7 @@ void acvmInfo(const std::string& output_path) "width" : 3 }, "opcodes_supported" : ["arithmetic", "directive", "brillig", "memory_init", "memory_op"], - "black_box_functions_supported" : ["and", "xor", "range", "sha256", "blake2s", "keccak256", "schnorr_verify", "pedersen", "hash_to_field_128_security", "ecdsa_secp256k1", "ecdsa_secp256r1", "fixed_base_scalar_mul", "recursive_aggregation"] + "black_box_functions_supported" : ["and", "xor", "range", "sha256", "blake2s", "keccak256", "schnorr_verify", "pedersen", "pedersen_hash", "hash_to_field_128_security", "ecdsa_secp256k1", "ecdsa_secp256r1", "fixed_base_scalar_mul", "recursive_aggregation"] })"; size_t length = strlen(jsonData); diff --git a/barretenberg/ts/src/info.ts b/barretenberg/ts/src/info.ts index 3dffc9bff43..d6f22a752e5 100644 --- a/barretenberg/ts/src/info.ts +++ b/barretenberg/ts/src/info.ts @@ -14,6 +14,7 @@ export const acvmInfoJson = { 'keccak256', 'schnorr_verify', 'pedersen', + 'pedersen_hash', 'hash_to_field_128_security', 'ecdsa_secp256k1', 'ecdsa_secp256r1', From f561be966ed6e39514a3be1d99fdce596b333afe Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 15:36:04 +0000 Subject: [PATCH 14/15] pedersen to pedersen commitment --- .../acir_format/acir_to_constraint_buf.hpp | 2 +- .../dsl/acir_format/serde/acir.hpp | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 523d8245e92..0c2f63a1817 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -122,7 +122,7 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci .result = arg.output.value, .signature = map(arg.signature, [](auto& e) { return e.witness.value; }), }); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.pedersen_constraints.push_back(PedersenConstraint{ .scalars = map(arg.inputs, [](auto& e) { return e.witness.value; }), .hash_index = arg.domain_separator, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 20cfb17c9ee..cc106e9e91e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -82,14 +82,14 @@ struct BlackBoxFuncCall { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct Pedersen { + struct PedersenCommitment { std::vector inputs; uint32_t domain_separator; std::array outputs; - friend bool operator==(const Pedersen&, const Pedersen&); + friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); std::vector bincodeSerialize() const; - static Pedersen bincodeDeserialize(std::vector); + static PedersenCommitment bincodeDeserialize(std::vector); }; struct PedersenHash { @@ -183,7 +183,7 @@ struct BlackBoxFuncCall { SHA256, Blake2s, SchnorrVerify, - Pedersen, + PedersenCommitment, PedersenHash, HashToField128Security, EcdsaSecp256k1, @@ -2122,7 +2122,7 @@ Circuit::BlackBoxFuncCall::SchnorrVerify serde::Deserializable BlackBoxFuncCall::Pedersen::bincodeSerialize() const +inline std::vector BlackBoxFuncCall::PedersenCommitment::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxFuncCall::Pedersen BlackBoxFuncCall::Pedersen::bincodeDeserialize(std::vector input) +inline BlackBoxFuncCall::PedersenCommitment BlackBoxFuncCall::PedersenCommitment::bincodeDeserialize( + std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw_or_abort("Some input bytes were not read"); } @@ -2157,8 +2158,8 @@ inline BlackBoxFuncCall::Pedersen BlackBoxFuncCall::Pedersen::bincodeDeserialize template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Pedersen& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxFuncCall::PedersenCommitment& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); @@ -2167,10 +2168,10 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BlackBoxFuncCall::Pedersen serde::Deserializable::deserialize( - Deserializer& deserializer) +Circuit::BlackBoxFuncCall::PedersenCommitment serde::Deserializable< + Circuit::BlackBoxFuncCall::PedersenCommitment>::deserialize(Deserializer& deserializer) { - Circuit::BlackBoxFuncCall::Pedersen obj; + Circuit::BlackBoxFuncCall::PedersenCommitment obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); From afc61f0683fb497835cc148482f11d796aa5ac47 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 15:46:52 +0000 Subject: [PATCH 15/15] change serialization --- .../dsl/acir_format/serde/acir.hpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index cc106e9e91e..dc1e8e14821 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -468,14 +468,14 @@ struct BlackBoxOp { static SchnorrVerify bincodeDeserialize(std::vector); }; - struct Pedersen { + struct PedersenCommitment { Circuit::HeapVector inputs; Circuit::RegisterIndex domain_separator; Circuit::HeapArray output; - friend bool operator==(const Pedersen&, const Pedersen&); + friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); std::vector bincodeSerialize() const; - static Pedersen bincodeDeserialize(std::vector); + static PedersenCommitment bincodeDeserialize(std::vector); }; struct PedersenHash { @@ -505,7 +505,7 @@ struct BlackBoxOp { EcdsaSecp256k1, EcdsaSecp256r1, SchnorrVerify, - Pedersen, + PedersenCommitment, PedersenHash, FixedBaseScalarMul> value; @@ -3128,7 +3128,7 @@ Circuit::BlackBoxOp::SchnorrVerify serde::Deserializable BlackBoxOp::Pedersen::bincodeSerialize() const +inline std::vector BlackBoxOp::PedersenCommitment::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxOp::Pedersen BlackBoxOp::Pedersen::bincodeDeserialize(std::vector input) +inline BlackBoxOp::PedersenCommitment BlackBoxOp::PedersenCommitment::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw_or_abort("Some input bytes were not read"); } @@ -3163,8 +3163,8 @@ inline BlackBoxOp::Pedersen BlackBoxOp::Pedersen::bincodeDeserialize(std::vector template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Pedersen& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxOp::PedersenCommitment& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); @@ -3173,10 +3173,10 @@ void serde::Serializable::serialize(const Circuit template <> template -Circuit::BlackBoxOp::Pedersen serde::Deserializable::deserialize( +Circuit::BlackBoxOp::PedersenCommitment serde::Deserializable::deserialize( Deserializer& deserializer) { - Circuit::BlackBoxOp::Pedersen obj; + Circuit::BlackBoxOp::PedersenCommitment obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer);