Skip to content

Commit

Permalink
Update circuits structs for public functions (#304)
Browse files Browse the repository at this point in the history
* WIP

* Add public data to base rollup inputs

* Add public data tree snapshots to base and merge rollup public inputs

* Fixed build

* Build fixed

* New kernel circuit input types

* Update base rollup inputs and public inputs in ts

* Rename PrivateKernelPublicInputs to include both kernel circuits

* Fix factory method

* Add missing callContext to public circuit public inputs serialization

* Update ts structs to match changes in cpp

* Move makeEmpty helper functions to static methods

* Update test snapshot

* Update kernel serialization test

* Rename some factory and empty methods

* Fix base rollup inputs created from circuit block builder

* Fix the most annoying bug ever

* Vertical whitespace

* Update snapshots

* Update hash constructor snapshot

* Restructure circuits.js structs

* Rename old to historic in new structs

---------

Co-authored-by: Santiago Palladino <[email protected]>
  • Loading branch information
PhilWindle and spalladino authored Apr 20, 2023
1 parent 453999b commit dc0da4c
Show file tree
Hide file tree
Showing 96 changed files with 2,452 additions and 1,074 deletions.
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "index.hpp"
#include <barretenberg/stdlib/types/types.hpp>

#include "private_kernel/previous_kernel_data.hpp"
#include "previous_kernel_data.hpp"
#include "private_kernel/private_inputs.hpp"

namespace aztec3::circuits::abis {
Expand Down
19 changes: 9 additions & 10 deletions circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#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/private_kernel/new_contract_data.hpp"
#include "aztec3/circuits/abis/new_contract_data.hpp"
#include "private_circuit_public_inputs.hpp"
#include "tx_request.hpp"
#include "tx_context.hpp"
Expand All @@ -12,9 +12,9 @@
#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 "private_kernel/previous_kernel_data.hpp"
#include "previous_kernel_data.hpp"
#include "private_kernel/private_inputs.hpp"
#include "private_kernel/public_inputs.hpp"
#include "kernel_circuit_public_inputs.hpp"

#include <aztec3/circuits/hash.hpp>
#include <aztec3/constants.hpp>
Expand All @@ -31,9 +31,9 @@ using aztec3::circuits::compute_constructor_hash;
using aztec3::circuits::compute_contract_address;
using aztec3::circuits::abis::FunctionData;
using aztec3::circuits::abis::FunctionLeafPreimage;
using aztec3::circuits::abis::NewContractData;
using aztec3::circuits::abis::TxContext;
using aztec3::circuits::abis::TxRequest;
using aztec3::circuits::abis::private_kernel::NewContractData;
using NT = aztec3::utils::types::NativeTypes;

// Cbind helper functions
Expand Down Expand Up @@ -403,7 +403,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_base_rollup_inputs(uint8_
WASM_EXPORT const char* abis__test_roundtrip_serialize_previous_kernel_data(uint8_t const* kernel_data_buf,
uint32_t* size)
{
return as_string_output<aztec3::circuits::abis::private_kernel::PreviousKernelData<NT>>(kernel_data_buf, size);
return as_string_output<aztec3::circuits::abis::PreviousKernelData<NT>>(kernel_data_buf, size);
}

WASM_EXPORT const char* abis__test_roundtrip_serialize_base_or_merge_rollup_public_inputs(
Expand Down Expand Up @@ -441,17 +441,16 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs(uin
return as_string_output<aztec3::circuits::abis::private_kernel::PrivateInputs<NT>>(input, size);
}

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


WASM_EXPORT const char* abis__test_roundtrip_serialize_function_leaf_preimage(uint8_t const* function_leaf_preimage_buf, uint32_t* size)
WASM_EXPORT const char* abis__test_roundtrip_serialize_function_leaf_preimage(uint8_t const* function_leaf_preimage_buf,
uint32_t* size)
{
return as_string_output<aztec3::circuits::abis::FunctionLeafPreimage<NT>>(function_leaf_preimage_buf, size);
}


} // extern "C"
4 changes: 2 additions & 2 deletions circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "tx_request.hpp"
#include "function_leaf_preimage.hpp"
#include "aztec3/circuits/abis/private_kernel/new_contract_data.hpp"
#include "aztec3/circuits/abis/new_contract_data.hpp"

#include <barretenberg/stdlib/merkle_tree/membership.hpp>
#include <barretenberg/numeric/random/engine.hpp>
Expand All @@ -13,7 +13,7 @@
namespace {

using NT = aztec3::utils::types::NativeTypes;
using aztec3::circuits::abis::private_kernel::NewContractData;
using aztec3::circuits::abis::NewContractData;

auto& engine = numeric::random::get_debug_engine();

Expand Down
30 changes: 11 additions & 19 deletions circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "function_data.hpp"
#include "private_circuit_public_inputs.hpp"
#include "public_circuit_public_inputs.hpp"
#include "kernel_circuit_public_inputs.hpp"

#include <barretenberg/stdlib/primitives/witness/witness.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
Expand All @@ -15,28 +16,19 @@ using aztec3::utils::types::NativeTypes;
using std::conditional;
using std::is_same;

enum class CallType {
Public,
Private,
};

template <typename NCT, CallType call_type> struct CallStackItem {
template <typename NCT, template <class> typename PrivatePublic> struct CallStackItem {
typedef typename NCT::address address;
typedef typename NCT::boolean boolean;
typedef typename NCT::fr fr;

template <typename T>
using PublicInputs = typename std::
conditional<call_type == CallType::Public, PublicCircuitPublicInputs<T>, PrivateCircuitPublicInputs<T>>::type;

// 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
// `contract_address` _does not change_. Amongst other things, it's used as a lookup for
// getting the correct code from the tree. There is a separate `storage_contract_address`
// within a CallStackItem which varies depending on whether this is a call or delegatecall.
address contract_address = 0;
FunctionData<NCT> function_data{};
PublicInputs<NCT> public_inputs{};
typename PrivatePublic<NCT>::AppCircuitPublicInputs public_inputs{};

boolean operator==(CallContext<NCT> const& other) const
{
Expand All @@ -45,14 +37,14 @@ template <typename NCT, CallType call_type> struct CallStackItem {
};

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

// Capture the composer:
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); };

CallStackItem<CircuitTypes<Composer>, call_type> call_stack_item = {
CallStackItem<CircuitTypes<Composer>, PrivatePublic> call_stack_item = {
to_ct(contract_address),
function_data.to_circuit_type(composer),
public_inputs.to_circuit_type(composer),
Expand All @@ -75,8 +67,8 @@ template <typename NCT, CallType call_type> struct CallStackItem {
}
}; // namespace aztec3::circuits::abis

template <typename NCT, CallType call_type>
void read(uint8_t const*& it, CallStackItem<NCT, call_type>& call_stack_item)
template <typename NCT, template <class> typename PrivatePublic>
void read(uint8_t const*& it, CallStackItem<NCT, PrivatePublic>& call_stack_item)
{
using serialize::read;

Expand All @@ -85,8 +77,8 @@ void read(uint8_t const*& it, CallStackItem<NCT, call_type>& call_stack_item)
read(it, call_stack_item.public_inputs);
};

template <typename NCT, CallType call_type>
void write(std::vector<uint8_t>& buf, CallStackItem<NCT, call_type> const& call_stack_item)
template <typename NCT, template <class> typename PrivatePublic>
void write(std::vector<uint8_t>& buf, CallStackItem<NCT, PrivatePublic> const& call_stack_item)
{
using serialize::write;

Expand All @@ -95,8 +87,8 @@ void write(std::vector<uint8_t>& buf, CallStackItem<NCT, call_type> const& call_
write(buf, call_stack_item.public_inputs);
};

template <typename NCT, CallType call_type>
std::ostream& operator<<(std::ostream& os, CallStackItem<NCT, call_type> const& call_stack_item)
template <typename NCT, template <class> typename PrivatePublic>
std::ostream& operator<<(std::ostream& os, CallStackItem<NCT, PrivatePublic> const& call_stack_item)
{
return os << "contract_address: " << call_stack_item.contract_address << "\n"
<< "function_data: " << call_stack_item.function_data << "\n"
Expand Down
Loading

0 comments on commit dc0da4c

Please sign in to comment.