From 72e004a84810350a7c6cbbcd2586048ce949d3e2 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 20:00:07 +0000 Subject: [PATCH 01/10] use test_data_ssa_refactor --- acir_tests/run_acir_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index 2767f2ec90..6531a28b6b 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -18,10 +18,10 @@ if [ ! -d acir_tests ]; then git clone -b $BRANCH --filter=blob:none --no-checkout https://github.com/noir-lang/noir.git cd noir git sparse-checkout init --cone - git sparse-checkout set crates/nargo_cli/tests/test_data + git sparse-checkout set crates/nargo_cli/tests/test_data_ssa_refactor git checkout cd .. - mv noir/crates/nargo_cli/tests/test_data acir_tests + mv noir/crates/nargo_cli/tests/test_data_ssa_refactor acir_tests rm -rf noir fi fi From 4f7377a1331c662e0b23c3d4b1da4242f26e0b5d Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 20:00:38 +0000 Subject: [PATCH 02/10] use branch in noir that generates the artifacts --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index 6531a28b6b..6f042c5a1d 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -e BB=$PWD/${BB:-../cpp/build/bin/bb} CRS_PATH=~/.bb-crs -BRANCH=master +BRANCH=kw/add-bb-tests # Pull down the test vectors from the noir repo, if we don't have the folder already. if [ ! -d acir_tests ]; then From 75a3acab0c398aee5efe282deda31dfb09d238b3 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 20:01:09 +0000 Subject: [PATCH 03/10] skip 9_conditional for now --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index 6f042c5a1d..a9f877d1c5 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -35,7 +35,7 @@ fail_dirs=$(grep "^fail" config.toml | sed 's/fail = \[//;s/\]//;s/\"//g;s/ //g' # Convert them to array exclude_array=($exclude_dirs) fail_array=($fail_dirs) -skip_array=(diamond_deps_0 workspace workspace_default_member) +skip_array=(diamond_deps_0 workspace workspace_default_member 9_conditional) function test() { echo -n "Testing $1... " From d7d18843a638c813c28e5494a089f4894985737c Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 20:01:33 +0000 Subject: [PATCH 04/10] update acir.hpp file --- .../dsl/acir_format/serde/acir.hpp | 760 ++++++++++-------- 1 file changed, 440 insertions(+), 320 deletions(-) diff --git a/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index e37ed6ca54..5a4327bf26 100644 --- a/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -5,6 +5,231 @@ namespace Circuit { +struct Witness { + uint32_t value; + + friend bool operator==(const Witness&, const Witness&); + std::vector bincodeSerialize() const; + static Witness bincodeDeserialize(std::vector); +}; + +struct FunctionInput { + Circuit::Witness witness; + uint32_t num_bits; + + friend bool operator==(const FunctionInput&, const FunctionInput&); + std::vector bincodeSerialize() const; + static FunctionInput bincodeDeserialize(std::vector); +}; + +struct BlackBoxFuncCall { + + struct AND { + Circuit::FunctionInput lhs; + Circuit::FunctionInput rhs; + Circuit::Witness output; + + friend bool operator==(const AND&, const AND&); + std::vector bincodeSerialize() const; + static AND bincodeDeserialize(std::vector); + }; + + struct XOR { + Circuit::FunctionInput lhs; + Circuit::FunctionInput rhs; + Circuit::Witness output; + + friend bool operator==(const XOR&, const XOR&); + std::vector bincodeSerialize() const; + static XOR bincodeDeserialize(std::vector); + }; + + struct RANGE { + Circuit::FunctionInput input; + + friend bool operator==(const RANGE&, const RANGE&); + std::vector bincodeSerialize() const; + static RANGE bincodeDeserialize(std::vector); + }; + + struct SHA256 { + std::vector inputs; + std::vector outputs; + + friend bool operator==(const SHA256&, const SHA256&); + std::vector bincodeSerialize() const; + static SHA256 bincodeDeserialize(std::vector); + }; + + struct Blake2s { + std::vector inputs; + std::vector outputs; + + friend bool operator==(const Blake2s&, const Blake2s&); + std::vector bincodeSerialize() const; + static Blake2s bincodeDeserialize(std::vector); + }; + + struct SchnorrVerify { + Circuit::FunctionInput public_key_x; + Circuit::FunctionInput public_key_y; + std::vector signature; + std::vector message; + Circuit::Witness output; + + friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); + std::vector bincodeSerialize() const; + static SchnorrVerify bincodeDeserialize(std::vector); + }; + + struct Pedersen { + std::vector inputs; + uint32_t domain_separator; + std::array outputs; + + friend bool operator==(const Pedersen&, const Pedersen&); + std::vector bincodeSerialize() const; + static Pedersen bincodeDeserialize(std::vector); + }; + + struct HashToField128Security { + std::vector inputs; + Circuit::Witness output; + + friend bool operator==(const HashToField128Security&, const HashToField128Security&); + std::vector bincodeSerialize() const; + static HashToField128Security bincodeDeserialize(std::vector); + }; + + struct EcdsaSecp256k1 { + std::vector public_key_x; + std::vector public_key_y; + std::vector signature; + std::vector hashed_message; + Circuit::Witness output; + + friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); + std::vector bincodeSerialize() const; + static EcdsaSecp256k1 bincodeDeserialize(std::vector); + }; + + struct EcdsaSecp256r1 { + std::vector public_key_x; + std::vector public_key_y; + std::vector signature; + std::vector hashed_message; + Circuit::Witness output; + + friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); + std::vector bincodeSerialize() const; + static EcdsaSecp256r1 bincodeDeserialize(std::vector); + }; + + struct FixedBaseScalarMul { + Circuit::FunctionInput input; + std::array outputs; + + friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); + std::vector bincodeSerialize() const; + static FixedBaseScalarMul bincodeDeserialize(std::vector); + }; + + struct Keccak256 { + std::vector inputs; + std::vector outputs; + + friend bool operator==(const Keccak256&, const Keccak256&); + std::vector bincodeSerialize() const; + static Keccak256 bincodeDeserialize(std::vector); + }; + + struct Keccak256VariableLength { + std::vector inputs; + Circuit::FunctionInput var_message_size; + std::vector outputs; + + friend bool operator==(const Keccak256VariableLength&, const Keccak256VariableLength&); + std::vector bincodeSerialize() const; + static Keccak256VariableLength bincodeDeserialize(std::vector); + }; + + struct RecursiveAggregation { + std::vector verification_key; + std::vector proof; + std::vector public_inputs; + Circuit::FunctionInput key_hash; + std::optional> input_aggregation_object; + std::vector output_aggregation_object; + + friend bool operator==(const RecursiveAggregation&, const RecursiveAggregation&); + std::vector bincodeSerialize() const; + static RecursiveAggregation bincodeDeserialize(std::vector); + }; + + std::variant + value; + + friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); + std::vector bincodeSerialize() const; + static BlackBoxFuncCall bincodeDeserialize(std::vector); +}; + +struct BlockId { + uint32_t value; + + friend bool operator==(const BlockId&, const BlockId&); + std::vector bincodeSerialize() const; + static BlockId bincodeDeserialize(std::vector); +}; + +struct Expression { + std::vector> mul_terms; + std::vector> linear_combinations; + std::string q_c; + + friend bool operator==(const Expression&, const Expression&); + std::vector bincodeSerialize() const; + static Expression bincodeDeserialize(std::vector); +}; + +struct BrilligInputs { + + struct Single { + Circuit::Expression value; + + friend bool operator==(const Single&, const Single&); + std::vector bincodeSerialize() const; + static Single bincodeDeserialize(std::vector); + }; + + struct Array { + std::vector value; + + friend bool operator==(const Array&, const Array&); + std::vector bincodeSerialize() const; + static Array bincodeDeserialize(std::vector); + }; + + std::variant value; + + friend bool operator==(const BrilligInputs&, const BrilligInputs&); + std::vector bincodeSerialize() const; + static BrilligInputs bincodeDeserialize(std::vector); +}; + struct BinaryFieldOp { struct Add { @@ -400,351 +625,134 @@ struct BrilligOpcode { static Mov bincodeDeserialize(std::vector); }; - struct Load { - Circuit::RegisterIndex destination; - Circuit::RegisterIndex source_pointer; - - friend bool operator==(const Load&, const Load&); - std::vector bincodeSerialize() const; - static Load bincodeDeserialize(std::vector); - }; - - struct Store { - Circuit::RegisterIndex destination_pointer; - Circuit::RegisterIndex source; - - friend bool operator==(const Store&, const Store&); - std::vector bincodeSerialize() const; - static Store bincodeDeserialize(std::vector); - }; - - struct BlackBox { - Circuit::BlackBoxOp value; - - friend bool operator==(const BlackBox&, const BlackBox&); - std::vector bincodeSerialize() const; - static BlackBox bincodeDeserialize(std::vector); - }; - - struct Trap { - friend bool operator==(const Trap&, const Trap&); - std::vector bincodeSerialize() const; - static Trap bincodeDeserialize(std::vector); - }; - - struct Stop { - friend bool operator==(const Stop&, const Stop&); - std::vector bincodeSerialize() const; - static Stop bincodeDeserialize(std::vector); - }; - - std::variant - value; - - friend bool operator==(const BrilligOpcode&, const BrilligOpcode&); - std::vector bincodeSerialize() const; - static BrilligOpcode bincodeDeserialize(std::vector); -}; - -struct Witness { - uint32_t value; - - friend bool operator==(const Witness&, const Witness&); - std::vector bincodeSerialize() const; - static Witness bincodeDeserialize(std::vector); -}; - -struct Expression { - std::vector> mul_terms; - std::vector> linear_combinations; - std::string q_c; - - friend bool operator==(const Expression&, const Expression&); - std::vector bincodeSerialize() const; - static Expression bincodeDeserialize(std::vector); -}; - -struct BrilligInputs { - - struct Single { - Circuit::Expression value; - - friend bool operator==(const Single&, const Single&); - std::vector bincodeSerialize() const; - static Single bincodeDeserialize(std::vector); - }; - - struct Array { - std::vector value; - - friend bool operator==(const Array&, const Array&); - std::vector bincodeSerialize() const; - static Array bincodeDeserialize(std::vector); - }; - - std::variant value; - - friend bool operator==(const BrilligInputs&, const BrilligInputs&); - std::vector bincodeSerialize() const; - static BrilligInputs bincodeDeserialize(std::vector); -}; - -struct BrilligOutputs { - - struct Simple { - Circuit::Witness value; - - friend bool operator==(const Simple&, const Simple&); - std::vector bincodeSerialize() const; - static Simple bincodeDeserialize(std::vector); - }; - - struct Array { - std::vector value; - - friend bool operator==(const Array&, const Array&); - std::vector bincodeSerialize() const; - static Array bincodeDeserialize(std::vector); - }; - - std::variant value; - - friend bool operator==(const BrilligOutputs&, const BrilligOutputs&); - std::vector bincodeSerialize() const; - static BrilligOutputs bincodeDeserialize(std::vector); -}; - -struct ForeignCallOutput { - - struct Single { - Circuit::Value value; - - friend bool operator==(const Single&, const Single&); - std::vector bincodeSerialize() const; - static Single bincodeDeserialize(std::vector); - }; - - struct Array { - std::vector value; - - friend bool operator==(const Array&, const Array&); - std::vector bincodeSerialize() const; - static Array bincodeDeserialize(std::vector); - }; - - std::variant value; - - friend bool operator==(const ForeignCallOutput&, const ForeignCallOutput&); - std::vector bincodeSerialize() const; - static ForeignCallOutput bincodeDeserialize(std::vector); -}; - -struct ForeignCallResult { - std::vector values; - - friend bool operator==(const ForeignCallResult&, const ForeignCallResult&); - std::vector bincodeSerialize() const; - static ForeignCallResult bincodeDeserialize(std::vector); -}; - -struct Brillig { - std::vector inputs; - std::vector outputs; - std::vector foreign_call_results; - std::vector bytecode; - std::optional predicate; - - friend bool operator==(const Brillig&, const Brillig&); - std::vector bincodeSerialize() const; - static Brillig bincodeDeserialize(std::vector); -}; - -struct FunctionInput { - Circuit::Witness witness; - uint32_t num_bits; - - friend bool operator==(const FunctionInput&, const FunctionInput&); - std::vector bincodeSerialize() const; - static FunctionInput bincodeDeserialize(std::vector); -}; - -struct BlackBoxFuncCall { - - struct AND { - Circuit::FunctionInput lhs; - Circuit::FunctionInput rhs; - Circuit::Witness output; - - friend bool operator==(const AND&, const AND&); - std::vector bincodeSerialize() const; - static AND bincodeDeserialize(std::vector); - }; - - struct XOR { - Circuit::FunctionInput lhs; - Circuit::FunctionInput rhs; - Circuit::Witness output; - - friend bool operator==(const XOR&, const XOR&); - std::vector bincodeSerialize() const; - static XOR bincodeDeserialize(std::vector); - }; - - struct RANGE { - Circuit::FunctionInput input; - - friend bool operator==(const RANGE&, const RANGE&); - std::vector bincodeSerialize() const; - static RANGE bincodeDeserialize(std::vector); - }; - - struct SHA256 { - std::vector inputs; - std::vector outputs; - - friend bool operator==(const SHA256&, const SHA256&); - std::vector bincodeSerialize() const; - static SHA256 bincodeDeserialize(std::vector); - }; - - struct Blake2s { - std::vector inputs; - std::vector outputs; - - friend bool operator==(const Blake2s&, const Blake2s&); - std::vector bincodeSerialize() const; - static Blake2s bincodeDeserialize(std::vector); - }; - - struct SchnorrVerify { - Circuit::FunctionInput public_key_x; - Circuit::FunctionInput public_key_y; - std::vector signature; - std::vector message; - Circuit::Witness output; - - friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); - std::vector bincodeSerialize() const; - static SchnorrVerify bincodeDeserialize(std::vector); - }; - - struct Pedersen { - std::vector inputs; - uint32_t domain_separator; - std::array outputs; + struct Load { + Circuit::RegisterIndex destination; + Circuit::RegisterIndex source_pointer; - friend bool operator==(const Pedersen&, const Pedersen&); + friend bool operator==(const Load&, const Load&); std::vector bincodeSerialize() const; - static Pedersen bincodeDeserialize(std::vector); + static Load bincodeDeserialize(std::vector); }; - struct HashToField128Security { - std::vector inputs; - Circuit::Witness output; + struct Store { + Circuit::RegisterIndex destination_pointer; + Circuit::RegisterIndex source; - friend bool operator==(const HashToField128Security&, const HashToField128Security&); + friend bool operator==(const Store&, const Store&); std::vector bincodeSerialize() const; - static HashToField128Security bincodeDeserialize(std::vector); + static Store bincodeDeserialize(std::vector); }; - struct EcdsaSecp256k1 { - std::vector public_key_x; - std::vector public_key_y; - std::vector signature; - std::vector hashed_message; - Circuit::Witness output; + struct BlackBox { + Circuit::BlackBoxOp value; - friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); + friend bool operator==(const BlackBox&, const BlackBox&); std::vector bincodeSerialize() const; - static EcdsaSecp256k1 bincodeDeserialize(std::vector); + static BlackBox bincodeDeserialize(std::vector); }; - struct EcdsaSecp256r1 { - std::vector public_key_x; - std::vector public_key_y; - std::vector signature; - std::vector hashed_message; - Circuit::Witness output; + struct Trap { + friend bool operator==(const Trap&, const Trap&); + std::vector bincodeSerialize() const; + static Trap bincodeDeserialize(std::vector); + }; - friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); + struct Stop { + friend bool operator==(const Stop&, const Stop&); std::vector bincodeSerialize() const; - static EcdsaSecp256r1 bincodeDeserialize(std::vector); + static Stop bincodeDeserialize(std::vector); }; - struct FixedBaseScalarMul { - Circuit::FunctionInput input; - std::array outputs; + std::variant + value; - friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); + friend bool operator==(const BrilligOpcode&, const BrilligOpcode&); + std::vector bincodeSerialize() const; + static BrilligOpcode bincodeDeserialize(std::vector); +}; + +struct BrilligOutputs { + + struct Simple { + Circuit::Witness value; + + friend bool operator==(const Simple&, const Simple&); std::vector bincodeSerialize() const; - static FixedBaseScalarMul bincodeDeserialize(std::vector); + static Simple bincodeDeserialize(std::vector); }; - struct Keccak256 { - std::vector inputs; - std::vector outputs; + struct Array { + std::vector value; - friend bool operator==(const Keccak256&, const Keccak256&); + friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; - static Keccak256 bincodeDeserialize(std::vector); + static Array bincodeDeserialize(std::vector); }; - struct Keccak256VariableLength { - std::vector inputs; - Circuit::FunctionInput var_message_size; - std::vector outputs; + std::variant value; - friend bool operator==(const Keccak256VariableLength&, const Keccak256VariableLength&); + friend bool operator==(const BrilligOutputs&, const BrilligOutputs&); + std::vector bincodeSerialize() const; + static BrilligOutputs bincodeDeserialize(std::vector); +}; + +struct ForeignCallOutput { + + struct Single { + Circuit::Value value; + + friend bool operator==(const Single&, const Single&); std::vector bincodeSerialize() const; - static Keccak256VariableLength bincodeDeserialize(std::vector); + static Single bincodeDeserialize(std::vector); }; - struct RecursiveAggregation { - std::vector verification_key; - std::vector proof; - std::vector public_inputs; - Circuit::FunctionInput key_hash; - std::optional> input_aggregation_object; - std::vector output_aggregation_object; + struct Array { + std::vector value; - friend bool operator==(const RecursiveAggregation&, const RecursiveAggregation&); + friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; - static RecursiveAggregation bincodeDeserialize(std::vector); + static Array bincodeDeserialize(std::vector); }; - std::variant - value; + std::variant value; - friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); + friend bool operator==(const ForeignCallOutput&, const ForeignCallOutput&); std::vector bincodeSerialize() const; - static BlackBoxFuncCall bincodeDeserialize(std::vector); + static ForeignCallOutput bincodeDeserialize(std::vector); +}; + +struct ForeignCallResult { + std::vector values; + + friend bool operator==(const ForeignCallResult&, const ForeignCallResult&); + std::vector bincodeSerialize() const; + static ForeignCallResult bincodeDeserialize(std::vector); +}; + +struct Brillig { + std::vector inputs; + std::vector outputs; + std::vector foreign_call_results; + std::vector bytecode; + std::optional predicate; + + friend bool operator==(const Brillig&, const Brillig&); + std::vector bincodeSerialize() const; + static Brillig bincodeDeserialize(std::vector); }; struct LogInfo { @@ -839,14 +847,6 @@ struct Directive { static Directive bincodeDeserialize(std::vector); }; -struct BlockId { - uint32_t value; - - friend bool operator==(const BlockId&, const BlockId&); - std::vector bincodeSerialize() const; - static BlockId bincodeDeserialize(std::vector); -}; - struct MemOp { Circuit::Expression operation; Circuit::Expression index; @@ -925,7 +925,25 @@ struct Opcode { static Brillig bincodeDeserialize(std::vector); }; - std::variant value; + struct MemoryOp { + Circuit::BlockId block_id; + Circuit::MemOp op; + + friend bool operator==(const MemoryOp&, const MemoryOp&); + std::vector bincodeSerialize() const; + static MemoryOp bincodeDeserialize(std::vector); + }; + + struct MemoryInit { + Circuit::BlockId block_id; + std::vector init; + + friend bool operator==(const MemoryInit&, const MemoryInit&); + std::vector bincodeSerialize() const; + static MemoryInit bincodeDeserialize(std::vector); + }; + + std::variant value; friend bool operator==(const Opcode&, const Opcode&); std::vector bincodeSerialize() const; @@ -5847,6 +5865,108 @@ Circuit::Opcode::Brillig serde::Deserializable::deseri namespace Circuit { +inline bool operator==(const Opcode::MemoryOp& lhs, const Opcode::MemoryOp& rhs) +{ + if (!(lhs.block_id == rhs.block_id)) { + return false; + } + if (!(lhs.op == rhs.op)) { + return false; + } + return true; +} + +inline std::vector Opcode::MemoryOp::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline Opcode::MemoryOp Opcode::MemoryOp::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::Opcode::MemoryOp& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.block_id, serializer); + serde::Serializable::serialize(obj.op, serializer); +} + +template <> +template +Circuit::Opcode::MemoryOp serde::Deserializable::deserialize(Deserializer& deserializer) +{ + Circuit::Opcode::MemoryOp obj; + obj.block_id = serde::Deserializable::deserialize(deserializer); + obj.op = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + +inline bool operator==(const Opcode::MemoryInit& lhs, const Opcode::MemoryInit& rhs) +{ + if (!(lhs.block_id == rhs.block_id)) { + return false; + } + if (!(lhs.init == rhs.init)) { + return false; + } + return true; +} + +inline std::vector Opcode::MemoryInit::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline Opcode::MemoryInit Opcode::MemoryInit::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::Opcode::MemoryInit& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.block_id, serializer); + serde::Serializable::serialize(obj.init, serializer); +} + +template <> +template +Circuit::Opcode::MemoryInit serde::Deserializable::deserialize(Deserializer& deserializer) +{ + Circuit::Opcode::MemoryInit obj; + obj.block_id = serde::Deserializable::deserialize(deserializer); + obj.init = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Circuit { + inline bool operator==(const PublicInputs& lhs, const PublicInputs& rhs) { if (!(lhs.value == rhs.value)) { From 96397ac8de561939c71b76ddae868686cafe1f25 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 22:11:37 +0100 Subject: [PATCH 05/10] Update acir_tests/run_acir_tests.sh --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index a9f877d1c5..b5158fdc9f 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -e BB=$PWD/${BB:-../cpp/build/bin/bb} CRS_PATH=~/.bb-crs -BRANCH=kw/add-bb-tests +BRANCH=master # Pull down the test vectors from the noir repo, if we don't have the folder already. if [ ! -d acir_tests ]; then From 03daf2c9e0d136cf04e2a11df7421a98f83ed4eb Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 21:29:01 +0000 Subject: [PATCH 06/10] add throw for new variants accordingly --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 195998a4b0..d3923ac92b 100644 --- a/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -1,6 +1,7 @@ #pragma once #include "acir_format.hpp" #include "barretenberg/common/container.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/dsl/acir_format/blake2s_constraint.hpp" #include "barretenberg/dsl/acir_format/block_constraint.hpp" #include "barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp" @@ -254,6 +255,10 @@ acir_format circuit_buf_to_acir_format(std::vector const& buf) handle_memory(arg.value, true, af); } else if constexpr (std::is_same_v) { handle_memory(arg.value, false, af); + } else if constexpr (std::is_same_v) { + throw_or_abort("memory init unimplemented"); + } else if constexpr (std::is_same_v) { + throw_or_abort("memory op unimplemented"); } }, gate.value); From 29f7bf3491cd30d5248354aac1e085d72e3761bb Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 24 Jul 2023 22:26:34 +0000 Subject: [PATCH 07/10] do not ignore 9_conditional --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index b5158fdc9f..6531a28b6b 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -35,7 +35,7 @@ fail_dirs=$(grep "^fail" config.toml | sed 's/fail = \[//;s/\]//;s/\"//g;s/ //g' # Convert them to array exclude_array=($exclude_dirs) fail_array=($fail_dirs) -skip_array=(diamond_deps_0 workspace workspace_default_member 9_conditional) +skip_array=(diamond_deps_0 workspace workspace_default_member) function test() { echo -n "Testing $1... " From 8069826197ff1d965ff5d48db51ff16b9153c245 Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Tue, 25 Jul 2023 22:12:19 +0200 Subject: [PATCH 08/10] chore: Handle MemoryInit and MemoryOp (#630) --- .../acir_format/acir_to_constraint_buf.hpp | 55 ++++++++++++++++++- .../dsl/acir_format/serde/acir.hpp | 6 ++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index d3923ac92b..4acabafe59 100644 --- a/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -234,6 +234,44 @@ void handle_memory(Circuit::MemoryBlock const& mem_block, bool is_ram, acir_form af.block_constraints.push_back(BlockConstraint{ .init = init, .trace = trace, .type = (BlockType)is_ram }); } +BlockConstraint handle_memory_init(Circuit::Opcode::MemoryInit const& mem_init) +{ + BlockConstraint block{ .init = {}, .trace = {}, .type = BlockType::ROM }; + std::vector init; + std::vector trace; + + auto len = mem_init.init.size(); + for (size_t i = 0; i < len; ++i) { + block.init.push_back(poly_triple{ + .a = mem_init.init[i].value, + .b = 0, + .c = 0, + .q_m = 0, + .q_l = 1, + .q_r = 0, + .q_o = 0, + .q_c = 0, + }); + } + return block; +} + +void handle_memory_op(Circuit::Opcode::MemoryOp const& mem_op, BlockConstraint& block) +{ + uint8_t access_type = 1; + if (mem_op.op.is_rom()) { + access_type = 0; + } + if (block.type == BlockType::ROM && access_type == 1) { + block.type = BlockType::RAM; + } + + MemOp acir_mem_op = MemOp{ .access_type = access_type, + .index = serialize_arithmetic_gate(mem_op.op.index), + .value = serialize_arithmetic_gate(mem_op.op.value) }; + block.trace.push_back(acir_mem_op); +} + acir_format circuit_buf_to_acir_format(std::vector const& buf) { auto circuit = Circuit::Circuit::bincodeDeserialize(buf); @@ -242,7 +280,7 @@ acir_format circuit_buf_to_acir_format(std::vector const& buf) af.varnum = circuit.current_witness_index + 1; af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }), map(circuit.return_values.value, [](auto e) { return e.value; }) }); - + std::map block_id_to_block_constraint; for (auto gate : circuit.opcodes) { std::visit( [&](auto&& arg) { @@ -256,13 +294,24 @@ acir_format circuit_buf_to_acir_format(std::vector const& buf) } else if constexpr (std::is_same_v) { handle_memory(arg.value, false, af); } else if constexpr (std::is_same_v) { - throw_or_abort("memory init unimplemented"); + auto block = handle_memory_init(arg); + uint32_t block_id = arg.block_id.value; + block_id_to_block_constraint[block_id] = block; } else if constexpr (std::is_same_v) { - throw_or_abort("memory op unimplemented"); + auto block = block_id_to_block_constraint.find(arg.block_id.value); + if (block == block_id_to_block_constraint.end()) { + throw_or_abort("unitialized MemoryOp"); + } + handle_memory_op(arg, block->second); } }, gate.value); } + for (const auto& [block_id, block] : block_id_to_block_constraint) { + if (!block.trace.empty()) { + af.block_constraints.push_back(block); + } + } return af; } diff --git a/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 5a4327bf26..01aef1ef9e 100644 --- a/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -855,6 +855,12 @@ struct MemOp { friend bool operator==(const MemOp&, const MemOp&); std::vector bincodeSerialize() const; static MemOp bincodeDeserialize(std::vector); + + bool is_rom() const + { + return this->operation.mul_terms.size() == 0 && this->operation.linear_combinations.size() == 0 && + uint256_t(this->operation.q_c) == 0; + } }; struct MemoryBlock { From 8da081d746c6ebce1dde5851e2acd3e4a5a743a3 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 25 Jul 2023 20:53:15 +0000 Subject: [PATCH 09/10] use branch --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index 6531a28b6b..f9e0a525c6 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -e BB=$PWD/${BB:-../cpp/build/bin/bb} CRS_PATH=~/.bb-crs -BRANCH=master +BRANCH=kw/update-acir-tests # Pull down the test vectors from the noir repo, if we don't have the folder already. if [ ! -d acir_tests ]; then From 9eb486c978aabfd3bca5fc8171435b958ab7f443 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 25 Jul 2023 22:34:03 +0100 Subject: [PATCH 10/10] Update acir_tests/run_acir_tests.sh --- acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acir_tests/run_acir_tests.sh b/acir_tests/run_acir_tests.sh index f9e0a525c6..6531a28b6b 100755 --- a/acir_tests/run_acir_tests.sh +++ b/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -e BB=$PWD/${BB:-../cpp/build/bin/bb} CRS_PATH=~/.bb-crs -BRANCH=kw/update-acir-tests +BRANCH=master # Pull down the test vectors from the noir repo, if we don't have the folder already. if [ ! -d acir_tests ]; then