From 2abfa6b9e804ec12eeb293ec37dc11150f636539 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 7 Sep 2023 19:35:08 +0000 Subject: [PATCH 1/4] update serialization --- .../dsl/acir_format/serde/acir.hpp | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 60ca1a2c07e..92839b90ec2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -126,7 +126,8 @@ struct BlackBoxFuncCall { }; struct FixedBaseScalarMul { - Circuit::FunctionInput input; + Circuit::FunctionInput low; + Circuit::FunctionInput high; std::array outputs; friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); @@ -467,7 +468,8 @@ struct BlackBoxOp { }; struct FixedBaseScalarMul { - Circuit::RegisterIndex input; + Circuit::RegisterIndex low; + Circuit::RegisterIndex high; Circuit::HeapArray result; friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); @@ -2379,7 +2381,10 @@ namespace Circuit { inline bool operator==(const BlackBoxFuncCall::FixedBaseScalarMul& lhs, const BlackBoxFuncCall::FixedBaseScalarMul& rhs) { - if (!(lhs.input == rhs.input)) { + if (!(lhs.low == rhs.low)) { + return false; + } + if (!(lhs.high == rhs.high)) { return false; } if (!(lhs.outputs == rhs.outputs)) { @@ -2413,7 +2418,8 @@ template void serde::Serializable::serialize( const Circuit::BlackBoxFuncCall::FixedBaseScalarMul& obj, Serializer& serializer) { - serde::Serializable::serialize(obj.input, serializer); + serde::Serializable::serialize(obj.low, serializer); + serde::Serializable::serialize(obj.high, serializer); serde::Serializable::serialize(obj.outputs, serializer); } @@ -2423,7 +2429,8 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable< Circuit::BlackBoxFuncCall::FixedBaseScalarMul>::deserialize(Deserializer& deserializer) { Circuit::BlackBoxFuncCall::FixedBaseScalarMul obj; - obj.input = serde::Deserializable::deserialize(deserializer); + obj.low = serde::Deserializable::deserialize(deserializer); + obj.high = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } @@ -3134,7 +3141,10 @@ namespace Circuit { inline bool operator==(const BlackBoxOp::FixedBaseScalarMul& lhs, const BlackBoxOp::FixedBaseScalarMul& rhs) { - if (!(lhs.input == rhs.input)) { + if (!(lhs.low == rhs.low)) { + return false; + } + if (!(lhs.high == rhs.high)) { return false; } if (!(lhs.result == rhs.result)) { @@ -3167,7 +3177,8 @@ template void serde::Serializable::serialize( const Circuit::BlackBoxOp::FixedBaseScalarMul& obj, Serializer& serializer) { - serde::Serializable::serialize(obj.input, serializer); + serde::Serializable::serialize(obj.low, serializer); + serde::Serializable::serialize(obj.high, serializer); serde::Serializable::serialize(obj.result, serializer); } @@ -3177,7 +3188,8 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable::deserialize(deserializer); + obj.low = serde::Deserializable::deserialize(deserializer); + obj.high = serde::Deserializable::deserialize(deserializer); obj.result = serde::Deserializable::deserialize(deserializer); return obj; } From 000e6e95bb2835a72156dd6931881d02538762f2 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 7 Sep 2023 19:35:51 +0000 Subject: [PATCH 2/4] modify serialization and `FixedBaseScalarMul` struct --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 3 ++- .../barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp | 6 ++++-- .../barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index b33c935590f..ef84daaabb1 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -158,7 +158,8 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci }); } else if constexpr (std::is_same_v) { af.fixed_base_scalar_mul_constraints.push_back(FixedBaseScalarMul{ - .scalar = arg.input.witness.value, + .low = arg.low.witness.value, + .high = arg.high.witness.value, .pub_key_x = arg.outputs[0].value, .pub_key_y = arg.outputs[1].value, }); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp index 18f1b59f4cd..d54f8a33c98 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp @@ -5,8 +5,10 @@ namespace acir_format { void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input) { - field_ct scalar_as_field = field_ct::from_witness_index(&builder, input.scalar); - auto public_key = group_ct::fixed_base_scalar_mul_g1<254>(scalar_as_field); + field_ct low_as_field = field_ct::from_witness_index(&builder, input.low); + field_ct high_as_field = field_ct::from_witness_index(&builder, input.high); + (void)high_as_field; + auto public_key = group_ct::fixed_base_scalar_mul_g1<254>(low_as_field); builder.assert_equal(public_key.x.witness_index, input.pub_key_x); builder.assert_equal(public_key.y.witness_index, input.pub_key_y); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp index 2a7088e67ad..fe4917a8d2a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp @@ -6,12 +6,13 @@ namespace acir_format { struct FixedBaseScalarMul { - uint32_t scalar; + uint32_t low; + uint32_t high; uint32_t pub_key_x; uint32_t pub_key_y; // for serialization, update with any new fields - MSGPACK_FIELDS(scalar, pub_key_x, pub_key_y); + MSGPACK_FIELDS(low, high, pub_key_x, pub_key_y); friend bool operator==(FixedBaseScalarMul const& lhs, FixedBaseScalarMul const& rhs) = default; }; From c71a91ba4ad4009f87e7494a7e4cb91f1a64020e Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 7 Sep 2023 19:36:09 +0000 Subject: [PATCH 3/4] point to branch with new serialization code --- circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh index 7b97f287385..49a31097b22 100755 --- a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh +++ b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -eu BIN=${BIN:-../cpp/build/bin/bb} FLOW=${FLOW:-prove_and_verify} CRS_PATH=~/.bb-crs -BRANCH=master +BRANCH=kw/fix-scalar-mul VERBOSE=${VERBOSE:-} NAMED_TEST=${1:-} From a3ada3f7f1b9e3319f57239ad99abbd88c2a8cfc Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 7 Sep 2023 21:53:56 +0000 Subject: [PATCH 4/4] use master --- circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh index 49a31097b22..7b97f287385 100755 --- a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh +++ b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh @@ -7,7 +7,7 @@ set -eu BIN=${BIN:-../cpp/build/bin/bb} FLOW=${FLOW:-prove_and_verify} CRS_PATH=~/.bb-crs -BRANCH=kw/fix-scalar-mul +BRANCH=master VERBOSE=${VERBOSE:-} NAMED_TEST=${1:-}