From 54c36cbc9b7ee3d3bae921b600820ae515c94a87 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:09:32 +0000 Subject: [PATCH 1/6] chore: document `witness_buf_to_witness_data` --- .../dsl/acir_format/acir_to_constraint_buf.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 097d77ce393..967c20eae35 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -328,18 +328,25 @@ acir_format circuit_buf_to_acir_format(std::vector const& buf) return af; } +/** + * @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format. + * + * @param buf Serialized of a witness + * @return A `WitnessVector` equivalent to the passed `WitnessMap`. + * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. + * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. + */ WitnessVector witness_buf_to_witness_data(std::vector const& buf) { auto w = WitnessMap::WitnessMap::bincodeDeserialize(buf); WitnessVector wv; // TODO(https://github.com/AztecProtocol/barretenberg/issues/816): Does "index" need to be initialized to 0 once we - // get rid of the +1 offeet in noir? + // get rid of the +1 offset in noir? size_t index = 1; for (auto& e : w.value) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/824): Document what this mechanism is doing. It - // appears to be somewhat unrelated to the const 0 issue (but see discussion in issue for caveats). See 2_div - // for an example of when this gets used. Seems like a mechanism for adding 0s intermittently between known - // witness values. + // ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned. + // To ensure that witnesses sit at the correct indicies in the `WitnessVector` we fill any indices + // which do not exist within the `WitnessMap` with the dummy value of zero. while (index < e.first.value) { wv.push_back(barretenberg::fr(0)); index++; From 169fe7be75ed53864e2bb315f5bd0184bf6e22ea Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:10:35 +0000 Subject: [PATCH 2/6] chore: fix half-written line --- .../src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 967c20eae35..60b60341652 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -331,7 +331,7 @@ acir_format circuit_buf_to_acir_format(std::vector const& buf) /** * @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format. * - * @param buf Serialized of a witness + * @param buf Serialized representation of a `WitnessMap`. * @return A `WitnessVector` equivalent to the passed `WitnessMap`. * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. From 6fdfdb03b6d16160fe0ccf4fb555e17071f2990a Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:10:57 +0000 Subject: [PATCH 3/6] chore: grammar --- .../src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 60b60341652..4dc4a2eddf9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -345,7 +345,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) size_t index = 1; for (auto& e : w.value) { // ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned. - // To ensure that witnesses sit at the correct indicies in the `WitnessVector` we fill any indices + // To ensure that witnesses sit at the correct indicies in the `WitnessVector`, we fill any indices // which do not exist within the `WitnessMap` with the dummy value of zero. while (index < e.first.value) { wv.push_back(barretenberg::fr(0)); From a389cbe81c36226874f8b66bcebf9636db9f6ff8 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:11:23 +0000 Subject: [PATCH 4/6] chore: spelling --- .../src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 4dc4a2eddf9..491c2e79de4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -345,7 +345,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) size_t index = 1; for (auto& e : w.value) { // ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned. - // To ensure that witnesses sit at the correct indicies in the `WitnessVector`, we fill any indices + // To ensure that witnesses sit at the correct indices in the `WitnessVector`, we fill any indices // which do not exist within the `WitnessMap` with the dummy value of zero. while (index < e.first.value) { wv.push_back(barretenberg::fr(0)); From 0b19b041c0d92bd9b9847583b687f4c9f68751ed Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:21:47 +0000 Subject: [PATCH 5/6] chore: remove unnecessary offset --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 491c2e79de4..31d189329d2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -340,9 +340,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) { auto w = WitnessMap::WitnessMap::bincodeDeserialize(buf); WitnessVector wv; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/816): Does "index" need to be initialized to 0 once we - // get rid of the +1 offset in noir? - size_t index = 1; + size_t index = 0; for (auto& e : w.value) { // ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned. // To ensure that witnesses sit at the correct indices in the `WitnessVector`, we fill any indices From 1540abb3f82ef6ecbb4d5fff1d116bc2b3359cff Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 11 Jan 2024 11:57:43 +0000 Subject: [PATCH 6/6] Revert "chore: remove unnecessary offset" This reverts commit 0b19b041c0d92bd9b9847583b687f4c9f68751ed. --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 31d189329d2..491c2e79de4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -340,7 +340,9 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) { auto w = WitnessMap::WitnessMap::bincodeDeserialize(buf); WitnessVector wv; - size_t index = 0; + // TODO(https://github.com/AztecProtocol/barretenberg/issues/816): Does "index" need to be initialized to 0 once we + // get rid of the +1 offset in noir? + size_t index = 1; for (auto& e : w.value) { // ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned. // To ensure that witnesses sit at the correct indices in the `WitnessVector`, we fill any indices