From 98c08217fdf7b69e7edb9e6e2451b30954fcb531 Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 8 Jan 2024 15:52:18 +0000 Subject: [PATCH 1/5] add ACIR opcodes for ECADD and ECDOUBLE --- .../dsl/acir_format/acir_format.hpp | 3 + .../dsl/acir_format/ec_operations.cpp | 31 ++ .../dsl/acir_format/ec_operations.hpp | 35 ++ .../dsl/acir_format/serde/acir.hpp | 299 +++++++++++++++++- noir/acvm-repo/acir/codegen/acir.cpp | 236 +++++++++++++- .../acir/src/circuit/black_box_functions.rs | 8 + .../opcodes/black_box_function_call.rs | 20 +- .../acvm/src/compiler/transformers/mod.rs | 8 + noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs | 6 + .../barretenberg_blackbox_solver/src/lib.rs | 18 ++ noir/acvm-repo/blackbox_solver/src/lib.rs | 12 + noir/acvm-repo/brillig/src/black_box.rs | 4 + noir/acvm-repo/brillig_vm/src/black_box.rs | 16 + noir/acvm-repo/brillig_vm/src/lib.rs | 16 + .../brillig/brillig_gen/brillig_black_box.rs | 37 +++ .../src/brillig/brillig_ir/debug_show.rs | 20 ++ .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 22 ++ .../ssa/acir_gen/acir_ir/generated_acir.rs | 22 +- .../src/ssa/ir/instruction/call.rs | 4 +- noir/tooling/lsp/src/solver.rs | 18 ++ 20 files changed, 827 insertions(+), 8 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.cpp create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.hpp 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 1f00b202b9f..f7f5be43853 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -4,6 +4,7 @@ #include "barretenberg/serialize/msgpack.hpp" #include "blake2s_constraint.hpp" #include "block_constraint.hpp" +#include "ec_operations.hpp" #include "ecdsa_secp256k1.hpp" #include "ecdsa_secp256r1.hpp" #include "fixed_base_scalar_mul.hpp" @@ -35,6 +36,8 @@ struct acir_format { std::vector pedersen_constraints; std::vector pedersen_hash_constraints; std::vector fixed_base_scalar_mul_constraints; + std::vector ec_add_constraints; + std::vector ec_double_constraints; std::vector recursion_constraints; // A standard plonk arithmetic constraint, as defined in the poly_triple struct, consists of selector values diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.cpp new file mode 100644 index 00000000000..fc657ccebb1 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.cpp @@ -0,0 +1,31 @@ +#include "ec_operations.hpp" +#include "barretenberg/dsl/types.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +#include "barretenberg/proof_system/arithmetization/gate_data.hpp" + +namespace acir_format { + +template void create_ec_add_constraint(Builder& builder, const EcAdd& input) +{ + // TODO + builder.assert_equal(input.input1_x, input.input1_x); + ASSERT(false); +} + +template void create_ec_add_constraint(UltraCircuitBuilder& builder, const EcAdd& input); +template void create_ec_add_constraint(GoblinUltraCircuitBuilder& builder, + const EcAdd& input); + +template void create_ec_double_constraint(Builder& builder, const EcDouble& input) +{ + // TODO + builder.assert_equal(input.input_x, input.input_x); + ASSERT(false); +} + +template void create_ec_double_constraint(UltraCircuitBuilder& builder, const EcDouble& input); +template void create_ec_double_constraint(GoblinUltraCircuitBuilder& builder, + const EcDouble& input); + +} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.hpp new file mode 100644 index 00000000000..f6d8e6168eb --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.hpp @@ -0,0 +1,35 @@ +#pragma once +#include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" +#include + +namespace acir_format { + +struct EcAdd { + uint32_t input1_x; + uint32_t input1_y; + uint32_t input2_x; + uint32_t input2_y; + uint32_t result_x; + uint32_t result_y; + + // for serialization, update with any new fields + MSGPACK_FIELDS(input1_x, input1_y, input2_x, input2_y, result_x, result_y); + friend bool operator==(EcAdd const& lhs, EcAdd const& rhs) = default; +}; + +template void create_ec_add_constraint(Builder& builder, const EcAdd& input); + +struct EcDouble { + uint32_t input_x; + uint32_t input_y; + uint32_t result_x; + uint32_t result_y; + + // for serialization, update with any new fields + MSGPACK_FIELDS(input_x, input_y, result_x, result_y); + friend bool operator==(EcDouble const& lhs, EcDouble const& rhs) = default; +}; + +template void create_ec_double_constraint(Builder& builder, const EcDouble& input); +} // namespace acir_format 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 2d124e2a7b2..369caaae689 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -136,6 +136,28 @@ struct BlackBoxFuncCall { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; + struct EcAdd { + Circuit::FunctionInput input1_x; + Circuit::FunctionInput input1_y; + Circuit::FunctionInput input2_x; + Circuit::FunctionInput input2_y; + std::array outputs; + + friend bool operator==(const EcAdd&, const EcAdd&); + std::vector bincodeSerialize() const; + static EcAdd bincodeDeserialize(std::vector); + }; + + struct EcDouble { + Circuit::FunctionInput input_x; + Circuit::FunctionInput input_y; + std::array outputs; + + friend bool operator==(const EcDouble&, const EcDouble&); + std::vector bincodeSerialize() const; + static EcDouble bincodeDeserialize(std::vector); + }; + struct Keccak256 { std::vector inputs; std::vector outputs; @@ -179,6 +201,8 @@ struct BlackBoxFuncCall { EcdsaSecp256k1, EcdsaSecp256r1, FixedBaseScalarMul, + EcAdd, + EcDouble, Keccak256, Keccak256VariableLength, RecursiveAggregation> @@ -479,6 +503,28 @@ struct BlackBoxOp { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; + struct EcAdd { + Circuit::RegisterIndex input1_x; + Circuit::RegisterIndex input1_y; + Circuit::RegisterIndex input2_x; + Circuit::RegisterIndex input2_y; + Circuit::HeapArray result; + + friend bool operator==(const EcAdd&, const EcAdd&); + std::vector bincodeSerialize() const; + static EcAdd bincodeDeserialize(std::vector); + }; + + struct EcDouble { + Circuit::RegisterIndex input1_x; + Circuit::RegisterIndex input1_y; + Circuit::HeapArray result; + + friend bool operator==(const EcDouble&, const EcDouble&); + std::vector bincodeSerialize() const; + static EcDouble bincodeDeserialize(std::vector); + }; + std::variant + FixedBaseScalarMul, + EcAdd, + EcDouble> value; friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); @@ -872,7 +920,7 @@ struct OpcodeLocation { }; struct PublicInputs { - std::vector value; + std::vector value; friend bool operator==(const PublicInputs&, const PublicInputs&); std::vector bincodeSerialize() const; @@ -2409,6 +2457,130 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable< namespace Circuit { +inline bool operator==(const BlackBoxFuncCall::EcAdd& lhs, const BlackBoxFuncCall::EcAdd& rhs) +{ + if (!(lhs.input1_x == rhs.input1_x)) { + return false; + } + if (!(lhs.input1_y == rhs.input1_y)) { + return false; + } + if (!(lhs.input2_x == rhs.input2_x)) { + return false; + } + if (!(lhs.input2_y == rhs.input2_y)) { + return false; + } + if (!(lhs.outputs == rhs.outputs)) { + return false; + } + return true; +} + +inline std::vector BlackBoxFuncCall::EcAdd::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxFuncCall::EcAdd BlackBoxFuncCall::EcAdd::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcAdd& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.input2_x, serializer); + serde::Serializable::serialize(obj.input2_y, serializer); + serde::Serializable::serialize(obj.outputs, serializer); +} + +template <> +template +Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable::deserialize( + Deserializer& deserializer) +{ + Circuit::BlackBoxFuncCall::EcAdd obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.input2_x = serde::Deserializable::deserialize(deserializer); + obj.input2_y = serde::Deserializable::deserialize(deserializer); + obj.outputs = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + +inline bool operator==(const BlackBoxFuncCall::EcDouble& lhs, const BlackBoxFuncCall::EcDouble& rhs) +{ + if (!(lhs.input_x == rhs.input_x)) { + return false; + } + if (!(lhs.input_y == rhs.input_y)) { + return false; + } + if (!(lhs.outputs == rhs.outputs)) { + return false; + } + return true; +} + +inline std::vector BlackBoxFuncCall::EcDouble::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxFuncCall::EcDouble BlackBoxFuncCall::EcDouble::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcDouble& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.input_x, serializer); + serde::Serializable::serialize(obj.input_y, serializer); + serde::Serializable::serialize(obj.outputs, serializer); +} + +template <> +template +Circuit::BlackBoxFuncCall::EcDouble serde::Deserializable::deserialize( + Deserializer& deserializer) +{ + Circuit::BlackBoxFuncCall::EcDouble obj; + obj.input_x = serde::Deserializable::deserialize(deserializer); + obj.input_y = serde::Deserializable::deserialize(deserializer); + obj.outputs = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + inline bool operator==(const BlackBoxFuncCall::Keccak256& lhs, const BlackBoxFuncCall::Keccak256& rhs) { if (!(lhs.inputs == rhs.inputs)) { @@ -3172,6 +3344,129 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable BlackBoxOp::EcAdd::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxOp::EcAdd BlackBoxOp::EcAdd::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcAdd& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.input2_x, serializer); + serde::Serializable::serialize(obj.input2_y, serializer); + serde::Serializable::serialize(obj.result, serializer); +} + +template <> +template +Circuit::BlackBoxOp::EcAdd serde::Deserializable::deserialize(Deserializer& deserializer) +{ + Circuit::BlackBoxOp::EcAdd obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.input2_x = serde::Deserializable::deserialize(deserializer); + obj.input2_y = serde::Deserializable::deserialize(deserializer); + obj.result = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + +inline bool operator==(const BlackBoxOp::EcDouble& lhs, const BlackBoxOp::EcDouble& rhs) +{ + if (!(lhs.input1_x == rhs.input1_x)) { + return false; + } + if (!(lhs.input1_y == rhs.input1_y)) { + return false; + } + if (!(lhs.result == rhs.result)) { + return false; + } + return true; +} + +inline std::vector BlackBoxOp::EcDouble::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BlackBoxOp::EcDouble BlackBoxOp::EcDouble::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Circuit + +template <> +template +void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcDouble& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.result, serializer); +} + +template <> +template +Circuit::BlackBoxOp::EcDouble serde::Deserializable::deserialize( + Deserializer& deserializer) +{ + Circuit::BlackBoxOp::EcDouble obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.result = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + inline bool operator==(const BlockId& lhs, const BlockId& rhs) { if (!(lhs.value == rhs.value)) { diff --git a/noir/acvm-repo/acir/codegen/acir.cpp b/noir/acvm-repo/acir/codegen/acir.cpp index 18532940752..a9214e05452 100644 --- a/noir/acvm-repo/acir/codegen/acir.cpp +++ b/noir/acvm-repo/acir/codegen/acir.cpp @@ -136,6 +136,28 @@ namespace Circuit { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; + struct EcAdd { + Circuit::FunctionInput input1_x; + Circuit::FunctionInput input1_y; + Circuit::FunctionInput input2_x; + Circuit::FunctionInput input2_y; + std::array outputs; + + friend bool operator==(const EcAdd&, const EcAdd&); + std::vector bincodeSerialize() const; + static EcAdd bincodeDeserialize(std::vector); + }; + + struct EcDouble { + Circuit::FunctionInput input_x; + Circuit::FunctionInput input_y; + std::array outputs; + + friend bool operator==(const EcDouble&, const EcDouble&); + std::vector bincodeSerialize() const; + static EcDouble bincodeDeserialize(std::vector); + }; + struct Keccak256 { std::vector inputs; std::vector outputs; @@ -168,7 +190,7 @@ namespace Circuit { static RecursiveAggregation bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; @@ -465,7 +487,29 @@ namespace Circuit { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - std::variant value; + struct EcAdd { + Circuit::RegisterIndex input1_x; + Circuit::RegisterIndex input1_y; + Circuit::RegisterIndex input2_x; + Circuit::RegisterIndex input2_y; + Circuit::HeapArray result; + + friend bool operator==(const EcAdd&, const EcAdd&); + std::vector bincodeSerialize() const; + static EcAdd bincodeDeserialize(std::vector); + }; + + struct EcDouble { + Circuit::RegisterIndex input1_x; + Circuit::RegisterIndex input1_y; + Circuit::HeapArray result; + + friend bool operator==(const EcDouble&, const EcDouble&); + std::vector bincodeSerialize() const; + static EcDouble bincodeDeserialize(std::vector); + }; + + std::variant value; friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); std::vector bincodeSerialize() const; @@ -2103,6 +2147,100 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable BlackBoxFuncCall::EcAdd::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BlackBoxFuncCall::EcAdd BlackBoxFuncCall::EcAdd::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::EcAdd &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.input2_x, serializer); + serde::Serializable::serialize(obj.input2_y, serializer); + serde::Serializable::serialize(obj.outputs, serializer); +} + +template <> +template +Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxFuncCall::EcAdd obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.input2_x = serde::Deserializable::deserialize(deserializer); + obj.input2_y = serde::Deserializable::deserialize(deserializer); + obj.outputs = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + + inline bool operator==(const BlackBoxFuncCall::EcDouble &lhs, const BlackBoxFuncCall::EcDouble &rhs) { + if (!(lhs.input_x == rhs.input_x)) { return false; } + if (!(lhs.input_y == rhs.input_y)) { return false; } + if (!(lhs.outputs == rhs.outputs)) { return false; } + return true; + } + + inline std::vector BlackBoxFuncCall::EcDouble::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BlackBoxFuncCall::EcDouble BlackBoxFuncCall::EcDouble::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::EcDouble &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.input_x, serializer); + serde::Serializable::serialize(obj.input_y, serializer); + serde::Serializable::serialize(obj.outputs, serializer); +} + +template <> +template +Circuit::BlackBoxFuncCall::EcDouble serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxFuncCall::EcDouble obj; + obj.input_x = serde::Deserializable::deserialize(deserializer); + obj.input_y = serde::Deserializable::deserialize(deserializer); + obj.outputs = serde::Deserializable::deserialize(deserializer); + return obj; +} + namespace Circuit { inline bool operator==(const BlackBoxFuncCall::Keccak256 &lhs, const BlackBoxFuncCall::Keccak256 &rhs) { @@ -2688,6 +2826,100 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable BlackBoxOp::EcAdd::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BlackBoxOp::EcAdd BlackBoxOp::EcAdd::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::EcAdd &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.input2_x, serializer); + serde::Serializable::serialize(obj.input2_y, serializer); + serde::Serializable::serialize(obj.result, serializer); +} + +template <> +template +Circuit::BlackBoxOp::EcAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxOp::EcAdd obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.input2_x = serde::Deserializable::deserialize(deserializer); + obj.input2_y = serde::Deserializable::deserialize(deserializer); + obj.result = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + + inline bool operator==(const BlackBoxOp::EcDouble &lhs, const BlackBoxOp::EcDouble &rhs) { + if (!(lhs.input1_x == rhs.input1_x)) { return false; } + if (!(lhs.input1_y == rhs.input1_y)) { return false; } + if (!(lhs.result == rhs.result)) { return false; } + return true; + } + + inline std::vector BlackBoxOp::EcDouble::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BlackBoxOp::EcDouble BlackBoxOp::EcDouble::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::EcDouble &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.input1_x, serializer); + serde::Serializable::serialize(obj.input1_y, serializer); + serde::Serializable::serialize(obj.result, serializer); +} + +template <> +template +Circuit::BlackBoxOp::EcDouble serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxOp::EcDouble obj; + obj.input1_x = serde::Deserializable::deserialize(deserializer); + obj.input1_y = serde::Deserializable::deserialize(deserializer); + obj.result = serde::Deserializable::deserialize(deserializer); + return obj; +} + namespace Circuit { inline bool operator==(const BlockId &lhs, const BlockId &rhs) { diff --git a/noir/acvm-repo/acir/src/circuit/black_box_functions.rs b/noir/acvm-repo/acir/src/circuit/black_box_functions.rs index b2dcbd73ef6..0dd2605a39c 100644 --- a/noir/acvm-repo/acir/src/circuit/black_box_functions.rs +++ b/noir/acvm-repo/acir/src/circuit/black_box_functions.rs @@ -41,6 +41,10 @@ pub enum BlackBoxFunc { /// Compute a recursive aggregation object when verifying a proof inside another circuit. /// This outputted aggregation object will then be either checked in a top-level verifier or aggregated upon again. RecursiveAggregation, + /// Addition over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined. + EcAdd, + /// Point doubling over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined. + EcDouble } impl std::fmt::Display for BlackBoxFunc { @@ -59,6 +63,8 @@ impl BlackBoxFunc { BlackBoxFunc::PedersenHash => "pedersen_hash", BlackBoxFunc::EcdsaSecp256k1 => "ecdsa_secp256k1", BlackBoxFunc::FixedBaseScalarMul => "fixed_base_scalar_mul", + BlackBoxFunc::EcAdd => "ec_add", + BlackBoxFunc::EcDouble => "ec_double", BlackBoxFunc::AND => "and", BlackBoxFunc::XOR => "xor", BlackBoxFunc::RANGE => "range", @@ -77,6 +83,8 @@ impl BlackBoxFunc { "ecdsa_secp256k1" => Some(BlackBoxFunc::EcdsaSecp256k1), "ecdsa_secp256r1" => Some(BlackBoxFunc::EcdsaSecp256r1), "fixed_base_scalar_mul" => Some(BlackBoxFunc::FixedBaseScalarMul), + "ec_add" => Some(BlackBoxFunc::EcAdd), + "ec_double" => Some(BlackBoxFunc::EcDouble), "and" => Some(BlackBoxFunc::AND), "xor" => Some(BlackBoxFunc::XOR), "range" => Some(BlackBoxFunc::RANGE), diff --git a/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs b/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs index ded3b0898a0..7ab2cc8b1bd 100644 --- a/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs +++ b/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs @@ -75,6 +75,18 @@ pub enum BlackBoxFuncCall { high: FunctionInput, outputs: (Witness, Witness), }, + EcAdd { + input1_x: FunctionInput, + input1_y: FunctionInput, + input2_x: FunctionInput, + input2_y: FunctionInput, + outputs: (Witness, Witness), + }, + EcDouble { + input_x: FunctionInput, + input_y: FunctionInput, + outputs: (Witness, Witness), + }, Keccak256 { inputs: Vec, outputs: Vec, @@ -127,6 +139,8 @@ impl BlackBoxFuncCall { BlackBoxFuncCall::EcdsaSecp256k1 { .. } => BlackBoxFunc::EcdsaSecp256k1, BlackBoxFuncCall::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1, BlackBoxFuncCall::FixedBaseScalarMul { .. } => BlackBoxFunc::FixedBaseScalarMul, + BlackBoxFuncCall::EcAdd { .. } => BlackBoxFunc::EcAdd, + BlackBoxFuncCall::EcDouble { .. } => BlackBoxFunc::EcDouble, BlackBoxFuncCall::Keccak256 { .. } => BlackBoxFunc::Keccak256, BlackBoxFuncCall::Keccak256VariableLength { .. } => BlackBoxFunc::Keccak256, BlackBoxFuncCall::RecursiveAggregation { .. } => BlackBoxFunc::RecursiveAggregation, @@ -148,6 +162,8 @@ impl BlackBoxFuncCall { vec![*lhs, *rhs] } BlackBoxFuncCall::FixedBaseScalarMul { low, high, .. } => vec![*low, *high], + BlackBoxFuncCall::EcAdd { input1_x, input1_y, input2_x, input2_y, .. } => vec![*input1_x, *input1_y, *input2_x, *input2_y], + BlackBoxFuncCall::EcDouble { input_x, input_y, .. } => vec![*input_x, *input_y], BlackBoxFuncCall::RANGE { input } => vec![*input], BlackBoxFuncCall::SchnorrVerify { public_key_x, @@ -241,7 +257,9 @@ impl BlackBoxFuncCall { | BlackBoxFuncCall::PedersenHash { output, .. } | BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output], BlackBoxFuncCall::FixedBaseScalarMul { outputs, .. } - | BlackBoxFuncCall::PedersenCommitment { outputs, .. } => vec![outputs.0, outputs.1], + | BlackBoxFuncCall::PedersenCommitment { outputs, .. } + | BlackBoxFuncCall::EcAdd { outputs, .. } + | BlackBoxFuncCall::EcDouble { outputs, .. } => vec![outputs.0, outputs.1], BlackBoxFuncCall::RANGE { .. } => vec![], BlackBoxFuncCall::Keccak256VariableLength { outputs, .. } => outputs.to_vec(), } diff --git a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs index 664e0f9ac9a..db1e61ba630 100644 --- a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -125,6 +125,14 @@ pub(super) fn transform_internal( outputs, .. } + | acir::circuit::opcodes::BlackBoxFuncCall::EcAdd { + outputs, + .. + } + | acir::circuit::opcodes::BlackBoxFuncCall::EcDouble { + outputs, + .. + } | acir::circuit::opcodes::BlackBoxFuncCall::PedersenCommitment { outputs, .. diff --git a/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs b/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs index ad15b121383..209c85c225b 100644 --- a/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs +++ b/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs @@ -153,6 +153,12 @@ pub(crate) fn solve( BlackBoxFuncCall::FixedBaseScalarMul { low, high, outputs } => { fixed_base_scalar_mul(backend, initial_witness, *low, *high, *outputs) } + BlackBoxFuncCall::EcAdd { outputs, input1_x, input1_y, input2_x, input2_y } => { + todo!(); + } + BlackBoxFuncCall::EcDouble { outputs, input_x, input_y } => { + todo!(); + } BlackBoxFuncCall::RecursiveAggregation { output_aggregation_object, .. } => { // Solve the output of the recursive aggregation to zero to prevent missing assignment errors // The correct value will be computed by the backend diff --git a/noir/acvm-repo/barretenberg_blackbox_solver/src/lib.rs b/noir/acvm-repo/barretenberg_blackbox_solver/src/lib.rs index 5d2ab834536..0a1282da95e 100644 --- a/noir/acvm-repo/barretenberg_blackbox_solver/src/lib.rs +++ b/noir/acvm-repo/barretenberg_blackbox_solver/src/lib.rs @@ -92,4 +92,22 @@ impl BlackBoxFunctionSolver for BarretenbergSolver { ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { fixed_base_scalar_mul(low, high) } + + fn ec_add( + &self, + input1_x: &FieldElement, + input1_y: &FieldElement, + input2_x: &FieldElement, + input2_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + todo!(); + } + + fn ec_double( + &self, + input_x: &FieldElement, + input_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + todo!(); + } } diff --git a/noir/acvm-repo/blackbox_solver/src/lib.rs b/noir/acvm-repo/blackbox_solver/src/lib.rs index cf2cf295f7a..4a64e01ed8e 100644 --- a/noir/acvm-repo/blackbox_solver/src/lib.rs +++ b/noir/acvm-repo/blackbox_solver/src/lib.rs @@ -47,6 +47,18 @@ pub trait BlackBoxFunctionSolver { low: &FieldElement, high: &FieldElement, ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>; + fn ec_add( + &self, + input1_x: &FieldElement, + input1_y: &FieldElement, + input2_x: &FieldElement, + input2_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>; + fn ec_double( + &self, + input_x: &FieldElement, + input_x: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>; } pub fn sha256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { diff --git a/noir/acvm-repo/brillig/src/black_box.rs b/noir/acvm-repo/brillig/src/black_box.rs index 41e54ab2705..0eb321b6818 100644 --- a/noir/acvm-repo/brillig/src/black_box.rs +++ b/noir/acvm-repo/brillig/src/black_box.rs @@ -41,4 +41,8 @@ pub enum BlackBoxOp { PedersenHash { inputs: HeapVector, domain_separator: RegisterIndex, output: RegisterIndex }, /// Performs scalar multiplication over the embedded curve. FixedBaseScalarMul { low: RegisterIndex, high: RegisterIndex, result: HeapArray }, + /// Performs addtion over the embedded curve. + EcAdd { input1_x: RegisterIndex, input1_y: RegisterIndex, input2_x: RegisterIndex, input2_y: RegisterIndex, result: HeapArray }, + /// Performs point doubling over the embedded curve. + EcDouble { input1_x: RegisterIndex, input1_y: RegisterIndex, result: HeapArray }, } diff --git a/noir/acvm-repo/brillig_vm/src/black_box.rs b/noir/acvm-repo/brillig_vm/src/black_box.rs index bf05522f89a..5cec3bdaf3c 100644 --- a/noir/acvm-repo/brillig_vm/src/black_box.rs +++ b/noir/acvm-repo/brillig_vm/src/black_box.rs @@ -140,6 +140,22 @@ pub(crate) fn evaluate_black_box( memory.write_slice(registers.get(result.pointer).to_usize(), &[x.into(), y.into()]); Ok(()) } + BlackBoxOp::EcAdd { input1_x, input1_y, input2_x, input2_y, result } => { + let input1_x = registers.get(*input1_x).to_field(); + let input1_y = registers.get(*input1_y).to_field(); + let input2_x = registers.get(*input2_x).to_field(); + let input2_y = registers.get(*input2_y).to_field(); + let (x, y) = solver.ec_add(&input1_x, &input1_y, &input2_x, &input2_y)?; + memory.write_slice(registers.get(result.pointer).to_usize(), &[x.into(), y.into()]); + Ok(()) + } + BlackBoxOp::EcDouble { input1_x, input1_y, result } => { + let input1_x = registers.get(*input1_x).to_field(); + let input1_y = registers.get(*input1_y).to_field(); + let (x, y) = solver.ec_double(&input1_x, &input1_y)?; + memory.write_slice(registers.get(result.pointer).to_usize(), &[x.into(), y.into()]); + Ok(()) + } BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { let inputs: Vec = read_heap_vector(memory, registers, inputs).iter().map(|x| x.to_field()).collect(); diff --git a/noir/acvm-repo/brillig_vm/src/lib.rs b/noir/acvm-repo/brillig_vm/src/lib.rs index 482b9b36d77..df4c8135bce 100644 --- a/noir/acvm-repo/brillig_vm/src/lib.rs +++ b/noir/acvm-repo/brillig_vm/src/lib.rs @@ -451,6 +451,22 @@ impl BlackBoxFunctionSolver for DummyBlackBoxSolver { ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { Ok((4_u128.into(), 5_u128.into())) } + fn ec_add( + &self, + _input1_x: &FieldElement, + _input1_y: &FieldElement, + _input2_x: &FieldElement, + _input2_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Ok((5_u128.into(), 6_u128.into())) + } + fn ec_double( + &self, + _input1_x: &FieldElement, + _input1_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Ok((7_u128.into(), 8_u128.into())) + } } #[cfg(test)] diff --git a/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index d7f83c32cdf..abbb829b51b 100644 --- a/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -147,6 +147,43 @@ pub(crate) fn convert_black_box_call( ) } } + BlackBoxFunc::EcAdd => { + if let ( + [BrilligVariable::Simple(input1_x), BrilligVariable::Simple(input1_y), + BrilligVariable::Simple(input2_x), BrilligVariable::Simple(input2_y)], + [BrilligVariable::BrilligArray(result_array)], + ) = (function_arguments, function_results) + { + brillig_context.black_box_op_instruction(BlackBoxOp::EcAdd { + input1_x: *input1_x, + input1_y: *input1_y, + input2_x: *input2_x, + input2_y: *input2_y, + result: result_array.to_heap_array(), + }); + } else { + unreachable!( + "ICE: EcAdd expects four register arguments and one array result" + ) + } + } + BlackBoxFunc::EcDouble => { + if let ( + [BrilligVariable::Simple(input1_x), BrilligVariable::Simple(input1_y)], + [BrilligVariable::BrilligArray(result_array)], + ) = (function_arguments, function_results) + { + brillig_context.black_box_op_instruction(BlackBoxOp::EcDouble { + input1_x: *input1_x, + input1_y: *input1_y, + result: result_array.to_heap_array(), + }); + } else { + unreachable!( + "ICE: EcAdd expects two register arguments and one array result" + ) + } + } _ => unimplemented!("ICE: Black box function {:?} is not implemented", bb_func), } } diff --git a/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs b/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs index aae74849b8c..16c5dcfa894 100644 --- a/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs +++ b/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs @@ -396,6 +396,26 @@ impl DebugShow { result ); } + BlackBoxOp::EcAdd { input1_x, input1_y, input2_x, input2_y, result } => { + debug_println!( + self.enable_debug_trace, + " EC_ADD ({} {}) ({} {}) -> {}", + input1_x, + input1_y, + input2_x, + input2_y, + result + ); + } + BlackBoxOp::EcDouble { input1_x, input1_y, result } => { + debug_println!( + self.enable_debug_trace, + " EC_DOUBLE ({} {}) -> {}", + input1_x, + input1_y, + result + ); + } BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { debug_println!( self.enable_debug_trace, diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index e039a7793c0..5fd36976153 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1640,6 +1640,28 @@ fn execute_brillig( "FixedBaseScalarMul is not supported".to_string(), )) } + fn ec_add( + &self, + _input1_x: &FieldElement, + _input1_y: &FieldElement, + _input2_x: &FieldElement, + _input2_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Err(BlackBoxResolutionError::Failed( + BlackBoxFunc::EcAdd, + "EcAdd is not supported".to_string(), + )) + } + fn ec_double( + &self, + _input_x: &FieldElement, + _input_y: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Err(BlackBoxResolutionError::Failed( + BlackBoxFunc::EcDouble, + "EcDouble is not supported".to_string(), + )) + } } // Set input values diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index bd8271260af..0f19da000bd 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -204,6 +204,18 @@ impl GeneratedAcir { high: inputs[1][0], outputs: (outputs[0], outputs[1]), }, + BlackBoxFunc::EcAdd => BlackBoxFuncCall::EcAdd { + input1_x: inputs[0][0], + input1_y: inputs[1][0], + input2_x: inputs[2][0], + input2_y: inputs[3][0], + outputs: (outputs[0], outputs[1]), + }, + BlackBoxFunc::EcDouble => BlackBoxFuncCall::EcDouble { + input_x: inputs[0][0], + input_y: inputs[1][0], + outputs: (outputs[0], outputs[1]), + }, BlackBoxFunc::Keccak256 => { let var_message_size = match inputs.to_vec().pop() { Some(var_message_size) => var_message_size[0], @@ -586,6 +598,10 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { BlackBoxFunc::FixedBaseScalarMul => Some(2), // Recursive aggregation has a variable number of inputs BlackBoxFunc::RecursiveAggregation => None, + // Addtion over the embedded curve: input are coordinates (x1,y1) and (x2,y2) of the Grumpkin points + BlackBoxFunc::EcAdd => Some(4), + // Doubling over the embedded curve: input is (x,y) coordinate of the point. + BlackBoxFunc::EcDouble => Some(2), } } @@ -609,9 +625,11 @@ fn black_box_expected_output_size(name: BlackBoxFunc) -> Option { BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 | BlackBoxFunc::EcdsaSecp256r1 => Some(1), - // Output of fixed based scalar mul over the embedded curve + // Output of operations over the embedded curve // will be 2 field elements representing the point. - BlackBoxFunc::FixedBaseScalarMul => Some(2), + BlackBoxFunc::FixedBaseScalarMul + | BlackBoxFunc::EcAdd + | BlackBoxFunc::EcDouble => Some(2), // Recursive aggregation has a variable number of outputs BlackBoxFunc::RecursiveAggregation => None, } diff --git a/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs b/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs index cada0b97f93..3886fd76378 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs @@ -404,7 +404,9 @@ fn simplify_black_box_func( BlackBoxFunc::FixedBaseScalarMul | BlackBoxFunc::SchnorrVerify | BlackBoxFunc::PedersenCommitment - | BlackBoxFunc::PedersenHash => { + | BlackBoxFunc::PedersenHash + | BlackBoxFunc::EcAdd + | BlackBoxFunc::EcDouble => { // Currently unsolvable here as we rely on an implementation in the backend. SimplifyResult::None } diff --git a/noir/tooling/lsp/src/solver.rs b/noir/tooling/lsp/src/solver.rs index 090f71d63b4..5d95c88e49b 100644 --- a/noir/tooling/lsp/src/solver.rs +++ b/noir/tooling/lsp/src/solver.rs @@ -39,6 +39,24 @@ impl BlackBoxFunctionSolver for WrapperSolver { ) -> Result { self.0.pedersen_hash(inputs, domain_separator) } + + fn ec_add( + &self, + input1_x: &acvm::FieldElement, + input1_y: &acvm::FieldElement, + input2_x: &acvm::FieldElement, + input2_y: &acvm::FieldElement, + ) -> Result<(acvm::FieldElement, acvm::FieldElement), acvm::BlackBoxResolutionError> { + self.0.ec_add(input1_x, input1_y, input2_x, input2_y) + } + + fn ec_double( + &self, + input_x: &acvm::FieldElement, + input_y: &acvm::FieldElement, + ) -> Result<(acvm::FieldElement, acvm::FieldElement), acvm::BlackBoxResolutionError> { + self.0.ec_double(input_x, input_y) + } } // We also have a mocked implementation of the `BlackBoxFunctionSolver` trait for use in tests From 523b6aeadac74dbf6fff100421d6318a033effcd Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 8 Jan 2024 17:24:29 +0000 Subject: [PATCH 2/5] Fix unit tests --- .../src/barretenberg/dsl/acir_format/acir_format.cpp | 10 ++++++++++ .../barretenberg/dsl/acir_format/acir_format.test.cpp | 10 ++++++++++ .../dsl/acir_format/block_constraint.test.cpp | 2 ++ .../dsl/acir_format/ecdsa_secp256k1.test.cpp | 4 ++++ .../dsl/acir_format/ecdsa_secp256r1.test.cpp | 8 ++++++++ .../dsl/acir_format/recursion_constraint.test.cpp | 4 ++++ 6 files changed, 38 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 516fa1aaa89..a1fd8a40e9c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -141,6 +141,16 @@ void build_constraints(Builder& builder, acir_format const& constraint_system, b create_fixed_base_constraint(builder, constraint); } + // Add ec add constraints + for (const auto& constraint : constraint_system.ec_add_constraints) { + create_ec_add_constraint(builder, constraint); + } + + // Add ec double + for (const auto& constraint : constraint_system.ec_double_constraints) { + create_ec_double_constraint(builder, constraint); + } + // Add block constraints for (const auto& constraint : constraint_system.block_constraints) { create_block_constraints(builder, constraint, has_valid_witness_assignments); 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 a4f64e0791c..0a4dbf83e07 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 @@ -42,6 +42,8 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { constraint }, .block_constraints = {}, @@ -148,6 +150,8 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { expr_a, expr_b, expr_c, expr_d }, .block_constraints = {} }; @@ -212,6 +216,8 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { poly_triple{ .a = schnorr_constraint.result, @@ -299,6 +305,8 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { poly_triple{ .a = schnorr_constraint.result, @@ -405,6 +413,8 @@ TEST_F(AcirFormatTests, TestVarKeccak) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { dummy }, .block_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 a20de2c75db..1003dba0aa9 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 @@ -123,6 +123,8 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = { block }, 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 9bcbc89ec87..73dbd8fe246 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 @@ -102,6 +102,8 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = {}, @@ -142,6 +144,8 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_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 5d26a4b7a37..e497ad4e136 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 @@ -136,6 +136,8 @@ TEST(ECDSASecp256r1, test_hardcoded) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = {}, @@ -177,6 +179,8 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = {}, @@ -216,6 +220,8 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = {}, @@ -250,6 +256,8 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_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 c4decf04a3a..23e624cb732 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 @@ -95,6 +95,8 @@ Builder create_inner_circuit() .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = { expr_a, expr_b, expr_c, expr_d }, .block_constraints = {} }; @@ -252,6 +254,8 @@ Builder create_outer_circuit(std::vector& inner_circuits) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = recursion_constraints, .constraints = {}, .block_constraints = {} }; From d150cd92a8b223c3eb4861664a874039dd8aa5ac Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 8 Jan 2024 17:57:39 +0000 Subject: [PATCH 3/5] fix unit test(2) --- .../cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp | 2 ++ .../src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp | 2 ++ 2 files changed, 4 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 cbb53fa931f..5e61e2d4b1f 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 @@ -464,6 +464,8 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_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 3c76a1ce379..cc9a5a2e607 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 @@ -187,6 +187,8 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) .pedersen_constraints = {}, .pedersen_hash_constraints = {}, .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, .recursion_constraints = {}, .constraints = {}, .block_constraints = {}, From d88d4b34fb38c9830d39a694258e5feefa1cf1b2 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:12:22 +0000 Subject: [PATCH 4/5] Update noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs --- .../noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index 1db567d0584..14aec73dd42 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -605,7 +605,7 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { BlackBoxFunc::FixedBaseScalarMul => Some(2), // Recursive aggregation has a variable number of inputs BlackBoxFunc::RecursiveAggregation => None, - // Addtion over the embedded curve: input are coordinates (x1,y1) and (x2,y2) of the Grumpkin points + // Addition over the embedded curve: input are coordinates (x1,y1) and (x2,y2) of the Grumpkin points BlackBoxFunc::EcAdd => Some(4), // Doubling over the embedded curve: input is (x,y) coordinate of the point. BlackBoxFunc::EcDouble => Some(2), From 0e40f318e92b7e2ac9f4c0c3d2fecbd930bf9c33 Mon Sep 17 00:00:00 2001 From: guipublic Date: Tue, 9 Jan 2024 13:21:38 +0000 Subject: [PATCH 5/5] rename ecadd to embeddedcurveadd --- .../dsl/acir_format/serde/acir.hpp | 138 +++++++++--------- noir/acvm-repo/acir/codegen/acir.cpp | 92 ++++++------ .../acir/src/circuit/black_box_functions.rs | 12 +- .../opcodes/black_box_function_call.rs | 16 +- .../acvm/src/compiler/transformers/mod.rs | 4 +- noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs | 4 +- noir/acvm-repo/brillig/src/black_box.rs | 4 +- noir/acvm-repo/brillig_vm/src/black_box.rs | 4 +- .../brillig/brillig_gen/brillig_black_box.rs | 12 +- .../src/brillig/brillig_ir/debug_show.rs | 8 +- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 4 +- .../ssa/acir_gen/acir_ir/generated_acir.rs | 12 +- .../src/ssa/ir/instruction/call.rs | 4 +- 13 files changed, 159 insertions(+), 155 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 3a0855f9964..b3c2106a4fe 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -145,26 +145,26 @@ struct BlackBoxFuncCall { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct EcAdd { + struct EmbeddedCurveAdd { Circuit::FunctionInput input1_x; Circuit::FunctionInput input1_y; Circuit::FunctionInput input2_x; Circuit::FunctionInput input2_y; std::array outputs; - friend bool operator==(const EcAdd&, const EcAdd&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static EcAdd bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; - struct EcDouble { + struct EmbeddedCurveDouble { Circuit::FunctionInput input_x; Circuit::FunctionInput input_y; std::array outputs; - friend bool operator==(const EcDouble&, const EcDouble&); + friend bool operator==(const EmbeddedCurveDouble&, const EmbeddedCurveDouble&); std::vector bincodeSerialize() const; - static EcDouble bincodeDeserialize(std::vector); + static EmbeddedCurveDouble bincodeDeserialize(std::vector); }; struct Keccak256 { @@ -218,8 +218,8 @@ struct BlackBoxFuncCall { EcdsaSecp256k1, EcdsaSecp256r1, FixedBaseScalarMul, - EcAdd, - EcDouble, + EmbeddedCurveAdd, + EmbeddedCurveDouble, Keccak256, Keccak256VariableLength, Keccakf1600, @@ -521,26 +521,26 @@ struct BlackBoxOp { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct EcAdd { + struct EmbeddedCurveAdd { Circuit::RegisterIndex input1_x; Circuit::RegisterIndex input1_y; Circuit::RegisterIndex input2_x; Circuit::RegisterIndex input2_y; Circuit::HeapArray result; - friend bool operator==(const EcAdd&, const EcAdd&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static EcAdd bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; - struct EcDouble { + struct EmbeddedCurveDouble { Circuit::RegisterIndex input1_x; Circuit::RegisterIndex input1_y; Circuit::HeapArray result; - friend bool operator==(const EcDouble&, const EcDouble&); + friend bool operator==(const EmbeddedCurveDouble&, const EmbeddedCurveDouble&); std::vector bincodeSerialize() const; - static EcDouble bincodeDeserialize(std::vector); + static EmbeddedCurveDouble bincodeDeserialize(std::vector); }; std::variant + EmbeddedCurveAdd, + EmbeddedCurveDouble> value; friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); @@ -853,12 +853,12 @@ struct MemOp { struct Opcode { - struct Arithmetic { + struct AssertZero { Circuit::Expression value; - friend bool operator==(const Arithmetic&, const Arithmetic&); + friend bool operator==(const AssertZero&, const AssertZero&); std::vector bincodeSerialize() const; - static Arithmetic bincodeDeserialize(std::vector); + static AssertZero bincodeDeserialize(std::vector); }; struct BlackBoxFuncCall { @@ -904,7 +904,7 @@ struct Opcode { static MemoryInit bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const Opcode&, const Opcode&); std::vector bincodeSerialize() const; @@ -938,7 +938,7 @@ struct OpcodeLocation { }; struct PublicInputs { - std::vector value; + std::vector value; friend bool operator==(const PublicInputs&, const PublicInputs&); std::vector bincodeSerialize() const; @@ -2527,7 +2527,7 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable< namespace Circuit { -inline bool operator==(const BlackBoxFuncCall::EcAdd& lhs, const BlackBoxFuncCall::EcAdd& rhs) +inline bool operator==(const BlackBoxFuncCall::EmbeddedCurveAdd& lhs, const BlackBoxFuncCall::EmbeddedCurveAdd& rhs) { if (!(lhs.input1_x == rhs.input1_x)) { return false; @@ -2547,17 +2547,18 @@ inline bool operator==(const BlackBoxFuncCall::EcAdd& lhs, const BlackBoxFuncCal return true; } -inline std::vector BlackBoxFuncCall::EcAdd::bincodeSerialize() const +inline std::vector BlackBoxFuncCall::EmbeddedCurveAdd::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxFuncCall::EcAdd BlackBoxFuncCall::EcAdd::bincodeDeserialize(std::vector input) +inline BlackBoxFuncCall::EmbeddedCurveAdd BlackBoxFuncCall::EmbeddedCurveAdd::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"); } @@ -2568,8 +2569,8 @@ inline BlackBoxFuncCall::EcAdd BlackBoxFuncCall::EcAdd::bincodeDeserialize(std:: template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcAdd& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxFuncCall::EmbeddedCurveAdd& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); @@ -2580,10 +2581,10 @@ void serde::Serializable::serialize(const Circ template <> template -Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable::deserialize( - Deserializer& deserializer) +Circuit::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable< + Circuit::BlackBoxFuncCall::EmbeddedCurveAdd>::deserialize(Deserializer& deserializer) { - Circuit::BlackBoxFuncCall::EcAdd obj; + Circuit::BlackBoxFuncCall::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -2594,7 +2595,8 @@ Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable BlackBoxFuncCall::EcDouble::bincodeSerialize() const +inline std::vector BlackBoxFuncCall::EmbeddedCurveDouble::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxFuncCall::EcDouble BlackBoxFuncCall::EcDouble::bincodeDeserialize(std::vector input) +inline BlackBoxFuncCall::EmbeddedCurveDouble BlackBoxFuncCall::EmbeddedCurveDouble::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"); } @@ -2629,8 +2632,8 @@ inline BlackBoxFuncCall::EcDouble BlackBoxFuncCall::EcDouble::bincodeDeserialize template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcDouble& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxFuncCall::EmbeddedCurveDouble& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input_x, serializer); serde::Serializable::serialize(obj.input_y, serializer); @@ -2639,10 +2642,10 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BlackBoxFuncCall::EcDouble serde::Deserializable::deserialize( - Deserializer& deserializer) +Circuit::BlackBoxFuncCall::EmbeddedCurveDouble serde::Deserializable< + Circuit::BlackBoxFuncCall::EmbeddedCurveDouble>::deserialize(Deserializer& deserializer) { - Circuit::BlackBoxFuncCall::EcDouble obj; + Circuit::BlackBoxFuncCall::EmbeddedCurveDouble obj; obj.input_x = serde::Deserializable::deserialize(deserializer); obj.input_y = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); @@ -3454,7 +3457,7 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable BlackBoxOp::EcAdd::bincodeSerialize() const +inline std::vector BlackBoxOp::EmbeddedCurveAdd::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxOp::EcAdd BlackBoxOp::EcAdd::bincodeDeserialize(std::vector input) +inline BlackBoxOp::EmbeddedCurveAdd BlackBoxOp::EmbeddedCurveAdd::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"); } @@ -3495,8 +3498,8 @@ inline BlackBoxOp::EcAdd BlackBoxOp::EcAdd::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcAdd& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxOp::EmbeddedCurveAdd& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); @@ -3507,9 +3510,10 @@ void serde::Serializable::serialize(const Circuit::B template <> template -Circuit::BlackBoxOp::EcAdd serde::Deserializable::deserialize(Deserializer& deserializer) +Circuit::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize( + Deserializer& deserializer) { - Circuit::BlackBoxOp::EcAdd obj; + Circuit::BlackBoxOp::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -3520,7 +3524,7 @@ Circuit::BlackBoxOp::EcAdd serde::Deserializable::de namespace Circuit { -inline bool operator==(const BlackBoxOp::EcDouble& lhs, const BlackBoxOp::EcDouble& rhs) +inline bool operator==(const BlackBoxOp::EmbeddedCurveDouble& lhs, const BlackBoxOp::EmbeddedCurveDouble& rhs) { if (!(lhs.input1_x == rhs.input1_x)) { return false; @@ -3534,17 +3538,17 @@ inline bool operator==(const BlackBoxOp::EcDouble& lhs, const BlackBoxOp::EcDoub return true; } -inline std::vector BlackBoxOp::EcDouble::bincodeSerialize() const +inline std::vector BlackBoxOp::EmbeddedCurveDouble::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline BlackBoxOp::EcDouble BlackBoxOp::EcDouble::bincodeDeserialize(std::vector input) +inline BlackBoxOp::EmbeddedCurveDouble BlackBoxOp::EmbeddedCurveDouble::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"); } @@ -3555,8 +3559,8 @@ inline BlackBoxOp::EcDouble BlackBoxOp::EcDouble::bincodeDeserialize(std::vector template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcDouble& obj, - Serializer& serializer) +void serde::Serializable::serialize( + const Circuit::BlackBoxOp::EmbeddedCurveDouble& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); @@ -3565,10 +3569,10 @@ void serde::Serializable::serialize(const Circuit template <> template -Circuit::BlackBoxOp::EcDouble serde::Deserializable::deserialize( +Circuit::BlackBoxOp::EmbeddedCurveDouble serde::Deserializable::deserialize( Deserializer& deserializer) { - Circuit::BlackBoxOp::EcDouble obj; + Circuit::BlackBoxOp::EmbeddedCurveDouble obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.result = serde::Deserializable::deserialize(deserializer); @@ -5404,7 +5408,7 @@ Circuit::Opcode serde::Deserializable::deserialize(Deserializer namespace Circuit { -inline bool operator==(const Opcode::Arithmetic& lhs, const Opcode::Arithmetic& rhs) +inline bool operator==(const Opcode::AssertZero& lhs, const Opcode::AssertZero& rhs) { if (!(lhs.value == rhs.value)) { return false; @@ -5412,17 +5416,17 @@ inline bool operator==(const Opcode::Arithmetic& lhs, const Opcode::Arithmetic& return true; } -inline std::vector Opcode::Arithmetic::bincodeSerialize() const +inline std::vector Opcode::AssertZero::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline Opcode::Arithmetic Opcode::Arithmetic::bincodeDeserialize(std::vector input) +inline Opcode::AssertZero Opcode::AssertZero::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"); } @@ -5433,7 +5437,7 @@ inline Opcode::Arithmetic Opcode::Arithmetic::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Circuit::Opcode::Arithmetic& obj, +void serde::Serializable::serialize(const Circuit::Opcode::AssertZero& obj, Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); @@ -5441,9 +5445,9 @@ void serde::Serializable::serialize(const Circuit:: template <> template -Circuit::Opcode::Arithmetic serde::Deserializable::deserialize(Deserializer& deserializer) +Circuit::Opcode::AssertZero serde::Deserializable::deserialize(Deserializer& deserializer) { - Circuit::Opcode::Arithmetic obj; + Circuit::Opcode::AssertZero obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } diff --git a/noir/acvm-repo/acir/codegen/acir.cpp b/noir/acvm-repo/acir/codegen/acir.cpp index a4e16f478bf..d0b920e057c 100644 --- a/noir/acvm-repo/acir/codegen/acir.cpp +++ b/noir/acvm-repo/acir/codegen/acir.cpp @@ -145,26 +145,26 @@ namespace Circuit { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct EcAdd { + struct EmbeddedCurveAdd { Circuit::FunctionInput input1_x; Circuit::FunctionInput input1_y; Circuit::FunctionInput input2_x; Circuit::FunctionInput input2_y; std::array outputs; - friend bool operator==(const EcAdd&, const EcAdd&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static EcAdd bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; - struct EcDouble { + struct EmbeddedCurveDouble { Circuit::FunctionInput input_x; Circuit::FunctionInput input_y; std::array outputs; - friend bool operator==(const EcDouble&, const EcDouble&); + friend bool operator==(const EmbeddedCurveDouble&, const EmbeddedCurveDouble&); std::vector bincodeSerialize() const; - static EcDouble bincodeDeserialize(std::vector); + static EmbeddedCurveDouble bincodeDeserialize(std::vector); }; struct Keccak256 { @@ -206,7 +206,7 @@ namespace Circuit { static RecursiveAggregation bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; @@ -503,29 +503,29 @@ namespace Circuit { static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct EcAdd { + struct EmbeddedCurveAdd { Circuit::RegisterIndex input1_x; Circuit::RegisterIndex input1_y; Circuit::RegisterIndex input2_x; Circuit::RegisterIndex input2_y; Circuit::HeapArray result; - friend bool operator==(const EcAdd&, const EcAdd&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static EcAdd bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; - struct EcDouble { + struct EmbeddedCurveDouble { Circuit::RegisterIndex input1_x; Circuit::RegisterIndex input1_y; Circuit::HeapArray result; - friend bool operator==(const EcDouble&, const EcDouble&); + friend bool operator==(const EmbeddedCurveDouble&, const EmbeddedCurveDouble&); std::vector bincodeSerialize() const; - static EcDouble bincodeDeserialize(std::vector); + static EmbeddedCurveDouble bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); std::vector bincodeSerialize() const; @@ -2206,7 +2206,7 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable BlackBoxFuncCall::EcAdd::bincodeSerialize() const { + inline std::vector BlackBoxFuncCall::EmbeddedCurveAdd::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline BlackBoxFuncCall::EcAdd BlackBoxFuncCall::EcAdd::bincodeDeserialize(std::vector input) { + inline BlackBoxFuncCall::EmbeddedCurveAdd BlackBoxFuncCall::EmbeddedCurveAdd::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 serde::deserialization_error("Some input bytes were not read"); } @@ -2234,7 +2234,7 @@ namespace Circuit { template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EmbeddedCurveAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); serde::Serializable::serialize(obj.input2_x, serializer); @@ -2244,8 +2244,8 @@ void serde::Serializable::serialize(const Circ template <> template -Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::EcAdd obj; +Circuit::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxFuncCall::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -2256,22 +2256,22 @@ Circuit::BlackBoxFuncCall::EcAdd serde::Deserializable BlackBoxFuncCall::EcDouble::bincodeSerialize() const { + inline std::vector BlackBoxFuncCall::EmbeddedCurveDouble::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline BlackBoxFuncCall::EcDouble BlackBoxFuncCall::EcDouble::bincodeDeserialize(std::vector input) { + inline BlackBoxFuncCall::EmbeddedCurveDouble BlackBoxFuncCall::EmbeddedCurveDouble::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 serde::deserialization_error("Some input bytes were not read"); } @@ -2282,7 +2282,7 @@ namespace Circuit { template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcDouble &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EmbeddedCurveDouble &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input_x, serializer); serde::Serializable::serialize(obj.input_y, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2290,8 +2290,8 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BlackBoxFuncCall::EcDouble serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::EcDouble obj; +Circuit::BlackBoxFuncCall::EmbeddedCurveDouble serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxFuncCall::EmbeddedCurveDouble obj; obj.input_x = serde::Deserializable::deserialize(deserializer); obj.input_y = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); @@ -2920,7 +2920,7 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable BlackBoxOp::EcAdd::bincodeSerialize() const { + inline std::vector BlackBoxOp::EmbeddedCurveAdd::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline BlackBoxOp::EcAdd BlackBoxOp::EcAdd::bincodeDeserialize(std::vector input) { + inline BlackBoxOp::EmbeddedCurveAdd BlackBoxOp::EmbeddedCurveAdd::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 serde::deserialization_error("Some input bytes were not read"); } @@ -2948,7 +2948,7 @@ namespace Circuit { template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Circuit::BlackBoxOp::EmbeddedCurveAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); serde::Serializable::serialize(obj.input2_x, serializer); @@ -2958,8 +2958,8 @@ void serde::Serializable::serialize(const Circuit::B template <> template -Circuit::BlackBoxOp::EcAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::EcAdd obj; +Circuit::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxOp::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -2970,22 +2970,22 @@ Circuit::BlackBoxOp::EcAdd serde::Deserializable::de namespace Circuit { - inline bool operator==(const BlackBoxOp::EcDouble &lhs, const BlackBoxOp::EcDouble &rhs) { + inline bool operator==(const BlackBoxOp::EmbeddedCurveDouble &lhs, const BlackBoxOp::EmbeddedCurveDouble &rhs) { if (!(lhs.input1_x == rhs.input1_x)) { return false; } if (!(lhs.input1_y == rhs.input1_y)) { return false; } if (!(lhs.result == rhs.result)) { return false; } return true; } - inline std::vector BlackBoxOp::EcDouble::bincodeSerialize() const { + inline std::vector BlackBoxOp::EmbeddedCurveDouble::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline BlackBoxOp::EcDouble BlackBoxOp::EcDouble::bincodeDeserialize(std::vector input) { + inline BlackBoxOp::EmbeddedCurveDouble BlackBoxOp::EmbeddedCurveDouble::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 serde::deserialization_error("Some input bytes were not read"); } @@ -2996,7 +2996,7 @@ namespace Circuit { template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcDouble &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Circuit::BlackBoxOp::EmbeddedCurveDouble &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); serde::Serializable::serialize(obj.result, serializer); @@ -3004,8 +3004,8 @@ void serde::Serializable::serialize(const Circuit template <> template -Circuit::BlackBoxOp::EcDouble serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::EcDouble obj; +Circuit::BlackBoxOp::EmbeddedCurveDouble serde::Deserializable::deserialize(Deserializer &deserializer) { + Circuit::BlackBoxOp::EmbeddedCurveDouble obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.result = serde::Deserializable::deserialize(deserializer); diff --git a/noir/acvm-repo/acir/src/circuit/black_box_functions.rs b/noir/acvm-repo/acir/src/circuit/black_box_functions.rs index db7c8bd15b6..78bc4121de7 100644 --- a/noir/acvm-repo/acir/src/circuit/black_box_functions.rs +++ b/noir/acvm-repo/acir/src/circuit/black_box_functions.rs @@ -46,9 +46,9 @@ pub enum BlackBoxFunc { /// This outputted aggregation object will then be either checked in a top-level verifier or aggregated upon again. RecursiveAggregation, /// Addition over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined. - EcAdd, + EmbeddedCurveAdd, /// Point doubling over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined. - EcDouble + EmbeddedCurveDouble } impl std::fmt::Display for BlackBoxFunc { @@ -68,8 +68,8 @@ impl BlackBoxFunc { BlackBoxFunc::PedersenHash => "pedersen_hash", BlackBoxFunc::EcdsaSecp256k1 => "ecdsa_secp256k1", BlackBoxFunc::FixedBaseScalarMul => "fixed_base_scalar_mul", - BlackBoxFunc::EcAdd => "ec_add", - BlackBoxFunc::EcDouble => "ec_double", + BlackBoxFunc::EmbeddedCurveAdd => "ec_add", + BlackBoxFunc::EmbeddedCurveDouble => "ec_double", BlackBoxFunc::AND => "and", BlackBoxFunc::XOR => "xor", BlackBoxFunc::RANGE => "range", @@ -90,8 +90,8 @@ impl BlackBoxFunc { "ecdsa_secp256k1" => Some(BlackBoxFunc::EcdsaSecp256k1), "ecdsa_secp256r1" => Some(BlackBoxFunc::EcdsaSecp256r1), "fixed_base_scalar_mul" => Some(BlackBoxFunc::FixedBaseScalarMul), - "ec_add" => Some(BlackBoxFunc::EcAdd), - "ec_double" => Some(BlackBoxFunc::EcDouble), + "ec_add" => Some(BlackBoxFunc::EmbeddedCurveAdd), + "ec_double" => Some(BlackBoxFunc::EmbeddedCurveDouble), "and" => Some(BlackBoxFunc::AND), "xor" => Some(BlackBoxFunc::XOR), "range" => Some(BlackBoxFunc::RANGE), diff --git a/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs b/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs index 2c8f796b7da..2ac4d558b68 100644 --- a/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs +++ b/noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs @@ -79,14 +79,14 @@ pub enum BlackBoxFuncCall { high: FunctionInput, outputs: (Witness, Witness), }, - EcAdd { + EmbeddedCurveAdd { input1_x: FunctionInput, input1_y: FunctionInput, input2_x: FunctionInput, input2_y: FunctionInput, outputs: (Witness, Witness), }, - EcDouble { + EmbeddedCurveDouble { input_x: FunctionInput, input_y: FunctionInput, outputs: (Witness, Witness), @@ -137,8 +137,8 @@ impl BlackBoxFuncCall { BlackBoxFuncCall::EcdsaSecp256k1 { .. } => BlackBoxFunc::EcdsaSecp256k1, BlackBoxFuncCall::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1, BlackBoxFuncCall::FixedBaseScalarMul { .. } => BlackBoxFunc::FixedBaseScalarMul, - BlackBoxFuncCall::EcAdd { .. } => BlackBoxFunc::EcAdd, - BlackBoxFuncCall::EcDouble { .. } => BlackBoxFunc::EcDouble, + BlackBoxFuncCall::EmbeddedCurveAdd { .. } => BlackBoxFunc::EmbeddedCurveAdd, + BlackBoxFuncCall::EmbeddedCurveDouble { .. } => BlackBoxFunc::EmbeddedCurveDouble, BlackBoxFuncCall::Keccak256 { .. } => BlackBoxFunc::Keccak256, BlackBoxFuncCall::Keccak256VariableLength { .. } => BlackBoxFunc::Keccak256, BlackBoxFuncCall::Keccakf1600 { .. } => BlackBoxFunc::Keccakf1600, @@ -163,8 +163,8 @@ impl BlackBoxFuncCall { vec![*lhs, *rhs] } BlackBoxFuncCall::FixedBaseScalarMul { low, high, .. } => vec![*low, *high], - BlackBoxFuncCall::EcAdd { input1_x, input1_y, input2_x, input2_y, .. } => vec![*input1_x, *input1_y, *input2_x, *input2_y], - BlackBoxFuncCall::EcDouble { input_x, input_y, .. } => vec![*input_x, *input_y], + BlackBoxFuncCall::EmbeddedCurveAdd { input1_x, input1_y, input2_x, input2_y, .. } => vec![*input1_x, *input1_y, *input2_x, *input2_y], + BlackBoxFuncCall::EmbeddedCurveDouble { input_x, input_y, .. } => vec![*input_x, *input_y], BlackBoxFuncCall::RANGE { input } => vec![*input], BlackBoxFuncCall::SchnorrVerify { public_key_x, @@ -255,8 +255,8 @@ impl BlackBoxFuncCall { | BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output], BlackBoxFuncCall::FixedBaseScalarMul { outputs, .. } | BlackBoxFuncCall::PedersenCommitment { outputs, .. } - | BlackBoxFuncCall::EcAdd { outputs, .. } - | BlackBoxFuncCall::EcDouble { outputs, .. } => vec![outputs.0, outputs.1], + | BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } + | BlackBoxFuncCall::EmbeddedCurveDouble { outputs, .. } => vec![outputs.0, outputs.1], BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => vec![], BlackBoxFuncCall::Keccak256VariableLength { outputs, .. } => outputs.to_vec(), } diff --git a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs index 0f38b4d26c7..bb4dd9e66b2 100644 --- a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -122,11 +122,11 @@ pub(super) fn transform_internal( outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::EcAdd { + | acir::circuit::opcodes::BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::EcDouble { + | acir::circuit::opcodes::BlackBoxFuncCall::EmbeddedCurveDouble { outputs, .. } diff --git a/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs b/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs index 61e4fbf2ecc..db58795c881 100644 --- a/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs +++ b/noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs @@ -177,10 +177,10 @@ pub(crate) fn solve( BlackBoxFuncCall::FixedBaseScalarMul { low, high, outputs } => { fixed_base_scalar_mul(backend, initial_witness, *low, *high, *outputs) } - BlackBoxFuncCall::EcAdd { outputs, input1_x, input1_y, input2_x, input2_y } => { + BlackBoxFuncCall::EmbeddedCurveAdd { outputs, input1_x, input1_y, input2_x, input2_y } => { todo!(); } - BlackBoxFuncCall::EcDouble { outputs, input_x, input_y } => { + BlackBoxFuncCall::EmbeddedCurveDouble { outputs, input_x, input_y } => { todo!(); } // Recursive aggregation will be entirely handled by the backend and is not solved by the ACVM diff --git a/noir/acvm-repo/brillig/src/black_box.rs b/noir/acvm-repo/brillig/src/black_box.rs index 0eb321b6818..4c755f8eae2 100644 --- a/noir/acvm-repo/brillig/src/black_box.rs +++ b/noir/acvm-repo/brillig/src/black_box.rs @@ -42,7 +42,7 @@ pub enum BlackBoxOp { /// Performs scalar multiplication over the embedded curve. FixedBaseScalarMul { low: RegisterIndex, high: RegisterIndex, result: HeapArray }, /// Performs addtion over the embedded curve. - EcAdd { input1_x: RegisterIndex, input1_y: RegisterIndex, input2_x: RegisterIndex, input2_y: RegisterIndex, result: HeapArray }, + EmbeddedCurveAdd { input1_x: RegisterIndex, input1_y: RegisterIndex, input2_x: RegisterIndex, input2_y: RegisterIndex, result: HeapArray }, /// Performs point doubling over the embedded curve. - EcDouble { input1_x: RegisterIndex, input1_y: RegisterIndex, result: HeapArray }, + EmbeddedCurveDouble { input1_x: RegisterIndex, input1_y: RegisterIndex, result: HeapArray }, } diff --git a/noir/acvm-repo/brillig_vm/src/black_box.rs b/noir/acvm-repo/brillig_vm/src/black_box.rs index 5cec3bdaf3c..1b67e52f9b0 100644 --- a/noir/acvm-repo/brillig_vm/src/black_box.rs +++ b/noir/acvm-repo/brillig_vm/src/black_box.rs @@ -140,7 +140,7 @@ pub(crate) fn evaluate_black_box( memory.write_slice(registers.get(result.pointer).to_usize(), &[x.into(), y.into()]); Ok(()) } - BlackBoxOp::EcAdd { input1_x, input1_y, input2_x, input2_y, result } => { + BlackBoxOp::EmbeddedCurveAdd { input1_x, input1_y, input2_x, input2_y, result } => { let input1_x = registers.get(*input1_x).to_field(); let input1_y = registers.get(*input1_y).to_field(); let input2_x = registers.get(*input2_x).to_field(); @@ -149,7 +149,7 @@ pub(crate) fn evaluate_black_box( memory.write_slice(registers.get(result.pointer).to_usize(), &[x.into(), y.into()]); Ok(()) } - BlackBoxOp::EcDouble { input1_x, input1_y, result } => { + BlackBoxOp::EmbeddedCurveDouble { input1_x, input1_y, result } => { let input1_x = registers.get(*input1_x).to_field(); let input1_y = registers.get(*input1_y).to_field(); let (x, y) = solver.ec_double(&input1_x, &input1_y)?; diff --git a/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index 36c52ccdb34..8235cbf6340 100644 --- a/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/noir/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -169,14 +169,14 @@ pub(crate) fn convert_black_box_call( ) } } - BlackBoxFunc::EcAdd => { + BlackBoxFunc::EmbeddedCurveAdd => { if let ( [BrilligVariable::Simple(input1_x), BrilligVariable::Simple(input1_y), BrilligVariable::Simple(input2_x), BrilligVariable::Simple(input2_y)], [BrilligVariable::BrilligArray(result_array)], ) = (function_arguments, function_results) { - brillig_context.black_box_op_instruction(BlackBoxOp::EcAdd { + brillig_context.black_box_op_instruction(BlackBoxOp::EmbeddedCurveAdd { input1_x: *input1_x, input1_y: *input1_y, input2_x: *input2_x, @@ -185,24 +185,24 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EcAdd expects four register arguments and one array result" + "ICE: EmbeddedCurveAdd expects four register arguments and one array result" ) } } - BlackBoxFunc::EcDouble => { + BlackBoxFunc::EmbeddedCurveDouble => { if let ( [BrilligVariable::Simple(input1_x), BrilligVariable::Simple(input1_y)], [BrilligVariable::BrilligArray(result_array)], ) = (function_arguments, function_results) { - brillig_context.black_box_op_instruction(BlackBoxOp::EcDouble { + brillig_context.black_box_op_instruction(BlackBoxOp::EmbeddedCurveDouble { input1_x: *input1_x, input1_y: *input1_y, result: result_array.to_heap_array(), }); } else { unreachable!( - "ICE: EcAdd expects two register arguments and one array result" + "ICE: EmbeddedCurveAdd expects two register arguments and one array result" ) } } diff --git a/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs b/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs index 16c5dcfa894..0d35d948694 100644 --- a/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs +++ b/noir/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs @@ -396,10 +396,10 @@ impl DebugShow { result ); } - BlackBoxOp::EcAdd { input1_x, input1_y, input2_x, input2_y, result } => { + BlackBoxOp::EmbeddedCurveAdd { input1_x, input1_y, input2_x, input2_y, result } => { debug_println!( self.enable_debug_trace, - " EC_ADD ({} {}) ({} {}) -> {}", + " EMBEDDED_CURVE_ADD ({} {}) ({} {}) -> {}", input1_x, input1_y, input2_x, @@ -407,10 +407,10 @@ impl DebugShow { result ); } - BlackBoxOp::EcDouble { input1_x, input1_y, result } => { + BlackBoxOp::EmbeddedCurveDouble { input1_x, input1_y, result } => { debug_println!( self.enable_debug_trace, - " EC_DOUBLE ({} {}) -> {}", + " EMBEDDED_CURVE_DOUBLE ({} {}) -> {}", input1_x, input1_y, result diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index a75721151fa..f8b8579eb66 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1757,7 +1757,7 @@ fn execute_brillig( _input2_y: &FieldElement, ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { Err(BlackBoxResolutionError::Failed( - BlackBoxFunc::EcAdd, + BlackBoxFunc::EmbeddedCurveAdd, "EcAdd is not supported".to_string(), )) } @@ -1767,7 +1767,7 @@ fn execute_brillig( _input_y: &FieldElement, ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { Err(BlackBoxResolutionError::Failed( - BlackBoxFunc::EcDouble, + BlackBoxFunc::EmbeddedCurveDouble, "EcDouble is not supported".to_string(), )) } diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index 23a8269a9ce..04152127660 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -205,14 +205,14 @@ impl GeneratedAcir { high: inputs[1][0], outputs: (outputs[0], outputs[1]), }, - BlackBoxFunc::EcAdd => BlackBoxFuncCall::EcAdd { + BlackBoxFunc::EmbeddedCurveAdd => BlackBoxFuncCall::EmbeddedCurveAdd { input1_x: inputs[0][0], input1_y: inputs[1][0], input2_x: inputs[2][0], input2_y: inputs[3][0], outputs: (outputs[0], outputs[1]), }, - BlackBoxFunc::EcDouble => BlackBoxFuncCall::EcDouble { + BlackBoxFunc::EmbeddedCurveDouble => BlackBoxFuncCall::EmbeddedCurveDouble { input_x: inputs[0][0], input_y: inputs[1][0], outputs: (outputs[0], outputs[1]), @@ -594,9 +594,9 @@ fn black_box_func_expected_input_size(name: BlackBoxFunc) -> Option { // Recursive aggregation has a variable number of inputs BlackBoxFunc::RecursiveAggregation => None, // Addition over the embedded curve: input are coordinates (x1,y1) and (x2,y2) of the Grumpkin points - BlackBoxFunc::EcAdd => Some(4), + BlackBoxFunc::EmbeddedCurveAdd => Some(4), // Doubling over the embedded curve: input is (x,y) coordinate of the point. - BlackBoxFunc::EcDouble => Some(2), + BlackBoxFunc::EmbeddedCurveDouble => Some(2), } } @@ -627,8 +627,8 @@ fn black_box_expected_output_size(name: BlackBoxFunc) -> Option { // Output of operations over the embedded curve // will be 2 field elements representing the point. BlackBoxFunc::FixedBaseScalarMul - | BlackBoxFunc::EcAdd - | BlackBoxFunc::EcDouble => Some(2), + | BlackBoxFunc::EmbeddedCurveAdd + | BlackBoxFunc::EmbeddedCurveDouble => Some(2), // Recursive aggregation has a variable number of outputs BlackBoxFunc::RecursiveAggregation => None, } diff --git a/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs b/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs index b68ec9b6319..5b3a1669bff 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs @@ -407,8 +407,8 @@ fn simplify_black_box_func( | BlackBoxFunc::SchnorrVerify | BlackBoxFunc::PedersenCommitment | BlackBoxFunc::PedersenHash - | BlackBoxFunc::EcAdd - | BlackBoxFunc::EcDouble => { + | BlackBoxFunc::EmbeddedCurveAdd + | BlackBoxFunc::EmbeddedCurveDouble => { // Currently unsolvable here as we rely on an implementation in the backend. SimplifyResult::None }