Skip to content

Commit

Permalink
feat: intial private kernel (#549)
Browse files Browse the repository at this point in the history
* prelim / very-broken commit where Jean and I started implementing the initial private kernel and moving logic between it and the inner kernel

* wip - fix some compilation issues, remove unused imports, remove
update_end_values leftover

* wip - some minor changes and comments after pairing with David

* wip: additional compilation fixes

* Refactor helper functions in private kernel tests

* wip - Fix linking issue and comment out some tests

* wip - repair native and circuit tests

* wip - include using double quotes and remove unused code

* wip - fixing circuit_create_proof_cbinds test and adapting
private_kernel_sim function to the inner/init split

* wip - fix clang tidy issue

* wip - post master merger fixes and remove test on new nullifiers

* wip - fix clang tidy issue

* wip - fix clang tidy issue

* wip - fix typescript tests and data structure split

* wip - format typescript

* wip - replace CONSTRUCTOR_ARGS by FUNCTION_ARGS

* wip - add nullifier and l1-l2-message tree roots in initial private
kernel circuit

* wip - post merge fix

* Migrate common.hpp functions into non-templated ones

* refactor(sol): use Hash.sha256ToField library where required (#637)

* refactor(sol): use Hash.sha256ToField library where required

* fmt :)

* feat: expose bytes32 hash directly

* fmt: https://i.pinimg.com/originals/81/23/a1/8123a132c007eab782d6ca9bed517eb3.jpg

---------

Co-authored-by: Maddiaa0 <addaboy@gmail.com>

* fix: Add checks for arg-type (#638)

* fix: Add checks for arg-type

* fix: support arg of 'number' type

* fix: correct wrapped fr in acir sim

* no need to force encode in some e2e tests!

---------

Co-authored-by: Maddiaa0 <addaboy@gmail.com>
Co-authored-by: Rahul Kothari <rahul.kothari.201@gmail.com>

* fix: naming consistency in messaging (messageHash -> message) (#641)

* fix: contentHash -> content

* fix: update content in nr

* fix: update incorrect message hash naming

---------

Co-authored-by: Maddiaa0 <addaboy@gmail.com>

* chore: remove unknown casts in archiver test (#648)

Removes intermediate casts to unknown from archiver test, which hide
type errors in the args of the mocked event.

* Consolidation code for contract_logic

* e2e fixing: Initialise public and private call stack and comment out some checks

* Renaming file native_private_kernel_initial.XPP into
native_private_kernel_init.XPP

* Rename native_private_kernel_circuit into
native_private_kernel_circuit_inner

* Simplify if/else clause on deployment contract boolean in contract logic

* abis test snapshot - restore from master for vk hash

* Remove old TODO comments

* Fork FUNCTION_ARGS into FUNCTION/CONSTRUCTOR_ARGS generator indices

* Move code copying public/private_call_stack in PKC init

* Clang tidy fix

* Add clarifications into a comment

* Added comments

* remove empty lines

---------

Co-authored-by: jeanmon <jean@aztecprotocol.com>
Co-authored-by: Maddiaa <47148561+Maddiaa0@users.noreply.github.com>
Co-authored-by: Maddiaa0 <addaboy@gmail.com>
Co-authored-by: Lasse Herskind <16536249+LHerskind@users.noreply.github.com>
Co-authored-by: Rahul Kothari <rahul.kothari.201@gmail.com>
Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
  • Loading branch information
7 people authored May 25, 2023
1 parent 9b3fdeb commit 032f2a0
Show file tree
Hide file tree
Showing 34 changed files with 1,373 additions and 803 deletions.
1 change: 0 additions & 1 deletion circuits/cpp/src/aztec3/circuits/abis/.test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "index.hpp"
#include "previous_kernel_data.hpp"
#include "private_kernel/private_inputs.hpp"

#include "aztec3/circuits/abis/combined_accumulated_data.hpp"

Expand Down
12 changes: 9 additions & 3 deletions circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "private_circuit_public_inputs.hpp"
#include "tx_context.hpp"
#include "tx_request.hpp"
#include "private_kernel/private_inputs.hpp"
#include "private_kernel/private_kernel_inputs_inner.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"
Expand All @@ -18,6 +18,7 @@

#include "aztec3/circuits/abis/combined_accumulated_data.hpp"
#include "aztec3/circuits/abis/new_contract_data.hpp"
#include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp"
#include "aztec3/circuits/abis/signed_tx_request.hpp"
#include "aztec3/circuits/abis/types.hpp"
#include <aztec3/circuits/hash.hpp>
Expand Down Expand Up @@ -441,9 +442,14 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_signed_tx_request(uint8_t
return as_string_output<aztec3::circuits::abis::SignedTxRequest<NT>>(input, size);
}

WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs(uint8_t const* input, uint32_t* size)
WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size)
{
return as_string_output<aztec3::circuits::abis::private_kernel::PrivateInputs<NT>>(input, size);
return as_string_output<aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner<NT>>(input, size);
}

WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_init(uint8_t const* input, uint32_t* size)
{
return as_string_output<aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit<NT>>(input, size);
}

WASM_EXPORT const char* abis__test_roundtrip_serialize_kernel_circuit_public_inputs(uint8_t const* input,
Expand Down
1 change: 0 additions & 1 deletion circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "c_bind.h"

#include "function_leaf_preimage.hpp"
#include "tx_request.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,64 @@
#pragma once

#include "private_call_data.hpp"
#include "../combined_accumulated_data.hpp"
#include "../previous_kernel_data.hpp"
#include "../signed_tx_request.hpp"

#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/native_types.hpp>

#include <barretenberg/stdlib/primitives/witness/witness.hpp>
#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/native_types.hpp"

namespace aztec3::circuits::abis::private_kernel {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct PrivateInputs {
template <typename NCT> struct PrivateKernelInputsInit {
using fr = typename NCT::fr;
using boolean = typename NCT::boolean;

SignedTxRequest<NCT> signed_tx_request{};
PreviousKernelData<NCT> previous_kernel{};
PrivateCallData<NCT> private_call{};

boolean operator==(PrivateInputs<NCT> const& other) const
boolean operator==(PrivateKernelInputsInit<NCT> const& other) const
{
return signed_tx_request == other.signed_tx_request && previous_kernel == other.previous_kernel &&
private_call == other.private_call;
return signed_tx_request == other.signed_tx_request && private_call == other.private_call;
};

template <typename Composer> PrivateInputs<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
template <typename Composer>
PrivateKernelInputsInit<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

PrivateInputs<CircuitTypes<Composer>> private_inputs = {
PrivateKernelInputsInit<CircuitTypes<Composer>> private_inputs = {
// TODO to_ct(signature),
signed_tx_request.to_circuit_type(composer),
previous_kernel.to_circuit_type(composer),
private_call.to_circuit_type(composer),
};

return private_inputs;
};
};

template <typename NCT> void read(uint8_t const*& it, PrivateInputs<NCT>& private_inputs)
template <typename NCT> void read(uint8_t const*& it, PrivateKernelInputsInit<NCT>& private_inputs)
{
using serialize::read;

read(it, private_inputs.signed_tx_request);
read(it, private_inputs.previous_kernel);
read(it, private_inputs.private_call);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, PrivateInputs<NCT> const& private_inputs)
template <typename NCT> void write(std::vector<uint8_t>& buf, PrivateKernelInputsInit<NCT> const& private_inputs)
{
using serialize::write;

write(buf, private_inputs.signed_tx_request);
write(buf, private_inputs.previous_kernel);
write(buf, private_inputs.private_call);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, PrivateInputs<NCT> const& private_inputs)
template <typename NCT> std::ostream& operator<<(std::ostream& os, PrivateKernelInputsInit<NCT> const& private_inputs)
{
return os << "signed_tx_request:\n"
<< private_inputs.signed_tx_request << "\n"
<< "previous_kernel:\n"
<< private_inputs.previous_kernel << "\n"
<< "private_call:\n"
<< private_inputs.private_call << "\n";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#include "private_call_data.hpp"
#include "../previous_kernel_data.hpp"

#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/convert.hpp"
#include "aztec3/utils/types/native_types.hpp"

#include <barretenberg/stdlib/primitives/witness/witness.hpp>

namespace aztec3::circuits::abis::private_kernel {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct PrivateKernelInputsInner {
using fr = typename NCT::fr;
using boolean = typename NCT::boolean;

PreviousKernelData<NCT> previous_kernel{};
PrivateCallData<NCT> private_call{};

boolean operator==(PrivateKernelInputsInner<NCT> const& other) const
{
return previous_kernel == other.previous_kernel && private_call == other.private_call;
};

template <typename Composer>
PrivateKernelInputsInner<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

PrivateKernelInputsInner<CircuitTypes<Composer>> private_inputs = {
previous_kernel.to_circuit_type(composer),
private_call.to_circuit_type(composer),
};

return private_inputs;
};
};

template <typename NCT> void read(uint8_t const*& it, PrivateKernelInputsInner<NCT>& private_inputs)
{
using serialize::read;

read(it, private_inputs.previous_kernel);
read(it, private_inputs.private_call);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, PrivateKernelInputsInner<NCT> const& private_inputs)
{
using serialize::write;

write(buf, private_inputs.previous_kernel);
write(buf, private_inputs.private_call);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, PrivateKernelInputsInner<NCT> const& private_inputs)
{
return os << "previous_kernel:\n"
<< private_inputs.previous_kernel << "\n"
<< "private_call:\n"
<< private_inputs.private_call << "\n";
}

} // namespace aztec3::circuits::abis::private_kernel
Loading

0 comments on commit 032f2a0

Please sign in to comment.