diff --git a/.circleci/config.yml b/.circleci/config.yml index e90371e69a21..62977ae6112d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,6 +92,17 @@ jobs: name: "Build" command: cond_spot_run_build circuits-wasm-linux-clang-assert 64 + circuits-x86_64-linux-clang-tidy: + docker: + - image: aztecprotocol/alpine-build-image + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Build" + command: cond_spot_run_build circuits-x86_64-linux-clang-tidy 64 + circuits-x86_64-linux-clang: docker: - image: aztecprotocol/alpine-build-image @@ -420,6 +431,7 @@ workflows: jobs: - circuits-wasm-linux-clang: *defaults - circuits-wasm-linux-clang-assert: *defaults + - circuits-x86_64-linux-clang-tidy: *defaults - circuits-x86_64-linux-clang: *defaults - circuits-x86_64-linux-clang-assert: *defaults - circuits-wasm-tests: diff --git a/build_manifest.json b/build_manifest.json index 78120b027970..c6b39043b809 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -15,6 +15,14 @@ ], "dependencies": [] }, + "circuits-x86_64-linux-clang-tidy": { + "buildDir": "circuits/cpp", + "dockerfile": "dockerfiles/Dockerfile.x86_64-linux-clang-tidy", + "rebuildPatterns": [ + "^circuits/" + ], + "dependencies": [] + }, "circuits-x86_64-linux-clang": { "buildDir": "circuits/cpp", "dockerfile": "dockerfiles/Dockerfile.x86_64-linux-clang", diff --git a/circuits/CODING_STANDARD.md b/circuits/CODING_STANDARD.md new file mode 100644 index 000000000000..057691cbf687 --- /dev/null +++ b/circuits/CODING_STANDARD.md @@ -0,0 +1,306 @@ +## C++ Standard for Aztec Circuits + +### Sticking to the Standard + +Read the standards and stick to them! There is some automation to help with this, but **the automation is far from comprehensive**. + +Here are the types of automation that should help stick to the standard: +1. The VSCode workspace file `circuits.code-workspace` is configured to automatically format your code nicely when you save a C++ file. + * It uses `cpp/.clang-format` for this +2. These workspace settings are also configured to warn you (with yellow squiggles) when something does not follow some of the rules. + * It uses `cpp/.clangd` for this +3. A tidy check is run in CI + * Job fails if your code would be changed by `./scripts/tidy.sh fix` +4. To perform some auto-tidying of your code, run `./scripts/tidy.sh fix` from `cpp/` + * **Commit your code first** since tidying will occasionally mess up your code! + * This will run `clang-tidy` on all C++ source files + * It uses `cpp/.clang-tidy` * and formats tidied code with `cpp/.clang-format` + * **Manually review any fixes to your code!** + * If you disagree with an auto-fix or if it is buggy, use `// NOLINT...` ([more here](https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics)) + * If you believe we should reject an entire class of tidy fixes, consider explicitly omitting from our checks or errors in `./clang-tidy` + * Discuss with others first + * _Note:_ tidying takes a while! + * **You may need to run this multiple times!** + * An error (with an auto-fix) in one round may prevent certain subsequent fixes + * A fix in the one round may introduce more potential for fixes + +### The Standard + +1. **general** + * when something is not covered below, fall back to [Google's style guide](https://google.github.io/styleguide/cppguide.html) + * all TODOs should mention a username, email or bug number + ``` + // TODO(dbanks12) + // TODO(david@aztecprotocol.com) + // TODO(bug 12345) + ``` + * if your editor warns you about a line of code fix it! + * consider doing so even if you didn't write that code +1. **spacing** + * 4 spaces except for access-specifiers (`public`/`protected`/`private`) which can use 2 + * namespaces are not indented + * for continued indentation, just be sane + * remove trailing spaces at end of line (use a plugin) + * include a newline at the end of a file + ``` + namespace my_namespace { + class MyClass { + public: + // ... public stuff + + protected: + // ... protected stuff + + private: + // ... private stuff + + void my_private_function0(int arg0, + int arg1) + { + // ... + } + + void my_private_function1( + int arg0, + int arg1) + { + // ... + } + } + } // namespace my_namespace + + ``` +1. **braces** + * functions use curly brace alone on newline + * namespaces, classes, structs, enums, ifs, and loops use curely brace on same line + * examples + ``` + void my_function() + { + // ... + } + + for (int i = 0; i < max; i++) { + // ... + } + + if (something_is_true) { + // ... + } + + struct MyStruct { + // ... + } + ``` +1. **naming** + * `snake_case` for files, namespaces and local variables/members + * `CamelCase` for classes, structs, enums, types + * exceptions types can be made for types if trying to mimic a std type's name like `uint` or `field_ct` + * `ALL_CAPS` for `constexpr`s, global constants, and macros + * do use + * Clear names + * Descriptive names + * don't use + * abbreviations + * words with letters removed + * acronyms + * single letter names + * Unless writing maths, in which case use your best judgement and follow the naming of a _linked_ paper +1. `auto` + * include `*`, `&`, and/or `const` even when using `auto` + * use when type is evident + * use when type should be deduced automatically based on expr + * use in loops to iterate over members of a container + * don't use if it makes type unclear + * don't use you need to enforce a type + * examples + ``` + auto my_var = my_function_with_unclear_return_type(); // BAD + auto my_var = get_new_of_type_a(); // GOOD + ``` +1. `const` and `constexpr` + * use `const` whenever possible to express immutability + * use `constexpr` whenever a `const` can be computed at compile-time + * place `const`/`constexpr` BEFORE the core type as is done in bberg stdlib + * examples + ``` + const int my_const = 0; + constexpr int MY_CONST = 0; + ``` +1. `namespace` and `using` + * never do `using namespace my_namespace;` which causes namespace pollution and reduces readability + * [see here for google's corresponding rule](https://clang.llvm.org/extra/clang-tidy/checks/google/build-using-namespace.html) + * avoid doing `typedef my::OldType NewType` and instead do `using NewType = my::OldType` + * namespaces should exactly match directory structure. If you create a nested namespace, create a nested directory for it + * example for directory `aztec3/circuits/abis/private_kernel`: + ``` + namespace aztec3::circuits::abis::private_kernel { + // ... + } // namespace aztec3::circuits::abis::private_kernel + ``` + * use`init.hpp` *only* for core/critical renames like `NT/CT` and for toggling core types like `Composer` + * use unnamed/anonymous namespaces to import and shorten external names into *just this one file* + * all of a file's external imports belong in a single anonymous namespace `namespace { ...\n } // namespace` at the very top of the file directly after `#include`s + * use `using Rename = old::namespace::prefix::Name;` to import and shorten names from external namespaces + * avoid using renames to obscure template params (`using A = A;`) + * never use renames to remove the `std::` prefix + * never use renames to remove a `NT::` or `CT::` prefix + * `test.cpp` tests must always explicitly import every single name they intend to use + * they might want to test over multiple namespaces, native and circuit types, and composer types + * avoid calling barretenberg's functions directly and instead go through interface files like `circuit_types` and +`native_types` + * `using` statements should be sorted case according to the `LexicographicNumeric` rules + * see the `SortUsingDeclarations` section of the [LLVM Clang Format Style Options document](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) + * if your IDE is telling you that an include or name is unused in a file, remove it! +1. **includes** + * start every header with `#pragma once` + * `index.hpp` should include common headers that will be referenced by most cpp/hpp files in the current directory + * `init.hpp` should inject ONLY critical renames (like `NT`/`CT`) and type toggles (like Composer) + * example `using NT = aztec3::utils::types::NativeTypes;` + * avoid including headers via relative paths (`../../other_dir`) unless they are a subdir (`subdir/header.hpp`) + * use full path like `aztec3/circuits/hash.hpp` + * ordering of includes + * this source file's header + * essentials (if present) + * `"index.hpp"` + * `"init.hpp"` + * headers nearby + * headers from this directory (no `/`) + * headers from this project using relative path (`"private/private_kernel_inputs.hpp"`) + * Note: headers in this group are sorted in the above order (no `/` first, relative paths second) + * headers from this project using full path (starts with aztec3: `"aztec3/constants.hpp"`) + * barretenberg headers + * `` or other third party headers specified in `.clang-format` + * C++ standard library headers + * use quotes internal headers + * use angle braces for std library and external library headers + * this includes barretenberg + * each group of includes should be sorted case sensitive alphabetically + * each group of includes should be newline-separated + * example: + ``` + #include "this_file.hpp" + + #include "index.hpp" + #include "init.hpp" + + #include "my_file_a_in_this_dir.hpp" + #include "my_file_b_in_this_dir.hpp" + #include "other_dir/file_a_nearby.hpp" + #include "other_dir/file_b_nearby.hpp" + + #include "aztec3/file_a_in_project.hpp" + #include "aztec3/file_b_in_project.hpp" + + #include + #include + + #include + + #include + #include + ``` +1. **access specifiers** + * order them `public`, `protected`, `private` +1. **struct and array initialization** + * use `MyStruct my_inst{};` + * will call default constructor if exists and otherwise will value-initialize members to zero (or will call *their* default constructors if they exist) + * explicitly initialize struct members with default values: `NT::fr my_fr = 0;` + * initialize arrays using `std::array my_arr{};` + * this value-initializes all entries to 0 if T has no default constructor, otherwise calls default constructor for each + * arrays of fields/`fr` are different! Use `zero_array` helper function for initialization + * `std::array vk_path = zero_array();` + * This is necessary because `fr` *does* have a default constructor that intentionally does *not* intialize its members to 0 +1. **references** + * use them whenever possible for function arguments since pass by reference is cheaper + * make arg references "const" if they should not be modified inside a function +1. **avoid C-style coding** + * avoid `malloc/free` + * use `std::array/vector` instead of `int[]` + * use references instead of pointers when possible + * if pointers are necessary, use smart pointers (`std::unique_ptr/shared_ptr`) instead of raw pointers + * avoid C-style casts (use `static_cast` or `reinterpret_cast`) +1. **comments** + * use doxygen docstrings (will include format example) + ``` + /** + * @brief Brief description + * @details more details + * @tparam mytemplateparam description + * @param myfunctionarg description + * @return describe return value + * @see otherRelevantFunction() + * @see [mylink](url) + */ + ``` + * every file should have a meaningful comment + * every class/struct/function/test should have a meaningful comment + * class/struct comment might == file comment + * comment function preconditions ("arg x must be < 100") +1. **side-effects** + * avoid functions with side effects when it is easy enough to just have pure functions + * if a function modifies its arguments, it should be made very clear that this is happening + * same with class methods that modify members + * function arguments should be `const` when they will not be modified +1. **global state** + * no +1. **docs** + * every subdir should have a readme +1. **functions** + * use `[[nodiscard]]` if it makes no sense to call this function and discard return value + ``` + [[nodiscard] int my_function() + { + // ... + return some_int; + } + + // later can't do + my_function(); + + // can only do + int capture_ret = my_function(); + ``` + * if there is a name clash, prefix parameter with underscore like `_myparam` + ``` + void my_function(int _my_var) + { + my_var = _my_var; + } + ``` +1. **macros** + * avoid macros as much as possible with exceptions for + * testing + * debug utilities + * agreed upon macro infrastructure (like cbinds) +1. **misc** + * use `uintN_t` instead of a primitive type (e.g. `size_t`) when a specific type width must be guaranteed + * avoid signed types (`int`, `long`, `char` etc) unless signedness is required + * signed types are susceptible to undefined behavior on overflow/underflow + * initialize pointers to `nullptr` + * constructors with single arguments should be marked `explicit` to prevent unwanted conversions + * if a constructor is meant to do nothing, do `A() = default;` instead of `A(){}` ([explanation here](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-default.html)) + * definitely don't do `A(){};` (with semicolon) which can't even be auto-fixed by `clang-tidy` + * explicitly use `override` when overriding a parent class' member ([explanation here](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-override.html)) + * avoid multiple declarations on the same line + * do: + ``` + int a = 0; + int b = 0; + ``` + * dont: + ``` + int a, b = 0, 0; + ``` + * use `std::vector::emplace_back` instead of `push_back` + * don't use `std::make_pair` when using `emplace_back` ([unnecessary as explained here](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html)) + * **no magic numbers** even if there is a comment explaining them + + +## References + +1. [Mike's Draft C++ Standard](https://hackmd.io/@aztec-network/B1r36lhmj?type=view) +2. [Barretenberg's `.clangd`](https://github.com/AztecProtocol/barretenberg/blob/master/cpp/.clangd) +3. [Barretenberg's `.clang-format`](https://github.com/AztecProtocol/barretenberg/blob/master/cpp/.clang-format) +4. [LLVM's Clang Format Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) +5. [Google's Style Guide](https://google.github.io/styleguide/cppguide.html) \ No newline at end of file diff --git a/circuits/README.md b/circuits/README.md index fc66f6b0c0dc..dfd6ef640c5f 100644 --- a/circuits/README.md +++ b/circuits/README.md @@ -2,6 +2,10 @@ ###### tags: `aztec-3, circuits` +## Contributing + +See [CODING_STANDARD.md](./CODING_STANDARD.md)** before contributing! + ## Repository Overview The [`aztec3-circpuits`](https://github.com/AztecProtocol/aztec3-packages) circuits folder contains circuits and related C++ code (`cpp/`) for Aztec3 along with Typescript wrappers (`ts/`). diff --git a/circuits/circuits.code-workspace b/circuits/circuits.code-workspace index 5346f324bb29..aec11f53b2b0 100644 --- a/circuits/circuits.code-workspace +++ b/circuits/circuits.code-workspace @@ -108,6 +108,10 @@ // "clangd.path": "clangd-15", // + // LLDB + // + "lldb.dereferencePointers": true, + // // CMake // // Location of base CMakeLists file @@ -161,11 +165,9 @@ } ] }, - // - // GTest adapter (not currently used) - // "[cpp]": { - "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" - } + "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd", + "editor.formatOnSave": true, + }, } } diff --git a/circuits/cpp/.dockerignore b/circuits/cpp/.dockerignore index 94dbd3ee2709..d2b2f132ae70 100644 --- a/circuits/cpp/.dockerignore +++ b/circuits/cpp/.dockerignore @@ -2,6 +2,8 @@ build build-wasm docker* .* +!.clang-format +!.clang-tidy src/wasi-sdk* barretenberg/cpp/build* barretenberg/cpp/docker* diff --git a/circuits/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-tidy b/circuits/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-tidy new file mode 100644 index 000000000000..6064bc941c48 --- /dev/null +++ b/circuits/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-tidy @@ -0,0 +1,23 @@ +FROM alpine:3.17 AS builder +RUN apk update \ + && apk upgrade \ + && apk add --no-cache \ + build-base \ + clang15 \ + clang15-extra-tools \ + openmp-dev \ + cmake \ + ninja \ + git \ + curl \ + perl \ + bash \ + python3 + +WORKDIR /usr/src/circuits/cpp + +COPY . . + +# Configure cmake and check if code is tidy +RUN cmake --preset default +RUN ./scripts/tidy.sh fix \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 215dd6d9d04a..5a67848bd2be 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -1,11 +1,12 @@ -#include -#include -#include #include "index.hpp" - #include "previous_kernel_data.hpp" #include "private_kernel/private_inputs.hpp" +#include +#include + +#include + namespace { // Composer using Composer = plonk::UltraComposer; @@ -13,7 +14,7 @@ using Composer = plonk::UltraComposer; // Types using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; -} // namespace +} // namespace namespace aztec3::circuits::abis { @@ -21,7 +22,7 @@ class abi_tests : public ::testing::Test {}; TEST(abi_tests, native_read_write_call_context) { - CallContext call_context = { + CallContext const call_context = { .msg_sender = 1, .storage_contract_address = 2, .portal_contract_address = 3, @@ -40,7 +41,7 @@ TEST(abi_tests, native_read_write_call_context) TEST(abi_tests, native_read_write_function_data) { - FunctionData function_data = { + FunctionData const function_data = { .function_selector = 11, .is_private = false, .is_constructor = false, @@ -73,7 +74,7 @@ TEST(abi_tests, native_read_write_function_data) TEST(abi_tests, native_to_circuit_function_data) { - FunctionData native_function_data = { + FunctionData const native_function_data = { .function_selector = 11, .is_private = false, .is_constructor = false, @@ -82,14 +83,14 @@ TEST(abi_tests, native_to_circuit_function_data) info("function data: ", native_function_data); Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); - FunctionData circuit_function_data = native_function_data.to_circuit_type(composer); + FunctionData const circuit_function_data = native_function_data.to_circuit_type(composer); info("function data: ", circuit_function_data); } TEST(abi_tests, native_call_context) { - CallContext call_context = { + CallContext const call_context = { .msg_sender = 10, .storage_contract_address = 11, .portal_contract_address = 12, @@ -102,7 +103,7 @@ TEST(abi_tests, native_call_context) TEST(abi_tests, native_to_circuit_call_context) { - CallContext native_call_context = { + CallContext const native_call_context = { .msg_sender = 10, .storage_contract_address = 11, .portal_contract_address = 12, @@ -113,9 +114,9 @@ TEST(abi_tests, native_to_circuit_call_context) info("call context: ", native_call_context); Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); - CallContext circuit_call_context = native_call_context.to_circuit_type(composer); + CallContext const circuit_call_context = native_call_context.to_circuit_type(composer); info("call context: ", circuit_call_context); } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/append_only_tree_snapshot.hpp b/circuits/cpp/src/aztec3/circuits/abis/append_only_tree_snapshot.hpp index 2eaf8c8763bd..1815a11e92f8 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/append_only_tree_snapshot.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/append_only_tree_snapshot.hpp @@ -8,9 +8,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct AppendOnlyTreeSnapshot { - - typedef typename NCT::fr fr; - typedef typename NCT::uint32 uint32; + using fr = typename NCT::fr; + using uint32 = typename NCT::uint32; fr root = 0; uint32 next_available_leaf_index; @@ -40,4 +39,4 @@ template std::ostream& operator<<(std::ostream& os, AppendOnlyTre << "next_available_leaf_index: " << obj.next_available_leaf_index << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index e4a15a6d4899..195b180c09fd 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -1,30 +1,31 @@ #include "c_bind.h" -#include "barretenberg/srs/reference_string/mem_reference_string.hpp" -#include "aztec3/circuits/abis/function_data.hpp" -#include "aztec3/circuits/abis/function_leaf_preimage.hpp" -#include "aztec3/circuits/abis/new_contract_data.hpp" -#include "private_circuit_public_inputs.hpp" -#include "tx_request.hpp" -#include "tx_context.hpp" + #include "function_data.hpp" #include "function_leaf_preimage.hpp" -#include "rollup/base/base_rollup_inputs.hpp" -#include "rollup/base/base_or_merge_rollup_public_inputs.hpp" -#include "rollup/root/root_rollup_public_inputs.hpp" -#include "rollup/root/root_rollup_inputs.hpp" +#include "kernel_circuit_public_inputs.hpp" #include "previous_kernel_data.hpp" +#include "private_circuit_public_inputs.hpp" +#include "tx_context.hpp" +#include "tx_request.hpp" #include "private_kernel/private_inputs.hpp" -#include "kernel_circuit_public_inputs.hpp" #include "public_kernel/public_kernel_inputs.hpp" #include "public_kernel/public_kernel_inputs_no_previous_kernel.hpp" +#include "rollup/base/base_or_merge_rollup_public_inputs.hpp" +#include "rollup/base/base_rollup_inputs.hpp" +#include "rollup/root/root_rollup_inputs.hpp" +#include "rollup/root/root_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/function_data.hpp" +#include "aztec3/circuits/abis/function_leaf_preimage.hpp" +#include "aztec3/circuits/abis/new_contract_data.hpp" #include #include - -#include #include -#include +#include + +#include "barretenberg/srs/reference_string/mem_reference_string.hpp" #include +#include namespace { @@ -63,20 +64,20 @@ template void rightfill_with_zeroleaves(std::vector leaves.insert(leaves.end(), max_leaves - leaves.size(), zero_leaf); } -} // namespace +} // namespace // Note: We don't have a simple way of calling the barretenberg c-bind. // Mimick bbmalloc behaviour. static void* bbmalloc(size_t size) { - auto ptr = aligned_alloc(64, size); + auto* ptr = aligned_alloc(64, size); return ptr; } /** Copy this string to a bbmalloc'd buffer */ static const char* bbmalloc_copy_string(const char* data, size_t len) { - char* output_copy = (char*)bbmalloc(len + 1); + char* output_copy = static_cast(bbmalloc(len + 1)); memcpy(output_copy, data, len + 1); return output_copy; } @@ -89,8 +90,8 @@ template static const char* as_string_output(uint8_t const* input_b read(input_buf, obj); std::ostringstream stream; stream << obj; - std::string str = stream.str(); - *size = (uint32_t)str.size(); + std::string const str = stream.str(); + *size = static_cast(str.size()); return bbmalloc_copy_string(str.c_str(), *size); } @@ -102,8 +103,8 @@ template static const char* as_serialized_output(uint8_t const* inp read(input_buf, obj); std::vector stream; write(stream, obj); - *size = (uint32_t)stream.size(); - return bbmalloc_copy_string((char*)stream.data(), *size); + *size = static_cast(stream.size()); + return bbmalloc_copy_string(reinterpret_cast(stream.data()), *size); } #define WASM_EXPORT __attribute__((visibility("default"))) @@ -153,7 +154,7 @@ WASM_EXPORT void abis__compute_function_selector(char const* func_sig_cstr, uint // hash the function signature using keccak256 auto keccak_hash = ethash_keccak256(reinterpret_cast(func_sig_cstr), strlen(func_sig_cstr)); // get a pointer to the start of the hash bytes - uint8_t const* hash_bytes = reinterpret_cast(&keccak_hash.word64s[0]); + auto const* hash_bytes = reinterpret_cast(&keccak_hash.word64s[0]); // get the correct number of bytes from the hash and copy into output buffer std::copy_n(hash_bytes, aztec3::FUNCTION_SELECTOR_NUM_BYTES, output); } @@ -214,11 +215,11 @@ WASM_EXPORT void abis__compute_function_tree_root(uint8_t const* function_leaves // fill in nonzero leaves to start read(function_leaves_in, leaves); // fill in zero leaves to complete tree - NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage + NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage rightfill_with_zeroleaves(leaves, zero_leaf); // compute the root of this complete tree, return - NT::fr root = plonk::stdlib::merkle_tree::compute_tree_root_native(leaves); + NT::fr const root = plonk::stdlib::merkle_tree::compute_tree_root_native(leaves); // serialize and return root NT::fr::serialize_to_buffer(root, root_out); @@ -243,10 +244,10 @@ WASM_EXPORT void abis__compute_function_tree(uint8_t const* function_leaves_in, // fill in nonzero leaves to start read(function_leaves_in, leaves); // fill in zero leaves to complete tree - NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage + NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage rightfill_with_zeroleaves(leaves, zero_leaf); - std::vector tree = plonk::stdlib::merkle_tree::compute_tree_native(leaves); + std::vector const tree = plonk::stdlib::merkle_tree::compute_tree_native(leaves); // serialize and return tree write(tree_nodes_out, tree); @@ -278,7 +279,7 @@ WASM_EXPORT void abis__hash_constructor(uint8_t const* function_data_buf, read(args_buf, args); read(constructor_vk_hash_buf, constructor_vk_hash); - NT::fr constructor_hash = compute_constructor_hash(function_data, args, constructor_vk_hash); + NT::fr const constructor_hash = compute_constructor_hash(function_data, args, constructor_vk_hash); NT::fr::serialize_to_buffer(constructor_hash, output); } @@ -441,4 +442,4 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_function_leaf_preimage(ui return as_string_output>(function_leaf_preimage_buf, size); } -} // extern "C" +} // extern "C" diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index 39ba2ab3e1e5..dc9df6d36cca 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -1,12 +1,12 @@ #include "c_bind.h" - -#include "tx_request.hpp" #include "function_leaf_preimage.hpp" +#include "tx_request.hpp" + #include "aztec3/circuits/abis/new_contract_data.hpp" -#include -#include #include +#include +#include #include @@ -42,7 +42,7 @@ template std::string bytes_to_hex_str(std::array tx_request = TxRequest{ + TxRequest const tx_request = TxRequest{ .from = NT::fr::random_element(), .to = NT::fr::random_element(), .function_data = FunctionData(), @@ -75,7 +75,7 @@ TEST(abi_tests, hash_tx_request) abis__hash_tx_request(buf.data(), output.data()); // Convert buffer to `fr` for comparison to in-test calculated hash - NT::fr got_hash = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_hash = NT::fr::serialize_from_buffer(output.data()); // Confirm cbind output == hash of tx request EXPECT_EQ(got_hash, tx_request.hash()); @@ -93,7 +93,7 @@ TEST(abi_tests, compute_function_selector_transfer) // get the selector as a hex string // compare against known good selector from solidity // In solidity where selectors are 4 bytes it is a9059cbb - std::string full_selector = "a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b"; + std::string const full_selector = "a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b"; EXPECT_EQ(bytes_to_hex_str(output), full_selector.substr(0, FUNCTION_SELECTOR_NUM_BYTES * 2)); } @@ -108,7 +108,7 @@ TEST(abi_tests, compute_function_selector_transferFrom) // get the selector as a hex string // compare against known good selector from solidity - std::string full_selector = "23b872dd7302113369cda2901243429419bec145408fa8b352b3dd92b66c680b"; + std::string const full_selector = "23b872dd7302113369cda2901243429419bec145408fa8b352b3dd92b66c680b"; EXPECT_EQ(bytes_to_hex_str(output), full_selector.substr(0, FUNCTION_SELECTOR_NUM_BYTES * 2)); } @@ -117,7 +117,7 @@ TEST(abi_tests, hash_vk) // Initialize some random VK data NT::VKData vk_data; vk_data.composer_type = engine.get_random_uint32(); - vk_data.circuit_size = uint32_t(1) << (engine.get_random_uint8() >> 3); // must be a power of two + vk_data.circuit_size = static_cast(1) << (engine.get_random_uint8() >> 3); // must be a power of two vk_data.num_public_inputs = engine.get_random_uint32(); vk_data.commitments["test1"] = g1::element::random_element(); vk_data.commitments["test2"] = g1::element::random_element(); @@ -134,10 +134,10 @@ TEST(abi_tests, hash_vk) abis__hash_vk(vk_data_vec.data(), output.data()); // Convert buffer to `fr` for comparison to in-test calculated hash - NT::fr got_hash = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_hash = NT::fr::serialize_from_buffer(output.data()); // Calculate the expected hash in-test - NT::fr expected_hash = vk_data.compress_native(aztec3::GeneratorIndex::VK); + NT::fr const expected_hash = vk_data.compress_native(aztec3::GeneratorIndex::VK); // Confirm cbind output == expected hash EXPECT_EQ(got_hash, expected_hash); @@ -146,7 +146,7 @@ TEST(abi_tests, hash_vk) TEST(abi_tests, compute_function_leaf) { // Construct FunctionLeafPreimage with some randomized fields - FunctionLeafPreimage preimage = FunctionLeafPreimage{ + auto const preimage = FunctionLeafPreimage{ .function_selector = engine.get_random_uint32(), .is_private = static_cast(engine.get_random_uint8() & 1), .vk_hash = NT::fr::random_element(), @@ -160,14 +160,14 @@ TEST(abi_tests, compute_function_leaf) std::array output = { 0 }; abis__compute_function_leaf(preimage_buf.data(), output.data()); - NT::fr got_leaf = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_leaf = NT::fr::serialize_from_buffer(output.data()); EXPECT_EQ(got_leaf, preimage.hash()); } TEST(abi_tests, compute_function_tree_root) { // randomize number of non-zero leaves such that `0 < num_nonzero_leaves <= FUNCTION_TREE_NUM_LEAVES` - uint8_t num_nonzero_leaves = engine.get_random_uint8() % (FUNCTION_TREE_NUM_LEAVES + 1); + uint8_t const num_nonzero_leaves = engine.get_random_uint8() % (FUNCTION_TREE_NUM_LEAVES + 1); // generate some random leaves std::vector leaves_frs; @@ -181,12 +181,12 @@ TEST(abi_tests, compute_function_tree_root) // call cbind and get output (root) std::array output = { 0 }; abis__compute_function_tree_root(leaves_bytes_vec.data(), output.data()); - NT::fr got_root = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_root = NT::fr::serialize_from_buffer(output.data()); // compare cbind results with direct computation // add the zero leaves to the vector of fields and pass to barretenberg helper - NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage + NT::fr const zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage for (size_t l = num_nonzero_leaves; l < FUNCTION_TREE_NUM_LEAVES; l++) { leaves_frs.push_back(zero_leaf); } @@ -197,7 +197,7 @@ TEST(abi_tests, compute_function_tree_root) TEST(abi_tests, compute_function_tree) { // randomize number of non-zero leaves such that `0 < num_nonzero_leaves <= FUNCTION_TREE_NUM_LEAVES` - uint8_t num_nonzero_leaves = engine.get_random_uint8() % (FUNCTION_TREE_NUM_LEAVES + 1); + uint8_t const num_nonzero_leaves = engine.get_random_uint8() % (FUNCTION_TREE_NUM_LEAVES + 1); // generate some random leaves std::vector leaves_frs; @@ -224,7 +224,7 @@ TEST(abi_tests, compute_function_tree) // compare cbind results with direct computation // add the zero leaves to the vector of fields and pass to barretenberg helper - NT::fr zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage + NT::fr const zero_leaf = FunctionLeafPreimage().hash(); // hash of empty/0 preimage for (size_t l = num_nonzero_leaves; l < FUNCTION_TREE_NUM_LEAVES; l++) { leaves_frs.push_back(zero_leaf); } @@ -235,14 +235,13 @@ TEST(abi_tests, compute_function_tree) TEST(abi_tests, hash_constructor) { // Randomize required values - FunctionData func_data = - FunctionData{ .function_selector = 10, .is_private = true, .is_constructor = false }; + auto const func_data = FunctionData{ .function_selector = 10, .is_private = true, .is_constructor = false }; std::array args; for (size_t i = 0; i < aztec3::ARGS_LENGTH; i++) { args[i] = fr::random_element(); } - NT::fr constructor_vk_hash = NT::fr::random_element(); + NT::fr const constructor_vk_hash = NT::fr::random_element(); // Write the function data and args to a buffer std::vector func_data_buf; @@ -261,10 +260,10 @@ TEST(abi_tests, hash_constructor) abis__hash_constructor(func_data_buf.data(), args_buf.data(), constructor_vk_hash_buf.data(), output.data()); // Convert buffer to `fr` for comparison to in-test calculated hash - NT::fr got_hash = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_hash = NT::fr::serialize_from_buffer(output.data()); // Calculate the expected hash in-test - NT::fr expected_hash = NT::compress( + NT::fr const expected_hash = NT::compress( { func_data.hash(), NT::compress(args, aztec3::GeneratorIndex::CONSTRUCTOR_ARGS), constructor_vk_hash }, aztec3::GeneratorIndex::CONSTRUCTOR); @@ -275,10 +274,10 @@ TEST(abi_tests, hash_constructor) TEST(abi_tests, compute_contract_address) { // Randomize required values - NT::fr deployer_address = NT::fr::random_element(); - NT::fr contract_address_salt = NT::fr::random_element(); - NT::fr function_tree_root = NT::fr::random_element(); - NT::fr constructor_hash = NT::fr::random_element(); + NT::fr const deployer_address = NT::fr::random_element(); + NT::fr const contract_address_salt = NT::fr::random_element(); + NT::fr const function_tree_root = NT::fr::random_element(); + NT::fr const constructor_hash = NT::fr::random_element(); // Serialize values to buffers std::array deployer_address_buf = { 0 }; @@ -301,10 +300,10 @@ TEST(abi_tests, compute_contract_address) output.data()); // Convert buffer to `fr` for comparison to in-test calculated contract address - NT::fr got_address = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_address = NT::fr::serialize_from_buffer(output.data()); // Calculate the expected contract address in-test - NT::fr expected_address = + NT::fr const expected_address = NT::compress({ deployer_address, contract_address_salt, function_tree_root, constructor_hash }, aztec3::GeneratorIndex::CONTRACT_ADDRESS); @@ -315,7 +314,7 @@ TEST(abi_tests, compute_contract_address) TEST(abi_tests, compute_contract_leaf) { // Construct ContractLeafPreimage with some randomized fields - NewContractData preimage = NewContractData{ + NewContractData const preimage = NewContractData{ .contract_address = NT::fr::random_element(), .portal_contract_address = NT::fr::random_element(), .function_tree_root = NT::fr::random_element(), @@ -328,8 +327,8 @@ TEST(abi_tests, compute_contract_leaf) std::array output = { 0 }; abis__compute_contract_leaf(preimage_buf.data(), output.data()); - NT::fr got_leaf = NT::fr::serialize_from_buffer(output.data()); + NT::fr const got_leaf = NT::fr::serialize_from_buffer(output.data()); EXPECT_EQ(got_leaf, preimage.hash()); } -} // namespace aztec3::circuits::abis +} // namespace aztec3::circuits::abis diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp index ebfba426d733..27fa45e29484 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp @@ -1,12 +1,13 @@ #pragma once -#include -#include -#include +#include #include #include #include -#include + +#include +#include +#include namespace aztec3::circuits::abis { @@ -14,9 +15,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct CallContext { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; address msg_sender = 0; address storage_contract_address = 0; @@ -64,7 +65,7 @@ template struct CallContext { fr hash() const { - std::vector inputs = { + std::vector const inputs = { msg_sender.to_field(), storage_contract_address.to_field(), portal_contract_address, fr(is_delegate_call), fr(is_static_call), fr(is_contract_deployment), }; @@ -131,4 +132,4 @@ template std::ostream& operator<<(std::ostream& os, CallContext typename PrivatePublic> struct CallStackItem { - typedef typename NCT::address address; - typedef typename NCT::boolean boolean; - typedef typename NCT::fr fr; + using address = typename NCT::address; + using boolean = typename NCT::boolean; + using fr = typename NCT::fr; // This is the _actual_ contract address relating to where this function's code resides in the // contract tree. Regardless of whether this is a call or delegatecall, this diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp index d88ff6d89824..91f148576504 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp @@ -1,16 +1,18 @@ #pragma once -#include "optionally_revealed_data.hpp" #include "new_contract_data.hpp" -#include "public_data_transition.hpp" +#include "optionally_revealed_data.hpp" #include "public_data_read.hpp" +#include "public_data_transition.hpp" + #include "aztec3/constants.hpp" -#include -#include -#include #include -#include #include #include +#include + +#include +#include +#include namespace aztec3::circuits::abis { @@ -20,9 +22,9 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct CombinedAccumulatedData { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; - typedef typename NCT::AggregationObject AggregationObject; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; + using AggregationObject = typename NCT::AggregationObject; AggregationObject aggregation_object{}; @@ -251,4 +253,4 @@ template std::ostream& operator<<(std::ostream& os, CombinedAccum << accum_data.state_reads << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp index f5d8ffece81a..b6e075040798 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp @@ -3,10 +3,11 @@ #include "combined_historic_tree_roots.hpp" #include "tx_context.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -17,8 +18,8 @@ using plonk::stdlib::witness_t; using std::is_same; template struct CombinedConstantData { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; CombinedHistoricTreeRoots historic_tree_roots{}; TxContext tx_context{}; @@ -85,4 +86,4 @@ template std::ostream& operator<<(std::ostream& os, CombinedConst << "tx_context: " << constant_data.tx_context << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp index 35286bcd9e68..9bdc2fb44c40 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp @@ -1,9 +1,11 @@ #pragma once -#include -#include +#include "private_historic_tree_roots.hpp" + #include #include -#include "private_historic_tree_roots.hpp" +#include + +#include namespace aztec3::circuits::abis { @@ -14,8 +16,8 @@ using plonk::stdlib::witness_t; using std::is_same; template struct CombinedHistoricTreeRoots { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; PrivateHistoricTreeRoots private_historic_tree_roots{}; @@ -79,4 +81,4 @@ std::ostream& operator<<(std::ostream& os, CombinedHistoricTreeRoots const& return os << "private_historic_tree_roots: " << historic_tree_roots.private_historic_tree_roots << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp index dd52a09065d7..1f7cd7f64659 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp @@ -1,11 +1,12 @@ #pragma once -#include -#include -#include #include #include #include +#include +#include +#include + namespace aztec3::circuits::abis { using aztec3::utils::types::CircuitTypes; @@ -14,9 +15,9 @@ using plonk::stdlib::witness_t; using std::is_same; template struct ContractDeploymentData { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr constructor_vk_hash = 0; fr function_tree_root = 0; @@ -85,7 +86,7 @@ template struct ContractDeploymentData { fr hash() const { - std::vector inputs = { + std::vector const inputs = { constructor_vk_hash, function_tree_root, contract_address_salt, @@ -124,4 +125,4 @@ template std::ostream& operator<<(std::ostream& os, ContractDeplo << "portal_contract_address: " << data.portal_contract_address << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp index 66d2a84f3967..0e8646da1378 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp @@ -1,8 +1,8 @@ #pragma once +#include #include #include #include -#include namespace aztec3::circuits::abis { @@ -12,11 +12,11 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct FunctionData { - typedef typename NCT::uint32 uint32; - typedef typename NCT::boolean boolean; - typedef typename NCT::fr fr; + using uint32 = typename NCT::uint32; + using boolean = typename NCT::boolean; + using fr = typename NCT::fr; - uint32 function_selector; // e.g. 1st 4-bytes of abi-encoding of function. + uint32 function_selector; // e.g. 1st 4-bytes of abi-encoding of function. boolean is_private = false; boolean is_constructor = false; @@ -68,7 +68,7 @@ template struct FunctionData { // TODO: this can all be packed into 1 field element, so this `hash` function should just return that field element. fr hash() const { - std::vector inputs = { + std::vector const inputs = { fr(function_selector), fr(is_private), fr(is_constructor), @@ -103,4 +103,4 @@ template std::ostream& operator<<(std::ostream& os, FunctionData< << "is_constructor: " << function_data.is_constructor << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp index 04498db2a7fb..616f4b561208 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp @@ -1,8 +1,8 @@ #pragma once +#include #include #include #include -#include namespace aztec3::circuits::abis { @@ -26,10 +26,9 @@ using std::is_same; * - writing a preimage to an ostream */ template struct FunctionLeafPreimage { - - typedef typename NCT::boolean boolean; - typedef typename NCT::fr fr; - typedef typename NCT::uint32 uint32; + using boolean = typename NCT::boolean; + using fr = typename NCT::fr; + using uint32 = typename NCT::uint32; uint32 function_selector = 0; boolean is_private = false; @@ -86,7 +85,7 @@ template struct FunctionLeafPreimage { fr hash() const { - std::vector inputs = { + std::vector const inputs = { function_selector, fr(is_private), vk_hash, @@ -124,4 +123,4 @@ template std::ostream& operator<<(std::ostream& os, FunctionLeafP << "acir_hash: " << preimage.acir_hash << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/index.hpp b/circuits/cpp/src/aztec3/circuits/abis/index.hpp index 1c6769333bc7..e589b66d7e7e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/index.hpp @@ -2,6 +2,5 @@ #include "call_stack_item.hpp" #include "function_data.hpp" #include "private_circuit_public_inputs.hpp" -#include "private_circuit_public_inputs.hpp" #include "state_read.hpp" #include "state_transition.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp index 043d89088428..b9cac3abca29 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp @@ -1,10 +1,12 @@ #pragma once #include "combined_accumulated_data.hpp" #include "combined_constant_data.hpp" -#include -#include + #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -15,13 +17,13 @@ using std::conditional; using std::is_same; template struct KernelCircuitPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; CombinedAccumulatedData end{}; CombinedConstantData constants{}; - boolean is_private = true; // TODO: might need to instantiate from witness! + boolean is_private = true; // TODO: might need to instantiate from witness! boolean operator==(KernelCircuitPublicInputs const& other) const { @@ -100,4 +102,4 @@ template std::ostream& operator<<(std::ostream& os, KernelCircuit << "is_private: " << public_inputs.is_private << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp index 42423997a0b1..233546028255 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp @@ -1,8 +1,8 @@ #pragma once -#include #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" +#include namespace aztec3::circuits::abis { using aztec3::utils::zero_array; @@ -11,9 +11,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct MembershipWitness { - - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr leaf_index; std::array sibling_path = zero_array(); @@ -61,4 +60,4 @@ template std::ostream& operator<<(std::ostream& o << "sibling_path: " << obj.sibling_path << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp index 9790d6061233..dcd5d3e68fb3 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp @@ -3,6 +3,7 @@ #include "aztec3/constants.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" + #include "barretenberg/stdlib/primitives/witness/witness.hpp" namespace aztec3::circuits::abis { @@ -12,9 +13,9 @@ using plonk::stdlib::witness_t; using std::is_same; template struct NewContractData { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; address contract_address = 0; address portal_contract_address = 0; @@ -69,7 +70,7 @@ template struct NewContractData { fr hash() const { - std::vector inputs = { + std::vector const inputs = { fr(contract_address), fr(portal_contract_address), fr(function_tree_root), @@ -114,4 +115,4 @@ template std::ostream& operator<<(std::ostream& os, NewContractDa template using ContractLeafPreimage = NewContractData; -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp index c86f936b44e9..93718cbf08b8 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp @@ -1,10 +1,12 @@ #pragma once #include "function_data.hpp" -#include + #include -#include #include #include +#include + +#include namespace aztec3::circuits::abis { using aztec3::utils::zero_array; @@ -12,9 +14,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct OptionallyRevealedData { - typedef typename NCT::address address; - typedef typename NCT::boolean boolean; - typedef typename NCT::fr fr; + using address = typename NCT::address; + using boolean = typename NCT::boolean; + using fr = typename NCT::fr; fr call_stack_item_hash = 0; FunctionData function_data{}; @@ -140,4 +142,4 @@ template std::ostream& operator<<(std::ostream& os, OptionallyRev << "called_from_public_l2: " << data.called_from_public_l2 << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp index 42f697bacdcf..999af692a056 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp @@ -1,11 +1,12 @@ #pragma once #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" -#include -#include -#include -#include #include #include +#include + +#include +#include +#include namespace aztec3::circuits::abis { @@ -15,13 +16,13 @@ using std::is_same; // @todo Naming should not be previous. Annoying. template struct PreviousKernelData { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; - typedef typename NCT::VK VK; - typedef typename NCT::uint32 uint32; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; + using VK = typename NCT::VK; + using uint32 = typename NCT::uint32; - KernelCircuitPublicInputs public_inputs{}; // TODO: not needed as already contained in proof? - NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? + KernelCircuitPublicInputs public_inputs{}; // TODO: not needed as already contained in proof? + NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? std::shared_ptr vk; // TODO: this index and path are meant to be those of a leaf within the tree of _kernel circuit_ vks; not the tree @@ -48,7 +49,7 @@ template struct PreviousKernelData { PreviousKernelData> data = { public_inputs.to_circuit_type(composer), - proof, // Notice: not converted! Stays as native. + proof, // Notice: not converted! Stays as native. CT::VK::from_witness(&composer, vk), to_ct(vk_index), to_ct(vk_path), @@ -57,7 +58,7 @@ template struct PreviousKernelData { return data; }; -}; // namespace aztec3::circuits::abis::private_kernel +}; // namespace aztec3::circuits::abis::private_kernel template inline void read(B& buf, verification_key& key) { @@ -103,4 +104,4 @@ template std::ostream& operator<<(std::ostream& os, PreviousKerne << "vk_path: " << kernel_data.vk_path << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index 2873cc756803..bd2be5c0dbb0 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -2,16 +2,17 @@ #include "call_context.hpp" #include "contract_deployment_data.hpp" + #include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include namespace aztec3::circuits::abis { @@ -20,8 +21,8 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template class PrivateCircuitPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; public: CallContext call_context{}; @@ -153,7 +154,7 @@ template class PrivateCircuitPublicInputs { template void spread_arr_into_vec(std::array const& arr, std::vector& vec) const { const auto arr_size = sizeof(arr) / sizeof(fr); - vec.insert(vec.end(), &arr[0], &arr[0] + arr_size); + vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } }; @@ -225,8 +226,8 @@ std::ostream& operator<<(std::ostream& os, PrivateCircuitPublicInputs const // which aren't set by the circuit can then be safely set to zero when calling `set_public` (by checking for // std::nullopt) template class OptionalPrivateCircuitPublicInputs { - typedef typename NCT::fr fr; - typedef typename std::optional opt_fr; + using fr = typename NCT::fr; + using opt_fr = typename std::optional; public: std::optional> call_context; @@ -249,7 +250,7 @@ template class OptionalPrivateCircuitPublicInputs { std::optional> contract_deployment_data; - OptionalPrivateCircuitPublicInputs() {} + OptionalPrivateCircuitPublicInputs() = default; OptionalPrivateCircuitPublicInputs(std::optional> const& call_context, @@ -288,7 +289,6 @@ template class OptionalPrivateCircuitPublicInputs { static OptionalPrivateCircuitPublicInputs create() { - auto new_inputs = OptionalPrivateCircuitPublicInputs(); new_inputs.call_context = std::nullopt; @@ -537,13 +537,13 @@ template class OptionalPrivateCircuitPublicInputs { std::array arr_values = map(arr, get_opt_value); const auto arr_size = sizeof(arr_values) / sizeof(fr); - vec.insert(vec.end(), &arr_values[0], &arr_values[0] + arr_size); + vec.insert(vec.end(), arr_values.data(), arr_values.data() + arr_size); } template void spread_arr_into_vec(std::array const& arr, std::vector& vec) const { const auto arr_size = sizeof(arr) / sizeof(fr); - vec.insert(vec.end(), &arr[0], &arr[0] + arr_size); + vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } template @@ -563,7 +563,7 @@ template class OptionalPrivateCircuitPublicInputs { if (!element) { element = - T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` + T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` fr(*element).assert_is_zero(); } } @@ -576,7 +576,7 @@ template class OptionalPrivateCircuitPublicInputs { if (!element) { element = ABIStruct().to_circuit_type( - composer); // convert the nullopt value to a circuit witness value of `0` + composer); // convert the nullopt value to a circuit witness value of `0` (*element).template assert_is_zero(); } } @@ -588,7 +588,7 @@ template class OptionalPrivateCircuitPublicInputs { fr(*e).set_public(); } } -}; // namespace aztec3::circuits::abis +}; // namespace aztec3::circuits::abis template void read(uint8_t const*& it, OptionalPrivateCircuitPublicInputs& private_circuit_public_inputs) @@ -653,4 +653,4 @@ std::ostream& operator<<(std::ostream& os, OptionalPrivateCircuitPublicInputs -#include #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -12,13 +13,13 @@ using plonk::stdlib::witness_t; using std::is_same; template struct PrivateHistoricTreeRoots { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr private_data_tree_root = 0; fr nullifier_tree_root = 0; fr contract_tree_root = 0; - fr private_kernel_vk_tree_root = 0; // TODO: future enhancement + fr private_kernel_vk_tree_root = 0; // TODO: future enhancement boolean operator==(PrivateHistoricTreeRoots const& other) const { @@ -100,4 +101,4 @@ std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots const& << "private_kernel_vk_tree_root: " << historic_tree_roots.private_kernel_vk_tree_root << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp index fb4b4bdd486d..d3fb6ecda574 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis::private_kernel { @@ -11,8 +12,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct Globals { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr min_timestamp = 0; @@ -38,4 +39,4 @@ template struct Globals { } }; -} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp index c37646d008ff..42a5f30f0caa 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp @@ -1,17 +1,18 @@ #pragma once -#include "aztec3/constants.hpp" -#include "aztec3/utils/array.hpp" #include "call_context_reconciliation_data.hpp" #include "../call_stack_item.hpp" #include "../membership_witness.hpp" #include "../types.hpp" -#include -#include -#include +#include "aztec3/constants.hpp" +#include "aztec3/utils/array.hpp" #include #include +#include + +#include +#include namespace aztec3::circuits::abis::private_kernel { @@ -21,10 +22,10 @@ using plonk::stdlib::witness_t; using std::is_same; template struct PrivateCallData { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; - typedef typename NCT::VK VK; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; + using VK = typename NCT::VK; CallStackItem call_stack_item{}; @@ -32,13 +33,13 @@ template struct PrivateCallData { // std::array, PUBLIC_CALL_STACK_LENGTH> public_call_stack_preimages; - NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? + NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? std::shared_ptr vk; MembershipWitness function_leaf_membership_witness{}; MembershipWitness contract_leaf_membership_witness{}; - fr portal_contract_address = 0; // an ETH address + fr portal_contract_address = 0; // an ETH address fr acir_hash = 0; boolean operator==(PrivateCallData const& other) const @@ -67,8 +68,8 @@ template struct PrivateCallData { map(private_call_stack_preimages, to_circuit_type), - proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function - // currently works. + proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function + // currently works. CT::VK::from_witness(&composer, vk), to_circuit_type(function_leaf_membership_witness), @@ -80,7 +81,7 @@ template struct PrivateCallData { return data; }; -}; // namespace aztec3::circuits::abis::private_kernel +}; // namespace aztec3::circuits::abis::private_kernel template void read(uint8_t const*& it, PrivateCallData& obj) { @@ -128,4 +129,4 @@ template std::ostream& operator<<(std::ostream& os, PrivateCallDa << "acir_hash: " << obj.acir_hash << "\n"; } -} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_inputs.hpp index f978830e1271..607b397a8b35 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_inputs.hpp @@ -1,14 +1,15 @@ #pragma once +#include "private_call_data.hpp" #include "../combined_accumulated_data.hpp" #include "../previous_kernel_data.hpp" -#include "private_call_data.hpp" #include "../signed_tx_request.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis::private_kernel { @@ -17,8 +18,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct PrivateInputs { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; SignedTxRequest signed_tx_request{}; PreviousKernelData previous_kernel{}; @@ -73,4 +74,4 @@ template std::ostream& operator<<(std::ostream& os, PrivateInputs << private_inputs.private_call << "\n"; } -} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::abis::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp index 9e90e80db6d5..574cbd037f39 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp @@ -1,15 +1,16 @@ #pragma once #include "call_context.hpp" -#include "state_transition.hpp" #include "state_read.hpp" +#include "state_transition.hpp" #include "../../constants.hpp" -#include -#include #include -#include #include +#include + +#include +#include namespace aztec3::circuits::abis { @@ -18,9 +19,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct PublicCircuitPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; - typedef typename NCT::address address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; + using address = typename NCT::address; CallContext call_context{}; @@ -109,9 +110,9 @@ template struct PublicCircuitPublicInputs { template void spread_arr_into_vec(std::array const& arr, std::vector& vec) const { const auto arr_size = sizeof(arr) / sizeof(fr); - vec.insert(vec.end(), &arr[0], &arr[0] + arr_size); + vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } -}; // namespace aztec3::circuits::abis +}; // namespace aztec3::circuits::abis template void read(uint8_t const*& it, PublicCircuitPublicInputs& public_circuit_public_inputs) { @@ -177,4 +178,4 @@ std::ostream& operator<<(std::ostream& os, PublicCircuitPublicInputs const& << "prover_address: " << pis.prover_address << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp index 276e2177bc01..e24354f2269e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp @@ -1,9 +1,10 @@ #pragma once #include "aztec3/constants.hpp" -#include -#include -#include #include +#include +#include + +#include namespace aztec3::circuits::abis { @@ -12,8 +13,8 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct PublicDataRead { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr leaf_index = 0; fr value = 0; @@ -92,4 +93,4 @@ template std::ostream& operator<<(std::ostream& os, PublicDataRea << "value: " << state_transition.value << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_transition.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_transition.hpp index 954aac0c6cfc..fa0408779459 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_transition.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_transition.hpp @@ -1,9 +1,10 @@ #pragma once #include "aztec3/constants.hpp" -#include -#include -#include #include +#include +#include + +#include namespace aztec3::circuits::abis { @@ -12,8 +13,8 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct PublicDataTransition { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr leaf_index = 0; fr old_value = 0; @@ -100,4 +101,4 @@ template std::ostream& operator<<(std::ostream& os, PublicDataTra << "new_value: " << state_transition.new_value << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp index ed59188e6199..bcc9f3850033 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp @@ -1,15 +1,16 @@ #pragma once -#include "aztec3/constants.hpp" -#include "aztec3/utils/array.hpp" #include "../call_stack_item.hpp" #include "../types.hpp" -#include -#include -#include +#include "aztec3/constants.hpp" +#include "aztec3/utils/array.hpp" #include #include +#include + +#include +#include namespace aztec3::circuits::abis::public_kernel { @@ -19,18 +20,18 @@ using plonk::stdlib::witness_t; using std::is_same; template struct PublicCallData { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; - typedef typename NCT::VK VK; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; + using VK = typename NCT::VK; CallStackItem call_stack_item{}; std::array, PUBLIC_CALL_STACK_LENGTH> public_call_stack_preimages{}; - NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? + NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? - fr portal_contract_address = 0; // an ETH address + fr portal_contract_address = 0; // an ETH address fr bytecode_hash = 0; boolean operator==(PublicCallData const& other) const @@ -57,8 +58,8 @@ template struct PublicCallData { map(public_call_stack_preimages, to_circuit_type), - proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function - // currently works. + proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function + // currently works. // CT::VK::from_witness(&composer, vk), // to_circuit_type(function_leaf_membership_witness), @@ -106,4 +107,4 @@ template std::ostream& operator<<(std::ostream& os, PublicCallDat << "bytecode_hash: " << obj.bytecode_hash << "\n"; } -} // namespace aztec3::circuits::abis::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::abis::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp index c783de20d97e..049be84fad35 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp @@ -1,13 +1,14 @@ #pragma once -#include "../previous_kernel_data.hpp" #include "public_call_data.hpp" +#include "../previous_kernel_data.hpp" #include "../signed_tx_request.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis::public_kernel { @@ -16,8 +17,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct PublicKernelInputs { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; PreviousKernelData previous_kernel{}; PublicCallData public_call{}; @@ -64,4 +65,4 @@ template std::ostream& operator<<(std::ostream& os, PublicKernelI << public_kernel_inputs.public_call << "\n"; } -} // namespace aztec3::circuits::abis::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::abis::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs_no_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs_no_previous_kernel.hpp index 9fcccbaca12d..7c57ae6f5f0f 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs_no_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs_no_previous_kernel.hpp @@ -1,13 +1,14 @@ #pragma once +#include "public_call_data.hpp" #include "../previous_kernel_data.hpp" #include "../signed_tx_request.hpp" -#include "public_call_data.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis::public_kernel { @@ -16,8 +17,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct PublicKernelInputsNoPreviousKernel { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; SignedTxRequest signed_tx_request{}; PublicCallData public_call{}; @@ -68,4 +69,4 @@ std::ostream& operator<<(std::ostream& os, PublicKernelInputsNoPreviousKernel -#include -#include -#include -#include "../../append_only_tree_snapshot.hpp" #include "../../append_only_tree_snapshot.hpp" #include "../constant_rollup_data.hpp" +#include +#include +#include + +#include + namespace aztec3::circuits::abis { using aztec3::utils::types::CircuitTypes; @@ -17,8 +18,8 @@ const uint32_t BASE_ROLLUP_TYPE = 0; const uint32_t MERGE_ROLLUP_TYPE = 1; template struct BaseOrMergeRollupPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::AggregationObject AggregationObject; + using fr = typename NCT::fr; + using AggregationObject = typename NCT::AggregationObject; uint32_t rollup_type; // subtree height is always 0 for base. @@ -125,4 +126,4 @@ template std::ostream& operator<<(std::ostream& os, BaseOrMergeRo << obj.calldata_hash << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp index 18b245817700..163fdaaa2306 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp @@ -1,10 +1,12 @@ #pragma once #include "../../append_only_tree_snapshot.hpp" -#include "../../previous_kernel_data.hpp" #include "../../membership_witness.hpp" -#include "../nullifier_leaf_preimage.hpp" +#include "../../previous_kernel_data.hpp" #include "../constant_rollup_data.hpp" +#include "../nullifier_leaf_preimage.hpp" + #include "aztec3/constants.hpp" + #include namespace aztec3::circuits::abis { @@ -14,8 +16,7 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct BaseRollupInputs { - - typedef typename NCT::fr fr; + using fr = typename NCT::fr; std::array, 2> kernel_data; @@ -123,4 +124,4 @@ template std::ostream& operator<<(std::ostream& os, BaseRollupInp << obj.constants << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp index 4f1f1ef53224..c76a94bb1b0a 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp @@ -8,8 +8,7 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct ConstantRollupData { - - typedef typename NCT::fr fr; + using fr = typename NCT::fr; // The very latest roots as at the very beginning of the entire rollup: AppendOnlyTreeSnapshot start_tree_of_historic_private_data_tree_roots_snapshot{}; @@ -65,4 +64,4 @@ template std::ostream& operator<<(std::ostream& os, ConstantRollu << "merge_rollup_vk_hash: " << obj.merge_rollup_vk_hash << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp index deee5f79fa7f..759f1ed2e411 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp @@ -1,9 +1,10 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include -#include #include #include +#include + #include namespace aztec3::circuits::abis { @@ -37,4 +38,4 @@ template std::ostream& operator<<(std::ostream& os, MergeRollupIn return os << "previous_rollup_data: " << obj.previous_rollup_data << "\n"; }; -} // namespace aztec3::circuits::abis +} // namespace aztec3::circuits::abis diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp index 205e6beafa74..c31dce73fe3d 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp @@ -3,9 +3,10 @@ #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" -#include #include #include +#include + #include namespace aztec3::circuits::abis { @@ -56,4 +57,4 @@ template std::ostream& operator<<(std::ostream& os, PreviousRollu << "vk_sibling_path: " << obj.vk_sibling_path << "\n"; }; -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp index 35dc3f1ceba7..85c677a2f312 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp @@ -1,6 +1,7 @@ #pragma once #include "aztec3/utils/types/circuit_types.hpp" + #include "barretenberg/stdlib/merkle_tree/hash.hpp" #include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp" namespace aztec3::circuits::abis { @@ -10,9 +11,8 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct NullifierLeafPreimage { - - typedef typename NCT::fr fr; - typedef typename NCT::uint32 uint32; + using fr = typename NCT::fr; + using uint32 = typename NCT::uint32; fr leaf_value = 0; uint32 next_index; @@ -48,4 +48,4 @@ template std::ostream& operator<<(std::ostream& os, NullifierLeaf << "next_index: " << obj.next_index << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index f93c3fcbaaaa..672c49fa7081 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -4,9 +4,10 @@ #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" #include "aztec3/constants.hpp" -#include #include #include +#include + #include namespace aztec3::circuits::abis { @@ -18,7 +19,7 @@ using aztec3::utils::types::NativeTypes; // Hit when running aztec3-packages/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts."calls // root_rollup__sim" template struct RootRollupInputs { - typedef typename NCT::fr fr; + using fr = typename NCT::fr; // All below are shared between the base and merge rollups std::array, 2> previous_rollup_data; @@ -55,4 +56,4 @@ template std::ostream& operator<<(std::ostream& os, RootRollupInp << "new_historic_contract_tree_roots: " << obj.new_historic_contract_tree_root_sibling_path << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp index e3c16e386783..a2d1b560b1f4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp @@ -1,12 +1,13 @@ #pragma once -#include "barretenberg/crypto/sha256/sha256.hpp" - #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include #include #include +#include + +#include "barretenberg/crypto/sha256/sha256.hpp" + #include namespace aztec3::circuits::abis { @@ -15,8 +16,8 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct RootRollupPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::AggregationObject AggregationObject; + using fr = typename NCT::fr; + using AggregationObject = typename NCT::AggregationObject; // All below are shared between the base and merge rollups AggregationObject end_aggregation_object; @@ -135,4 +136,4 @@ template std::ostream& operator<<(std::ostream& os, RootRollupPub << "calldata_hash: " << obj.calldata_hash << "\n"; }; -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/signed_tx_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/signed_tx_request.hpp index 87f2edd606d3..71b906712dcb 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/signed_tx_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/signed_tx_request.hpp @@ -2,10 +2,11 @@ #include "tx_request.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -13,8 +14,8 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct SignedTxRequest { - typedef typename NCT::boolean boolean; - typedef typename NCT::ecdsa_signature Signature; + using boolean = typename NCT::boolean; + using Signature = typename NCT::ecdsa_signature; TxRequest tx_request{}; Signature signature{}; @@ -80,4 +81,4 @@ template std::ostream& operator<<(std::ostream& os, SignedTxReque << "signature: " << signed_tx_request.signature << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/state_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/state_read.hpp index dd4129f5e17f..2a72a4ebc746 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/state_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/state_read.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -11,8 +12,8 @@ using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; template struct StateRead { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr storage_slot = 0; fr current_value = 0; @@ -50,7 +51,7 @@ template struct StateRead { fr hash() const { - std::vector inputs = { + std::vector const inputs = { storage_slot, current_value, }; @@ -91,4 +92,4 @@ template std::ostream& operator<<(std::ostream& os, StateRead -#include -#include #include +#include +#include + +#include namespace aztec3::circuits::abis { @@ -11,8 +12,8 @@ using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; template struct StateTransition { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr storage_slot = 0; fr old_value = 0; @@ -53,7 +54,7 @@ template struct StateTransition { fr hash() const { - std::vector inputs = { + std::vector const inputs = { storage_slot, old_value, new_value, @@ -99,4 +100,4 @@ template std::ostream& operator<<(std::ostream& os, StateTransiti << "new_value: " << state_transition.new_value << "\n"; } -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp index 0283cfda2deb..b66e29c1f803 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp @@ -1,12 +1,14 @@ #pragma once #include "contract_deployment_data.hpp" #include "function_data.hpp" -#include -#include + #include #include +#include + #include #include +#include namespace aztec3::circuits::abis { @@ -14,9 +16,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct TxContext { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; boolean is_fee_payment_tx = false; boolean is_rebate_payment_tx = false; @@ -77,7 +79,7 @@ template struct TxContext { fr hash() const { - std::vector inputs = { + std::vector const inputs = { fr(is_fee_payment_tx), fr(is_rebate_payment_tx), fr(is_contract_deployment_tx), @@ -118,4 +120,4 @@ template std::ostream& operator<<(std::ostream& os, TxContext + #include -#include #include #include +#include + +#include namespace aztec3::circuits::abis { @@ -14,9 +16,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template struct TxRequest { - typedef typename NCT::address address; - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using address = typename NCT::address; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; address from = 0; address to = 0; @@ -65,7 +67,7 @@ template struct TxRequest { template void spread_arr_into_vec(std::array const& arr, std::vector& vec) const { const auto arr_size = sizeof(arr) / sizeof(fr); - vec.insert(vec.end(), &arr[0], &arr[0] + arr_size); + vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } }; @@ -106,4 +108,4 @@ template std::ostream& operator<<(std::ostream& os, TxRequest +#include "private_circuit_public_inputs.hpp" +#include "public_circuit_public_inputs.hpp" -#include -#include -#include -#include +#include #include #include #include #include -#include "private_circuit_public_inputs.hpp" -#include "public_circuit_public_inputs.hpp" +#include +#include +#include +#include namespace aztec3::circuits::abis { template struct PrivateTypes { - typedef PrivateCircuitPublicInputs AppCircuitPublicInputs; + using AppCircuitPublicInputs = PrivateCircuitPublicInputs; }; template struct PublicTypes { - typedef PublicCircuitPublicInputs AppCircuitPublicInputs; + using AppCircuitPublicInputs = PublicCircuitPublicInputs; }; -} // namespace aztec3::circuits::abis \ No newline at end of file +} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index c3f2b22aee92..adfe4b1b0e2a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -3,33 +3,29 @@ // #include // #include -#include #include +#include + // #include "utxo_state_var.hpp" #include "contract.hpp" #include "function_execution_context.hpp" #include "oracle_wrapper.hpp" #include "utxo_datum.hpp" - -#include "notes/note_interface.hpp" - #include "notes/default_private_note/note.hpp" #include "notes/default_private_note/note_preimage.hpp" - #include "notes/default_singleton_private_note/note.hpp" #include "notes/default_singleton_private_note/note_preimage.hpp" - +#include "notes/note_interface.hpp" #include "state_vars/field_state_var.hpp" #include "state_vars/mapping_state_var.hpp" -#include "state_vars/utxo_state_var.hpp" #include "state_vars/utxo_set_state_var.hpp" +#include "state_vars/utxo_state_var.hpp" #include - -#include #include +#include #include namespace { @@ -58,7 +54,6 @@ using aztec3::circuits::apps::state_vars::MappingStateVar; using aztec3::circuits::apps::state_vars::UTXOSetStateVar; using aztec3::circuits::apps::state_vars::UTXOStateVar; -using aztec3::circuits::apps::notes::NoteInterface; using aztec3::circuits::apps::notes::DefaultPrivateNote; @@ -67,9 +62,9 @@ using aztec3::circuits::apps::notes::DefaultSingletonPrivateNote; // State variables // Get rid of ugle `Composer` template arg from our state var types: template struct SpecialisedTypes { - typedef MappingStateVar mapping; - typedef UTXOStateVar utxo; - typedef UTXOSetStateVar utxo_set; + using mapping = MappingStateVar; + using utxo = UTXOStateVar; + using utxo_set = UTXOSetStateVar; }; template using Mapping = typename SpecialisedTypes::mapping; @@ -78,31 +73,31 @@ template using UTXO = typename SpecialisedTypes::utxo; template using UTXOSet = typename SpecialisedTypes::utxo_set; using Field = FieldStateVar; -} // namespace +} // namespace namespace aztec3::circuits::apps { class state_var_tests : public ::testing::Test { protected: - NativeOracle get_test_native_oracle(DB& db) + static NativeOracle get_test_native_oracle(DB& db) { const NT::address contract_address = 12345; const NT::fr msg_sender_private_key = 123456789; const NT::address msg_sender = NT::fr( uint256_t(0x01071e9a23e0f7edULL, 0x5d77b35d1830fa3eULL, 0xc6ba3660bb1f0c0bULL, 0x2ef9f7f09867fd6eULL)); - FunctionData function_data{ - .function_selector = 1, // TODO: deduce this from the contract, somehow. + FunctionData const function_data{ + .function_selector = 1, // TODO: deduce this from the contract, somehow. .is_private = true, .is_constructor = false, }; - CallContext call_context{ .msg_sender = msg_sender, - .storage_contract_address = contract_address, - .portal_contract_address = 0, - .is_delegate_call = false, - .is_static_call = false, - .is_contract_deployment = false }; + CallContext const call_context{ .msg_sender = msg_sender, + .storage_contract_address = contract_address, + .portal_contract_address = 0, + .is_delegate_call = false, + .is_static_call = false, + .is_contract_deployment = false }; return NativeOracle(db, contract_address, function_data, call_context, msg_sender_private_key); }; @@ -213,11 +208,11 @@ TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) old_note.remove(); - CT::fr old_value = *(old_note.get_preimage().value); + CT::fr const old_value = *(old_note.get_preimage().value); CT::fr new_value = old_value + 5; - my_utxo.insert({ .value = new_value, // + my_utxo.insert({ .value = new_value, // .owner = msg_sender, .creator_address = msg_sender, .memo = 1234 }); @@ -227,7 +222,7 @@ TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) // Here, we test that the shared_ptr of a note, stored within the exec_ctx, works. TODO: put this in its own little // test, instead of this ever-growing beast test. auto new_note_pointers = exec_ctx.get_new_notes(); - std::shared_ptr debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); + std::shared_ptr const debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); // info("new_note_pointers: ", new_note_pointers); // info("*(new_note_pointers[0]): ", debug_note->get_preimage()); @@ -260,15 +255,15 @@ TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) UTXOSet balances(&exec_ctx, "balances"); // Imagine these were passed into the function as args: - CT::fr amount = 5; + CT::fr const amount = 5; CT::address to_address = 765976; const auto& msg_sender = oracle_wrapper.get_msg_sender(); std::vector old_balance_notes = balances.get(2, { .owner = msg_sender }); - CT::fr old_value_1 = *(old_balance_notes[0].get_preimage().value); - CT::fr old_value_2 = *(old_balance_notes[1].get_preimage().value); + CT::fr const old_value_1 = *(old_balance_notes[0].get_preimage().value); + CT::fr const old_value_2 = *(old_balance_notes[1].get_preimage().value); old_balance_notes[0].remove(); old_balance_notes[1].remove(); @@ -289,7 +284,7 @@ TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) // Here, we test that the shared_ptr of a note, stored within the exec_ctx, works. TODO: put this in its own little // test, instead of this ever-growing beast test. auto new_note_pointers = exec_ctx.get_new_notes(); - std::shared_ptr debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); + std::shared_ptr const debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); // info("new_note_pointers: ", new_note_pointers); // info("*(new_note_pointers[0]): ", debug_note->get_preimage()); @@ -337,7 +332,7 @@ TEST_F(state_var_tests, circuit_initialise_utxo_of_default_singleton_private_not // Here, we test that the shared_ptr of a note, stored within the exec_ctx, works. TODO: put this in its own little // test, instead of this ever-growing beast test. auto new_note_pointers = exec_ctx.get_new_notes(); - std::shared_ptr debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); + std::shared_ptr const debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); // info("new_note_pointers: ", new_note_pointers); // info("*(new_note_pointers[0]): ", debug_note->get_preimage()); @@ -372,12 +367,12 @@ TEST_F(state_var_tests, circuit_modify_utxo_of_default_singleton_private_note_fr old_note.remove(); - CT::fr old_value = *(old_note.get_preimage().value); + CT::fr const old_value = *(old_note.get_preimage().value); CT::fr new_value = old_value + 5; my_utxo.insert({ - .value = new_value, // + .value = new_value, // .owner = msg_sender, }); @@ -386,7 +381,7 @@ TEST_F(state_var_tests, circuit_modify_utxo_of_default_singleton_private_note_fr // Here, we test that the shared_ptr of a note, stored within the exec_ctx, works. TODO: put this in its own little // test, instead of this ever-growing beast test. auto new_note_pointers = exec_ctx.get_new_notes(); - std::shared_ptr debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); + std::shared_ptr const debug_note = std::dynamic_pointer_cast(new_note_pointers[0]); // info("new_note_pointers: ", new_note_pointers); // info("*(new_note_pointers[0]): ", debug_note->get_preimage()); @@ -394,4 +389,4 @@ TEST_F(state_var_tests, circuit_modify_utxo_of_default_singleton_private_note_fr // info("new_nullifiers: ", new_nullifiers); } -} // namespace aztec3::circuits::apps \ No newline at end of file +} // namespace aztec3::circuits::apps \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp index e7741e0f262d..f5cfdecb8515 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp @@ -18,8 +18,8 @@ using NT = aztec3::utils::types::NativeTypes; // template class FunctionExecutionContext; template class Contract { - typedef typename NCT::fr fr; - typedef typename NCT::uint32 uint32; + using fr = typename NCT::fr; + using uint32 = typename NCT::uint32; public: const std::string contract_name; @@ -36,15 +36,14 @@ template class Contract { std::map> imported_contracts; - Contract(std::string const& contract_name) - : contract_name(contract_name) + explicit Contract(std::string const& contract_name) : contract_name(contract_name) { // exec_ctx.register_contract(this); } void set_functions(std::vector> const& functions); - void import_contracts(std::vector>> const import_declarations); + void import_contracts(std::vector>> import_declarations); Contract& get_imported_contract(std::string const& name) { @@ -101,7 +100,7 @@ template class Contract { } }; -} // namespace aztec3::circuits::apps +} // namespace aztec3::circuits::apps // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/contract.tpp b/circuits/cpp/src/aztec3/circuits/apps/contract.tpp index ca980073ba4e..c752f0014ca2 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/contract.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/contract.tpp @@ -27,7 +27,7 @@ template void Contract::set_functions(std::vector{ - .function_selector = uint32(i), + .function_selector = static_cast(i), .is_private = function.is_private, .is_constructor = function.is_constructor, }; @@ -65,7 +65,7 @@ template FunctionData Contract::get_function_data_by_na template void Contract::import_l1_function(L1FunctionInterfaceStruct const& l1_function_struct) { - L1FunctionInterface l1_function = L1FunctionInterface(this, l1_function_struct); + L1FunctionInterface const l1_function = L1FunctionInterface(this, l1_function_struct); l1_functions.insert(std::make_pair(l1_function_struct.function_name, l1_function)); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_declaration.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_declaration.hpp index 8519953727a6..df774b359266 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_declaration.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_declaration.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include #include #include +#include + +#include namespace aztec3::circuits::apps { @@ -12,11 +13,11 @@ using plonk::stdlib::witness_t; // This exists just so that designated initialisers can be used when passing this info to a function, for readability. template struct FunctionDeclaration { - typedef typename NCT::boolean boolean; + using boolean = typename NCT::boolean; std::string name; boolean is_private = false; boolean is_constructor = false; }; -} // namespace aztec3::circuits::apps \ No newline at end of file +} // namespace aztec3::circuits::apps \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp index 7d28615ca32a..99dd08c8c52f 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp @@ -2,23 +2,18 @@ #include "contract.hpp" #include "oracle_wrapper.hpp" - #include "notes/note_interface.hpp" - #include "opcodes/opcodes.hpp" -#include - #include #include #include #include - -#include +#include +#include #include - -#include +#include namespace aztec3::circuits::apps { @@ -40,10 +35,10 @@ using aztec3::utils::types::to_ct; using aztec3::utils::types::to_nt; template class FunctionExecutionContext { - typedef NativeTypes NT; - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::address address; + using NT = NativeTypes; + using CT = CircuitTypes; + using fr = typename CT::fr; + using address = typename CT::address; // We restrict only the opcodes to be able to push to the private members of the exec_ctx. // This will just help us build better separation of concerns. @@ -168,7 +163,7 @@ template class FunctionExecutionContext { // Convert function name to bytes and use the first 4 bytes as the function encoding, for now: std::vector f_name_bytes(f_name.begin(), f_name.end()); std::vector f_encoding_bytes(f_name_bytes.begin(), f_name_bytes.begin() + 4); - uint32_t f_encoding; + uint32_t f_encoding = 0; memcpy(&f_encoding, f_encoding_bytes.data(), sizeof(f_encoding)); fr f_encoding_ct = fr(f_encoding); @@ -188,9 +183,9 @@ template class FunctionExecutionContext { }; const CallContext f_call_context_ct{ - .msg_sender = oracle.get_this_contract_address(), // the sender is `this` contract! + .msg_sender = oracle.get_this_contract_address(), // the sender is `this` contract! .storage_contract_address = f_contract_address, - .portal_contract_address = 0, // TODO + .portal_contract_address = 0, // TODO .is_delegate_call = false, .is_static_call = false, .is_contract_deployment = false, @@ -201,9 +196,9 @@ template class FunctionExecutionContext { f_function_data_ct.template to_native_type(), f_call_context_ct.template to_native_type(), oracle.get_msg_sender_private_key() - .get_value() // TODO: consider whether a nested function should even be able to access - // a private key, given that the call is now coming from a contract - // (which cannot own a secret), rather than a human. + .get_value() // TODO: consider whether a nested function should even be able to + // access a private key, given that the call is now coming from a + // contract (which cannot own a secret), rather than a human. ); Composer f_composer = Composer("../barretenberg/cpp/srs_db/ignition"); @@ -240,7 +235,7 @@ template class FunctionExecutionContext { args[i].assert_equal(f_public_inputs_ct.args[i]); } - CallStackItem f_call_stack_item_ct{ + CallStackItem const f_call_stack_item_ct{ .contract_address = f_contract_address, .function_data = f_function_data_ct, .public_inputs = f_public_inputs_ct, @@ -333,4 +328,4 @@ template class FunctionExecutionContext { } }; -} // namespace aztec3::circuits::apps \ No newline at end of file +} // namespace aztec3::circuits::apps \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/l1_call.hpp b/circuits/cpp/src/aztec3/circuits/apps/l1_call.hpp index 97e6bd5f6937..808a224f82fe 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/l1_call.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/l1_call.hpp @@ -2,10 +2,11 @@ #include "l1_function_interface.hpp" -#include -#include #include #include +#include + +#include namespace aztec3::circuits::apps { @@ -20,19 +21,17 @@ template class L1Call { L1FunctionInterface& l1_function; std::vector args; fr hash_of_argument_encodings = 0; - fr partial_l1_call_stack_item = 0; // keccak(function_selector, hash_of_argument_encodings) + fr partial_l1_call_stack_item = 0; // keccak(function_selector, hash_of_argument_encodings) - L1Call(L1FunctionInterface const& l1_function, std::vector const& args) - : l1_function(l1_function) - , args(args) + L1Call(L1FunctionInterface const& l1_function, std::vector const& args) : l1_function(l1_function), args(args) { /// TODO: in reality, we'll need to use keccak hash here, as this will need to be replecated on-chain. if (args.size() == 0) { hash_of_argument_encodings = 0; } else { - hash_of_argument_encodings = args[0]; // lazy stub for a hash! + hash_of_argument_encodings = args[0]; // lazy stub for a hash! } - partial_l1_call_stack_item = function_selector; // lazy stub for a hash! + partial_l1_call_stack_item = function_selector; // lazy stub for a hash! } bool operator==(L1Call const&) const = default; @@ -81,4 +80,4 @@ template std::ostream& operator<<(std::ostream& os, L1Call c << "partial_l1_call_stack_item: " << l1_call.partial_l1_call_stack_item << "\n"; } -} // namespace aztec3::circuits::apps \ No newline at end of file +} // namespace aztec3::circuits::apps \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/l1_function_interface.hpp b/circuits/cpp/src/aztec3/circuits/apps/l1_function_interface.hpp index c372cca33fb1..b67693cb3fa4 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/l1_function_interface.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/l1_function_interface.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include #include #include +#include + +#include namespace aztec3::circuits::apps { @@ -14,7 +15,7 @@ template class Contract; // We use the struct to retain designated initialisation, to make contract creation more readable. template struct L1FunctionInterfaceStruct { - typedef typename NCT::fr fr; + using fr = typename NCT::fr; std::string function_name; fr function_selector = 0; @@ -22,7 +23,7 @@ template struct L1FunctionInterfaceStruct { }; template class L1FunctionInterface { - typedef typename NCT::fr fr; + using fr = typename NCT::fr; public: Contract* contract; @@ -30,7 +31,7 @@ template class L1FunctionInterface { fr function_selector = 0; size_t num_params = 0; - L1FunctionInterface() {} + L1FunctionInterface() = default; L1FunctionInterface(Contract* contract, L1FunctionInterfaceStruct const& l1_fn_struct) : contract(contract) @@ -49,10 +50,10 @@ template class L1FunctionInterface { void call(std::vector args) { // TODO: implement this function. - (void)args; // So the compiler doesn't complain about an unused var. + (void)args; // So the compiler doesn't complain about an unused var. } }; -} // namespace aztec3::circuits::apps +} // namespace aztec3::circuits::apps // #include "l1_function_interface.tpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp index 4f89ac10620f..2d5e966dde7f 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp @@ -1,37 +1,36 @@ #pragma once -#include "../note_interface.hpp" - #include "note_preimage.hpp" #include "nullifier_preimage.hpp" +#include "../note_interface.hpp" -#include #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { template class StateVar; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { -using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! +using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template class DefaultPrivateNote : public NoteInterface { public: - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; - typedef typename CT::address address; - typedef typename CT::boolean boolean; + using CT = CircuitTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; + using address = typename CT::address; + using boolean = typename CT::boolean; using NotePreimage = DefaultPrivateNotePreimage, ValueType>; using NullifierPreimage = DefaultPrivateNoteNullifierPreimage>; - public: + StateVar* state_var; private: @@ -44,10 +43,9 @@ template class DefaultPrivateNote : publ public: DefaultPrivateNote(StateVar* state_var, NotePreimage note_preimage) - : state_var(state_var) - , note_preimage(note_preimage){}; + : state_var(state_var), note_preimage(note_preimage){}; - ~DefaultPrivateNote() {} + ~DefaultPrivateNote() override = default; // OVERRIDE METHODS: @@ -116,7 +114,7 @@ template class DefaultPrivateNote : publ bool is_partial() const; }; -} // namespace aztec3::circuits::apps::notes +} // namespace aztec3::circuits::apps::notes // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp index f34bd1152023..caecfaa24270 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp @@ -68,10 +68,10 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_com return *commitment; } - grumpkin_point storage_slot_point = state_var->storage_slot_point; + grumpkin_point const storage_slot_point = state_var->storage_slot_point; - std::vector inputs; - std::vector generators; + std::vector const inputs; + std::vector const generators; auto gen_pair_address = [&](std::optional
const& input, size_t const hash_sub_index) { if (!input) { @@ -127,7 +127,7 @@ typename CircuitTypes::grumpkin_point DefaultPrivateNote: grumpkin_point storage_slot_point = state_var->storage_slot_point; std::vector inputs; - std::vector generators; + std::vector const generators; auto gen_pair_address = [&](std::optional
const& input, size_t const hash_sub_index) { return input ? std::make_pair((*input).to_field(), @@ -180,7 +180,7 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nul compute_commitment(); } - fr& owner_private_key = get_oracle().get_msg_sender_private_key(); + fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); nullifier = DefaultPrivateNote::compute_nullifier(*commitment, owner_private_key, note_preimage.is_dummy); @@ -196,8 +196,8 @@ template typename CircuitTypes::fr DefaultPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); - fr dummy_commitment = oracle.generate_random_element(); - fr& owner_private_key = oracle.get_msg_sender_private_key(); + fr const dummy_commitment = oracle.generate_random_element(); + fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; return DefaultPrivateNote::compute_nullifier(dummy_commitment, owner_private_key, is_dummy_commitment); @@ -246,8 +246,7 @@ template void DefaultPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const DefaultPrivateNote& advice_note_ref = - dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index a74fe5a43905..1e4eb3a7f111 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -1,14 +1,13 @@ #pragma once +#include +#include +#include + #include #include - #include -#include -#include -#include - namespace aztec3::circuits::apps::notes { using aztec3::utils::types::CircuitTypes; @@ -16,16 +15,16 @@ using aztec3::utils::types::NativeTypes; using crypto::generators::generator_index_t; template struct DefaultPrivateNotePreimage { - typedef typename NCT::fr fr; - typedef typename NCT::address address; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using address = typename NCT::address; + using boolean = typename NCT::boolean; // No custom constructors so that designated initializers can be used (for readability of test circuits). std::optional value; std::optional
owner; std::optional
creator_address; - std::optional memo; // numerical representation of a string + std::optional memo; // numerical representation of a string std::optional salt; std::optional nonce; @@ -73,7 +72,6 @@ template struct DefaultPrivateNotePreimage { template auto to_native_type() const { - static_assert(!std::is_same::value); auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; @@ -141,4 +139,4 @@ std::ostream& operator<<(std::ostream& os, DefaultPrivateNotePreimage co << "is_dummy: " << preimage.is_dummy << "\n"; } -} // namespace aztec3::circuits::apps::notes \ No newline at end of file +} // namespace aztec3::circuits::apps::notes \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp index a8d4cf802eaf..bc05f8c8cff5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp @@ -1,13 +1,12 @@ #pragma once +#include +#include +#include + #include #include - #include -#include -#include -#include - namespace aztec3::circuits::apps::notes { using aztec3::utils::types::CircuitTypes; @@ -15,8 +14,8 @@ using aztec3::utils::types::NativeTypes; using crypto::generators::generator_index_t; template struct DefaultPrivateNoteNullifierPreimage { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr commitment; fr owner_private_key; @@ -68,4 +67,4 @@ std::ostream& operator<<(std::ostream& os, DefaultPrivateNoteNullifierPreimage #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { template class StateVar; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { -using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! +using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; template class DefaultSingletonPrivateNote : public NoteInterface { public: - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; - typedef typename CT::address address; - typedef typename CT::boolean boolean; + using CT = CircuitTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; + using address = typename CT::address; + using boolean = typename CT::boolean; using NotePreimage = DefaultSingletonPrivateNotePreimage, ValueType>; using NullifierPreimage = DefaultSingletonPrivateNoteNullifierPreimage>; - public: + StateVar* state_var; private: @@ -43,10 +42,9 @@ template class DefaultSingletonPrivateNo public: DefaultSingletonPrivateNote(StateVar* state_var, NotePreimage note_preimage) - : state_var(state_var) - , note_preimage(note_preimage){}; + : state_var(state_var), note_preimage(note_preimage){}; - ~DefaultSingletonPrivateNote() {} + ~DefaultSingletonPrivateNote() override = default; // OVERRIDE METHODS: @@ -101,7 +99,7 @@ template class DefaultSingletonPrivateNo bool is_partial() const; }; -} // namespace aztec3::circuits::apps::notes +} // namespace aztec3::circuits::apps::notes // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp index a2f253389a73..09d38ce43c1c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp @@ -68,10 +68,10 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co return *commitment; } - grumpkin_point storage_slot_point = state_var->storage_slot_point; + grumpkin_point const storage_slot_point = state_var->storage_slot_point; - std::vector inputs; - std::vector generators; + std::vector const inputs; + std::vector const generators; auto gen_pair_address = [&](std::optional
const& input, size_t const hash_sub_index) { if (!input) { @@ -119,7 +119,7 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co compute_commitment(); } - fr& owner_private_key = get_oracle().get_msg_sender_private_key(); + fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); nullifier = DefaultSingletonPrivateNote::compute_nullifier(*commitment, owner_private_key); nullifier_preimage = { @@ -133,8 +133,8 @@ template typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); - fr dummy_commitment = oracle.generate_random_element(); - fr& owner_private_key = oracle.get_msg_sender_private_key(); + fr const dummy_commitment = oracle.generate_random_element(); + fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; return DefaultSingletonPrivateNote::compute_nullifier( @@ -184,8 +184,7 @@ template void DefaultSingletonPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const DefaultSingletonPrivateNote& advice_note_ref = - dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp index e01695fa7874..bac26ade68b8 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp @@ -1,14 +1,13 @@ #pragma once +#include +#include +#include + #include #include - #include -#include -#include -#include - namespace aztec3::circuits::apps::notes { using aztec3::utils::types::CircuitTypes; @@ -16,10 +15,10 @@ using aztec3::utils::types::NativeTypes; using crypto::generators::generator_index_t; template struct DefaultSingletonPrivateNotePreimage { - typedef typename NCT::fr fr; - typedef typename NCT::grumpkin_point grumpkin_point; - typedef typename NCT::address address; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using grumpkin_point = typename NCT::grumpkin_point; + using address = typename NCT::address; + using boolean = typename NCT::boolean; // No custom constructors so that designated initializers can be used (for readability of test circuits). @@ -73,7 +72,6 @@ template struct DefaultSingletonPrivateNotePreimage { template auto to_native_type() const { - static_assert(!std::is_same::value); auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; @@ -135,4 +133,4 @@ std::ostream& operator<<(std::ostream& os, DefaultSingletonPrivateNotePreimage +#include +#include + #include #include - #include -#include -#include -#include - namespace aztec3::circuits::apps::notes { using aztec3::utils::types::CircuitTypes; @@ -15,8 +14,8 @@ using aztec3::utils::types::NativeTypes; using crypto::generators::generator_index_t; template struct DefaultSingletonPrivateNoteNullifierPreimage { - typedef typename NCT::fr fr; - typedef typename NCT::boolean boolean; + using fr = typename NCT::fr; + using boolean = typename NCT::boolean; fr commitment; fr owner_private_key; @@ -69,4 +68,4 @@ std::ostream& operator<<(std::ostream& os, DefaultSingletonPrivateNoteNullifierP << "is_dummy: " << preimage.is_dummy << "\n"; } -} // namespace aztec3::circuits::apps::notes \ No newline at end of file +} // namespace aztec3::circuits::apps::notes \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp index a3ecb73cbd1a..ff0349909e9a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include namespace aztec3::circuits::apps::notes { @@ -17,16 +17,16 @@ using aztec3::utils::types::NativeTypes; */ template class NoteInterface { public: - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; - typedef typename CT::address address; - typedef typename CT::boolean boolean; + using CT = CircuitTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; + using address = typename CT::address; + using boolean = typename CT::boolean; // Destructor explicitly made virtual, to ensure that the destructor of the derived class is called if the derived // object is deleted through a pointer to this base class. (In many places in the code, files handle // `NoteInterface*` pointers instead of the derived class). - virtual ~NoteInterface() {} + virtual ~NoteInterface() = default; // TODO: maybe rather than have this be a pure interface, we should have a constructor and the `state_var*` and // `note_preimage` members here (although that would require a NotePreimage template param). @@ -51,4 +51,4 @@ template class NoteInterface { virtual fr generate_nonce() = 0; }; -} // namespace aztec3::circuits::apps::notes \ No newline at end of file +} // namespace aztec3::circuits::apps::notes \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp index e75a1eca7b02..35e68bc1b9f4 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp @@ -1,20 +1,21 @@ #pragma once -#include -#include #include +#include + +#include namespace aztec3::circuits::apps::state_vars { template class StateVar; template class UTXOStateVar; template class UTXOSetStateVar; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::opcodes { -using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! -using aztec3::circuits::apps::state_vars::UTXOSetStateVar; // Don't #include it! -using aztec3::circuits::apps::state_vars::UTXOStateVar; // Don't #include it! +using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! +using aztec3::circuits::apps::state_vars::UTXOSetStateVar; // Don't #include it! +using aztec3::circuits::apps::state_vars::UTXOStateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; @@ -32,8 +33,8 @@ using plonk::stdlib::witness_t; */ template class Opcodes { public: - typedef CircuitTypes CT; - typedef typename CT::address address; + using CT = CircuitTypes; + using address = typename CT::address; /** * @brief @@ -50,10 +51,9 @@ template class Opcodes { * - Generate constraints to prove each datum's existence in the tree * - Validate the data */ - template - static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, - size_t const& num_notes, - typename Note::NotePreimage const& advice); + template static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, + size_t const& num_notes, + typename Note::NotePreimage const& advice); /** * @brief Compute and push a new nullifier to the public inputs of this exec_ctx. @@ -73,7 +73,7 @@ template class Opcodes { static void UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage); }; -} // namespace aztec3::circuits::apps::opcodes +} // namespace aztec3::circuits::apps::opcodes // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp index 4e73e0ff174e..fae9e1f63384 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp @@ -33,10 +33,10 @@ Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, { auto& oracle = utxo_state_var->exec_ctx->oracle; - typename CT::grumpkin_point& storage_slot_point = utxo_state_var->storage_slot_point; + typename CT::grumpkin_point const& storage_slot_point = utxo_state_var->storage_slot_point; // Retrieve UTXO witness datum from the DB: - UTXOSLoadDatum utxo_datum = + UTXOSLoadDatum const utxo_datum = oracle.template get_utxo_sload_datum(storage_slot_point, advice); Note new_note{ utxo_state_var, utxo_datum.preimage }; @@ -68,7 +68,7 @@ std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* { auto& oracle = utxo_set_state_var->exec_ctx->oracle; - typename CT::grumpkin_point& storage_slot_point = utxo_set_state_var->storage_slot_point; + typename CT::grumpkin_point const& storage_slot_point = utxo_set_state_var->storage_slot_point; // Retrieve multiple UTXO witness datum's from the DB: std::vector> utxo_data = @@ -109,13 +109,13 @@ template template void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nullify) { - typename CT::fr nullifier = note_to_nullify.get_nullifier(); + typename CT::fr const nullifier = note_to_nullify.get_nullifier(); auto& exec_ctx = state_var->exec_ctx; exec_ctx->new_nullifiers.push_back(nullifier); - std::shared_ptr nullified_note_ptr = std::make_shared(note_to_nullify); + std::shared_ptr const nullified_note_ptr = std::make_shared(note_to_nullify); exec_ctx->nullified_notes.push_back(nullified_note_ptr); }; @@ -124,13 +124,13 @@ template template void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_initialise) { - typename CT::fr init_nullifier = note_to_initialise.get_initialisation_nullifier(); + typename CT::fr const init_nullifier = note_to_initialise.get_initialisation_nullifier(); auto& exec_ctx = state_var->exec_ctx; exec_ctx->new_nullifiers.push_back(init_nullifier); - std::shared_ptr init_note_ptr = std::make_shared(note_to_initialise); + std::shared_ptr const init_note_ptr = std::make_shared(note_to_initialise); // TODO: consider whether this should actually be pushed-to... exec_ctx->nullified_notes.push_back(init_note_ptr); @@ -146,7 +146,7 @@ void Opcodes::UTXO_SSTORE(StateVar* state_var, typename Note // Make a shared pointer, so we don't end up with a dangling pointer in the exec_ctx when this `new_note` // immediately goes out of scope. - std::shared_ptr new_note_ptr = std::make_shared(state_var, new_note_preimage); + std::shared_ptr const new_note_ptr = std::make_shared(state_var, new_note_preimage); exec_ctx->new_notes.push_back(new_note_ptr); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp index 192948a3cb76..857e18ef1e76 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp @@ -25,10 +25,10 @@ using aztec3::utils::types::CircuitTypes; * certain information. */ template class OracleWrapperInterface { - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; - typedef typename CT::address address; + using CT = CircuitTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; + using address = typename CT::address; public: Composer& composer; diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp index acfb262e231f..e582fbaec425 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp @@ -3,8 +3,8 @@ #include "state_var_base.hpp" #include "../function_execution_context.hpp" -#include #include +#include namespace aztec3::circuits::apps::state_vars { @@ -14,10 +14,10 @@ using aztec3::utils::types::NativeTypes; // TODO: we can probably generalise this to be a PrimitiveStateVar for any stdlib primitive. template class FieldStateVar : public StateVar { public: - typedef CircuitTypes CT; - typedef NativeTypes NT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; + using CT = CircuitTypes; + using NT = NativeTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; fr value = 0; @@ -27,7 +27,7 @@ template class FieldStateVar : public StateVar { return *this; } - FieldStateVar() {} + FieldStateVar() = default; // Instantiate a top-level var: FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, fr const& start_slot) @@ -50,4 +50,4 @@ template inline std::ostream& operator<<(std::ostream& os, F return os << v.value; } -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp index 5040f6f9051d..f977d168246d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp @@ -3,8 +3,8 @@ #include "state_var_base.hpp" // #include "../function_execution_context.hpp" -#include #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { @@ -13,7 +13,7 @@ template class FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! +using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; @@ -27,15 +27,15 @@ using aztec3::utils::types::NativeTypes; */ template class MappingStateVar : public StateVar { public: - typedef CircuitTypes CT; - typedef NativeTypes NT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; + using CT = CircuitTypes; + using NT = NativeTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; // native_storage_slot.x => value cache, to prevent creating constraints with each `at()` call. std::map value_cache; - MappingStateVar() {} + MappingStateVar() = default; // Instantiate a top-level mapping: MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) @@ -71,7 +71,7 @@ template class MappingStateVar : public StateVar std::tuple compute_slot_point_at_mapping_key(std::optional const& key); }; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp index cf0f2ffe188a..d555320afc00 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp @@ -44,27 +44,27 @@ template std::tuple MappingStateVar::compute_slot_point_at_mapping_key( NT::fr const& start_slot, size_t level_of_container_nesting, std::optional const& key) { - bool is_partial_slot = false; + bool const is_partial_slot = false; std::vector> input_pairs; // TODO: compare (in a test) this little calc against calling `compute_start_slot_point`. - input_pairs.push_back(std::make_pair( + input_pairs.emplace_back( start_slot, - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, 0 }))); // hash_sub_index 0 is reserved for the + generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, 0 })); // hash_sub_index 0 is reserved for the if (key) { - input_pairs.push_back(std::make_pair( - *key, generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, level_of_container_nesting }))); + input_pairs.emplace_back( + *key, generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, level_of_container_nesting })); } else { // If this mapping key has no mapping_key_value (std::nullopt), then we must be partially committing and // omitting this mapping key from that partial commitment. // So use a placeholder generator for this mapping key, to signify "this mapping key is missing". // Note: we can't just commit to a value of `0` for this mapping key, since `0` is a valid value to // commit to, and so "missing" is distinguished as follows. - input_pairs.push_back(std::make_pair( + input_pairs.emplace_back( NativeTypes::fr(1), - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT_PLACEHOLDER, level_of_container_nesting }))); + generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT_PLACEHOLDER, level_of_container_nesting })); } return std::make_tuple(NativeTypes::commit(input_pairs), is_partial_slot); @@ -113,14 +113,14 @@ template V& MappingStateVar::at(std if (!key) { native_key = std::nullopt; } else { - native_key = NativeTypes::fr((*key).get_value()); + native_key = static_cast((*key).get_value()); } - bool is_partial_slot; + bool is_partial_slot = false; NativeTypes::grumpkin_point native_new_slot_point; std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( this->start_slot.get_value(), this->level_of_container_nesting, native_key); - NativeTypes::fr native_lookup = native_new_slot_point.x; + NativeTypes::fr const native_lookup = native_new_slot_point.x; // Check cache if (this->value_cache.contains(native_lookup)) { @@ -130,13 +130,13 @@ template V& MappingStateVar::at(std // Create gates: grumpkin_point new_slot_point; std::tie(new_slot_point, is_partial_slot) = compute_slot_point_at_mapping_key(key); - NativeTypes::fr lookup = new_slot_point.x.get_value(); + NativeTypes::fr const lookup = new_slot_point.x.get_value(); if (lookup != native_lookup) { throw_or_abort("Expected lookup calcs to be equal!"); } - std::string value_name = this->state_var_name + (key ? format("[", *key, "]").c_str() : "[?]"); + std::string const value_name = this->state_var_name + (key ? format("[", *key, "]").c_str() : "[?]"); V value = V(this->exec_ctx, value_name, new_slot_point, this->level_of_container_nesting + 1, is_partial_slot); diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp index c45beb181052..4dc9f2d7dbeb 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { @@ -10,7 +10,7 @@ template class FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! +using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; @@ -22,10 +22,10 @@ using aztec3::utils::types::NativeTypes; */ template class StateVar { public: - typedef CircuitTypes CT; - typedef NativeTypes NT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; + using CT = CircuitTypes; + using NT = NativeTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; // The execution context of the function currently being executed. FunctionExecutionContext* exec_ctx; @@ -54,7 +54,7 @@ template class StateVar { // Optionally informs custom notes whether they should commit or partially-commit to this state. bool is_partial_slot = false; - StateVar() {} + StateVar() = default; // Instantiate a top-level state: StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name); @@ -63,8 +63,8 @@ template class StateVar { StateVar( FunctionExecutionContext* exec_ctx, std::string const& state_var_name, - grumpkin_point const& storage_slot_point, // the parent always calculates the storage_slot_point of its child. - size_t level_of_container_nesting, // the parent always calculates the level of nesting of its child. + grumpkin_point const& storage_slot_point, // the parent always calculates the storage_slot_point of its child. + size_t level_of_container_nesting, // the parent always calculates the level of nesting of its child. bool is_partial_slot = false) : exec_ctx(exec_ctx) , state_var_name(state_var_name) @@ -89,7 +89,7 @@ template class StateVar { grumpkin_point compute_slot_point(); }; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars // Importing in this way (rather than explicit instantiation of a template class at the bottom of a .cpp file) preserves // the following: diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp index 3a2510bc1781..8bf14032f66b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp @@ -2,8 +2,8 @@ #include "state_var_base.hpp" -#include #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { @@ -12,7 +12,7 @@ template class FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! +using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; @@ -27,14 +27,14 @@ using aztec3::utils::types::NativeTypes; */ template class UTXOSetStateVar : public StateVar { public: - typedef CircuitTypes CT; - typedef NativeTypes NT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; + using CT = CircuitTypes; + using NT = NativeTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; - typedef typename Note::NotePreimage NotePreimage; + using NotePreimage = typename Note::NotePreimage; - UTXOSetStateVar() {} + UTXOSetStateVar() = default; // Instantiate a top-level var: UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) @@ -59,6 +59,6 @@ template class UTXOSetStateVar : public State void insert(NotePreimage new_note_preimage); }; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars #include "utxo_set_state_var.tpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp index 900dc0dc9795..b9c1a41c3372 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp @@ -2,8 +2,8 @@ #include "state_var_base.hpp" -#include #include +#include // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { @@ -12,7 +12,7 @@ template class FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! +using aztec3::circuits::apps::FunctionExecutionContext; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; @@ -28,15 +28,15 @@ using aztec3::utils::types::NativeTypes; */ template class UTXOStateVar : public StateVar { public: - typedef CircuitTypes CT; - typedef NativeTypes NT; - typedef typename CT::fr fr; - typedef typename CT::grumpkin_point grumpkin_point; - typedef typename CT::address address; + using CT = CircuitTypes; + using NT = NativeTypes; + using fr = typename CT::fr; + using grumpkin_point = typename CT::grumpkin_point; + using address = typename CT::address; - typedef typename Note::NotePreimage NotePreimage; + using NotePreimage = typename Note::NotePreimage; - UTXOStateVar() {} + UTXOStateVar() = default; // Instantiate a top-level var: UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) @@ -68,6 +68,6 @@ template class UTXOStateVar : public StateVar void insert(NotePreimage new_note_preimage); }; -} // namespace aztec3::circuits::apps::state_vars +} // namespace aztec3::circuits::apps::state_vars #include "utxo_state_var.tpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp index 05bfaf1ff60d..300de51f2f8e 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp @@ -22,9 +22,9 @@ OptionalPrivateCircuitPublicInputs constructor(FunctionExecutionContext& exe // Convert params into circuit types: auto& composer = exec_ctx.composer; - CT::fr arg0 = to_ct(composer, args[0]); - CT::fr arg1 = to_ct(composer, args[1]); - CT::fr arg2 = to_ct(composer, args[2]); + CT::fr const arg0 = to_ct(composer, args[0]); + CT::fr const arg1 = to_ct(composer, args[1]); + CT::fr const arg2 = to_ct(composer, args[2]); auto& oracle = exec_ctx.oracle; const CT::address msg_sender = oracle.get_msg_sender(); @@ -53,4 +53,4 @@ OptionalPrivateCircuitPublicInputs constructor(FunctionExecutionContext& exe return public_inputs.to_native_type(); } -} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment +} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.hpp index 71851b822ac9..2fbe30bd7b78 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.hpp @@ -12,4 +12,4 @@ using aztec3::circuits::abis::OptionalPrivateCircuitPublicInputs; OptionalPrivateCircuitPublicInputs constructor(FunctionExecutionContext& exec_ctx, std::array const& args); -} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/contract.hpp index 02375e68bb75..843d1d66e0af 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/contract.hpp @@ -1,8 +1,7 @@ #pragma once -#include "init.hpp" - #include "contract.hpp" +#include "init.hpp" #include #include @@ -21,4 +20,4 @@ inline Contract init_contract() return contract; } -} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp index 59b559106c9f..b62f5b2c3f77 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp @@ -3,14 +3,12 @@ #include #include #include +#include #include #include - -#include #include - -#include #include +#include #include namespace aztec3::circuits::apps::test_apps::basic_contract_deployment { @@ -38,8 +36,8 @@ using apps::state_vars::UTXOSetStateVar; // Get rid of ugle `Composer` template arg from our state var types: template struct SpecialisedTypes { - typedef MappingStateVar mapping; - typedef UTXOSetStateVar utxo_set; + using mapping = MappingStateVar; + using utxo_set = UTXOSetStateVar; }; template using Mapping = typename SpecialisedTypes::mapping; @@ -47,4 +45,4 @@ template using UTXOSet = typename SpecialisedTypes::utxo_s using DefaultNote = apps::notes::DefaultPrivateNote; -} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::basic_contract_deployment \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp index be1ed72a5232..4b5db4c7d8ac 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp @@ -1,13 +1,14 @@ -#include "index.hpp" #include "contract.hpp" +#include "index.hpp" // #include // #include // #include -#include #include + +#include // #include // #include // #include @@ -16,20 +17,20 @@ namespace aztec3::circuits::apps::test_apps::escrow { class escrow_tests : public ::testing::Test { protected: - NativeOracle get_test_native_oracle(DB& db) + static NativeOracle get_test_native_oracle(DB& db) { const NT::address contract_address = 12345; const NT::fr msg_sender_private_key = 123456789; const NT::address msg_sender = NT::fr( uint256_t(0x01071e9a23e0f7edULL, 0x5d77b35d1830fa3eULL, 0xc6ba3660bb1f0c0bULL, 0x2ef9f7f09867fd6eULL)); - FunctionData function_data{ - .function_selector = 1, // TODO: deduce this from the contract, somehow. + FunctionData const function_data{ + .function_selector = 1, // TODO: deduce this from the contract, somehow. .is_private = true, .is_constructor = false, }; - CallContext call_context{ + CallContext const call_context{ .msg_sender = msg_sender, .storage_contract_address = contract_address, .portal_contract_address = 0, @@ -121,4 +122,4 @@ TEST_F(escrow_tests, circuit_withdraw) info("n: ", composer.num_gates); } -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/contract.hpp index 45655fbec4d3..6490d533c7d8 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/contract.hpp @@ -30,4 +30,4 @@ inline Contract init_contract() return contract; } -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp index 4c7b02452023..1ef4b8b4dca5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp @@ -67,4 +67,4 @@ OptionalPrivateCircuitPublicInputs deposit(FunctionExecutionContext& exec_ct // TODO: or, we'll be collecting this data in the exec_ctx. }; -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.hpp index 6151d792ebfb..9d96d1feb62a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.hpp @@ -12,4 +12,4 @@ using aztec3::circuits::abis::OptionalPrivateCircuitPublicInputs; OptionalPrivateCircuitPublicInputs deposit(FunctionExecutionContext& exec_ctx, std::array const& args); -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/index.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/index.hpp index 4cf1909486f6..ff3c61046c14 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/index.hpp @@ -1,5 +1,5 @@ -#include "init.hpp" #include "contract.hpp" #include "deposit.hpp" +#include "init.hpp" #include "transfer.hpp" #include "withdraw.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index 8d16620c6d48..d29311be6387 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -3,14 +3,12 @@ #include #include #include +#include #include #include - -#include #include - -#include #include +#include #include namespace aztec3::circuits::apps::test_apps::escrow { @@ -38,8 +36,8 @@ using apps::state_vars::UTXOSetStateVar; // Get rid of ugle `Composer` template arg from our state var types: template struct SpecialisedTypes { - typedef MappingStateVar mapping; - typedef UTXOSetStateVar utxo_set; + using mapping = MappingStateVar; + using utxo_set = UTXOSetStateVar; }; template using Mapping = typename SpecialisedTypes::mapping; @@ -47,4 +45,4 @@ template using UTXOSet = typename SpecialisedTypes::utxo_s using DefaultNote = apps::notes::DefaultPrivateNote; -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp index 7d99a7bc367a..677f03673c66 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp @@ -31,8 +31,8 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c CT::address to = to_ct(composer, _to); CT::fr asset_id = to_ct(composer, _asset_id); CT::fr memo = to_ct(composer, _memo); - CT::boolean reveal_msg_sender_to_recipient = to_ct(composer, _reveal_msg_sender_to_recipient); - CT::fr fee = to_ct(composer, _fee); + CT::boolean const reveal_msg_sender_to_recipient = to_ct(composer, _reveal_msg_sender_to_recipient); + CT::fr const fee = to_ct(composer, _fee); /**************************************************************** * Get States & Globals used by the function @@ -57,8 +57,8 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c std::vector old_balance_notes = balances[asset_id][msg_sender.to_field()].get(2, { .owner = msg_sender }); - CT::fr old_value_1 = *(old_balance_notes[0].get_preimage().value); - CT::fr old_value_2 = *(old_balance_notes[1].get_preimage().value); + CT::fr const old_value_1 = *(old_balance_notes[0].get_preimage().value); + CT::fr const old_value_2 = *(old_balance_notes[1].get_preimage().value); // MISSING: overflow & underflow checks, but I can't be bothered with safe_uint or range checks yet. CT::fr change = (old_value_1 + old_value_2) - (amount + fee); @@ -110,4 +110,4 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c return public_inputs.to_native_type(); }; -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.hpp index fa3fe7dfcdbd..a37203a08c48 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.hpp @@ -17,4 +17,4 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c NT::boolean const& _reveal_msg_sender_to_recipient, NT::fr const& _fee); -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp index 320ff01df443..b1c2d67d18ad 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp @@ -26,11 +26,11 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c // Convert arguments into circuit types: auto& composer = exec_ctx.composer; - CT::fr amount = to_ct(composer, _amount); + CT::fr const amount = to_ct(composer, _amount); CT::fr asset_id = to_ct(composer, _asset_id); CT::fr memo = to_ct(composer, _memo); - CT::fr l1_withdrawal_address = to_ct(composer, _l1_withdrawal_address); - CT::fr fee = to_ct(composer, _fee); + CT::fr const l1_withdrawal_address = to_ct(composer, _l1_withdrawal_address); + CT::fr const fee = to_ct(composer, _fee); /**************************************************************** * Get States & Globals used by the function @@ -52,8 +52,8 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c std::vector old_balance_notes = balances[asset_id][msg_sender.to_field()].get(2, { .owner = msg_sender }); - CT::fr old_value_1 = *(old_balance_notes[0].get_preimage().value); - CT::fr old_value_2 = *(old_balance_notes[1].get_preimage().value); + CT::fr const old_value_1 = *(old_balance_notes[0].get_preimage().value); + CT::fr const old_value_2 = *(old_balance_notes[1].get_preimage().value); // MISSING: overflow & underflow checks, but I can't be bothered with safe_uint or range checks yet. CT::fr change = (old_value_1 + old_value_2) - (amount + fee); @@ -102,4 +102,4 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c return public_inputs.to_native_type(); }; -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.hpp index 41a3c35d8703..51d47d4fa602 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.hpp @@ -16,4 +16,4 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c NT::fr const& _l1_withdrawal_address, NT::fr const& _fee); -} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp index a1d66728bcd9..6d90c6431a98 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp @@ -5,16 +5,16 @@ // #include -#include #include +#include + namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { class private_to_private_function_call_tests : public ::testing::Test {}; TEST(private_to_private_function_call_tests, circuit_private_to_private_function_call) { - C fn1_composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; @@ -24,7 +24,7 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function uint256_t(0x01071e9a23e0f7edULL, 0x5d77b35d1830fa3eULL, 0xc6ba3660bb1f0c0bULL, 0x2ef9f7f09867fd6eULL); const FunctionData function_data{ - .function_selector = 1, // TODO: deduce this from the contract, somehow. + .function_selector = 1, // TODO: deduce this from the contract, somehow. .is_private = true, .is_constructor = false, }; @@ -62,4 +62,4 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function info("n: ", fn1_composer.num_gates); } -} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/contract.hpp index a85fb0566cf2..ee4c3da41b11 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/contract.hpp @@ -40,4 +40,4 @@ inline Contract init_contract_2() return contract_2; } -} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp index 7e1b26f61c9b..72b4a1b0260c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp @@ -1,7 +1,7 @@ #include "function_1_1.hpp" -#include "function_2_1.hpp" #include "contract.hpp" +#include "function_2_1.hpp" #include @@ -85,4 +85,4 @@ void function_1_1(FunctionExecutionContext& exec_ctx, std::array const& _args); -} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp index a0069955cd39..719501518b3c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp @@ -6,7 +6,6 @@ namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { -using aztec3::circuits::abis::OptionalPrivateCircuitPublicInputs; void function_2_1(FunctionExecutionContext& exec_ctx, std::array const& _args) { @@ -41,7 +40,7 @@ void function_2_1(FunctionExecutionContext& exec_ctx, std::array const& _args); -} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/index.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/index.hpp index 61fdb7a6444d..80035d4a71c6 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/index.hpp @@ -1,4 +1,4 @@ -#include "init.hpp" #include "contract.hpp" #include "function_1_1.hpp" -#include "function_2_1.hpp" \ No newline at end of file +#include "function_2_1.hpp" +#include "init.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index 5da8cc6d0f14..98080b313fec 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -5,11 +5,9 @@ #include #include #include - #include - -#include #include +#include #include namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { @@ -36,11 +34,11 @@ using apps::state_vars::UTXOStateVar; // Get rid of ugle `Composer` template arg from our state var types: template struct SpecialisedTypes { - typedef UTXOStateVar utxo; + using utxo = UTXOStateVar; }; template using UTXO = typename SpecialisedTypes::utxo; using Note = apps::notes::DefaultSingletonPrivateNote; -} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file +} // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp index eb5c07b31064..0588a8dfed17 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include #include +#include + +#include namespace aztec3::circuits::apps { @@ -15,9 +16,9 @@ using plonk::stdlib::witness_t; * @tparam NotePreimage */ template struct UTXOSLoadDatum { - typedef typename NCT::fr fr; - typedef typename NCT::address address; - typedef typename NCT::uint32 uint32; + using fr = typename NCT::fr; + using address = typename NCT::address; + using uint32 = typename NCT::uint32; fr commitment = 0; address contract_address = 0; @@ -45,4 +46,4 @@ template struct UTXOSLoadDatum { }; }; -} // namespace aztec3::circuits::apps +} // namespace aztec3::circuits::apps diff --git a/circuits/cpp/src/aztec3/circuits/hash.hpp b/circuits/cpp/src/aztec3/circuits/hash.hpp index 8e5a2e2dd26b..5696d8904199 100644 --- a/circuits/cpp/src/aztec3/circuits/hash.hpp +++ b/circuits/cpp/src/aztec3/circuits/hash.hpp @@ -1,12 +1,13 @@ #pragma once -#include -#include #include "aztec3/circuits/abis/function_leaf_preimage.hpp" +#include #include #include #include +#include + namespace aztec3::circuits { using abis::FunctionData; @@ -18,17 +19,16 @@ template typename NCT::fr compute_args_hash(std::array -typename NCT::fr compute_constructor_hash(FunctionData function_data, - std::array args, - typename NCT::fr constructor_vk_hash) +template typename NCT::fr compute_constructor_hash(FunctionData function_data, + std::array args, + typename NCT::fr constructor_vk_hash) { using fr = typename NCT::fr; - fr function_data_hash = function_data.hash(); - fr args_hash = compute_args_hash(args); + fr const function_data_hash = function_data.hash(); + fr const args_hash = compute_args_hash(args); - std::vector inputs = { + std::vector const inputs = { function_data_hash, args_hash, constructor_vk_hash, @@ -37,16 +37,15 @@ typename NCT::fr compute_constructor_hash(FunctionData function_data, return NCT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR); } -template -typename NCT::address compute_contract_address(typename NCT::address deployer_address, - typename NCT::fr contract_address_salt, - typename NCT::fr function_tree_root, - typename NCT::fr constructor_hash) +template typename NCT::address compute_contract_address(typename NCT::address deployer_address, + typename NCT::fr contract_address_salt, + typename NCT::fr function_tree_root, + typename NCT::fr constructor_hash) { using fr = typename NCT::fr; using address = typename NCT::address; - std::vector inputs = { + std::vector const inputs = { deployer_address.to_field(), contract_address_salt, function_tree_root, @@ -61,7 +60,7 @@ typename NCT::fr add_contract_address_to_commitment(typename NCT::address contra { using fr = typename NCT::fr; - std::vector inputs = { + std::vector const inputs = { contract_address.to_field(), commitment, }; @@ -74,7 +73,7 @@ typename NCT::fr add_contract_address_to_nullifier(typename NCT::address contrac { using fr = typename NCT::fr; - std::vector inputs = { + std::vector const inputs = { contract_address.to_field(), nullifier, }; @@ -112,7 +111,7 @@ typename NCT::fr root_from_sibling_path(typename NCT::fr const& leaf, node = NCT::merkle_hash(node, siblingPath[i]); } } - return node; // root + return node; // root } /** @@ -147,7 +146,7 @@ typename NCT::fr root_from_sibling_path(typename NCT::fr const& leaf, } index >>= uint256_t(1); } - return node; // root + return node; // root } template @@ -176,8 +175,7 @@ void check_membership(Composer& composer, * @param function_leaf_sibling_path * @return NCT::fr */ -template -typename NCT::fr function_tree_root_from_siblings( +template typename NCT::fr function_tree_root_from_siblings( typename NCT::uint32 const& function_selector, typename NCT::boolean const& is_private, typename NCT::fr const& vk_hash, @@ -210,8 +208,7 @@ typename NCT::fr function_tree_root_from_siblings( * @param contract_leaf_sibling_path * @return NCT::fr */ -template -typename NCT::fr contract_tree_root_from_siblings( +template typename NCT::fr contract_tree_root_from_siblings( typename NCT::fr const& function_tree_root, typename NCT::address const& storage_contract_address, typename NCT::address const& portal_contract_address, @@ -266,11 +263,10 @@ template typename NCT::fr compute_public_data_tree_value(typename * @param storage_slot The storage slot to which the inserted element belongs * @return The index for insertion into the public data tree */ -template -typename NCT::fr compute_public_data_tree_index(typename NCT::fr const& contract_address, - typename NCT::fr const& storage_slot) +template typename NCT::fr compute_public_data_tree_index(typename NCT::fr const& contract_address, + typename NCT::fr const& storage_slot) { return NCT::compress({ contract_address, storage_slot }, GeneratorIndex::PUBLIC_LEAF_INDEX); } -} // namespace aztec3::circuits \ No newline at end of file +} // namespace aztec3::circuits \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 5deb22b99004..0ba2e29b7f6e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -1,36 +1,34 @@ +#include "c_bind.h" #include "index.hpp" #include "init.hpp" -#include "c_bind.h" +#include "aztec3/circuits/kernel/private/utils.hpp" #include "aztec3/constants.hpp" -#include - -#include -#include -#include - #include #include +#include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include +#include #include #include +#include +#include +#include +#include #include - -#include "aztec3/circuits/kernel/private/utils.hpp" +#include +#include +#include +#include #include #include #include #include + #include namespace { @@ -49,11 +47,9 @@ using aztec3::circuits::abis::SignedTxRequest; using aztec3::circuits::abis::TxContext; using aztec3::circuits::abis::TxRequest; -using aztec3::circuits::abis::CombinedAccumulatedData; using aztec3::circuits::abis::CombinedConstantData; using aztec3::circuits::abis::CombinedHistoricTreeRoots; using aztec3::circuits::abis::KernelCircuitPublicInputs; -using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::abis::PrivateHistoricTreeRoots; using aztec3::circuits::abis::private_kernel::PrivateCallData; using aztec3::circuits::abis::private_kernel::PrivateInputs; @@ -63,7 +59,6 @@ using aztec3::circuits::apps::test_apps::escrow::deposit; using DummyComposer = aztec3::utils::DummyComposer; -using aztec3::circuits::mock::mock_kernel_circuit; // A type representing any private circuit function // (for now it works for deposit and constructor) @@ -73,8 +68,8 @@ using private_function = std::function( // Some helper constants for trees constexpr size_t MAX_FUNCTION_LEAVES = 2 << (aztec3::FUNCTION_TREE_HEIGHT - 1); -const NT::fr EMPTY_FUNCTION_LEAF = FunctionLeafPreimage{}.hash(); // hash of empty/0 preimage -const NT::fr EMPTY_CONTRACT_LEAF = NewContractData{}.hash(); // hash of empty/0 preimage +const NT::fr EMPTY_FUNCTION_LEAF = FunctionLeafPreimage{}.hash(); // hash of empty/0 preimage +const NT::fr EMPTY_CONTRACT_LEAF = NewContractData{}.hash(); // hash of empty/0 preimage const auto& get_empty_function_siblings() { @@ -94,7 +89,7 @@ const auto& get_empty_contract_siblings() return EMPTY_CONTRACT_SIBLINGS; } -} // namespace +} // namespace namespace aztec3::circuits::kernel::private_kernel { @@ -114,7 +109,7 @@ void debugComposer(Composer const& composer) info("err: ", composer.err()); info("n: ", composer.get_num_gates()); #else - (void)composer; // only used in debug mode + (void)composer; // only used in debug mode #endif } @@ -131,12 +126,12 @@ void debugComposer(Composer const& composer) std::shared_ptr gen_func_vk(bool is_constructor, private_function const& func, size_t const num_args) { // Some dummy inputs to get the circuit to compile and get a VK - FunctionData dummy_function_data{ + FunctionData const dummy_function_data{ .is_private = true, .is_constructor = is_constructor, }; - CallContext dummy_call_context{ + CallContext const dummy_call_context{ .is_contract_deployment = is_constructor, }; @@ -182,7 +177,7 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, // Initialize some inputs to private call and kernel circuits //*************************************************************************** // TODO randomize inputs - NT::address contract_address = is_constructor ? 0 : 12345; // updated later if in constructor + NT::address contract_address = is_constructor ? 0 : 12345; // updated later if in constructor const NT::uint32 contract_leaf_index = 1; const NT::uint32 function_leaf_index = 1; const NT::fr portal_contract_address = 23456; @@ -192,10 +187,10 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, const NT::fr msg_sender_private_key = 123456789; const NT::address msg_sender = NT::fr(uint256_t(0x01071e9a23e0f7edULL, 0x5d77b35d1830fa3eULL, 0xc6ba3660bb1f0c0bULL, 0x2ef9f7f09867fd6eULL)); - const NT::address tx_origin = msg_sender; + const NT::address& tx_origin = msg_sender; - FunctionData function_data{ - .function_selector = 1, // TODO: deduce this from the contract, somehow. + FunctionData const function_data{ + .function_selector = 1, // TODO: deduce this from the contract, somehow. .is_private = true, .is_constructor = is_constructor, }; @@ -230,7 +225,7 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, stdlib::recursion::verification_key::compress_native(private_circuit_vk, GeneratorIndex::VK); ContractDeploymentData contract_deployment_data{}; - NT::fr contract_tree_root = 0; // TODO set properly for constructor? + NT::fr contract_tree_root = 0; // TODO set properly for constructor? if (is_constructor) { // TODO compute function tree root from leaves // create leaf preimage for each function and hash all into tree @@ -242,7 +237,7 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, // .vk_hash = private_circuit_vk_hash, // .acir_hash = acir_hash, //}; - std::vector function_leaves(MAX_FUNCTION_LEAVES, EMPTY_FUNCTION_LEAF); + std::vector const function_leaves(MAX_FUNCTION_LEAVES, EMPTY_FUNCTION_LEAF); // const NT::fr& function_tree_root = plonk::stdlib::merkle_tree::compute_tree_root_native(function_leaves); // TODO use actual function tree root computed from leaves @@ -295,21 +290,21 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, FunctionExecutionContext ctx(private_circuit_composer, oracle_wrapper); - OptionalPrivateCircuitPublicInputs opt_private_circuit_public_inputs = func(ctx, args); + OptionalPrivateCircuitPublicInputs const opt_private_circuit_public_inputs = func(ctx, args); PrivateCircuitPublicInputs private_circuit_public_inputs = opt_private_circuit_public_inputs.remove_optionality(); // TODO this should likely be handled as part of the DB/Oracle/Context infrastructure private_circuit_public_inputs.historic_contract_tree_root = contract_tree_root; auto private_circuit_prover = private_circuit_composer.create_prover(); - NT::Proof private_circuit_proof = private_circuit_prover.construct_proof(); + NT::Proof const private_circuit_proof = private_circuit_prover.construct_proof(); // info("\nproof: ", private_circuit_proof.proof_data); //*************************************************************************** // We can create a TxRequest from some of the above data. Users must sign a TxRequest in order to give permission // for a tx to take place - creating a SignedTxRequest. //*************************************************************************** - TxRequest tx_request = TxRequest{ + auto const tx_request = TxRequest{ .from = tx_origin, .to = contract_address, .function_data = function_data, @@ -325,7 +320,7 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, .chain_id = 1, }; - SignedTxRequest signed_tx_request = SignedTxRequest{ + auto const signed_tx_request = SignedTxRequest{ .tx_request = tx_request, //.signature = TODO: need a method for signing a TxRequest. @@ -411,7 +406,6 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, void validate_deployed_contract_address(PrivateInputs const& private_inputs, KernelCircuitPublicInputs const& public_inputs) { - auto tx_request = private_inputs.signed_tx_request.tx_request; auto cdd = private_inputs.signed_tx_request.tx_request.tx_context.contract_deployment_data; @@ -421,7 +415,7 @@ void validate_deployed_contract_address(PrivateInputs const& private_inputs, NT::compress(tx_request.args, CONSTRUCTOR_ARGS), private_circuit_vk_hash }, CONSTRUCTOR); - NT::fr expected_contract_address = + NT::fr const expected_contract_address = NT::compress({ tx_request.from, cdd.contract_address_salt, cdd.function_tree_root, expected_constructor_hash }, CONTRACT_ADDRESS); EXPECT_EQ(public_inputs.end.new_contracts[0].contract_address.to_field(), expected_contract_address); @@ -539,7 +533,7 @@ TEST(private_kernel_tests, circuit_create_proof_cbinds) // Now run the simulate/prove cbinds to make sure their outputs match //*************************************************************************** // TODO might be able to get rid of proving key buffer - uint8_t const* pk_buf; + uint8_t const* pk_buf = nullptr; private_kernel__init_proving_key(&pk_buf); // info("Proving key size: ", pk_size); @@ -554,14 +548,14 @@ TEST(private_kernel_tests, circuit_create_proof_cbinds) std::vector private_constructor_call_vec; write(private_constructor_call_vec, private_inputs.private_call); - uint8_t const* proof_data_buf; - uint8_t const* public_inputs_buf; + uint8_t const* proof_data_buf = nullptr; + uint8_t const* public_inputs_buf = nullptr; // info("Simulating to generate public inputs..."); - size_t public_inputs_size = private_kernel__sim(signed_constructor_tx_request_vec.data(), - nullptr, // no previous kernel on first iteration - private_constructor_call_vec.data(), - true, // first iteration - &public_inputs_buf); + size_t const public_inputs_size = private_kernel__sim(signed_constructor_tx_request_vec.data(), + nullptr, // no previous kernel on first iteration + private_constructor_call_vec.data(), + true, // first iteration + &public_inputs_buf); // TODO better equality check // for (size_t i = 0; i < public_inputs_size; i++) @@ -570,12 +564,12 @@ TEST(private_kernel_tests, circuit_create_proof_cbinds) } (void)public_inputs_size; // info("Proving"); - size_t proof_data_size = private_kernel__prove(signed_constructor_tx_request_vec.data(), - nullptr, // no previous kernel on first iteration - private_constructor_call_vec.data(), - pk_buf, - true, // first iteration - &proof_data_buf); + size_t const proof_data_size = private_kernel__prove(signed_constructor_tx_request_vec.data(), + nullptr, // no previous kernel on first iteration + private_constructor_call_vec.data(), + pk_buf, + true, // first iteration + &proof_data_buf); (void)proof_data_size; // info("Proof size: ", proof_data_size); // info("PublicInputs size: ", public_inputs_size); @@ -591,7 +585,7 @@ TEST(private_kernel_tests, circuit_create_proof_cbinds) */ TEST(private_kernel_tests, native_dummy_previous_kernel_cbind) { - uint8_t const* cbind_previous_kernel_buf; + uint8_t const* cbind_previous_kernel_buf = nullptr; size_t const cbind_buf_size = private_kernel__dummy_previous_kernel(&cbind_previous_kernel_buf); auto const& previous_kernel = utils::dummy_previous_kernel(); @@ -611,4 +605,4 @@ TEST(private_kernel_tests, native_dummy_previous_kernel_cbind) (void)cbind_buf_size; } -} // namespace aztec3::circuits::kernel::private_kernel +} // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index 78966aa8405c..2d06d0998634 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -1,42 +1,37 @@ +#include "c_bind.h" + #include "index.hpp" #include "init.hpp" #include "utils.hpp" -#include "c_bind.h" // TODO remove these? present in init/index? -#include -#include -#include "aztec3/circuits/abis/signed_tx_request.hpp" #include "aztec3/circuits/abis/private_kernel/private_call_data.hpp" -#include -#include +#include "aztec3/circuits/abis/signed_tx_request.hpp" #include "aztec3/circuits/kernel/private/utils.hpp" +#include +#include #include - -#include "barretenberg/srs/reference_string/env_reference_string.hpp" +#include +#include #include "barretenberg/common/serialize.hpp" #include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/srs/reference_string/env_reference_string.hpp" namespace { using Composer = plonk::UltraComposer; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; -using aztec3::circuits::abis::CombinedAccumulatedData; -using aztec3::circuits::abis::CombinedConstantData; -using aztec3::circuits::abis::CombinedHistoricTreeRoots; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::abis::SignedTxRequest; -using aztec3::circuits::abis::TxContext; using aztec3::circuits::abis::private_kernel::PrivateCallData; using aztec3::circuits::abis::private_kernel::PrivateInputs; using aztec3::circuits::kernel::private_kernel::native_private_kernel_circuit; using aztec3::circuits::kernel::private_kernel::private_kernel_circuit; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel; -using aztec3::circuits::mock::mock_kernel_circuit; -} // namespace +} // namespace #define WASM_EXPORT __attribute__((visibility("default"))) // WASM Cbinds @@ -47,7 +42,7 @@ WASM_EXPORT size_t private_kernel__init_proving_key(uint8_t const** pk_buf) { std::vector pk_vec(42, 0); - auto raw_buf = (uint8_t*)malloc(pk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(pk_vec.size()); memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size()); *pk_buf = raw_buf; @@ -64,7 +59,7 @@ WASM_EXPORT size_t private_kernel__init_verification_key(uint8_t const* pk_buf, std::vector vk_vec(42, 0); // write(vk_vec, vk_data); - auto raw_buf = (uint8_t*)malloc(vk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(vk_vec.size()); memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size()); *vk_buf = raw_buf; @@ -73,12 +68,12 @@ WASM_EXPORT size_t private_kernel__init_verification_key(uint8_t const* pk_buf, WASM_EXPORT size_t private_kernel__dummy_previous_kernel(uint8_t const** previous_kernel_buf) { - PreviousKernelData previous_kernel = dummy_previous_kernel(); + PreviousKernelData const previous_kernel = dummy_previous_kernel(); std::vector previous_kernel_vec; write(previous_kernel_vec, previous_kernel); - auto raw_buf = (uint8_t*)malloc(previous_kernel_vec.size()); + auto* raw_buf = (uint8_t*)malloc(previous_kernel_vec.size()); memcpy(raw_buf, (void*)previous_kernel_vec.data(), previous_kernel_vec.size()); *previous_kernel_buf = raw_buf; @@ -118,19 +113,19 @@ WASM_EXPORT size_t private_kernel__sim(uint8_t const* signed_tx_request_buf, read(previous_kernel_buf, previous_kernel); } - PrivateInputs private_inputs = PrivateInputs{ + PrivateInputs const private_inputs = PrivateInputs{ .signed_tx_request = signed_tx_request, .previous_kernel = previous_kernel, .private_call = private_call_data, }; - KernelCircuitPublicInputs public_inputs = native_private_kernel_circuit(composer, private_inputs); + KernelCircuitPublicInputs const public_inputs = native_private_kernel_circuit(composer, private_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *private_kernel_public_inputs_buf = raw_public_inputs_buf; @@ -147,7 +142,7 @@ WASM_EXPORT size_t private_kernel__prove(uint8_t const* signed_tx_request_buf, { // TODO might be able to get rid of proving key buffer // TODO do we want to accept it or just get it from our factory? - (void)pk_buf; // unused + (void)pk_buf; // unused auto crs_factory = std::make_shared(); SignedTxRequest signed_tx_request; @@ -170,7 +165,7 @@ WASM_EXPORT size_t private_kernel__prove(uint8_t const* signed_tx_request_buf, } else { read(previous_kernel_buf, previous_kernel); } - PrivateInputs private_inputs = PrivateInputs{ + PrivateInputs const private_inputs = PrivateInputs{ .signed_tx_request = signed_tx_request, .previous_kernel = previous_kernel, .private_call = private_call_data, @@ -185,7 +180,7 @@ WASM_EXPORT size_t private_kernel__prove(uint8_t const* signed_tx_request_buf, private_kernel_proof = private_kernel_prover.construct_proof(); // copy proof data to output buffer - auto raw_proof_buf = (uint8_t*)malloc(private_kernel_proof.proof_data.size()); + auto* raw_proof_buf = (uint8_t*)malloc(private_kernel_proof.proof_data.size()); memcpy(raw_proof_buf, (void*)private_kernel_proof.proof_data.data(), private_kernel_proof.proof_data.size()); *proof_data_buf = raw_proof_buf; @@ -194,10 +189,10 @@ WASM_EXPORT size_t private_kernel__prove(uint8_t const* signed_tx_request_buf, WASM_EXPORT size_t private_kernel__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) { - (void)vk_buf; // unused - (void)proof; // unused - (void)length; // unused - return true; + (void)vk_buf; // unused + (void)proof; // unused + (void)length; // unused + return 1U; } -} // extern "C" \ No newline at end of file +} // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/index.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/index.hpp index 4765e899a0ef..60f0e23967ef 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/index.hpp @@ -1,3 +1,3 @@ #include "init.hpp" -#include "private_kernel_circuit.hpp" -#include "native_private_kernel_circuit.hpp" \ No newline at end of file +#include "native_private_kernel_circuit.hpp" +#include "private_kernel_circuit.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp index c7790e9dc53a..6da9911174d9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp @@ -1,14 +1,11 @@ #pragma once -#include -#include +#include #include - +#include #include - -#include - -#include +#include #include +#include #include namespace aztec3::circuits::kernel::private_kernel { @@ -28,4 +25,4 @@ using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; using FunctionExecutionContext = aztec3::circuits::apps::FunctionExecutionContext; -} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp index c109a3e04459..5a7fffdbe8f7 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp @@ -1,14 +1,13 @@ #include "init.hpp" #include "aztec3/circuits/abis/function_leaf_preimage.hpp" -#include +#include "aztec3/constants.hpp" #include #include - +#include +#include #include #include -#include -#include "aztec3/constants.hpp" #include @@ -129,9 +128,9 @@ void contract_logic(DummyComposer& composer, } // Add new contract data if its a contract deployment function - NewContractData native_new_contract_data{ new_contract_address, - portal_contract_address, - contract_deployment_data.function_tree_root }; + NewContractData const native_new_contract_data{ new_contract_address, + portal_contract_address, + contract_deployment_data.function_tree_root }; array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, native_new_contract_data); @@ -159,7 +158,7 @@ void contract_logic(DummyComposer& composer, if (!is_contract_deployment) { auto const& computed_function_tree_root = function_tree_root_from_siblings( private_inputs.private_call.call_stack_item.function_data.function_selector, - true, // is_private + true, // is_private private_call_vk_hash, private_inputs.private_call.acir_hash, private_inputs.private_call.function_leaf_membership_witness.leaf_index, @@ -210,29 +209,27 @@ void update_end_values(DummyComposer& composer, array_push(public_inputs.end.new_nullifiers, private_inputs.signed_tx_request.tx_request.nonce); } - { // commitments & nullifiers + { // commitments & nullifiers std::array siloed_new_commitments; for (size_t i = 0; i < new_commitments.size(); ++i) { - siloed_new_commitments[i] = - new_commitments[i] == 0 - ? 0 - : add_contract_address_to_commitment(storage_contract_address, new_commitments[i]); + siloed_new_commitments[i] = new_commitments[i] == 0 ? 0 + : add_contract_address_to_commitment( + storage_contract_address, new_commitments[i]); } std::array siloed_new_nullifiers; for (size_t i = 0; i < new_nullifiers.size(); ++i) { - siloed_new_nullifiers[i] = - new_nullifiers[i] == 0 - ? 0 - : add_contract_address_to_nullifier(storage_contract_address, new_nullifiers[i]); + siloed_new_nullifiers[i] = new_nullifiers[i] == 0 ? 0 + : add_contract_address_to_nullifier( + storage_contract_address, new_nullifiers[i]); } push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); } - { // call stacks - auto& this_private_call_stack = private_call_public_inputs.private_call_stack; + { // call stacks + const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); } @@ -255,7 +252,6 @@ void validate_this_private_call_hash(DummyComposer& composer, PrivateInputs const& private_inputs, KernelCircuitPublicInputs& public_inputs) { - // TODO: this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' tx, // and the 'gas rebate' tx). const auto popped_private_call_hash = array_pop(public_inputs.end.private_call_stack); @@ -269,8 +265,8 @@ void validate_this_private_call_hash(DummyComposer& composer, void validate_this_private_call_stack(DummyComposer& composer, PrivateInputs const& private_inputs) { - auto& stack = private_inputs.private_call.call_stack_item.public_inputs.private_call_stack; - auto& preimages = private_inputs.private_call.private_call_stack_preimages; + const auto& stack = private_inputs.private_call.call_stack_item.public_inputs.private_call_stack; + const auto& preimages = private_inputs.private_call.private_call_stack_preimages; for (size_t i = 0; i < stack.size(); ++i) { const auto& hash = stack[i]; const auto& preimage = preimages[i]; @@ -299,9 +295,9 @@ void validate_inputs(DummyComposer& composer, PrivateInputs const& private_i // TODO: we might want to range-constrain the call_count to prevent some kind of overflow errors. Having said that, // iterating 2^254 times isn't feasible. - NT::fr start_private_call_stack_length = array_length(start.private_call_stack); - NT::fr start_public_call_stack_length = array_length(start.public_call_stack); - NT::fr start_l1_msg_stack_length = array_length(start.l1_msg_stack); + NT::fr const start_private_call_stack_length = array_length(start.private_call_stack); + NT::fr const start_public_call_stack_length = array_length(start.public_call_stack); + NT::fr const start_l1_msg_stack_length = array_length(start.l1_msg_stack); // Base Case if (is_base_case) { @@ -392,4 +388,4 @@ KernelCircuitPublicInputs native_private_kernel_circuit(DummyComposer& compo return public_inputs; }; -} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.hpp index 56c00ddcbc63..cbe24653faf4 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.hpp @@ -2,8 +2,8 @@ #include "init.hpp" -#include #include +#include #include namespace aztec3::circuits::kernel::private_kernel { @@ -17,4 +17,4 @@ using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_private_kernel_circuit(DummyComposer& composer, PrivateInputs const& _private_inputs); -} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index a7148faad668..75d4b487ffd5 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -1,14 +1,13 @@ -#include "aztec3/constants.hpp" #include "init.hpp" -#include - -#include +#include "aztec3/constants.hpp" #include #include - +#include #include +#include + namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; @@ -111,7 +110,7 @@ void update_end_values(PrivateInputs const& private_inputs, KernelCircuitPub const auto& contract_deployment_data = private_inputs.signed_tx_request.tx_request.tx_context.contract_deployment_data; - { // contract deployment + { // contract deployment // input storage contract address must be 0 if its a constructor call and non-zero otherwise auto is_contract_deployment = public_inputs.constants.tx_context.is_contract_deployment_tx; @@ -144,12 +143,12 @@ void update_end_values(PrivateInputs const& private_inputs, KernelCircuitPub auto contract_address_nullifier = CT::fr(CT::blake3s(blake_input)); // push the contract address nullifier to nullifier vector - CT::fr conditional_contract_address_nullifier = + CT::fr const conditional_contract_address_nullifier = CT::fr::conditional_assign(is_contract_deployment, contract_address_nullifier, CT::fr(0)); array_push(public_inputs.end.new_nullifiers, conditional_contract_address_nullifier); // Add new contract data if its a contract deployment function - NewContractData new_contract_data = NewContractData{ + auto const new_contract_data = NewContractData{ .contract_address = contract_address, .portal_contract_address = portal_contract_address, .function_tree_root = contract_deployment_data.function_tree_root, @@ -159,7 +158,7 @@ void update_end_values(PrivateInputs const& private_inputs, KernelCircuitPub new_contract_data); } - { // commitments, nullifiers, and contracts + { // commitments, nullifiers, and contracts std::array siloed_new_commitments; for (size_t i = 0; i < new_commitments.size(); ++i) { siloed_new_commitments[i] = CT::fr::conditional_assign( @@ -180,9 +179,9 @@ void update_end_values(PrivateInputs const& private_inputs, KernelCircuitPub push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); } - { // call stacks + { // call stacks // copy the private function circuit's callstack into the AggregatedData - auto& this_private_call_stack = private_call_public_inputs.private_call_stack; + const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); } @@ -224,8 +223,8 @@ void validate_this_private_call_hash(PrivateInputs const& private_inputs) */ void validate_this_private_call_stack(PrivateInputs const& private_inputs) { - auto& stack = private_inputs.private_call.call_stack_item.public_inputs.private_call_stack; - auto& preimages = private_inputs.private_call.private_call_stack_preimages; + const auto& stack = private_inputs.private_call.call_stack_item.public_inputs.private_call_stack; + const auto& preimages = private_inputs.private_call.private_call_stack_preimages; for (size_t i = 0; i < stack.size(); ++i) { const auto& hash = stack[i]; const auto& preimage = preimages[i]; @@ -258,15 +257,15 @@ void validate_inputs(PrivateInputs const& private_inputs) // These lengths are calculated by counting entries until a non-zero one is encountered // True array length is constant which is a property we need for circuit inputs, // but we want to know "length" in terms of how many nonzero entries have been inserted - CT::fr start_private_call_stack_length = array_length(start.private_call_stack); - CT::fr start_public_call_stack_length = array_length(start.public_call_stack); - CT::fr start_l1_msg_stack_length = array_length(start.l1_msg_stack); + CT::fr const start_private_call_stack_length = array_length(start.private_call_stack); + CT::fr const start_public_call_stack_length = array_length(start.public_call_stack); + CT::fr const start_l1_msg_stack_length = array_length(start.l1_msg_stack); // Recall: we can't do traditional `if` statements in a circuit; all code paths are always executed. The below is // some syntactic sugar, which seeks readability similar to an `if` statement. // Base Case - std::vector> base_case_conditions{ + std::vector> const base_case_conditions{ // TODO: change to allow 3 initial calls on the private call stack, so a fee can be paid and a gas // rebate can be paid. { start_private_call_stack_length == 1, "Private call stack must be length 1" }, @@ -297,7 +296,7 @@ void validate_inputs(PrivateInputs const& private_inputs) is_base_case.must_imply(base_case_conditions); // Recursive Case - std::vector> recursive_case_conditions{ + std::vector> const recursive_case_conditions{ { private_inputs.previous_kernel.public_inputs.is_private == true, "Cannot verify a non-private kernel snark in the private kernel circuit" }, { this_call_stack_item.function_data.is_constructor == false, @@ -355,4 +354,4 @@ KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, Private return public_inputs.to_native_type(); }; -} // namespace aztec3::circuits::kernel::private_kernel +} // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp index 80a33b300360..858bf06e6907 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp @@ -2,8 +2,8 @@ #include "init.hpp" -#include #include +#include namespace aztec3::circuits::kernel::private_kernel { @@ -13,4 +13,4 @@ using aztec3::circuits::abis::private_kernel::PrivateInputs; KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, PrivateInputs const& _private_inputs); KernelCircuitPublicInputs private_kernel_native(PrivateInputs const& private_inputs); -} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index 654440e5fb52..a4eb5adf2a2e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -1,9 +1,10 @@ #include "index.hpp" #include "init.hpp" -#include "barretenberg/proof_system/types/composer_type.hpp" -#include #include "aztec3/circuits/abis/new_contract_data.hpp" +#include + +#include "barretenberg/proof_system/types/composer_type.hpp" namespace { using NT = aztec3::utils::types::NativeTypes; @@ -11,7 +12,7 @@ using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::mock::mock_kernel_circuit; -} // namespace +} // namespace namespace aztec3::circuits::kernel::private_kernel::utils { @@ -46,17 +47,17 @@ std::shared_ptr fake_vk() */ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) { - PreviousKernelData init_previous_kernel{}; + PreviousKernelData const init_previous_kernel{}; auto crs_factory = std::make_shared(); Composer mock_kernel_composer = Composer(crs_factory); auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs); auto mock_kernel_prover = mock_kernel_composer.create_prover(); - NT::Proof mock_kernel_proof = + NT::Proof const mock_kernel_proof = real_vk_proof ? mock_kernel_prover.construct_proof() : NT::Proof{ .proof_data = std::vector(64, 0) }; - std::shared_ptr mock_kernel_vk = + std::shared_ptr const mock_kernel_vk = real_vk_proof ? mock_kernel_composer.compute_verification_key() : fake_vk(); PreviousKernelData previous_kernel = { @@ -70,4 +71,4 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) return previous_kernel; } -} // namespace aztec3::circuits::kernel::private_kernel::utils \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel::utils \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.hpp index fed871f7873f..269a5670c3c4 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.hpp @@ -5,10 +5,10 @@ namespace { using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::PreviousKernelData; -} // namespace +} // namespace namespace aztec3::circuits::kernel::private_kernel::utils { PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false); -} // namespace aztec3::circuits::kernel::private_kernel::utils \ No newline at end of file +} // namespace aztec3::circuits::kernel::private_kernel::utils \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index b78a9ab0b415..0996622bfc8a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -48,15 +48,13 @@ using aztec3::circuits::abis::SignedTxRequest; using aztec3::circuits::abis::TxContext; using aztec3::circuits::abis::TxRequest; using aztec3::circuits::abis::public_kernel::PublicCallData; -using aztec3::circuits::apps::FunctionExecutionContext; -using aztec3::utils::CircuitErrorCode; using aztec3::utils::source_arrays_are_in_target; using aztec3::utils::zero_array; } // namespace namespace aztec3::circuits::kernel::public_kernel { -typedef CallStackItem PublicCallStackItem; +using PublicCallStackItem = CallStackItem; template std::array array_of_values(NT::uint32& count, NT::uint32 num_values_required = SIZE) @@ -109,12 +107,12 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address, NT::uint32 seed = 0) { NT::uint32 count = seed + 1; - FunctionData function_data{ + FunctionData const function_data{ .function_selector = count, .is_private = false, .is_constructor = false, }; - CallContext call_context{ + CallContext const call_context{ .msg_sender = msg_sender, .storage_contract_address = storage_contract_address, .portal_contract_address = portal_contract_address, @@ -122,16 +120,17 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address, .is_static_call = false, .is_contract_deployment = false, }; - std::array args = array_of_values(count); - std::array return_values = array_of_values(count); - std::array emitted_events = array_of_values(count); - std::array public_call_stack = array_of_values(count); - std::array l1_msg_stack = array_of_values(count); - std::array, STATE_READS_LENGTH> reads = generate_state_reads(count); - std::array, STATE_TRANSITIONS_LENGTH> transitions = generate_state_transitions(count); + std::array const args = array_of_values(count); + std::array const return_values = array_of_values(count); + std::array const emitted_events = array_of_values(count); + std::array const public_call_stack = + array_of_values(count); + std::array const l1_msg_stack = array_of_values(count); + std::array, STATE_READS_LENGTH> const reads = generate_state_reads(count); + std::array, STATE_TRANSITIONS_LENGTH> const transitions = generate_state_transitions(count); // create the public circuit public inputs - PublicCircuitPublicInputs public_circuit_public_inputs = PublicCircuitPublicInputs{ + auto const public_circuit_public_inputs = PublicCircuitPublicInputs{ .call_context = call_context, .args = args, .return_values = return_values, @@ -142,7 +141,7 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address, .l1_msg_stack = l1_msg_stack, }; - PublicCallStackItem call_stack_item = PublicCallStackItem{ + auto call_stack_item = PublicCallStackItem{ .contract_address = contract_address, .function_data = function_data, .public_inputs = public_circuit_public_inputs, @@ -163,15 +162,15 @@ PublicKernelInputsNoPreviousKernel get_kernel_inputs_no_previous_kernel() const NT::fr portal_contract_address = 23456; const NT::address msg_sender = NT::fr(1); - const NT::address tx_origin = msg_sender; + const NT::address& tx_origin = msg_sender; - FunctionData function_data{ + FunctionData const function_data{ .function_selector = 1, .is_private = false, .is_constructor = false, }; - CallContext call_context{ + CallContext const call_context{ .msg_sender = msg_sender, .storage_contract_address = contract_address, .portal_contract_address = portal_contract_address, @@ -190,7 +189,7 @@ PublicKernelInputsNoPreviousKernel get_kernel_inputs_no_previous_kernel() // We can create a TxRequest from some of the above data. Users must sign a TxRequest in order to give permission // for a tx to take place - creating a SignedTxRequest. //*************************************************************************** - TxRequest tx_request = TxRequest{ + auto const tx_request = TxRequest{ .from = tx_origin, .to = contract_address, .function_data = function_data, @@ -206,7 +205,7 @@ PublicKernelInputsNoPreviousKernel get_kernel_inputs_no_previous_kernel() .chain_id = 1, }; - SignedTxRequest signed_tx_request = SignedTxRequest{ + auto const signed_tx_request = SignedTxRequest{ .tx_request = tx_request, //.signature = TODO: need a method for signing a TxRequest. @@ -230,19 +229,20 @@ PublicKernelInputsNoPreviousKernel get_kernel_inputs_no_previous_kernel() child_portal_contract_address++; } - std::array return_values = + std::array const return_values = array_of_values(seed, RETURN_VALUES_LENGTH / 2); - std::array emitted_events = + std::array const emitted_events = array_of_values(seed, EMITTED_EVENTS_LENGTH / 2); - std::array, STATE_TRANSITIONS_LENGTH> state_transitions = + std::array, STATE_TRANSITIONS_LENGTH> const state_transitions = generate_state_transitions(seed, STATE_TRANSITIONS_LENGTH / 2); - std::array, STATE_READS_LENGTH> state_reads = generate_state_reads(seed, STATE_READS_LENGTH / 2); - std::array l1_msg_stack = + std::array, STATE_READS_LENGTH> const state_reads = + generate_state_reads(seed, STATE_READS_LENGTH / 2); + std::array const l1_msg_stack = array_of_values(seed, L1_MSG_STACK_LENGTH / 2); - fr historic_public_data_tree_root = ++seed; + fr const historic_public_data_tree_root = ++seed; // create the public circuit public inputs - PublicCircuitPublicInputs public_circuit_public_inputs = PublicCircuitPublicInputs{ + auto const public_circuit_public_inputs = PublicCircuitPublicInputs{ .call_context = call_context, .args = args, .return_values = return_values, @@ -335,7 +335,7 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat { NT::uint32 seed = 1000000; const auto kernel_inputs_no_previous = get_kernel_inputs_no_previous_kernel(); - CombinedConstantData end_constants = { + CombinedConstantData const end_constants = { .historic_tree_roots = CombinedHistoricTreeRoots{ .private_historic_tree_roots = PrivateHistoricTreeRoots{ .private_data_tree_root = ++seed, @@ -355,7 +355,7 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat zero_array(); public_call_stack[0] = kernel_inputs_no_previous.public_call.call_stack_item.hash(); - CombinedAccumulatedData end_accumulated_data = { + CombinedAccumulatedData const end_accumulated_data = { .private_call_count = private_previous ? 1 : 0, .public_call_count = private_previous ? 0 : 1, .new_commitments = array_of_values(seed, private_previous ? 2 : 0), @@ -448,7 +448,7 @@ void validate_private_data_propagation(const PublicKernelInputs& inputs, TEST(public_kernel_tests, no_previous_kernel_public_call_should_succeed) { DummyComposer dc; - PublicKernelInputsNoPreviousKernel inputs = get_kernel_inputs_no_previous_kernel(); + PublicKernelInputsNoPreviousKernel const inputs = get_kernel_inputs_no_previous_kernel(); auto public_inputs = native_public_kernel_circuit_no_previous_kernel(dc, inputs); ASSERT_FALSE(dc.failed()); } @@ -456,7 +456,7 @@ TEST(public_kernel_tests, no_previous_kernel_public_call_should_succeed) TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated) { DummyComposer dc; - PublicKernelInputsNoPreviousKernel inputs = get_kernel_inputs_no_previous_kernel(); + PublicKernelInputsNoPreviousKernel const inputs = get_kernel_inputs_no_previous_kernel(); auto public_inputs = native_public_kernel_circuit_no_previous_kernel(dc, inputs); ASSERT_FALSE(dc.failed()); @@ -703,7 +703,7 @@ TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_ // redefine the child calls/stacks to use some delegate calls std::array child_call_stacks; - NT::uint32 seed = 1000; + NT::uint32 const seed = 1000; NT::fr child_contract_address = 100000; NT::fr child_portal_contract_address = 200000; NT::boolean is_delegate_call = false; @@ -741,8 +741,8 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in // set the first call stack item to be a delegate call std::array child_call_stacks; - NT::uint32 seed = 1000; - NT::fr child_contract_address = 100000; + NT::uint32 const seed = 1000; + NT::fr const child_contract_address = 100000; std::array call_stack_hashes; child_call_stacks[0] = // NOLINTNEXTLINE(readability-suspicious-call-argument) @@ -772,8 +772,8 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contr // set the first call stack item to be a delegate call std::array child_call_stacks; - NT::uint32 seed = 1000; - NT::fr child_contract_address = 100000; + NT::uint32 const seed = 1000; + NT::fr const child_contract_address = 100000; std::array call_stack_hashes; child_call_stacks[0] = generate_call_stack_item(child_contract_address, origin_msg_sender, @@ -801,9 +801,9 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contra // set the first call stack item to be a delegate call std::array child_call_stacks; - NT::uint32 seed = 1000; - NT::fr child_contract_address = 100000; - NT::fr child_portal_contract = 200000; + NT::uint32 const seed = 1000; + NT::fr const child_contract_address = 100000; + NT::fr const child_portal_contract = 200000; std::array call_stack_hashes; // NOLINTNEXTLINE(readability-suspicious-call-argument) child_call_stacks[0] = generate_call_stack_item(child_contract_address, @@ -824,7 +824,7 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contra TEST(public_kernel_tests, public_kernel_circuit_with_private_previous_kernel_should_succeed) { DummyComposer dc; - PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); + PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dc, inputs); ASSERT_FALSE(dc.failed()); } @@ -832,7 +832,7 @@ TEST(public_kernel_tests, public_kernel_circuit_with_private_previous_kernel_sho TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_previous_private_kernel) { DummyComposer dc; - PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); + PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dc, inputs); // test that the prior set of private kernel public inputs were copied to the outputs @@ -924,7 +924,7 @@ TEST(public_kernel_tests, previous_private_kernel_fails_if_incorrect_storage_con TEST(public_kernel_tests, public_kernel_circuit_with_public_previous_kernel_should_succeed) { DummyComposer dc; - PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); + PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(false); auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dc, inputs); ASSERT_FALSE(dc.failed()); } @@ -1016,7 +1016,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre array_length(inputs.public_call.call_stack_item.public_inputs.state_transitions)); const auto contract_address = inputs.public_call.call_stack_item.contract_address; - std::array, STATE_TRANSITIONS_LENGTH> expected_new_writes = + std::array, STATE_TRANSITIONS_LENGTH> const expected_new_writes = public_data_writes_from_state_transitions(inputs.public_call.call_stack_item.public_inputs.state_transitions, contract_address); @@ -1024,7 +1024,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre expected_new_writes, public_inputs.end.state_transitions)); - std::array, STATE_READS_LENGTH> expected_new_reads = public_data_reads_from_state_reads( + std::array, STATE_READS_LENGTH> const expected_new_reads = public_data_reads_from_state_reads( inputs.public_call.call_stack_item.public_inputs.state_reads, contract_address); ASSERT_TRUE(source_arrays_are_in_target( diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index c049d21a1d6f..3ecc464271d9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -1,17 +1,17 @@ -#include "aztec3/utils/dummy_composer.hpp" +#include "c_bind.h" + #include "index.hpp" #include "init.hpp" -#include "c_bind.h" -#include -#include +#include "aztec3/utils/dummy_composer.hpp" #include #include #include - -#include "barretenberg/srs/reference_string/env_reference_string.hpp" +#include +#include #include "barretenberg/common/serialize.hpp" +#include "barretenberg/srs/reference_string/env_reference_string.hpp" namespace { using Composer = plonk::UltraComposer; @@ -23,7 +23,7 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputsNoPreviousKernel; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_no_previous_kernel; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_private_previous_kernel; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_public_previous_kernel; -} // namespace +} // namespace #define WASM_EXPORT __attribute__((visibility("default"))) // WASM Cbinds @@ -33,7 +33,7 @@ WASM_EXPORT size_t public_kernel__init_proving_key(uint8_t const** pk_buf) { std::vector pk_vec(42, 0); - auto raw_buf = (uint8_t*)malloc(pk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(pk_vec.size()); memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size()); *pk_buf = raw_buf; @@ -44,9 +44,9 @@ WASM_EXPORT size_t public_kernel__init_verification_key(uint8_t const* pk_buf, u { std::vector vk_vec(42, 0); // TODO remove when proving key is used - (void)pk_buf; // unused + (void)pk_buf; // unused - auto raw_buf = (uint8_t*)malloc(vk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(vk_vec.size()); memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size()); *vk_buf = raw_buf; @@ -60,7 +60,7 @@ WASM_EXPORT size_t public_kernel__sim(uint8_t const* public_kernel_inputs_buf, u PublicKernelInputs public_kernel_inputs; read(public_kernel_inputs_buf, public_kernel_inputs); - KernelCircuitPublicInputs public_inputs = + KernelCircuitPublicInputs const public_inputs = public_kernel_inputs.previous_kernel.public_inputs.is_private ? native_public_kernel_circuit_private_previous_kernel(composer, public_kernel_inputs) : native_public_kernel_circuit_public_previous_kernel(composer, public_kernel_inputs); @@ -69,7 +69,7 @@ WASM_EXPORT size_t public_kernel__sim(uint8_t const* public_kernel_inputs_buf, u std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *public_inputs_buf = raw_public_inputs_buf; @@ -84,18 +84,18 @@ WASM_EXPORT size_t public_kernel_no_previous_kernel__sim(uint8_t const* public_k PublicKernelInputsNoPreviousKernel public_kernel_inputs; read(public_kernel_inputs_buf, public_kernel_inputs); - KernelCircuitPublicInputs public_inputs = + KernelCircuitPublicInputs const public_inputs = native_public_kernel_circuit_no_previous_kernel(composer, public_kernel_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *public_inputs_buf = raw_public_inputs_buf; return public_inputs_vec.size(); } -} // extern "C" \ No newline at end of file +} // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp index 14629603ec3c..b041bbc46178 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp @@ -1,6 +1,7 @@ -#include "init.hpp" #include "common.hpp" +#include "init.hpp" + namespace aztec3::circuits::kernel::public_kernel { void common_initialise_end_values(PublicKernelInputs const& public_kernel_inputs, @@ -48,4 +49,4 @@ void validate_this_public_call_hash(DummyComposer& composer, "calculated public_call_hash does not match provided public_call_hash at the top of the call stack", CircuitErrorCode::PUBLIC_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); }; -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index 901cb7ba6b83..59312ea30a37 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -2,15 +2,15 @@ #include "init.hpp" -#include -#include #include +#include +#include +#include #include #include -#include -#include -#include #include +#include +#include using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::KernelCircuitPublicInputs; @@ -193,9 +193,8 @@ void common_validate_inputs(DummyComposer& composer, KernelInput const& public_k * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_state_transitions(KernelInput const& public_kernel_inputs, - KernelCircuitPublicInputs& circuit_outputs) +template void propagate_valid_state_transitions(KernelInput const& public_kernel_inputs, + KernelCircuitPublicInputs& circuit_outputs) { const auto& contract_address = public_kernel_inputs.public_call.call_stack_item.contract_address; const auto& transitions = public_kernel_inputs.public_call.call_stack_item.public_inputs.state_transitions; @@ -219,9 +218,8 @@ void propagate_valid_state_transitions(KernelInput const& public_kernel_inputs, * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_state_reads(KernelInput const& public_kernel_inputs, - KernelCircuitPublicInputs& circuit_outputs) +template void propagate_valid_state_reads(KernelInput const& public_kernel_inputs, + KernelCircuitPublicInputs& circuit_outputs) { const auto& contract_address = public_kernel_inputs.public_call.call_stack_item.contract_address; const auto& reads = public_kernel_inputs.public_call.call_stack_item.public_inputs.state_reads; @@ -275,4 +273,4 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in void validate_this_public_call_hash(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs); -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/index.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/index.hpp index b470b5c425d9..30d7fc3bd2ed 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/index.hpp @@ -1,4 +1,4 @@ #include "init.hpp" #include "native_public_kernel_circuit_no_previous_kernel.hpp" -#include "native_public_kernel_circuit_public_previous_kernel.hpp" -#include "native_public_kernel_circuit_private_previous_kernel.hpp" \ No newline at end of file +#include "native_public_kernel_circuit_private_previous_kernel.hpp" +#include "native_public_kernel_circuit_public_previous_kernel.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index 8842cffc46b0..c473670ebfaa 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -1,15 +1,12 @@ #pragma once -#include +#include #include - #include - -#include - -#include +#include +#include #include +#include #include -#include namespace aztec3::circuits::kernel::public_kernel { @@ -27,4 +24,4 @@ using DB = oracle::FakeDB; using oracle::NativeOracle; using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.cpp index 5bedee458ffd..daaeeeeb0d65 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.cpp @@ -1,15 +1,15 @@ -#include "aztec3/utils/circuit_errors.hpp" -#include "init.hpp" - -#include -#include #include "native_public_kernel_circuit_no_previous_kernel.hpp" + #include "common.hpp" +#include "init.hpp" +#include "aztec3/constants.hpp" +#include "aztec3/utils/circuit_errors.hpp" +#include +#include +#include #include #include -#include -#include "aztec3/constants.hpp" namespace { @@ -43,7 +43,7 @@ void validate_inputs(DummyComposer& composer, PublicKernelInputsNoPreviousKernel "Storage contract address must be that of the called contract", aztec3::utils::CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_MISMATCH); } -} // namespace +} // namespace namespace aztec3::circuits::kernel::public_kernel { @@ -85,4 +85,4 @@ KernelCircuitPublicInputs native_public_kernel_circuit_no_previous_kernel( return public_inputs; }; -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.hpp index 241d0a13af6f..fff242d92676 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_no_previous_kernel.hpp @@ -1,10 +1,10 @@ #pragma once -#include "init.hpp" #include "common.hpp" +#include "init.hpp" -#include #include +#include #include namespace aztec3::circuits::kernel::public_kernel { @@ -15,4 +15,4 @@ using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_public_kernel_circuit_no_previous_kernel( DummyComposer& composer, PublicKernelInputsNoPreviousKernel const& public_kernel_inputs); -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp index 2b32606c26bf..e00d636a2787 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp @@ -1,14 +1,13 @@ -#include "aztec3/utils/circuit_errors.hpp" +#include "common.hpp" #include "init.hpp" - -#include -#include #include "native_public_kernel_circuit_public_previous_kernel.hpp" -#include "common.hpp" +#include "aztec3/constants.hpp" +#include "aztec3/utils/circuit_errors.hpp" +#include +#include #include #include -#include "aztec3/constants.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; @@ -37,7 +36,7 @@ void validate_inputs(DummyComposer& composer, PublicKernelInputs const& publ "Previous kernel must be private", CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); } -} // namespace +} // namespace namespace aztec3::circuits::kernel::public_kernel { @@ -81,4 +80,4 @@ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kern return public_inputs; }; -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp index e37d278f6892..b7176d8866a8 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp @@ -1,10 +1,10 @@ #pragma once -#include "init.hpp" #include "common.hpp" +#include "init.hpp" -#include #include +#include #include namespace aztec3::circuits::kernel::public_kernel { @@ -15,4 +15,4 @@ using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp index 5db585a00e36..4fb2d5ea6d84 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp @@ -1,17 +1,16 @@ -#include "init.hpp" - -#include -#include #include "native_public_kernel_circuit_public_previous_kernel.hpp" + #include "common.hpp" +#include "init.hpp" +#include "aztec3/constants.hpp" +#include +#include #include #include -#include "aztec3/constants.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; -using aztec3::utils::array_pop; /** * @brief Validates the kernel circuit inputs specific to having a public previous kernel * @param composer The circuit composer @@ -30,7 +29,7 @@ void validate_inputs(DummyComposer& composer, PublicKernelInputs const& publ "Previous kernel must be public", CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); } -} // namespace +} // namespace namespace aztec3::circuits::kernel::public_kernel { @@ -73,4 +72,4 @@ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kerne return public_inputs; }; -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp index eda9c74ad240..b5eaedb894e0 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp @@ -1,10 +1,10 @@ #pragma once -#include "init.hpp" #include "common.hpp" +#include "init.hpp" -#include #include +#include #include namespace aztec3::circuits::kernel::public_kernel { @@ -15,4 +15,4 @@ using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); -} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file +} // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp index 6cfa13c138b3..6d4e0c8e1cef 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include #include +#include namespace aztec3::circuits::mock { @@ -16,4 +16,4 @@ template void mock_circuit(Composer& composer, std::vector::compress(field_t(witness_t(&composer, 1)), field_t(witness_t(&composer, 1))); } -} // namespace aztec3::circuits::mock +} // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index 6b1f68aef260..40eaf5d66764 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -1,12 +1,13 @@ #pragma once +#include +#include +#include + #include #include +#include #include #include -#include -#include -#include -#include // #include namespace { @@ -34,8 +35,8 @@ KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, std::vector dummy_witness_indices; // 16 is the number of values added to `proof_witness_indices` at the end of `verify_proof`. for (size_t i = 0; i < 16; ++i) { - fr witness = fr(witness_t(&composer, i)); - uint32_t witness_index = witness.get_witness_index(); + fr const witness = fr(witness_t(&composer, i)); + uint32_t const witness_index = witness.get_witness_index(); dummy_witness_indices.push_back(witness_index); } public_inputs.end.aggregation_object.proof_witness_indices = dummy_witness_indices; @@ -53,4 +54,4 @@ KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, return public_inputs.template to_native_type(); } -} // namespace aztec3::circuits::mock +} // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index 9dcb4c95af11..d15592a60017 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -1,9 +1,11 @@ #pragma once #include "init.hpp" -#include + #include -#include +#include + #include +#include #include namespace aztec3::circuits::recursion { @@ -15,7 +17,7 @@ class Aggregator { const std::shared_ptr& vk, const NT::Proof& proof, const size_t& num_public_inputs, - const CT::AggregationObject previous_aggregation_output = CT::AggregationObject()) + const CT::AggregationObject& previous_aggregation_output = CT::AggregationObject()) { const Manifest recursive_manifest = Composer::create_manifest(num_public_inputs); @@ -25,4 +27,4 @@ class Aggregator { return result; } }; -} // namespace aztec3::circuits::recursion \ No newline at end of file +} // namespace aztec3::circuits::recursion \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/index.hpp b/circuits/cpp/src/aztec3/circuits/recursion/index.hpp index 73929b9357da..7dcb8cb73aba 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/index.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/index.hpp @@ -1,4 +1,4 @@ -#include "init.hpp" #include "aggregator.hpp" +#include "init.hpp" #include "play_app_circuit.hpp" #include "play_recursive_circuit.hpp" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp index 1a094d0175c3..b1fba0a146c6 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp @@ -1,10 +1,10 @@ #pragma once -#include #include +#include #include -#include #include +#include namespace aztec3::circuits::recursion { // Composer @@ -19,4 +19,4 @@ using aztec3::utils::types::to_ct; using plonk::stdlib::recursion::verify_proof; using transcript::Manifest; -} // namespace aztec3::circuits::recursion \ No newline at end of file +} // namespace aztec3::circuits::recursion \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/play.test.cpp b/circuits/cpp/src/aztec3/circuits/recursion/play.test.cpp index 413254fd157e..349c5d1b06e5 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/play.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/play.test.cpp @@ -1,4 +1,5 @@ #include "index.hpp" + #include // #include @@ -39,7 +40,7 @@ TEST(play_tests, circuit_play_app_proof_gen) } auto app_prover = app_composer.create_prover(); - proof app_proof = app_prover.construct_proof(); + proof const app_proof = app_prover.construct_proof(); info("app_proof: ", app_proof.proof_data); } @@ -53,10 +54,10 @@ TEST(play_tests, circuit_play_recursive_proof_gen) } auto app_prover = app_composer.create_prover(); - proof app_proof = app_prover.construct_proof(); + proof const app_proof = app_prover.construct_proof(); info("app_proof: ", app_proof.proof_data); - std::shared_ptr app_vk = app_composer.compute_verification_key(); + std::shared_ptr const app_vk = app_composer.compute_verification_key(); Composer recursive_composer = Composer("../barretenberg/cpp/srs_db/ignition"); auto aggregation_output = play_recursive_circuit(recursive_composer, app_vk, app_proof); @@ -76,8 +77,8 @@ TEST(play_tests, circuit_play_recursive_2_proof_gen) } auto app_prover = app_composer.create_prover(); - proof app_proof = app_prover.construct_proof(); - std::shared_ptr app_vk = app_composer.compute_verification_key(); + proof const app_proof = app_prover.construct_proof(); + std::shared_ptr const app_vk = app_composer.compute_verification_key(); //******************************************************************************* @@ -89,8 +90,8 @@ TEST(play_tests, circuit_play_recursive_2_proof_gen) } auto dummy_circuit_prover = dummy_circuit_composer.create_prover(); - proof dummy_circuit_proof = dummy_circuit_prover.construct_proof(); - std::shared_ptr dummy_circuit_vk = dummy_circuit_composer.compute_verification_key(); + proof const dummy_circuit_proof = dummy_circuit_prover.construct_proof(); + std::shared_ptr const dummy_circuit_vk = dummy_circuit_composer.compute_verification_key(); //******************************************************************************* @@ -104,9 +105,9 @@ TEST(play_tests, circuit_play_recursive_2_proof_gen) auto recursion_1_prover = recursion_1_composer.create_prover(); - proof recursion_1_proof = recursion_1_prover.construct_proof(); + proof const recursion_1_proof = recursion_1_prover.construct_proof(); - std::shared_ptr recursion_1_vk = recursion_1_composer.compute_verification_key(); + std::shared_ptr const recursion_1_vk = recursion_1_composer.compute_verification_key(); //******************************************************************************* @@ -123,4 +124,4 @@ TEST(play_tests, circuit_play_recursive_2_proof_gen) // std::shared_ptr recursion_2_vk = recursion_2_composer.compute_verification_key(); } -} // namespace aztec3::circuits::recursion \ No newline at end of file +} // namespace aztec3::circuits::recursion \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/play_app_circuit.hpp b/circuits/cpp/src/aztec3/circuits/recursion/play_app_circuit.hpp index a411b38d85b9..e2fbbb3360ad 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/play_app_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/play_app_circuit.hpp @@ -1,5 +1,6 @@ #pragma once #include "init.hpp" + #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -7,13 +8,13 @@ namespace aztec3::circuits::recursion { template void play_app_circuit(Composer& composer, NT::fr const& a_in, NT::fr const& b_in) { - CT::fr a = CT::witness(&composer, a_in); - CT::fr b = CT::witness(&composer, b_in); - CT::fr c = a * b; - CT::fr d = a + b + c; + CT::fr const a = CT::witness(&composer, a_in); + CT::fr const b = CT::witness(&composer, b_in); + CT::fr const c = a * b; + CT::fr const d = a + b + c; a.set_public(); d.set_public(); }; -} // namespace aztec3::circuits::recursion \ No newline at end of file +} // namespace aztec3::circuits::recursion \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/play_recursive_circuit.hpp b/circuits/cpp/src/aztec3/circuits/recursion/play_recursive_circuit.hpp index 3aef7895e708..854ee4a88216 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/play_recursive_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/play_recursive_circuit.hpp @@ -3,11 +3,11 @@ namespace aztec3::circuits::recursion { -CT::AggregationObject play_recursive_circuit(Composer& composer, - std::shared_ptr const& app_vk, - NT::Proof const& app_proof) +inline CT::AggregationObject play_recursive_circuit(Composer& composer, + std::shared_ptr const& app_vk, + NT::Proof const& app_proof) { - std::shared_ptr app_vk_ct = CT::VK::from_witness(&composer, app_vk); + std::shared_ptr const app_vk_ct = CT::VK::from_witness(&composer, app_vk); CT::AggregationObject aggregation_output = Aggregator::aggregate(&composer, app_vk_ct, app_proof, app_vk->num_public_inputs); @@ -17,23 +17,23 @@ CT::AggregationObject play_recursive_circuit(Composer& composer, return aggregation_output; }; -void dummy_circuit(Composer& composer, NT::fr const& a_in, NT::fr const& b_in) +inline void dummy_circuit(Composer& composer, NT::fr const& a_in, NT::fr const& b_in) { - CT::fr a = CT::witness(&composer, a_in); - CT::fr b = CT::witness(&composer, b_in); - CT::fr c = a * b; + CT::fr const a = CT::witness(&composer, a_in); + CT::fr const b = CT::witness(&composer, b_in); + CT::fr const c = a * b; c.set_public(); }; -CT::AggregationObject play_recursive_circuit_2(Composer& composer, - std::shared_ptr const& app_vk, - NT::Proof const& app_proof, - std::shared_ptr const& prev_recursive_vk, - NT::Proof const& prev_recursive_proof) +inline CT::AggregationObject play_recursive_circuit_2(Composer& composer, + std::shared_ptr const& app_vk, + NT::Proof const& app_proof, + std::shared_ptr const& prev_recursive_vk, + NT::Proof const& prev_recursive_proof) { - std::shared_ptr app_vk_ct = CT::VK::from_witness(&composer, app_vk); - std::shared_ptr prev_recursive_vk_ct = CT::VK::from_witness(&composer, prev_recursive_vk); + std::shared_ptr const app_vk_ct = CT::VK::from_witness(&composer, app_vk); + std::shared_ptr const prev_recursive_vk_ct = CT::VK::from_witness(&composer, prev_recursive_vk); info("composer failed 1? ", composer.failed()); @@ -60,4 +60,4 @@ CT::AggregationObject play_recursive_circuit_2(Composer& composer, return aggregation_object; }; -} // namespace aztec3::circuits::recursion \ No newline at end of file +} // namespace aztec3::circuits::recursion \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index a6ee1ca713f8..e983e8f40b22 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -1,49 +1,47 @@ +#include "c_bind.h" +#include "index.hpp" +#include "init.hpp" + #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/new_contract_data.hpp" #include "aztec3/circuits/abis/previous_kernel_data.hpp" #include "aztec3/circuits/abis/public_data_read.hpp" -#include "aztec3/circuits/kernel/private/utils.hpp" #include "aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp" -#include "aztec3/constants.hpp" -#include "barretenberg/crypto/sha256/sha256.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/stdlib/merkle_tree/memory_store.hpp" -#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" - +#include "aztec3/circuits/kernel/private/utils.hpp" #include "aztec3/circuits/rollup/test_utils/utils.hpp" -#include "index.hpp" -#include "init.hpp" -#include "c_bind.h" - -#include -#include - +#include "aztec3/constants.hpp" #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include #include - +#include +#include +#include +#include #include - +#include +#include #include +#include "barretenberg/crypto/sha256/sha256.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/stdlib/merkle_tree/memory_store.hpp" +#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include #include + +#include + #include #include -#include #include #include #include @@ -56,31 +54,11 @@ namespace { -using aztec3::circuits::abis::CallContext; -using aztec3::circuits::abis::CallStackItem; -using aztec3::circuits::abis::ContractDeploymentData; -using aztec3::circuits::abis::FunctionData; -using aztec3::circuits::abis::OptionalPrivateCircuitPublicInputs; -using aztec3::circuits::abis::PrivateCircuitPublicInputs; -using aztec3::circuits::abis::SignedTxRequest; -using aztec3::circuits::abis::TxContext; -using aztec3::circuits::abis::TxRequest; - -using aztec3::circuits::abis::CombinedAccumulatedData; -using aztec3::circuits::abis::CombinedConstantData; -using aztec3::circuits::abis::CombinedHistoricTreeRoots; -using aztec3::circuits::abis::KernelCircuitPublicInputs; + using aztec3::circuits::abis::PreviousKernelData; -using aztec3::circuits::abis::private_kernel::Globals; -using aztec3::circuits::abis::private_kernel::PrivateCallData; -using aztec3::circuits::abis::private_kernel::PrivateInputs; -using aztec3::circuits::apps::test_apps::basic_contract_deployment::constructor; -using aztec3::circuits::apps::test_apps::escrow::deposit; // using aztec3::circuits::mock::mock_circuit; -using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel; -using aztec3::circuits::mock::mock_kernel_circuit; using aztec3::circuits::rollup::test_utils::utils::base_rollup_inputs_from_kernels; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_initial_nullifier_tree; @@ -90,41 +68,37 @@ using aztec3::circuits::rollup::test_utils::utils::set_kernel_nullifiers; using aztec3::circuits::abis::AppendOnlyTreeSnapshot; -using aztec3::circuits::abis::MembershipWitness; -using aztec3::circuits::abis::NullifierLeafPreimage; using aztec3::circuits::rollup::native_base_rollup::BaseOrMergeRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::ConstantRollupData; using aztec3::circuits::rollup::native_base_rollup::NT; -using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::NewContractData; -using aztec3::circuits::abis::OptionallyRevealedData; using aztec3::circuits::rollup::test_utils::utils::make_public_read; using aztec3::circuits::rollup::test_utils::utils::make_public_write; using DummyComposer = aztec3::utils::DummyComposer; -} // namespace +} // namespace namespace aztec3::circuits::rollup::base::native_base_rollup_circuit { class base_rollup_tests : public ::testing::Test { protected: - void run_cbind(BaseRollupInputs& base_rollup_inputs, - BaseOrMergeRollupPublicInputs& expected_public_inputs, - bool compare_pubins = true) + static void run_cbind(BaseRollupInputs& base_rollup_inputs, + BaseOrMergeRollupPublicInputs& expected_public_inputs, + bool compare_pubins = true) { info("Retesting via cbinds...."); // TODO might be able to get rid of proving key buffer - uint8_t const* pk_buf; - size_t pk_size = base_rollup__init_proving_key(&pk_buf); + uint8_t const* pk_buf = nullptr; + size_t const pk_size = base_rollup__init_proving_key(&pk_buf); (void)pk_size; // info("Proving key size: ", pk_size); // TODO might be able to get rid of verification key buffer - uint8_t const* vk_buf; - size_t vk_size = base_rollup__init_verification_key(pk_buf, &vk_buf); + uint8_t const* vk_buf = nullptr; + size_t const vk_size = base_rollup__init_verification_key(pk_buf, &vk_buf); (void)vk_size; // info("Verification key size: ", vk_size); @@ -133,9 +107,9 @@ class base_rollup_tests : public ::testing::Test { // uint8_t const* proof_data; // size_t proof_data_size; - uint8_t const* public_inputs_buf; + uint8_t const* public_inputs_buf = nullptr; // info("simulating circuit via cbind"); - size_t public_inputs_size = base_rollup__sim(base_rollup_inputs_vec.data(), &public_inputs_buf); + size_t const public_inputs_size = base_rollup__sim(base_rollup_inputs_vec.data(), &public_inputs_buf); // info("Proof size: ", proof_data_size); // info("PublicInputs size: ", public_inputs_size); @@ -183,11 +157,11 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, emptyInputs); - AppendOnlyTreeSnapshot expectedStartContractTreeSnapshot = { + AppendOnlyTreeSnapshot const expectedStartContractTreeSnapshot = { .root = empty_contract_tree.root(), .next_available_leaf_index = 0, }; - AppendOnlyTreeSnapshot expectedEndContractTreeSnapshot = { + AppendOnlyTreeSnapshot const expectedEndContractTreeSnapshot = { .root = empty_contract_tree.root(), .next_available_leaf_index = 2, }; @@ -212,7 +186,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted) }; auto empty_contract_tree = native_base_rollup::MerkleTree(CONTRACT_TREE_HEIGHT); - AppendOnlyTreeSnapshot expected_start_contracts_snapshot = { + AppendOnlyTreeSnapshot const expected_start_contracts_snapshot = { .root = empty_contract_tree.root(), .next_available_leaf_index = 0, }; @@ -224,7 +198,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted) auto expected_end_contracts_snapshot_tree = stdlib::merkle_tree::MemoryTree(CONTRACT_TREE_HEIGHT); expected_end_contracts_snapshot_tree.update_element(0, expected_contract_leaf); - AppendOnlyTreeSnapshot expected_end_contracts_snapshot = { + AppendOnlyTreeSnapshot const expected_end_contracts_snapshot = { .root = expected_end_contracts_snapshot_tree.root(), .next_available_leaf_index = 2, }; @@ -281,7 +255,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr auto expected_end_contracts_snapshot_tree = start_contract_tree_snapshot; expected_end_contracts_snapshot_tree.update_element(12, expected_contract_leaf); - AppendOnlyTreeSnapshot expected_end_contracts_snapshot = { + AppendOnlyTreeSnapshot const expected_end_contracts_snapshot = { .root = expected_end_contracts_snapshot_tree.root(), .next_available_leaf_index = 14, }; @@ -312,14 +286,14 @@ TEST_F(base_rollup_tests, native_new_commitments_tree) // get sibling path auto private_data_tree = native_base_rollup::MerkleTree(PRIVATE_DATA_TREE_HEIGHT); - AppendOnlyTreeSnapshot expected_start_commitments_snapshot = { + AppendOnlyTreeSnapshot const expected_start_commitments_snapshot = { .root = private_data_tree.root(), .next_available_leaf_index = 0, }; for (size_t i = 0; i < new_commitments.size(); ++i) { private_data_tree.update_element(i, new_commitments[i]); } - AppendOnlyTreeSnapshot expected_end_commitments_snapshot = { + AppendOnlyTreeSnapshot const expected_end_commitments_snapshot = { .root = private_data_tree.root(), .next_available_leaf_index = 8, }; @@ -358,7 +332,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) // This is because 0 values are not actually inserted into the tree, rather the inserted subtree is left // empty to begin with. - std::array new_nullifiers = { 0, 0, 0, 0, 0, 0, 0, 0 }; + std::array const new_nullifiers = { 0, 0, 0, 0, 0, 0, 0, 0 }; auto nullifier_tree = get_initial_nullifier_tree({ 1, 2, 3, 4, 5, 6, 7 }); auto start_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); for (auto v : new_nullifiers) { @@ -370,10 +344,10 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) * RUN */ DummyComposer composer = DummyComposer(); - std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; - BaseRollupInputs empty_inputs = base_rollup_inputs_from_kernels(kernel_data); + std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; + BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels(kernel_data); - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, empty_inputs); /** @@ -411,9 +385,9 @@ void nullifier_insertion_test(std::array n } set_kernel_nullifiers(kernel_data[i], kernel_nullifiers); } - BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); + BaseRollupInputs const inputs = base_rollup_inputs_from_kernels(kernel_data); - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); /** * ASSERT @@ -440,8 +414,8 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) /** * DESCRIPTION */ - std::vector initial_values = { 5, 10, 15, 20, 25, 30, 35 }; - std::array nullifiers = { 6, 11, 16, 21, 26, 31, 36, 41 }; + std::vector const initial_values = { 5, 10, 15, 20, 25, 30, 35 }; + std::array const nullifiers = { 6, 11, 16, 21, 26, 31, 36, 41 }; auto nullifier_tree = get_initial_nullifier_tree(initial_values); auto expected_start_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); @@ -451,18 +425,18 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) auto expected_end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); DummyComposer composer = DummyComposer(); - BaseRollupInputs empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); + BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values_explicit(empty_inputs, nullifiers, initial_values); - BaseRollupInputs testing_inputs = std::get<0>(inputs_and_snapshots); + BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); /** * RUN */ // Run the circuit - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); /** @@ -507,13 +481,13 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) /** * RUN */ - BaseRollupInputs empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); + BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values_explicit( empty_inputs, new_nullifiers, initial_values); - BaseRollupInputs testing_inputs = std::get<0>(inputs_and_snapshots); + BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); // Run the circuit - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); /** @@ -558,14 +532,14 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) */ DummyComposer composer = DummyComposer(); - BaseRollupInputs empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); + BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); - std::array new_nullifiers = { 11, 0, 11, 0, 0, 0, 0, 0 }; + std::array const new_nullifiers = { 11, 0, 11, 0, 0, 0, 0, 0 }; std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values(empty_inputs, new_nullifiers, 1); - BaseRollupInputs testing_inputs = std::get<0>(inputs_and_snapshots); + BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); ASSERT_TRUE(composer.failed()); @@ -576,7 +550,7 @@ TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { DummyComposer composer = DummyComposer(); // calldata_hash should be computed from leafs of 704 0 bytes. (0x00) - std::vector zero_bytes_vec(704, 0); + std::vector const zero_bytes_vec(704, 0); auto hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = @@ -610,21 +584,21 @@ TEST_F(base_rollup_tests, native_calldata_hash) // nullifier leaf for (uint8_t i = 0; i < 4; ++i) { // nullifiers - input_data[i * 32 + 31] = i + 8; // 8 + input_data[i * 32 + 31] = i + 8; // 8 kernel_data[0].public_inputs.end.new_nullifiers[i] = fr(i + 8); // commitments - input_data[8 * 32 + i * 32 + 31] = i + 1; // 1 + input_data[8 * 32 + i * 32 + 31] = i + 1; // 1 kernel_data[0].public_inputs.end.new_commitments[i] = fr(i + 1); } // Kernel 2 for (uint8_t i = 0; i < 4; ++i) { // nullifiers - input_data[(i + 4) * 32 + 31] = i + 12; // 1 + input_data[(i + 4) * 32 + 31] = i + 12; // 1 kernel_data[1].public_inputs.end.new_nullifiers[i] = fr(i + 12); // commitments - input_data[8 * 32 + (i + 4) * 32 + 31] = i + 4 + 1; // 1 + input_data[8 * 32 + (i + 4) * 32 + 31] = i + 4 + 1; // 1 kernel_data[1].public_inputs.end.new_commitments[i] = fr(i + 4 + 1); } @@ -676,7 +650,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati // Test membership works for empty trees DummyComposer composer = DummyComposer(); - std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; + std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); auto private_data_tree = native_base_rollup::MerkleTree(PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT); @@ -692,7 +666,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati .sibling_path = sibling_path, }; - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_TRUE(composer.failed()); @@ -703,7 +677,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat { // Test membership works for empty trees DummyComposer composer = DummyComposer(); - std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; + std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); auto contract_tree = native_base_rollup::MerkleTree(CONTRACT_TREE_ROOTS_TREE_HEIGHT); @@ -719,7 +693,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat .sibling_path = sibling_path, }; - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_TRUE(composer.failed()); @@ -742,7 +716,7 @@ TEST_F(base_rollup_tests, native_aggregate) // TODO: Fix this when aggregation works DummyComposer composer = DummyComposer(); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); - BaseOrMergeRollupPublicInputs outputs = + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.kernel_data[0].public_inputs.end.aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); @@ -752,8 +726,8 @@ TEST_F(base_rollup_tests, native_aggregate) TEST_F(base_rollup_tests, native_subtree_height_is_0) { DummyComposer composer = DummyComposer(); - BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); - BaseOrMergeRollupPublicInputs outputs = + BaseRollupInputs const inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); + BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.rollup_subtree_height, fr(0)); ASSERT_FALSE(composer.failed()); @@ -892,4 +866,4 @@ TEST_F(base_rollup_tests, native_invalid_public_state_read) run_cbind(inputs, outputs); } -} // namespace aztec3::circuits::rollup::base::native_base_rollup_circuit +} // namespace aztec3::circuits::rollup::base::native_base_rollup_circuit diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 4cc5922c763d..927c4d758534 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -1,21 +1,21 @@ -#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "c_bind.h" + #include "index.hpp" #include "init.hpp" -#include "c_bind.h" -#include -#include -#include "aztec3/circuits/abis/signed_tx_request.hpp" #include "aztec3/circuits/abis/private_kernel/private_call_data.hpp" -#include +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/signed_tx_request.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include +#include #include - -#include "barretenberg/srs/reference_string/env_reference_string.hpp" +#include +#include #include "barretenberg/common/serialize.hpp" #include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/srs/reference_string/env_reference_string.hpp" namespace { using Composer = plonk::UltraComposer; @@ -25,7 +25,7 @@ using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; -} // namespace +} // namespace #define WASM_EXPORT __attribute__((visibility("default"))) // WASM Cbinds @@ -35,7 +35,7 @@ WASM_EXPORT size_t base_rollup__init_proving_key(uint8_t const** pk_buf) { std::vector pk_vec(42, 0); - auto raw_buf = (uint8_t*)malloc(pk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(pk_vec.size()); memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size()); *pk_buf = raw_buf; @@ -46,9 +46,9 @@ WASM_EXPORT size_t base_rollup__init_verification_key(uint8_t const* pk_buf, uin { std::vector vk_vec(42, 0); // TODO remove when proving key is used - (void)pk_buf; // unused + (void)pk_buf; // unused - auto raw_buf = (uint8_t*)malloc(vk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(vk_vec.size()); memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size()); *vk_buf = raw_buf; @@ -67,7 +67,7 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, BaseRollupInputs base_rollup_inputs; read(base_rollup_inputs_buf, base_rollup_inputs); - BaseOrMergeRollupPublicInputs public_inputs = base_rollup_circuit(composer, base_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = base_rollup_circuit(composer, base_rollup_inputs); // TODO for circuit proof version of this function // NT::Proof base_rollup_proof; @@ -80,7 +80,7 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *base_or_merge_rollup_public_inputs_buf = raw_public_inputs_buf; @@ -139,4 +139,4 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, // return true; // } -} // extern "C" \ No newline at end of file +} // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp index b88681081b0a..37cc215eebec 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -2,25 +2,25 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" -#include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" +#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/utils/circuit_errors.hpp" +#include "aztec3/utils/dummy_composer.hpp" +#include +#include +#include +#include +#include +#include + #include "barretenberg/stdlib/merkle_tree/memory_store.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "barretenberg/stdlib/merkle_tree/merkle_tree.hpp" #include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp" -#include -#include -#include "aztec3/utils/dummy_composer.hpp" - #include -#include #include -#include -#include -#include -#include +#include namespace aztec3::circuits::rollup::native_base_rollup { @@ -43,4 +43,4 @@ using NullifierTree = stdlib::merkle_tree::NullifierMemoryTree; using NullifierLeaf = stdlib::merkle_tree::nullifier_leaf; using SparseTree = stdlib::merkle_tree::MerkleTree; -} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index 6d532b4ed853..e26362b67753 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -1,9 +1,16 @@ +#include "init.hpp" + #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/public_data_read.hpp" #include "aztec3/circuits/abis/public_data_transition.hpp" #include "aztec3/circuits/hash.hpp" +#include "aztec3/circuits/rollup/components/components.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/circuit_errors.hpp" +#include +#include +#include + #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" @@ -11,26 +18,20 @@ #include "barretenberg/stdlib/merkle_tree/membership.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "barretenberg/stdlib/merkle_tree/merkle_tree.hpp" -#include "init.hpp" -#include "aztec3/circuits/rollup/components/components.hpp" #include #include -#include -#include -#include #include #include #include #include -using aztec3::circuits::check_membership; namespace aztec3::circuits::rollup::native_base_rollup { NT::fr calculate_empty_tree_root(const size_t depth) { - MerkleTree empty_tree = MerkleTree(depth); + MerkleTree const empty_tree = MerkleTree(depth); return empty_tree.root(); } @@ -53,7 +54,6 @@ bool verify_kernel_proof(NT::Proof const& kernel_proof) */ AggregationObject aggregate_proofs(BaseRollupInputs const& baseRollupInputs) { - // TODO: NOTE: for now we simply return the aggregation object from the first proof return baseRollupInputs.kernel_data[0].public_inputs.end.aggregation_object; } @@ -70,20 +70,17 @@ NT::fr get_prover_contribution_hash() std::vector calculate_contract_leaves(BaseRollupInputs const& baseRollupInputs) { - std::vector contract_leaves; for (size_t i = 0; i < 2; i++) { - auto new_contacts = baseRollupInputs.kernel_data[i].public_inputs.end.new_contracts; // loop over the new contracts // TODO: NOTE: we are currently assuming that there is only going to be one - for (size_t j = 0; j < new_contacts.size(); j++) { - - NT::address contract_address = new_contacts[j].contract_address; - NT::address portal_contract_address = new_contacts[j].portal_contract_address; - NT::fr function_tree_root = new_contacts[j].function_tree_root; + for (auto& new_contact : new_contacts) { + NT::address contract_address = new_contact.contract_address; + NT::address portal_contract_address = new_contact.portal_contract_address; + NT::fr const function_tree_root = new_contact.function_tree_root; // Pedersen hash of the 3 fields (contract_address, portal_contract_address, function_tree_root) auto contract_leaf = crypto::pedersen_commitment::compress_native( @@ -116,12 +113,11 @@ NT::fr calculate_contract_subtree(std::vector contract_leaves) NT::fr calculate_commitments_subtree(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { // Leaves that will be added to the new trees - std::array commitment_leaves; + std::array const commitment_leaves; MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_DEPTH); for (size_t i = 0; i < 2; i++) { - auto new_commitments = baseRollupInputs.kernel_data[i].public_inputs.end.new_commitments; // Our commitments size MUST be 4 to calculate our subtrees correctly @@ -180,13 +176,14 @@ std::array calculate_calldata_hash(BaseRollupInputs const& baseRollup std::copy(as_bytes.begin(), as_bytes.end(), calldata_hash_inputs_bytes.begin() + offset); } // TODO: double check this gpt code - std::vector calldata_hash_inputs_bytes_vec(calldata_hash_inputs_bytes.begin(), - calldata_hash_inputs_bytes.end()); + std::vector const calldata_hash_inputs_bytes_vec(calldata_hash_inputs_bytes.begin(), + calldata_hash_inputs_bytes.end()); auto h = sha256::sha256(calldata_hash_inputs_bytes_vec); // Split the hash into two fields, a high and a low - std::array buf_1, buf_2; + std::array buf_1; + std::array buf_2; for (uint8_t i = 0; i < 16; i++) { buf_1[i] = 0; buf_1[16 + i] = h[i]; @@ -213,10 +210,10 @@ void perform_historical_private_data_tree_membership_checks(DummyComposer& compo auto historic_root = baseRollupInputs.constants.start_tree_of_historic_private_data_tree_roots_snapshot.root; for (size_t i = 0; i < 2; i++) { - NT::fr leaf = + NT::fr const leaf = baseRollupInputs.kernel_data[i] .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root; - abis::MembershipWitness historic_root_witness = + abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_private_data_tree_root_membership_witnesses[i]; check_membership(composer, @@ -234,9 +231,10 @@ void perform_historical_contract_data_tree_membership_checks(DummyComposer& comp auto historic_root = baseRollupInputs.constants.start_tree_of_historic_contract_tree_roots_snapshot.root; for (size_t i = 0; i < 2; i++) { - NT::fr leaf = baseRollupInputs.kernel_data[i] - .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.contract_tree_root; - abis::MembershipWitness historic_root_witness = + NT::fr const leaf = + baseRollupInputs.kernel_data[i] + .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.contract_tree_root; + abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_contract_tree_root_membership_witnesses[i]; check_membership(composer, @@ -298,11 +296,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC // For each kernel circuit for (size_t i = 0; i < 2; i++) { - auto new_nullifiers = baseRollupInputs.kernel_data[i].public_inputs.end.new_nullifiers; // For each of our nullifiers for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { - // Witness containing index and path auto nullifier_index = 4 * i + j; @@ -314,7 +310,6 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC // TODO: reason about this more strongly, can this cause issues? if (nullifier != 0) { - // Create the nullifier leaf of the new nullifier to be inserted NullifierLeaf new_nullifier_leaf = { .value = nullifier, @@ -336,7 +331,6 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC if ((uint256_t(nullifier_insertion_subtree[k].value) < uint256_t(nullifier)) && (uint256_t(nullifier_insertion_subtree[k].nextValue) > uint256_t(nullifier) || nullifier_insertion_subtree[k].nextValue == 0)) { - matched = true; // Update pointers new_nullifier_leaf.nextIndex = nullifier_insertion_subtree[k].nextIndex; @@ -365,7 +359,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC } // Recreate the original low nullifier from the preimage - NullifierLeaf original_low_nullifier = NullifierLeaf{ + auto const original_low_nullifier = NullifierLeaf{ .value = low_nullifier_preimage.leaf_value, .nextIndex = low_nullifier_preimage.next_index, .nextValue = low_nullifier_preimage.next_value, @@ -380,9 +374,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC "low nullifier membership check"); // Calculate the new value of the low_nullifier_leaf - NullifierLeaf updated_low_nullifier = NullifierLeaf{ .value = low_nullifier_preimage.leaf_value, - .nextIndex = new_index, - .nextValue = nullifier }; + auto const updated_low_nullifier = NullifierLeaf{ .value = low_nullifier_preimage.leaf_value, + .nextIndex = new_index, + .nextValue = nullifier }; // We need another set of witness values for this current_nullifier_tree_root = root_from_sibling_path( @@ -392,7 +386,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC nullifier_insertion_subtree[nullifier_index] = new_nullifier_leaf; } else { // 0 case - NullifierLeaf new_nullifier_leaf = { + NullifierLeaf const new_nullifier_leaf = { .value = 0, .nextIndex = 0, .nextValue = 0, @@ -445,8 +439,9 @@ fr insert_state_transitions( const auto& state_write = state_transitions[i]; const auto& witness = witnesses[i + witnesses_offset]; - if (state_write.is_empty()) + if (state_write.is_empty()) { continue; + } composer.do_assert( witness.leaf_index == state_write.leaf_index, @@ -477,8 +472,9 @@ void validate_state_reads( const auto& state_read = state_reads[i]; const auto& witness = witnesses[i + witnesses_offset]; - if (state_read.is_empty()) + if (state_read.is_empty()) { continue; + } composer.do_assert( witness.leaf_index == state_read.leaf_index, @@ -531,18 +527,18 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseR { // Verify the previous kernel proofs for (size_t i = 0; i < 2; i++) { - NT::Proof proof = baseRollupInputs.kernel_data[i].proof; + NT::Proof const proof = baseRollupInputs.kernel_data[i].proof; composer.do_assert(verify_kernel_proof(proof), "kernel proof verification failed", CircuitErrorCode::BASE__KERNEL_PROOF_VERIFICATION_FAILED); } // First we compute the contract tree leaves - std::vector contract_leaves = calculate_contract_leaves(baseRollupInputs); + std::vector const contract_leaves = calculate_contract_leaves(baseRollupInputs); // Check contracts and commitments subtrees - NT::fr contracts_tree_subroot = calculate_contract_subtree(contract_leaves); - NT::fr commitments_tree_subroot = calculate_commitments_subtree(composer, baseRollupInputs); + NT::fr const contracts_tree_subroot = calculate_contract_subtree(contract_leaves); + NT::fr const commitments_tree_subroot = calculate_commitments_subtree(composer, baseRollupInputs); // Insert commitment subtrees: const auto empty_commitments_subtree_root = calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH); @@ -567,20 +563,20 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseR "empty contract subtree membership check"); // Insert nullifiers: - AppendOnlySnapshot end_nullifier_tree_snapshot = + AppendOnlySnapshot const end_nullifier_tree_snapshot = check_nullifier_tree_non_membership_and_insert_to_tree(composer, baseRollupInputs); // Validate public state reads and transitions, and update public data tree - fr end_public_data_tree_root = validate_and_process_public_state(composer, baseRollupInputs); + fr const end_public_data_tree_root = validate_and_process_public_state(composer, baseRollupInputs); // Calculate the overall calldata hash - std::array calldata_hash = calculate_calldata_hash(baseRollupInputs, contract_leaves); + std::array const calldata_hash = calculate_calldata_hash(baseRollupInputs, contract_leaves); // Perform membership checks that the notes provided exist within the historic trees data perform_historical_private_data_tree_membership_checks(composer, baseRollupInputs); perform_historical_contract_data_tree_membership_checks(composer, baseRollupInputs); - AggregationObject aggregation_object = aggregate_proofs(baseRollupInputs); + AggregationObject const aggregation_object = aggregate_proofs(baseRollupInputs); BaseOrMergeRollupPublicInputs public_inputs = { .rollup_type = abis::BASE_ROLLUP_TYPE, @@ -600,4 +596,4 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseR return public_inputs; } -} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp index cb4aba80d166..75ee5676fdb8 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp @@ -3,17 +3,16 @@ #include "init.hpp" // TODO: not needed right at this moment for native impl -#include -#include -#include - -#include #include -#include +#include #include +#include +#include +#include +#include namespace aztec3::circuits::rollup::native_base_rollup { BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs); -} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp index 7e100e7b62d5..8f776438660d 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp @@ -1,11 +1,13 @@ +#include "init.hpp" + #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/circuit_errors.hpp" + #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" -#include "init.hpp" #include #include @@ -100,12 +102,13 @@ std::array compute_calldata_hash(std::array, } // Compute the sha256 - std::vector calldata_hash_input_bytes_vec(calldata_hash_input_bytes.begin(), - calldata_hash_input_bytes.end()); + std::vector const calldata_hash_input_bytes_vec(calldata_hash_input_bytes.begin(), + calldata_hash_input_bytes.end()); auto h = sha256::sha256(calldata_hash_input_bytes_vec); // Split the hash into two fields, a high and a low - std::array buf_1, buf_2; + std::array buf_1; + std::array buf_2; for (uint8_t i = 0; i < 16; i++) { buf_1[i] = 0; buf_1[16 + i] = h[i]; @@ -138,4 +141,4 @@ void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer, utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); } -} // namespace aztec3::circuits::rollup::components \ No newline at end of file +} // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp index 05f82f2effbb..f6df9f8a8a7c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp @@ -1,8 +1,9 @@ #pragma once -#include "aztec3/utils/circuit_errors.hpp" #include "init.hpp" +#include "aztec3/utils/circuit_errors.hpp" + using aztec3::circuits::check_membership; using aztec3::circuits::root_from_sibling_path; @@ -24,14 +25,13 @@ void assert_equal_constants(DummyComposer& composer, AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -template -AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyComposer& composer, - AppendOnlySnapshot snapshot, - std::array siblingPath, - NT::fr emptySubtreeRoot, - NT::fr subtreeRootToInsert, - uint8_t subtreeDepth, - std::string const& message) +template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyComposer& composer, + AppendOnlySnapshot snapshot, + std::array siblingPath, + NT::fr emptySubtreeRoot, + NT::fr subtreeRootToInsert, + uint8_t subtreeDepth, + std::string const& message) { // TODO: Sanity check len of siblingPath > height of subtree // TODO: Ensure height of subtree is correct (eg 3 for commitments, 1 for contracts) @@ -44,10 +44,10 @@ AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyComposer& composer, auto new_root = root_from_sibling_path(subtreeRootToInsert, leafIndexAtDepth, siblingPath); // 2^subtreeDepth is the number of leaves added. 2^x = 1 << x - auto new_next_available_leaf_index = snapshot.next_available_leaf_index + (uint8_t(1) << subtreeDepth); + auto new_next_available_leaf_index = snapshot.next_available_leaf_index + (static_cast(1) << subtreeDepth); AppendOnlySnapshot newTreeSnapshot = { .root = new_root, .next_available_leaf_index = new_next_available_leaf_index }; return newTreeSnapshot; } -} // namespace aztec3::circuits::rollup::components \ No newline at end of file +} // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp index 78bd878c9766..24e55ccbeb91 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp @@ -2,19 +2,19 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" -#include -#include #include "aztec3/utils/dummy_composer.hpp" +#include #include - -#include -#include +#include #include +#include #include +#include + namespace aztec3::circuits::rollup::components { using NT = aztec3::utils::types::NativeTypes; @@ -26,4 +26,4 @@ using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupP using AppendOnlySnapshot = abis::AppendOnlyTreeSnapshot; using DummyComposer = aztec3::utils::DummyComposer; -} // namespace aztec3::circuits::rollup::components \ No newline at end of file +} // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index fc868f32344a..cf60efb24446 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -1,46 +1,43 @@ -#include -#include -#include "aztec3/circuits/rollup/merge/init.hpp" #include "c_bind.h" -#include "aztec3/circuits/rollup/test_utils/utils.hpp" #include "index.hpp" #include "init.hpp" +#include "aztec3/circuits/rollup/merge/init.hpp" +#include "aztec3/circuits/rollup/test_utils/utils.hpp" + +#include + +#include + namespace { -using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; -using aztec3::circuits::rollup::merge::merge_rollup_circuit; using aztec3::circuits::rollup::merge::MergeRollupInputs; using DummyComposer = aztec3::utils::DummyComposer; -using aztec3::circuits::rollup::test_utils::utils::base_rollup_inputs_from_kernels; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; -using aztec3::circuits::rollup::test_utils::utils::get_initial_nullifier_tree; using aztec3::circuits::rollup::test_utils::utils::get_merge_rollup_inputs; -using aztec3::circuits::rollup::test_utils::utils::set_kernel_commitments; -using aztec3::circuits::rollup::test_utils::utils::set_kernel_nullifiers; using NT = aztec3::utils::types::NativeTypes; using KernelData = aztec3::circuits::abis::PreviousKernelData; -} // namespace +} // namespace namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit { class merge_rollup_tests : public ::testing::Test { protected: - void run_cbind(MergeRollupInputs& merge_rollup_inputs, - BaseOrMergeRollupPublicInputs& expected_public_inputs, - bool compare_pubins = true) + static void run_cbind(MergeRollupInputs& merge_rollup_inputs, + BaseOrMergeRollupPublicInputs& expected_public_inputs, + bool compare_pubins = true) { info("Retesting via cbinds...."); std::vector merge_rollup_inputs_vec; write(merge_rollup_inputs_vec, merge_rollup_inputs); - uint8_t const* public_inputs_buf; + uint8_t const* public_inputs_buf = nullptr; // info("simulating circuit via cbind"); - size_t public_inputs_size; + size_t public_inputs_size = 0; info("creating proof"); - auto circuit_failure_ptr = + auto* circuit_failure_ptr = merge_rollup__sim(merge_rollup_inputs_vec.data(), &public_inputs_size, &public_inputs_buf); ASSERT_TRUE(circuit_failure_ptr == nullptr); // info("PublicInputs size: ", public_inputs_size); @@ -73,7 +70,7 @@ class merge_rollup_tests : public ::testing::Test { TEST_F(merge_rollup_tests, native_different_rollup_type_fails) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); @@ -87,7 +84,7 @@ TEST_F(merge_rollup_tests, native_different_rollup_type_fails) TEST_F(merge_rollup_tests, native_different_rollup_height_fails) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); @@ -101,7 +98,7 @@ TEST_F(merge_rollup_tests, native_different_rollup_height_fails) TEST_F(merge_rollup_tests, native_constants_different_failure) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); @@ -115,10 +112,10 @@ TEST_F(merge_rollup_tests, native_constants_different_failure) TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) { DummyComposer composerA = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composerA, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(composerA, kernels); auto inputA = inputs; inputA.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -162,7 +159,7 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); @@ -189,11 +186,11 @@ TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) TEST_F(merge_rollup_tests, native_start_and_end_snapshots) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); // check that start and end snapshots are set correctly ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot); @@ -221,7 +218,7 @@ TEST_F(merge_rollup_tests, native_start_and_end_snapshots) TEST_F(merge_rollup_tests, native_calldata_hash) { DummyComposer composer = DummyComposer(); - std::vector zero_bytes_vec(704, 0); + std::vector const zero_bytes_vec(704, 0); auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); std::array hash_input; @@ -230,16 +227,16 @@ TEST_F(merge_rollup_tests, native_calldata_hash) hash_input[32 + i] = call_data_hash_inner[i]; } - std::vector calldata_hash_input_bytes_vec(hash_input.begin(), hash_input.end()); + std::vector const calldata_hash_input_bytes_vec(hash_input.begin(), hash_input.end()); auto expected_calldata_hash = sha256::sha256(calldata_hash_input_bytes_vec); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); std::array actual_calldata_hash_fr = outputs.calldata_hash; auto high_buffer = actual_calldata_hash_fr[0].to_buffer(); @@ -258,12 +255,12 @@ TEST_F(merge_rollup_tests, native_calldata_hash) TEST_F(merge_rollup_tests, native_constants_dont_change) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants, outputs.constants); ASSERT_EQ(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants, outputs.constants); } @@ -272,12 +269,12 @@ TEST_F(merge_rollup_tests, native_aggregate) { // TODO: Fix this when aggregation works DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); ASSERT_FALSE(composer.failed()); @@ -286,7 +283,7 @@ TEST_F(merge_rollup_tests, native_aggregate) TEST_F(merge_rollup_tests, native_merge_cbind) { DummyComposer composer = DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); @@ -295,4 +292,4 @@ TEST_F(merge_rollup_tests, native_merge_cbind) BaseOrMergeRollupPublicInputs ignored_public_inputs; run_cbind(inputs, ignored_public_inputs, false); } -} // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit +} // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index 188d2e2d596b..c11810119aee 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -1,7 +1,9 @@ -#include "aztec3/utils/dummy_composer.hpp" -#include "index.hpp" #include "c_bind.h" +#include "index.hpp" + +#include "aztec3/utils/dummy_composer.hpp" + namespace { using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; @@ -9,7 +11,7 @@ using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::rollup::merge::merge_rollup_circuit; -} // namespace +} // namespace #define WASM_EXPORT __attribute__((visibility("default"))) // WASM Cbinds extern "C" { @@ -22,13 +24,13 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, MergeRollupInputs merge_rollup_inputs; read(merge_rollup_inputs_buf, merge_rollup_inputs); - BaseOrMergeRollupPublicInputs public_inputs = merge_rollup_circuit(composer, merge_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(composer, merge_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *merge_rollup_public_inputs_buf = raw_public_inputs_buf; *merge_rollup_public_inputs_size_out = public_inputs_vec.size(); @@ -38,4 +40,4 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, } return composer.alloc_and_serialize_first_failure(); } -} // extern "C" \ No newline at end of file +} // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp index 90a8537f903c..65b3f92b5f1f 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -2,18 +2,18 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" -#include -#include #include "aztec3/utils/dummy_composer.hpp" - -#include -#include +#include +#include #include +#include #include +#include + namespace aztec3::circuits::rollup::merge { using NT = aztec3::utils::types::NativeTypes; @@ -29,4 +29,4 @@ using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = utils::types::NativeTypes::AggregationObject; using AppendOnlySnapshot = abis::AppendOnlyTreeSnapshot; -} // namespace aztec3::circuits::rollup::merge \ No newline at end of file +} // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp index 3ab89a8157d2..58dcb6f2f63c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp @@ -1,11 +1,12 @@ #include "init.hpp" + +#include + #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" -#include - #include #include #include @@ -26,7 +27,7 @@ BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, Merg // check that both input proofs are either both "BASE" or "MERGE" and not a mix! // this prevents having wonky commitment, nullifier and contract subtrees. - AggregationObject aggregation_object = components::aggregate_proofs(left, right); + AggregationObject const aggregation_object = components::aggregate_proofs(left, right); components::assert_both_input_proofs_of_same_rollup_type(composer, left, right); auto current_height = components::assert_both_input_proofs_of_same_height_and_return(composer, left, right); components::assert_equal_constants(composer, left, right); @@ -54,4 +55,4 @@ BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, Merg return public_inputs; } -} // namespace aztec3::circuits::rollup::merge \ No newline at end of file +} // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp index c9980cfefb4c..419f0310a66a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp @@ -4,4 +4,4 @@ namespace aztec3::circuits::rollup::merge { BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, MergeRollupInputs const& mergeRollupInputs); -} // namespace aztec3::circuits::rollup::merge \ No newline at end of file +} // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 68d5479c528a..ddef42ee5f74 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -1,126 +1,98 @@ +#include "c_bind.h" +#include "index.hpp" +#include "init.hpp" + #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/new_contract_data.hpp" #include "aztec3/circuits/abis/previous_kernel_data.hpp" #include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp" +#include "aztec3/circuits/kernel/private/utils.hpp" #include "aztec3/circuits/rollup/base/init.hpp" -#include "aztec3/circuits/rollup/test_utils/utils.hpp" #include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" -#include "aztec3/circuits/kernel/private/utils.hpp" +#include "aztec3/circuits/rollup/test_utils/utils.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/dummy_composer.hpp" -#include "barretenberg/crypto/sha256/sha256.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" -#include "index.hpp" -#include "init.hpp" -#include "c_bind.h" - -#include -#include - #include #include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include +#include #include -#include #include - +#include +#include +#include +#include #include - +#include +#include #include +#include "barretenberg/crypto/sha256/sha256.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include #include -#include + #include + +#include #include #include #include namespace { -using aztec3::circuits::abis::CallContext; -using aztec3::circuits::abis::CallStackItem; -using aztec3::circuits::abis::ContractDeploymentData; -using aztec3::circuits::abis::FunctionData; -using aztec3::circuits::abis::OptionalPrivateCircuitPublicInputs; -using aztec3::circuits::abis::PrivateCircuitPublicInputs; -using aztec3::circuits::abis::SignedTxRequest; -using aztec3::circuits::abis::TxContext; -using aztec3::circuits::abis::TxRequest; - -using aztec3::circuits::abis::CombinedAccumulatedData; -using aztec3::circuits::abis::CombinedConstantData; -using aztec3::circuits::abis::CombinedHistoricTreeRoots; -using aztec3::circuits::abis::KernelCircuitPublicInputs; + using aztec3::circuits::abis::PreviousKernelData; -using aztec3::circuits::abis::PrivateHistoricTreeRoots; -using aztec3::circuits::abis::private_kernel::Globals; -using aztec3::circuits::abis::private_kernel::PrivateCallData; -using aztec3::circuits::abis::private_kernel::PrivateInputs; -using aztec3::circuits::apps::test_apps::basic_contract_deployment::constructor; -using aztec3::circuits::apps::test_apps::escrow::deposit; // using aztec3::circuits::mock::mock_circuit; -using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel; -using aztec3::circuits::mock::mock_kernel_circuit; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_root_rollup_inputs; using aztec3::circuits::rollup::test_utils::utils::set_kernel_commitments; -using aztec3::circuits::rollup::test_utils::utils::set_kernel_nullifiers; // using aztec3::circuits::mock::mock_kernel_inputs; using aztec3::circuits::abis::AppendOnlyTreeSnapshot; -using aztec3::circuits::abis::MembershipWitness; -using aztec3::circuits::abis::NullifierLeafPreimage; using aztec3::circuits::rollup::native_base_rollup::BaseOrMergeRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::ConstantRollupData; using aztec3::circuits::rollup::native_base_rollup::NT; -using aztec3::circuits::abis::PreviousRollupData; using aztec3::circuits::rollup::native_root_rollup::RootRollupInputs; using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; -using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::NewContractData; -using aztec3::circuits::abis::OptionallyRevealedData; using MemoryTree = proof_system::plonk::stdlib::merkle_tree::MemoryTree; using KernelData = aztec3::circuits::abis::PreviousKernelData; -} // namespace +} // namespace namespace aztec3::circuits::rollup::root::native_root_rollup_circuit { class root_rollup_tests : public ::testing::Test { protected: - void run_cbind(RootRollupInputs& root_rollup_inputs, - RootRollupPublicInputs& expected_public_inputs, - bool compare_pubins = true) + static void run_cbind(RootRollupInputs& root_rollup_inputs, + RootRollupPublicInputs& expected_public_inputs, + bool compare_pubins = true) { info("Retesting via cbinds...."); // TODO might be able to get rid of proving key buffer - uint8_t const* pk_buf; - size_t pk_size = root_rollup__init_proving_key(&pk_buf); + uint8_t const* pk_buf = nullptr; + size_t const pk_size = root_rollup__init_proving_key(&pk_buf); (void)pk_size; // info("Proving key size: ", pk_size); // TODO might be able to get rid of verification key buffer - uint8_t const* vk_buf; - size_t vk_size = root_rollup__init_verification_key(pk_buf, &vk_buf); + uint8_t const* vk_buf = nullptr; + size_t const vk_size = root_rollup__init_verification_key(pk_buf, &vk_buf); (void)vk_size; // info("Verification key size: ", vk_size); @@ -129,9 +101,9 @@ class root_rollup_tests : public ::testing::Test { // uint8_t const* proof_data; // size_t proof_data_size; - uint8_t const* public_inputs_buf; + uint8_t const* public_inputs_buf = nullptr; // info("simulating circuit via cbind"); - size_t public_inputs_size = root_rollup__sim(root_rollup_inputs_vec.data(), &public_inputs_buf); + size_t const public_inputs_size = root_rollup__sim(root_rollup_inputs_vec.data(), &public_inputs_buf); // info("Proof size: ", proof_data_size); // info("PublicInputs size: ", public_inputs_size); @@ -166,7 +138,7 @@ class root_rollup_tests : public ::testing::Test { TEST_F(root_rollup_tests, native_calldata_hash_empty_blocks) { - std::vector zero_bytes_vec(704, 0); + std::vector const zero_bytes_vec(704, 0); auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); std::array hash_input; @@ -175,12 +147,12 @@ TEST_F(root_rollup_tests, native_calldata_hash_empty_blocks) hash_input[32 + i] = call_data_hash_inner[i]; } - std::vector calldata_hash_input_bytes_vec(hash_input.begin(), hash_input.end()); + std::vector const calldata_hash_input_bytes_vec(hash_input.begin(), hash_input.end()); auto hash = sha256::sha256(calldata_hash_input_bytes_vec); utils::DummyComposer composer = utils::DummyComposer(); - std::array kernels = { + std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; RootRollupInputs inputs = get_root_rollup_inputs(composer, kernels); @@ -201,7 +173,7 @@ TEST_F(root_rollup_tests, native_calldata_hash_empty_blocks) EXPECT_FALSE(composer.failed()); // Expected hash of public inputs for an empty L2 block. Also used in the contract tests. - fr expected_hash = uint256_t("0013b2202a3e48b039cda7eef0976060d86e610d77fc9bb8cd5b0f1b561df48c"); + fr const expected_hash = uint256_t("0013b2202a3e48b039cda7eef0976060d86e610d77fc9bb8cd5b0f1b561df48c"); ASSERT_EQ(outputs.hash(), expected_hash); run_cbind(inputs, outputs, true); @@ -256,23 +228,23 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) kernels[2].public_inputs.end.new_contracts[0] = new_contract; // The start historic data snapshot - AppendOnlyTreeSnapshot start_historic_data_tree_snapshot = { .root = historic_data_tree.root(), - .next_available_leaf_index = 1 }; - AppendOnlyTreeSnapshot start_historic_contract_tree_snapshot = { .root = historic_contract_tree.root(), - .next_available_leaf_index = 1 }; + AppendOnlyTreeSnapshot const start_historic_data_tree_snapshot = { .root = historic_data_tree.root(), + .next_available_leaf_index = 1 }; + AppendOnlyTreeSnapshot const start_historic_contract_tree_snapshot = { .root = historic_contract_tree.root(), + .next_available_leaf_index = 1 }; // Insert the newest data root into the historic tree historic_data_tree.update_element(1, data_tree.root()); historic_contract_tree.update_element(1, contract_tree.root()); // Compute the end snapshot - AppendOnlyTreeSnapshot end_historic_data_tree_snapshot = { .root = historic_data_tree.root(), - .next_available_leaf_index = 2 }; - AppendOnlyTreeSnapshot end_historic_contract_tree_snapshot = { .root = historic_contract_tree.root(), - .next_available_leaf_index = 2 }; + AppendOnlyTreeSnapshot const end_historic_data_tree_snapshot = { .root = historic_data_tree.root(), + .next_available_leaf_index = 2 }; + AppendOnlyTreeSnapshot const end_historic_contract_tree_snapshot = { .root = historic_contract_tree.root(), + .next_available_leaf_index = 2 }; RootRollupInputs rootRollupInputs = get_root_rollup_inputs(composer, kernels); - RootRollupPublicInputs outputs = + RootRollupPublicInputs const outputs = aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, rootRollupInputs); // Check private data trees @@ -282,8 +254,8 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) ASSERT_EQ( outputs.end_private_data_tree_snapshot, rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot); - AppendOnlyTreeSnapshot expected_private_data_tree_snapshot = { .root = data_tree.root(), - .next_available_leaf_index = 16 }; + AppendOnlyTreeSnapshot const expected_private_data_tree_snapshot = { .root = data_tree.root(), + .next_available_leaf_index = 16 }; ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_private_data_tree_snapshot); // Check public data trees @@ -297,8 +269,8 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot); - AppendOnlyTreeSnapshot expected_contract_tree_snapshot{ .root = contract_tree.root(), - .next_available_leaf_index = 4 }; + AppendOnlyTreeSnapshot const expected_contract_tree_snapshot{ .root = contract_tree.root(), + .next_available_leaf_index = 4 }; ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_contract_tree_snapshot); // TODO: Check nullifier trees @@ -314,4 +286,4 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) EXPECT_FALSE(composer.failed()); } -} // namespace aztec3::circuits::rollup::root::native_root_rollup_circuit \ No newline at end of file +} // namespace aztec3::circuits::rollup::root::native_root_rollup_circuit \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index f3c1e423747d..c48b7886d1c1 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -1,19 +1,19 @@ +#include "c_bind.h" + #include "index.hpp" #include "init.hpp" -#include "c_bind.h" -#include -#include -#include "aztec3/circuits/abis/signed_tx_request.hpp" #include "aztec3/circuits/abis/private_kernel/private_call_data.hpp" -#include +#include "aztec3/circuits/abis/signed_tx_request.hpp" #include +#include #include - -#include "barretenberg/srs/reference_string/env_reference_string.hpp" +#include +#include #include "barretenberg/common/serialize.hpp" #include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/srs/reference_string/env_reference_string.hpp" namespace { using Composer = plonk::UltraComposer; @@ -23,7 +23,7 @@ using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; using aztec3::circuits::rollup::native_root_rollup::RootRollupInputs; using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; -} // namespace +} // namespace #define WASM_EXPORT __attribute__((visibility("default"))) // WASM Cbinds @@ -33,7 +33,7 @@ WASM_EXPORT size_t root_rollup__init_proving_key(uint8_t const** pk_buf) { std::vector pk_vec(42, 0); - auto raw_buf = (uint8_t*)malloc(pk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(pk_vec.size()); memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size()); *pk_buf = raw_buf; @@ -44,9 +44,9 @@ WASM_EXPORT size_t root_rollup__init_verification_key(uint8_t const* pk_buf, uin { std::vector vk_vec(42, 0); // TODO remove when proving key is used - (void)pk_buf; // unused + (void)pk_buf; // unused - auto raw_buf = (uint8_t*)malloc(vk_vec.size()); + auto* raw_buf = (uint8_t*)malloc(vk_vec.size()); memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size()); *vk_buf = raw_buf; @@ -60,13 +60,13 @@ WASM_EXPORT size_t root_rollup__sim(uint8_t const* root_rollup_inputs_buf, read(root_rollup_inputs_buf, root_rollup_inputs); DummyComposer composer = DummyComposer(); - RootRollupPublicInputs public_inputs = root_rollup_circuit(composer, root_rollup_inputs); + RootRollupPublicInputs const public_inputs = root_rollup_circuit(composer, root_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; write(public_inputs_vec, public_inputs); // copy public inputs to output buffer - auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); + auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *root_rollup_public_inputs_buf = raw_public_inputs_buf; @@ -75,10 +75,10 @@ WASM_EXPORT size_t root_rollup__sim(uint8_t const* root_rollup_inputs_buf, WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) { - (void)vk_buf; // unused - (void)proof; // unused - (void)length; // unused - return true; + (void)vk_buf; // unused + (void)proof; // unused + (void)length; // unused + return 1U; } -} // extern "C" \ No newline at end of file +} // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp index b646c57dfc7d..2a15f32de12e 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp @@ -2,18 +2,18 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" +#include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp" -#include -#include #include "aztec3/utils/dummy_composer.hpp" - -#include -#include +#include +#include #include +#include #include +#include + namespace aztec3::circuits::rollup::native_root_rollup { using NT = aztec3::utils::types::NativeTypes; @@ -26,4 +26,4 @@ using RootRollupPublicInputs = abis::RootRollupPublicInputs; using Aggregator = aztec3::circuits::recursion::Aggregator; -} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 325c39bdbd3f..64e0bd981f37 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -1,4 +1,11 @@ +#include "init.hpp" + #include "aztec3/constants.hpp" +#include +#include +#include +#include + #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" @@ -6,14 +13,9 @@ #include "barretenberg/stdlib/merkle_tree/membership.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "barretenberg/stdlib/merkle_tree/merkle_tree.hpp" -#include "init.hpp" #include #include -#include -#include -#include -#include #include #include #include @@ -83,4 +85,4 @@ RootRollupPublicInputs root_rollup_circuit(DummyComposer& composer, RootRollupIn return public_inputs; } -} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp index 21e16ccd93c3..5418ff7060b2 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp @@ -3,15 +3,14 @@ #include "init.hpp" // TODO: not needed right at this moment for native impl -#include -#include -#include - #include #include +#include +#include +#include namespace aztec3::circuits::rollup::native_root_rollup { RootRollupPublicInputs root_rollup_circuit(DummyComposer& composer, RootRollupInputs const& rootRollupInputs); -} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file +} // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp index 4aeb0005145c..c7eafd1364a9 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp @@ -2,25 +2,25 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" -#include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" -#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" -#include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp" -#include -#include +#include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" +#include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" +#include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" +#include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" +#include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" +#include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" #include "aztec3/utils/dummy_composer.hpp" +#include +#include +#include +#include +#include -#include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" -#include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" -#include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" +#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" +#include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp" #include -#include #include -#include -#include -#include -#include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" +#include namespace aztec3::circuits::rollup::test_utils { @@ -45,4 +45,4 @@ using NullifierLeaf = stdlib::merkle_tree::nullifier_leaf; using aztec3::circuits::abis::MembershipWitness; -} // namespace aztec3::circuits::rollup::test_utils \ No newline at end of file +} // namespace aztec3::circuits::rollup::test_utils \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.cpp index 7815bb85fbba..d6f27367de4a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.cpp @@ -1,22 +1,21 @@ #include "nullifier_tree_testing_harness.hpp" -#include + #include +#include + #include #include using NullifierMemoryTree = proof_system::plonk::stdlib::merkle_tree::NullifierMemoryTree; using nullifier_leaf = proof_system::plonk::stdlib::merkle_tree::nullifier_leaf; -NullifierMemoryTreeTestingHarness::NullifierMemoryTreeTestingHarness(size_t depth) - : NullifierMemoryTree(depth) -{} +NullifierMemoryTreeTestingHarness::NullifierMemoryTreeTestingHarness(size_t depth) : NullifierMemoryTree(depth) {} // Check for a larger value in an array bool check_has_less_than(std::vector const& values, fr const& value) { - // Must perform comparisons on integers - uint256_t value_as_uint = uint256_t(value); + auto const value_as_uint = uint256_t(value); for (auto const& v : values) { // info(v, " ", uint256_t(v) < value_as_uint); if (uint256_t(v) < value_as_uint) { @@ -31,7 +30,7 @@ std::tuple, std::vector>, std::vecto NullifierMemoryTreeTestingHarness::circuit_prep_batch_insert(std::vector const& values) { // Start insertion index - fr start_insertion_index = this->size(); + fr const start_insertion_index = this->size(); // Low nullifiers std::vector low_nullifiers; @@ -47,17 +46,17 @@ NullifierMemoryTreeTestingHarness::circuit_prep_batch_insert(std::vector con std::map> touched_nodes; // Keep track of 0 values - std::vector empty_sp(depth_, 0); - nullifier_leaf empty_leaf = { 0, 0, 0 }; - uint32_t empty_index = 0; + std::vector const empty_sp(depth_, 0); + nullifier_leaf const empty_leaf = { 0, 0, 0 }; + uint32_t const empty_index = 0; // Find the leaf with the value closest and less than `value` for each value for (size_t i = 0; i < values.size(); ++i) { auto new_value = values[i]; auto insertion_index = start_insertion_index + i; - size_t current; - bool is_already_present; + size_t current = 0; + bool is_already_present = false; std::tie(current, is_already_present) = find_closest_leaf(leaves_, new_value); // If the inserted value is 0, then we ignore and provide a dummy low nullifier @@ -88,9 +87,9 @@ NullifierMemoryTreeTestingHarness::circuit_prep_batch_insert(std::vector con if (pending_insertion_tree[j].value < new_value && (pending_insertion_tree[j].nextValue > new_value || pending_insertion_tree[j].nextValue == 0)) { // Add a new pending low nullifier for this value - nullifier_leaf new_leaf = { .value = new_value, - .nextIndex = pending_insertion_tree[j].nextIndex, - .nextValue = pending_insertion_tree[j].nextValue }; + nullifier_leaf const new_leaf = { .value = new_value, + .nextIndex = pending_insertion_tree[j].nextIndex, + .nextValue = pending_insertion_tree[j].nextValue }; pending_insertion_tree.push_back(new_leaf); // Update the pending low nullifier to point at the new value @@ -108,23 +107,23 @@ NullifierMemoryTreeTestingHarness::circuit_prep_batch_insert(std::vector con } else { // Update the touched mapping if (prev_nodes == touched_nodes.end()) { - std::vector new_touched_values = { new_value }; + std::vector const new_touched_values = { new_value }; touched_nodes[current] = new_touched_values; } else { prev_nodes->second.push_back(new_value); } - nullifier_leaf low_nullifier = leaves_[current].unwrap(); - std::vector sibling_path = this->get_sibling_path(current); + nullifier_leaf const low_nullifier = leaves_[current].unwrap(); + std::vector const sibling_path = this->get_sibling_path(current); sibling_paths.push_back(sibling_path); low_nullifier_indexes.push_back(static_cast(current)); low_nullifiers.push_back(low_nullifier); // Update the current low nullifier - nullifier_leaf new_leaf = { .value = low_nullifier.value, - .nextIndex = insertion_index, - .nextValue = new_value }; + nullifier_leaf const new_leaf = { .value = low_nullifier.value, + .nextIndex = insertion_index, + .nextValue = new_value }; // Update the old leaf in the tree // update old value in tree @@ -136,7 +135,7 @@ NullifierMemoryTreeTestingHarness::circuit_prep_batch_insert(std::vector con return std::make_tuple(low_nullifiers, sibling_paths, low_nullifier_indexes); } -void NullifierMemoryTreeTestingHarness::update_element_in_place(size_t index, nullifier_leaf leaf) +void NullifierMemoryTreeTestingHarness::update_element_in_place(size_t index, const nullifier_leaf& leaf) { // Find the leaf with the value closest and less than `value` this->leaves_[index].set(leaf); @@ -145,14 +144,13 @@ void NullifierMemoryTreeTestingHarness::update_element_in_place(size_t index, nu std::pair NullifierMemoryTreeTestingHarness::find_lower(fr const& value) { - size_t current; - bool is_already_present; + size_t current = 0; + bool is_already_present = false; std::tie(current, is_already_present) = find_closest_leaf(leaves_, value); // TODO: handle is already present case if (!is_already_present) { return std::make_pair(leaves_[current].unwrap(), current); - } else { - return std::make_pair(leaves_[current].unwrap(), current); } + return std::make_pair(leaves_[current].unwrap(), current); } \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.hpp index c1d4638f9043..f23d1b8cf7c7 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/nullifier_tree_testing_harness.hpp @@ -1,10 +1,12 @@ #pragma once +#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" + #include "barretenberg/stdlib/merkle_tree/hash.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp" #include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp" + #include -#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" /** * A version of the nullifier memory tree with extra methods specific to testing our rollup circuits. @@ -13,7 +15,7 @@ class NullifierMemoryTreeTestingHarness : public proof_system::plonk::stdlib::me using nullifier_leaf = proof_system::plonk::stdlib::merkle_tree::nullifier_leaf; public: - NullifierMemoryTreeTestingHarness(size_t depth); + explicit NullifierMemoryTreeTestingHarness(size_t depth); using MemoryTree::get_hash_path; using MemoryTree::root; @@ -40,7 +42,7 @@ class NullifierMemoryTreeTestingHarness : public proof_system::plonk::stdlib::me return { .root = root(), .next_available_leaf_index = static_cast(leaves_.size()) }; } - void update_element_in_place(size_t index, nullifier_leaf leaf); + void update_element_in_place(size_t index, const nullifier_leaf& leaf); // Get all of the sibling paths and low nullifier values required to craft an non membership / inclusion proofs std::tuple, std::vector>, std::vector> diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index b5393d9075fe..ac3aa2ece62b 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -1,18 +1,22 @@ +#include "utils.hpp" + +#include "init.hpp" +#include "nullifier_tree_testing_harness.hpp" + #include "aztec3/circuits/abis/membership_witness.hpp" +#include "aztec3/circuits/abis/new_contract_data.hpp" +#include "aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp" #include "aztec3/circuits/rollup/base/init.hpp" +#include "aztec3/constants.hpp" +#include +#include + #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/stdlib/merkle_tree/memory_store.hpp" #include "barretenberg/stdlib/merkle_tree/merkle_tree.hpp" -#include "nullifier_tree_testing_harness.hpp" -#include "utils.hpp" -#include "aztec3/constants.hpp" -#include "init.hpp" -#include -#include #include -#include "aztec3/circuits/abis/new_contract_data.hpp" -#include "aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp" +#include namespace { using NT = aztec3::utils::types::NativeTypes; @@ -34,7 +38,6 @@ using NullifierLeaf = stdlib::merkle_tree::nullifier_leaf; using MemoryStore = stdlib::merkle_tree::MemoryStore; using SparseTree = stdlib::merkle_tree::MerkleTree; -using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MembershipWitness; using MergeRollupInputs = aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::abis::PreviousRollupData; @@ -42,7 +45,7 @@ using aztec3::circuits::abis::PreviousRollupData; using nullifier_tree_testing_values = std::tuple; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel; -} // namespace +} // namespace namespace aztec3::circuits::rollup::test_utils::utils { @@ -83,7 +86,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne historic_contract_tree.update_element(0, contract_tree.root()); historic_l1_to_l2_msg_tree.update_element(0, MerkleTree(L1_TO_L2_MSG_TREE_HEIGHT).root()); - ConstantRollupData constantRollupData = { + ConstantRollupData const constantRollupData = { .start_tree_of_historic_private_data_tree_roots_snapshot = { .root = historic_private_data_tree.root(), .next_available_leaf_index = 1, @@ -118,7 +121,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne .constants = constantRollupData }; // Initialise nullifier tree with 0..7 - std::vector initial_values = { 1, 2, 3, 4, 5, 6, 7 }; + std::vector const initial_values = { 1, 2, 3, 4, 5, 6, 7 }; std::array nullifiers; for (size_t i = 0; i < 2; i++) { @@ -145,16 +148,18 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne for (size_t i = 0; i < 2; i++) { for (auto state_read : kernel_data[i].public_inputs.end.state_reads) { auto leaf_index = uint256_t(state_read.leaf_index); - if (state_read.is_empty() || visited_indices.contains(leaf_index)) + if (state_read.is_empty() || visited_indices.contains(leaf_index)) { continue; + } visited_indices.insert(leaf_index); public_data_tree.update_element(leaf_index, state_read.value); } for (auto state_write : kernel_data[i].public_inputs.end.state_transitions) { auto leaf_index = uint256_t(state_write.leaf_index); - if (state_write.is_empty() || visited_indices.contains(leaf_index)) + if (state_write.is_empty() || visited_indices.contains(leaf_index)) { continue; + } visited_indices.insert(leaf_index); public_data_tree.update_element(leaf_index, state_write.old_value); } @@ -167,8 +172,9 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne for (size_t i = 0; i < 2; i++) { for (size_t j = 0; j < STATE_READS_LENGTH; j++) { auto state_read = kernel_data[i].public_inputs.end.state_reads[j]; - if (state_read.is_empty()) + if (state_read.is_empty()) { continue; + } auto leaf_index = uint256_t(state_read.leaf_index); baseRollupInputs.new_state_reads_sibling_paths[i * STATE_READS_LENGTH + j] = MembershipWitness{ @@ -179,8 +185,9 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne for (size_t j = 0; j < STATE_TRANSITIONS_LENGTH; j++) { auto state_write = kernel_data[i].public_inputs.end.state_transitions[j]; - if (state_write.is_empty()) + if (state_write.is_empty()) { continue; + } auto leaf_index = uint256_t(state_write.leaf_index); public_data_tree.update_element(leaf_index, state_write.new_value); baseRollupInputs.new_state_transitions_sibling_paths[i * STATE_TRANSITIONS_LENGTH + j] = @@ -216,7 +223,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne MemoryStore public_data_tree_store; SparseTree public_data_tree(public_data_tree_store, PUBLIC_DATA_TREE_HEIGHT); - return base_rollup_inputs_from_kernels(kernel_data, private_data_tree, contract_tree, public_data_tree); + return base_rollup_inputs_from_kernels(std::move(kernel_data), private_data_tree, contract_tree, public_data_tree); } std::array, 2> get_previous_rollup_data(DummyComposer& composer, @@ -267,14 +274,14 @@ std::array, 2> get_previous_rollup_data(DummyComposer& co auto base_public_input_2 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, base_rollup_input_2); - PreviousRollupData previous_rollup1 = { + PreviousRollupData const previous_rollup1 = { .base_or_merge_rollup_public_inputs = base_public_input_1, .proof = kernel_data[0].proof, .vk = kernel_data[0].vk, .vk_index = 0, .vk_sibling_path = MembershipWitness(), }; - PreviousRollupData previous_rollup2 = { + PreviousRollupData const previous_rollup2 = { .base_or_merge_rollup_public_inputs = base_public_input_2, .proof = kernel_data[2].proof, .vk = kernel_data[2].vk, @@ -287,7 +294,7 @@ std::array, 2> get_previous_rollup_data(DummyComposer& co MergeRollupInputs get_merge_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data) { - MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(composer, kernel_data) }; + MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)) }; return inputs; } @@ -297,8 +304,8 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyComposer& composer, std::arr MerkleTree historic_contract_tree = MerkleTree(CONTRACT_TREE_ROOTS_TREE_HEIGHT); MerkleTree historic_l1_to_l2_msg_tree = MerkleTree(L1_TO_L2_MSG_TREE_ROOTS_TREE_HEIGHT); - MerkleTree private_data_tree = MerkleTree(PRIVATE_DATA_TREE_HEIGHT); - MerkleTree contract_tree = MerkleTree(CONTRACT_TREE_HEIGHT); + MerkleTree const private_data_tree = MerkleTree(PRIVATE_DATA_TREE_HEIGHT); + MerkleTree const contract_tree = MerkleTree(CONTRACT_TREE_HEIGHT); // Historic trees are initialised with an empty root at position 0. historic_private_data_tree.update_element(0, private_data_tree.root()); @@ -311,7 +318,7 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyComposer& composer, std::arr get_sibling_path(historic_contract_tree, 1, 0); RootRollupInputs rootRollupInputs = { - .previous_rollup_data = get_previous_rollup_data(composer, kernel_data), + .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)), .new_historic_private_data_tree_root_sibling_path = historic_data_sibling_path, .new_historic_contract_tree_root_sibling_path = historic_contract_sibling_path, }; @@ -328,11 +335,11 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyComposer& composer, std::arr * @param initial_values values to pre-populate the tree * @return NullifierMemoryTreeTestingHarness */ -NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector initial_values) +NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector& initial_values) { NullifierMemoryTreeTestingHarness nullifier_tree = NullifierMemoryTreeTestingHarness(NULLIFIER_TREE_HEIGHT); - for (size_t i = 0; i < initial_values.size(); ++i) { - nullifier_tree.update_element(initial_values[i]); + for (const auto& initial_value : initial_values) { + nullifier_tree.update_element(initial_value); } return nullifier_tree; } @@ -351,10 +358,10 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupI // Generate initial values lin spaved std::vector initial_values; for (size_t i = 1; i < 8; ++i) { - initial_values.push_back(i * spacing); + initial_values.emplace_back(i * spacing); } - return utils::generate_nullifier_tree_testing_values_explicit(inputs, nullifiers, initial_values); + return utils::generate_nullifier_tree_testing_values_explicit(std::move(inputs), nullifiers, initial_values); } nullifier_tree_testing_values generate_nullifier_tree_testing_values( @@ -363,30 +370,30 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values( // Generate initial values lin spaced std::vector initial_values; for (size_t i = 1; i < 8; ++i) { - initial_values.push_back(i * spacing); + initial_values.emplace_back(i * spacing); } - return utils::generate_nullifier_tree_testing_values_explicit(inputs, new_nullifiers, initial_values); + return utils::generate_nullifier_tree_testing_values_explicit(std::move(inputs), new_nullifiers, initial_values); } nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( BaseRollupInputs rollupInputs, std::array new_nullifiers, - std::vector initial_values) + const std::vector& initial_values) { - size_t start_tree_size = initial_values.size() + 1; + size_t const start_tree_size = initial_values.size() + 1; // Generate nullifier tree testing values NullifierMemoryTreeTestingHarness nullifier_tree = get_initial_nullifier_tree(initial_values); NullifierMemoryTreeTestingHarness reference_tree = get_initial_nullifier_tree(initial_values); - AppendOnlyTreeSnapshot nullifier_tree_start_snapshot = { + AppendOnlyTreeSnapshot const nullifier_tree_start_snapshot = { .root = nullifier_tree.root(), - .next_available_leaf_index = uint32_t(start_tree_size), + .next_available_leaf_index = static_cast(start_tree_size), }; const size_t NUMBER_OF_NULLIFIERS = KERNEL_NEW_NULLIFIERS_LENGTH * 2; std::array new_nullifier_leaves; - std::array, NUMBER_OF_NULLIFIERS> + std::array, NUMBER_OF_NULLIFIERS> const low_nullifier_leaves_preimages_witnesses; // Calculate the predecessor nullifier pre-images @@ -422,14 +429,14 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( new_nullifier_leaves_sibling_paths[i].end(), witness_array.begin()); - MembershipWitness witness = { - .leaf_index = NT::uint32(new_nullifier_leave_indexes[i]), + MembershipWitness const witness = { + .leaf_index = static_cast(new_nullifier_leave_indexes[i]), .sibling_path = witness_array, }; new_membership_witnesses[i] = witness; // Create circuit compatible preimages - issue created to remove this step - NullifierLeafPreimage preimage = { + NullifierLeafPreimage const preimage = { .leaf_value = new_nullifier_leaves_preimages[i].value, .next_index = NT::uint32(new_nullifier_leaves_preimages[i].nextIndex), .next_value = new_nullifier_leaves_preimages[i].nextValue, @@ -439,7 +446,7 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( // Get expected root with subtrees inserted correctly // Expected end state - AppendOnlyTreeSnapshot nullifier_tree_end_snapshot = { + AppendOnlyTreeSnapshot const nullifier_tree_end_snapshot = { .root = reference_tree.root(), .next_available_leaf_index = uint32_t(reference_tree.size()), }; @@ -465,4 +472,4 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( return std::make_tuple(rollupInputs, nullifier_tree_start_snapshot, nullifier_tree_end_snapshot); } -} // namespace aztec3::circuits::rollup::test_utils::utils \ No newline at end of file +} // namespace aztec3::circuits::rollup::test_utils::utils \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index 062f692d3d70..525bf17192e9 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -82,7 +82,7 @@ abis::AppendOnlyTreeSnapshot get_snapshot_of_tree_state(NullifierMemoryTreeT nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( BaseRollupInputs inputs, std::array new_nullifiers, - std::vector initial_values); + const std::vector& initial_values); nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupInputs inputs, size_t starting_insertion_value, @@ -91,7 +91,7 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupI nullifier_tree_testing_values generate_nullifier_tree_testing_values( BaseRollupInputs inputs, std::array new_nullifiers, size_t spacing); -NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(std::vector initial_values); +NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector& initial_values); KernelData get_empty_kernel(); diff --git a/circuits/cpp/src/aztec3/constants.hpp b/circuits/cpp/src/aztec3/constants.hpp index b961b50eeab4..f4f3674c9cfc 100644 --- a/circuits/cpp/src/aztec3/constants.hpp +++ b/circuits/cpp/src/aztec3/constants.hpp @@ -46,15 +46,15 @@ constexpr size_t NULLIFIER_SUBTREE_INCLUSION_CHECK_DEPTH = NULLIFIER_TREE_HEIGHT constexpr size_t PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT = 8; constexpr size_t CONTRACT_TREE_ROOTS_TREE_HEIGHT = 8; constexpr size_t L1_TO_L2_MSG_TREE_ROOTS_TREE_HEIGHT = 8; -constexpr size_t ROLLUP_VK_TREE_HEIGHT = 8; // TODO: update +constexpr size_t ROLLUP_VK_TREE_HEIGHT = 8; // TODO: update -constexpr size_t FUNCTION_SELECTOR_NUM_BYTES = 4; // must be <= 31 +constexpr size_t FUNCTION_SELECTOR_NUM_BYTES = 4; // must be <= 31 // Enumerate the hash_indices which are used for pedersen hashing // Start from 1 to avoid the default generators. enum GeneratorIndex { COMMITMENT = 1, - COMMITMENT_PLACEHOLDER, // for omitting some elements of the commitment when partially committing. + COMMITMENT_PLACEHOLDER, // for omitting some elements of the commitment when partially committing. OUTER_COMMITMENT, NULLIFIER_HASHED_PRIVATE_KEY, NULLIFIER, @@ -72,7 +72,7 @@ enum GeneratorIndex { CONTRACT_LEAF, CALL_CONTEXT, CALL_STACK_ITEM, - CALL_STACK_ITEM_2, // see function where it's used for explanation + CALL_STACK_ITEM_2, // see function where it's used for explanation L1_MSG_STACK_ITEM, PRIVATE_CIRCUIT_PUBLIC_INPUTS, PUBLIC_CIRCUIT_PUBLIC_INPUTS, @@ -102,4 +102,4 @@ enum PrivateStateNoteGeneratorIndex { enum PrivateStateType { PARTITIONED = 1, WHOLE }; -} // namespace aztec3 \ No newline at end of file +} // namespace aztec3 \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/oracle/fake_db.hpp b/circuits/cpp/src/aztec3/oracle/fake_db.hpp index 37825d5c8748..b46a137a2ede 100644 --- a/circuits/cpp/src/aztec3/oracle/fake_db.hpp +++ b/circuits/cpp/src/aztec3/oracle/fake_db.hpp @@ -1,12 +1,9 @@ #pragma once #include - -#include - #include #include - +#include #include namespace aztec3::oracle { @@ -25,7 +22,7 @@ using NT = aztec3::utils::types::NativeTypes; // A temporary stub, whilst building other things first. class FakeDB { public: - FakeDB() {} + FakeDB() = default; /** * For getting a singleton UTXO (not a set). @@ -34,7 +31,7 @@ class FakeDB { * type being a field. * So if you want to test other note types against this stub DB, you'll need to write your own stub DB entry. */ - UTXOSLoadDatum> get_utxo_sload_datum( + static UTXOSLoadDatum> get_utxo_sload_datum( NT::address const& contract_address, NT::grumpkin_point const& storage_slot_point, DefaultPrivateNotePreimage const& advice) @@ -42,9 +39,9 @@ class FakeDB { // NT::fr required_utxo_tree_root, // size_t utxo_tree_depth) { - (void)storage_slot_point; // Not used in this 'fake' implementation. + (void)storage_slot_point; // Not used in this 'fake' implementation. - DefaultPrivateNotePreimage preimage{ + DefaultPrivateNotePreimage const preimage{ .value = 100, .owner = advice.owner, .creator_address = 0, @@ -58,7 +55,7 @@ class FakeDB { const NT::fr required_utxo_tree_root = 2468; std::vector sibling_path(utxo_tree_depth); - std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. + std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. return { .commitment = 1, @@ -78,7 +75,7 @@ class FakeDB { * value type being a field. * So if you want to test other note types against this stub DB, you'll need to write your own stub DB entry. */ - std::vector>> get_utxo_sload_data( + static std::vector>> get_utxo_sload_data( NT::address const& contract_address, NT::grumpkin_point const& storage_slot_point, size_t const& num_notes, @@ -87,7 +84,7 @@ class FakeDB { // NT::fr required_utxo_tree_root, // size_t utxo_tree_depth) { - (void)storage_slot_point; // Not used in this 'fake' implementation. + (void)storage_slot_point; // Not used in this 'fake' implementation. std::vector>> data; @@ -95,10 +92,10 @@ class FakeDB { const NT::fr required_utxo_tree_root = 2468; std::vector sibling_path(utxo_tree_depth); - std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. + std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. for (size_t i = 0; i < num_notes; i++) { - DefaultPrivateNotePreimage preimage{ + DefaultPrivateNotePreimage const preimage{ .value = 100 + i, .owner = advice.owner, .creator_address = 0, @@ -129,7 +126,7 @@ class FakeDB { * the value type being a field. So if you want to test other note types against this stub DB, you'll need to write * your own stub DB entry. */ - UTXOSLoadDatum> get_utxo_sload_datum( + static UTXOSLoadDatum> get_utxo_sload_datum( NT::address const& contract_address, NT::grumpkin_point const& storage_slot_point, DefaultSingletonPrivateNotePreimage const& advice) @@ -137,9 +134,9 @@ class FakeDB { // NT::fr required_utxo_tree_root, // size_t utxo_tree_depth) { - (void)storage_slot_point; // Not used in this 'fake' implementation. + (void)storage_slot_point; // Not used in this 'fake' implementation. - DefaultSingletonPrivateNotePreimage preimage{ + DefaultSingletonPrivateNotePreimage const preimage{ .value = 100, .owner = advice.owner, .salt = 1234, @@ -150,7 +147,7 @@ class FakeDB { const NT::fr required_utxo_tree_root = 2468; std::vector sibling_path(utxo_tree_depth); - std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. + std::fill(sibling_path.begin(), sibling_path.end(), 1); // Fill with 1's to be lazy. TODO: return a valid path. return { .commitment = 1, @@ -164,4 +161,4 @@ class FakeDB { }; }; -} // namespace aztec3::oracle \ No newline at end of file +} // namespace aztec3::oracle \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/oracle/oracle.hpp b/circuits/cpp/src/aztec3/oracle/oracle.hpp index 2cf94c7860d3..6a9042e7a0ab 100644 --- a/circuits/cpp/src/aztec3/oracle/oracle.hpp +++ b/circuits/cpp/src/aztec3/oracle/oracle.hpp @@ -3,14 +3,11 @@ #include "fake_db.hpp" #include -#include #include - -#include - +#include #include #include - +#include #include namespace aztec3::oracle { @@ -130,7 +127,7 @@ template class NativeOracleInterface { // Note: actual_contract_address and function_data are NOT to be provided to the circuit, so don't include // getter methods for these in the OracleWrapper. - NT::address actual_contract_address; // not to be confused with call_context.storage_contract_address; + NT::address actual_contract_address; // not to be confused with call_context.storage_contract_address; FunctionData function_data; CallContext call_context; @@ -145,10 +142,11 @@ template class NativeOracleInterface { bool contract_deployment_data_already_got = false; // bool portal_contract_address_already_got = false; bool msg_sender_private_key_already_got = false; - std::string already_got_error = "Your circuit has already accessed this value. Don't ask the oracle twice, since " - "it shouldn't be trusted, and could lead to circuit bugs"; + std::string already_got_error = + "Your circuit has already accessed this value. Don't ask the oracle twice, since " + "it shouldn't be trusted, and could lead to circuit bugs"; }; -typedef NativeOracleInterface NativeOracle; +using NativeOracle = NativeOracleInterface; -} // namespace aztec3::oracle \ No newline at end of file +} // namespace aztec3::oracle \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/utils/array.hpp b/circuits/cpp/src/aztec3/utils/array.hpp index 3e9670a4de92..74d334df8927 100644 --- a/circuits/cpp/src/aztec3/utils/array.hpp +++ b/circuits/cpp/src/aztec3/utils/array.hpp @@ -1,5 +1,6 @@ #pragma once #include "./types/native_types.hpp" + #include "barretenberg/common/throw_or_abort.hpp" /** @@ -22,7 +23,7 @@ using NT = types::NativeTypes; template std::array zero_array() { std::array arr; - arr.fill(ELEMS_TYPE(0)); // Assumes that integer type can be used here in initialization + arr.fill(ELEMS_TYPE(0)); // Assumes that integer type can be used here in initialization return arr; } @@ -83,7 +84,7 @@ template size_t array_length(std::array const */ template T array_pop(std::array& arr) { - for (size_t i = arr.max_size() - 1; i != (size_t)-1; i--) { + for (size_t i = arr.max_size() - 1; i != static_cast(-1); i--) { if (!is_empty(arr[i])) { const auto temp = arr[i]; arr[i] = empty_value(); @@ -119,8 +120,9 @@ template void array_push(std::array& arr, T c template NT::boolean is_array_empty(std::array const& arr) { for (size_t i = 0; i < arr.size(); ++i) { - if (!is_empty(arr[i])) + if (!is_empty(arr[i])) { return false; + } } return true; }; @@ -139,8 +141,8 @@ template void push_array_to_array(std::array const& source, std::array& target) { // Check if the `source` array is too large vs the remaining capacity of the `target` array - size_t source_size = static_cast(uint256_t(array_length(source))); - size_t target_size = static_cast(uint256_t(array_length(target))); + size_t const source_size = static_cast(uint256_t(array_length(source))); + size_t const target_size = static_cast(uint256_t(array_length(target))); ASSERT(source_size <= size_2 - target_size); // Ensure that there are no non-zero values in the `target` array after the first zero-valued index @@ -176,8 +178,8 @@ bool source_arrays_are_in_target(std::array const& source1, std::array const& target) { // Check if the `source` arrays are too large vs the size of the `target` array - size_t source1_size = static_cast(uint256_t(array_length(source1))); - size_t source2_size = static_cast(uint256_t(array_length(source2))); + size_t const source1_size = static_cast(uint256_t(array_length(source1))); + size_t const source2_size = static_cast(uint256_t(array_length(source2))); ASSERT(source1_size + source2_size <= size_3); // first ensure that all non-empty items in the first source are in the target @@ -205,4 +207,4 @@ bool source_arrays_are_in_target(std::array const& source1, return true; } -} // namespace aztec3::utils +} // namespace aztec3::utils diff --git a/circuits/cpp/src/aztec3/utils/circuit_errors.hpp b/circuits/cpp/src/aztec3/utils/circuit_errors.hpp index a44e05d07945..9fc51fe2e3f3 100644 --- a/circuits/cpp/src/aztec3/utils/circuit_errors.hpp +++ b/circuits/cpp/src/aztec3/utils/circuit_errors.hpp @@ -77,7 +77,7 @@ enum CircuitErrorCode : uint16_t { struct CircuitError { CircuitErrorCode code = CircuitErrorCode::NO_ERROR; - std::string message = ""; + std::string message; static CircuitError no_error() { return { CircuitErrorCode::NO_ERROR, "" }; } }; @@ -107,4 +107,4 @@ inline std::ostream& operator<<(std::ostream& os, CircuitError const& obj) return os << "code: " << as_uint16_t(obj.code) << "\n" << "message: " << obj.message << "\n"; } -} // namespace aztec3::utils \ No newline at end of file +} // namespace aztec3::utils \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp index b254ddd8a4b5..205bd8e7811c 100644 --- a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp +++ b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp @@ -1,5 +1,6 @@ #pragma once #include "aztec3/utils/circuit_errors.hpp" + #include #include #include @@ -17,7 +18,7 @@ class DummyComposer { } } - bool failed() { return failure_msgs.size() > 0; } + bool failed() const { return !failure_msgs.empty(); } CircuitError get_first_failure() { @@ -29,7 +30,7 @@ class DummyComposer { uint8_t* alloc_and_serialize_first_failure() { - CircuitError failure = get_first_failure(); + CircuitError const failure = get_first_failure(); if (failure.code == CircuitErrorCode::NO_ERROR) { return nullptr; } @@ -39,10 +40,10 @@ class DummyComposer { write(circuit_failure_vec, failure); // copy to output buffer - auto raw_failure_buf = (uint8_t*)malloc(circuit_failure_vec.size()); + auto* raw_failure_buf = static_cast(malloc(circuit_failure_vec.size())); memcpy(raw_failure_buf, (void*)circuit_failure_vec.data(), circuit_failure_vec.size()); return raw_failure_buf; } }; -} // namespace aztec3::utils +} // namespace aztec3::utils diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index b625b5213460..f487b74a0dc5 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -1,68 +1,68 @@ #pragma once -#include -#include +#include "native_types.hpp" + +#include #include +#include +#include +#include +#include #include #include #include #include #include +#include +#include #include -#include #include -#include -#include -#include +#include #include #include -#include -#include -#include -#include "native_types.hpp" +#include using namespace proof_system::plonk; namespace aztec3::utils::types { template struct CircuitTypes { - // Basic uint types - typedef stdlib::bool_t boolean; - typedef stdlib::uint8 uint8; - typedef stdlib::uint16 uint16; - typedef stdlib::uint32 uint32; - typedef stdlib::uint64 uint64; + using boolean = stdlib::bool_t; + using uint8 = stdlib::uint8; + using uint16 = stdlib::uint16; + using uint32 = stdlib::uint32; + using uint64 = stdlib::uint64; // Types related to the bn254 curve - typedef stdlib::field_t fr; - typedef stdlib::safe_uint_t safe_fr; - typedef stdlib::address_t address; - typedef stdlib::bigfield fq; + using fr = stdlib::field_t; + using safe_fr = stdlib::safe_uint_t; + using address = stdlib::address_t; + using fq = stdlib::bigfield; - typedef stdlib::witness_t witness; + using witness = stdlib::witness_t; // typedef fq grumpkin_fr; // typedef fr grumpkin_fq; - typedef stdlib::point grumpkin_point; // affine - typedef stdlib::group grumpkin_group; + using grumpkin_point = stdlib::point; // affine + using grumpkin_group = stdlib::group; - typedef stdlib::bn254 bn254; + using bn254 = stdlib::bn254; // typedef bn254::g1_ct bn254_point; - typedef stdlib::element bn254_point; // affine + using bn254_point = stdlib::element; // affine - typedef stdlib::bit_array bit_array; - typedef stdlib::byte_array byte_array; - typedef stdlib::packed_byte_array packed_byte_array; + using bit_array = stdlib::bit_array; + using byte_array = stdlib::byte_array; + using packed_byte_array = stdlib::packed_byte_array; - typedef stdlib::schnorr::signature_bits schnorr_signature; - typedef stdlib::ecdsa::signature ecdsa_signature; + using schnorr_signature = stdlib::schnorr::signature_bits; + using ecdsa_signature = stdlib::ecdsa::signature; - typedef stdlib::recursion::aggregation_state AggregationObject; - typedef std::conditional_t, - stdlib::recursion::recursive_turbo_verifier_settings, - stdlib::recursion::recursive_ultra_verifier_settings> - recursive_inner_verifier_settings; - typedef stdlib::recursion::verification_key VK; + using AggregationObject = stdlib::recursion::aggregation_state; + using recursive_inner_verifier_settings = + std::conditional_t, + stdlib::recursion::recursive_turbo_verifier_settings, + stdlib::recursion::recursive_ultra_verifier_settings>; + using VK = stdlib::recursion::verification_key; // Notice: no CircuitType for a Proof: we only ever handle native; the verify_proof() function swallows the // 'circuit-type-ness' of the proof. @@ -76,7 +76,7 @@ template struct CircuitTypes { template static fr compress(std::array const& inputs, const size_t hash_index = 0) { - std::vector inputs_vec(std::begin(inputs), std::end(inputs)); + std::vector const inputs_vec(std::begin(inputs), std::end(inputs)); return plonk::stdlib::pedersen_commitment::compress(inputs_vec, hash_index); } @@ -123,4 +123,4 @@ template struct CircuitTypes { static byte_array blake3s(const byte_array& input) { return plonk::stdlib::blake3s(input); } }; -} // namespace aztec3::utils::types \ No newline at end of file +} // namespace aztec3::utils::types \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/utils/types/convert.hpp b/circuits/cpp/src/aztec3/utils/types/convert.hpp index a27aac9d5510..32658083df9d 100644 --- a/circuits/cpp/src/aztec3/utils/types/convert.hpp +++ b/circuits/cpp/src/aztec3/utils/types/convert.hpp @@ -1,11 +1,13 @@ #pragma once -#include +#include "circuit_types.hpp" +#include "native_types.hpp" + #include -#include #include -#include "native_types.hpp" -#include "circuit_types.hpp" +#include + +#include namespace aztec3::utils::types { @@ -16,7 +18,7 @@ namespace { template using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; -} // namespace +} // namespace /// TODO: Lots of identical functions here (but for their in/out types). Can we use templates? I couldn't figure out how /// to keep the NT:: or CT:: prefixes with templates. @@ -120,8 +122,7 @@ std::array::fr, SIZE> to_ct(Composer& composer, std::array return map(arr, ref_to_ct); }; -template -std::array::fr>, SIZE> to_ct( +template std::array::fr>, SIZE> to_ct( Composer& composer, std::array, SIZE> const& arr) { auto ref_to_ct = [&](std::optional const& e) { return to_ct(composer, e); }; @@ -148,14 +149,14 @@ template typename NT::fq to_nt(typename CT::fq con template typename NT::address to_nt(typename CT::address const& e) { - return NT::address(e.address_.get_value()); // TODO: add get_value() method to address types. + return NT::address(e.address_.get_value()); // TODO: add get_value() method to address types. }; template typename NT::uint32 to_nt(typename CT::uint32 const& e) { - NT::uint256 e_256 = e.get_value(); - NT::uint64 e_64 = e_256.data[0]; // TODO: check that this endianness is correct! - NT::uint32 e_32 = static_cast(e_64); + NT::uint256 const e_256 = e.get_value(); + NT::uint64 const e_64 = e_256.data[0]; // TODO: check that this endianness is correct! + auto const e_32 = static_cast(e_64); return e_32; }; @@ -243,8 +244,7 @@ std::array to_nt(std::array::fr, SI // return arr ? std::make_optional>(map(arr, ref_to_nt)) : std::nullopt; // }; -template -std::array, SIZE> to_nt( +template std::array, SIZE> to_nt( std::array::fr>, SIZE> const& arr) { auto ref_to_nt = [&](std::optional::fr> const& e) { return to_nt(e); }; @@ -252,4 +252,4 @@ std::array, SIZE> to_nt( return map(arr, ref_to_nt); }; -} // namespace aztec3::utils::types \ No newline at end of file +} // namespace aztec3::utils::types \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/utils/types/native_types.hpp b/circuits/cpp/src/aztec3/utils/types/native_types.hpp index ab0e2479ec18..50443d88d198 100644 --- a/circuits/cpp/src/aztec3/utils/types/native_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/native_types.hpp @@ -1,57 +1,57 @@ #pragma once -#include -#include +#include +#include #include +#include #include -#include #include #include #include #include #include -#include #include -#include +#include +#include #include -#include +#include namespace aztec3::utils::types { struct NativeTypes { - typedef bool boolean; + using boolean = bool; - typedef uint8_t uint8; - typedef uint16_t uint16; - typedef uint32_t uint32; - typedef uint64_t uint64; - typedef uint256_t uint256; + using uint8 = uint8_t; + using uint16 = uint16_t; + using uint32 = uint32_t; + using uint64 = uint64_t; + using uint256 = uint256_t; - typedef barretenberg::fr fr; - typedef proof_system::plonk::stdlib::address address; + using fr = barretenberg::fr; + using address = proof_system::plonk::stdlib::address; - typedef barretenberg::fq fq; + using fq = barretenberg::fq; // typedef fq grumpkin_fr; // typedef fr grumpkin_fq; - typedef grumpkin::g1::affine_element grumpkin_point; + using grumpkin_point = grumpkin::g1::affine_element; // typedef grumpkin::g1::element grumpkin_jac_point; - typedef grumpkin::g1 grumpkin_group; + using grumpkin_group = grumpkin::g1; - typedef barretenberg::g1::affine_element bn254_point; + using bn254_point = barretenberg::g1::affine_element; // typedef barretenberg::g1::element bn254_jac_point; // typedef barretenberg::g1 bn254_group; - typedef std::vector bit_array; - typedef std::vector byte_array; - typedef std::string packed_byte_array; + using bit_array = std::vector; + using byte_array = std::vector; + using packed_byte_array = std::string; - typedef crypto::schnorr::signature schnorr_signature; - typedef crypto::ecdsa::signature ecdsa_signature; + using schnorr_signature = crypto::schnorr::signature; + using ecdsa_signature = crypto::ecdsa::signature; - typedef proof_system::plonk::stdlib::recursion::native_aggregation_state AggregationObject; - typedef plonk::verification_key_data VKData; - typedef plonk::verification_key VK; - typedef plonk::proof Proof; + using AggregationObject = proof_system::plonk::stdlib::recursion::native_aggregation_state; + using VKData = plonk::verification_key_data; + using VK = plonk::verification_key; + using Proof = plonk::proof; /// TODO: lots of these compress / commit functions aren't actually used: remove them. @@ -63,7 +63,7 @@ struct NativeTypes { template static fr compress(std::array const& inputs, const size_t hash_index = 0) { - std::vector inputs_vec(std::begin(inputs), std::end(inputs)); + std::vector const inputs_vec(std::begin(inputs), std::end(inputs)); return crypto::pedersen_commitment::compress_native(inputs_vec, hash_index); } @@ -104,4 +104,4 @@ struct NativeTypes { static byte_array blake3s(const byte_array& input) { return blake3::blake3s(input); } }; -} // namespace aztec3::utils::types \ No newline at end of file +} // namespace aztec3::utils::types \ No newline at end of file