From b192159ce051035c882263262d193aee1a096cdf Mon Sep 17 00:00:00 2001
From: David Banks <47112877+dbanks12@users.noreply.github.com>
Date: Wed, 31 May 2023 17:20:11 -0400
Subject: [PATCH] feat(api): external cpp header for circuits
 (https://github.com/AztecProtocol/barretenberg/pull/489)

* missing header includes

* comments in api header with issues/todos
---
 barretenberg/cpp/.aztec-packages-commit       |  2 +-
 barretenberg/cpp/src/CMakeLists.txt           |  1 +
 .../cpp/src/barretenberg/barretenberg.hpp     | 74 +++++++++++++++++++
 .../cpp/src/barretenberg/common/container.hpp |  1 +
 .../cpp/src/barretenberg/common/map.hpp       |  1 +
 5 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 barretenberg/cpp/src/barretenberg/barretenberg.hpp

diff --git a/barretenberg/cpp/.aztec-packages-commit b/barretenberg/cpp/.aztec-packages-commit
index 9c53dd4c9ff..9c6074054fb 100644
--- a/barretenberg/cpp/.aztec-packages-commit
+++ b/barretenberg/cpp/.aztec-packages-commit
@@ -1 +1 @@
-84754bbb47e32c722a9c13de17c328ae15e58f01
\ No newline at end of file
+a952e233e2a436e37f295d06d1ce344aafba90d0
diff --git a/barretenberg/cpp/src/CMakeLists.txt b/barretenberg/cpp/src/CMakeLists.txt
index 7f12367c670..0623373a7f5 100644
--- a/barretenberg/cpp/src/CMakeLists.txt
+++ b/barretenberg/cpp/src/CMakeLists.txt
@@ -247,6 +247,7 @@ else()
     if(INSTALL_BARRETENBERG)
         # The `install` function takes targets to install in different destinations on the system.
         install(
+            # TODO(dbanks12): should only need to install API headers
             TARGETS barretenberg barretenberg_headers
             # We also give it an optional export name in case something wants to target the install.
             EXPORT barretenbergTargets
diff --git a/barretenberg/cpp/src/barretenberg/barretenberg.hpp b/barretenberg/cpp/src/barretenberg/barretenberg.hpp
new file mode 100644
index 00000000000..951ef5897f2
--- /dev/null
+++ b/barretenberg/cpp/src/barretenberg/barretenberg.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+// External Barretenberg C++ API
+#include "common/container.hpp"
+#include "common/map.hpp"
+#include "common/serialize.hpp"
+#include "common/streams.hpp"
+#include "common/throw_or_abort.hpp"
+#include "crypto/blake2s/blake2s.hpp"
+#include "crypto/blake3s/blake3s.hpp"
+#include "crypto/ecdsa/ecdsa.hpp"
+#include "crypto/generators/generator_data.hpp"
+#include "crypto/keccak/keccak.hpp"
+#include "crypto/pedersen_commitment/pedersen.hpp"
+#include "crypto/pedersen_hash/pedersen.hpp"
+#include "crypto/schnorr/schnorr.hpp"
+#include "crypto/sha256/sha256.hpp"
+#include "ecc/curves/bn254/fq.hpp"
+#include "ecc/curves/bn254/fr.hpp"
+#include "ecc/curves/bn254/g1.hpp"
+#include "ecc/curves/grumpkin/grumpkin.hpp"
+#include "numeric/random/engine.hpp"
+#include "numeric/uint256/uint256.hpp"
+#include "plonk/composer/turbo_plonk_composer.hpp"
+#include "plonk/composer/ultra_plonk_composer.hpp"
+#include "plonk/proof_system/types/proof.hpp"
+#include "plonk/proof_system/verification_key/verification_key.hpp"
+#include "proof_system/types/composer_type.hpp"
+// TODO(https://github.com/AztecProtocol/barretenberg/issues/491):
+//     consider helper header(s) for serialization and other non-stdlib includes
+//         - possibly: common, serialize, srs, transcript
+#include "serialize/cbind.hpp"
+#include "serialize/cbind_fwd.hpp"
+#include "serialize/msgpack.hpp"
+#include "serialize/test_helper.hpp"
+#include "srs/reference_string/env_reference_string.hpp"
+#include "srs/reference_string/mem_reference_string.hpp"
+#include "stdlib/commitment/pedersen/pedersen.hpp"
+#include "stdlib/commitment/pedersen/pedersen_plookup.hpp"
+#include "stdlib/encryption/ecdsa/ecdsa.hpp"
+#include "stdlib/encryption/schnorr/schnorr.hpp"
+#include "stdlib/hash/blake2s/blake2s.hpp"
+#include "stdlib/hash/blake3s/blake3s.hpp"
+#include "stdlib/hash/pedersen/pedersen.hpp"
+#include "stdlib/merkle_tree/hash.hpp"
+#include "stdlib/merkle_tree/membership.hpp"
+#include "stdlib/merkle_tree/memory_store.hpp"
+#include "stdlib/merkle_tree/memory_tree.hpp"
+#include "stdlib/merkle_tree/merkle_tree.hpp"
+// TODO(https://github.com/AztecProtocol/aztec-packages/issues/728):
+//     Consider moving nullifier tree logic out of barretenberg into aztec repo
+#include "stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp"
+#include "stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp"
+#include "stdlib/merkle_tree/nullifier_tree/nullifier_tree.hpp"
+#include "stdlib/primitives/address/address.hpp"
+#include "stdlib/primitives/bigfield/bigfield.hpp"
+#include "stdlib/primitives/biggroup/biggroup.hpp"
+#include "stdlib/primitives/bit_array/bit_array.hpp"
+#include "stdlib/primitives/bool/bool.hpp"
+#include "stdlib/primitives/byte_array/byte_array.hpp"
+#include "stdlib/primitives/curves/bn254.hpp"
+#include "stdlib/primitives/field/array.hpp"
+#include "stdlib/primitives/field/field.hpp"
+#include "stdlib/primitives/group/group.hpp"
+#include "stdlib/primitives/packed_byte_array/packed_byte_array.hpp"
+#include "stdlib/primitives/point/point.hpp"
+#include "stdlib/primitives/uint/uint.hpp"
+#include "stdlib/primitives/witness/witness.hpp"
+#include "stdlib/recursion/aggregation_state/aggregation_state.hpp"
+#include "stdlib/recursion/aggregation_state/native_aggregation_state.hpp"
+#include "stdlib/recursion/verification_key/verification_key.hpp"
+#include "stdlib/recursion/verifier/program_settings.hpp"
+#include "stdlib/recursion/verifier/verifier.hpp"
+#include "transcript/manifest.hpp"
diff --git a/barretenberg/cpp/src/barretenberg/common/container.hpp b/barretenberg/cpp/src/barretenberg/common/container.hpp
index 1c87bb1224a..f82a40075fc 100644
--- a/barretenberg/cpp/src/barretenberg/common/container.hpp
+++ b/barretenberg/cpp/src/barretenberg/common/container.hpp
@@ -2,6 +2,7 @@
 #include <stddef.h>
 #include <vector>
 #include <string>
+#include <algorithm>
 
 template <typename C> C slice(C const& container, size_t start)
 {
diff --git a/barretenberg/cpp/src/barretenberg/common/map.hpp b/barretenberg/cpp/src/barretenberg/common/map.hpp
index 79205f2bda5..1118131e6fe 100644
--- a/barretenberg/cpp/src/barretenberg/common/map.hpp
+++ b/barretenberg/cpp/src/barretenberg/common/map.hpp
@@ -1,5 +1,6 @@
 #pragma once
 #include <algorithm>
+#include <array>
 #include <type_traits>
 
 /*