Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read-requests generated by app circuit, checked in private kernel #619

Merged
merged 63 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a81e4e3
cherry-pick
dbanks12 May 18, 2023
ca9e8bf
add read requests to serialization and to_ct in private calldata
dbanks12 May 18, 2023
ef37d0f
fix convert for mw array
dbanks12 May 18, 2023
61b4703
add readRequests
dbanks12 May 22, 2023
b347df6
prettier
dbanks12 May 22, 2023
aaad35e
fixes
dbanks12 May 22, 2023
9154b37
non-empty readRequests in kernel prover test
dbanks12 May 22, 2023
20c9512
fix c++ private circuit public inputs
dbanks12 May 22, 2023
5188c2f
fix serialization and testing of new readRequests in structs
dbanks12 May 22, 2023
6f557f4
fixing noir code now that read-requests are there
dbanks12 May 23, 2023
96ea5df
formatting
dbanks12 May 23, 2023
d18b3d7
parent contract json but with proving key and return witnesses slimme…
dbanks12 May 23, 2023
8d9d343
fix getNotes noir function's return size
dbanks12 Jun 1, 2023
aebda26
merge master in
dbanks12 Jun 1, 2023
114cb45
ts formatting fixes
dbanks12 Jun 1, 2023
d083fce
read request membership checks in private kernel
dbanks12 Jun 2, 2023
028f966
fix
dbanks12 Jun 2, 2023
2a444b3
cleanup
dbanks12 Jun 2, 2023
26f9006
merge in master
dbanks12 Jun 2, 2023
0c8ab28
tidy
dbanks12 Jun 2, 2023
5bd416f
initialize historic root from read requests and check each later read…
dbanks12 Jun 3, 2023
c272f33
tidy
dbanks12 Jun 3, 2023
6131d12
update snapshots
dbanks12 Jun 4, 2023
c13dee3
attempt to fix e2e tests with read requests
dbanks12 Jun 5, 2023
eb5ef16
merge in master
dbanks12 Jun 5, 2023
eb55888
import fixes after merge
dbanks12 Jun 5, 2023
080abe0
put off historic root removal from app until later
dbanks12 Jun 5, 2023
6f3299b
simulator only gets commitment indices (not full witnesses), and comm…
dbanks12 Jun 8, 2023
8a29d24
merge in master except snaps and noir jsons
dbanks12 Jun 8, 2023
75bffc1
fix after merge. update noir jsons
dbanks12 Jun 8, 2023
42c515b
snapshot updates
dbanks12 Jun 8, 2023
dbd4266
merge master in minus noir jsons
dbanks12 Jun 8, 2023
34a9d42
update noir jsons
dbanks12 Jun 8, 2023
3992d35
remove whitespace db_oracle.ts
dbanks12 Jun 8, 2023
0272b2c
Fix PUBLIC_INPUTS coung comment in abi.nr
dbanks12 Jun 8, 2023
f134e5b
comment regarding deserializing notes in noir set.nr
dbanks12 Jun 8, 2023
575b268
add issue to TODO comment set.nr
dbanks12 Jun 8, 2023
06abba2
fix read requests tests in c++
dbanks12 Jun 8, 2023
68404d7
Merge branch 'db/read-membership-in-pkc' of github.com:AztecProtocol/…
dbanks12 Jun 8, 2023
aeb4975
prettier
dbanks12 Jun 8, 2023
e270991
first iteration gets historic private data root, other kernel iterati…
dbanks12 Jun 8, 2023
3cd5389
kernel tests for read requests must set historic data root
dbanks12 Jun 8, 2023
76d910c
bug discovered plus hacky workaround
dbanks12 Jun 9, 2023
ed84630
bug discovered plus hacky workaround
dbanks12 Jun 9, 2023
10d6412
Update yarn-project/circuits.js/src/structs/kernel/private_kernel.ts
dbanks12 Jun 9, 2023
dd176a8
Update yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts
dbanks12 Jun 9, 2023
2bbab06
no more camel case in hash hpp
dbanks12 Jun 9, 2023
d1fee2b
merged in master, still need to bump json
dbanks12 Jun 11, 2023
cceaf37
bump contract jsons after merge
dbanks12 Jun 11, 2023
401ae13
fix test merge
dbanks12 Jun 11, 2023
ea68b6c
read request tests fixed after merge and moved to other 'init' tests
dbanks12 Jun 11, 2023
4b2e227
add back commented out fromsiblingpath
dbanks12 Jun 11, 2023
09c2407
add inner kernel tests for read requests
dbanks12 Jun 11, 2023
f1c2426
add back missing merkle tree dep
dbanks12 Jun 11, 2023
78018d1
add back merkle dep
dbanks12 Jun 11, 2023
1837058
move fromSiblingPath into kernel oracle to avoid weird circular depen…
dbanks12 Jun 11, 2023
37915ad
merge in master
dbanks12 Jun 12, 2023
5164859
fix(sync): tx index off kernel bug (#805)
Maddiaa0 Jun 12, 2023
604af4f
cleanup after PR review
dbanks12 Jun 12, 2023
3407232
formatting
dbanks12 Jun 12, 2023
ac0232a
tidy
dbanks12 Jun 12, 2023
2efd2ec
merge in master, revert contracts package.json
dbanks12 Jun 12, 2023
0307d7d
merge in master
dbanks12 Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace aztec3::circuits::abis {
using aztec3::circuits::abis::PrivateHistoricTreeRoots;
using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using plonk::stdlib::witness_t;
using std::is_same;

template <typename NCT> struct CombinedHistoricTreeRoots {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace aztec3::circuits::abis {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using plonk::stdlib::witness_t;
using std::conditional;
using std::is_same;

template <typename NCT> struct KernelCircuitPublicInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ template <typename NCT> class PrivateCircuitPublicInputs {

std::array<fr, EMITTED_EVENTS_LENGTH> emitted_events = zero_array<fr, EMITTED_EVENTS_LENGTH>();

std::array<fr, READ_REQUESTS_LENGTH> read_requests = zero_array<fr, READ_REQUESTS_LENGTH>();

std::array<fr, NEW_COMMITMENTS_LENGTH> new_commitments = zero_array<fr, NEW_COMMITMENTS_LENGTH>();
std::array<fr, NEW_NULLIFIERS_LENGTH> new_nullifiers = zero_array<fr, NEW_NULLIFIERS_LENGTH>();

Expand All @@ -49,9 +51,10 @@ template <typename NCT> class PrivateCircuitPublicInputs {
boolean operator==(PrivateCircuitPublicInputs<NCT> const& other) const
{
return call_context == other.call_context && args == other.args && return_values == other.return_values &&
emitted_events == other.emitted_events && new_commitments == other.new_commitments &&
new_nullifiers == other.new_nullifiers && private_call_stack == other.private_call_stack &&
public_call_stack == other.public_call_stack && new_l2_to_l1_msgs == other.new_l2_to_l1_msgs &&
emitted_events == other.emitted_events && read_requests == other.read_requests &&
new_commitments == other.new_commitments && new_nullifiers == other.new_nullifiers &&
private_call_stack == other.private_call_stack && public_call_stack == other.public_call_stack &&
new_l2_to_l1_msgs == other.new_l2_to_l1_msgs &&
historic_private_data_tree_root == other.historic_private_data_tree_root &&
historic_nullifier_tree_root == other.historic_nullifier_tree_root &&
historic_contract_tree_root == other.historic_contract_tree_root &&
Expand All @@ -76,6 +79,8 @@ template <typename NCT> class PrivateCircuitPublicInputs {

to_ct(emitted_events),

to_ct(read_requests),

to_ct(new_commitments),
to_ct(new_nullifiers),

Expand Down Expand Up @@ -108,6 +113,8 @@ template <typename NCT> class PrivateCircuitPublicInputs {

to_nt(emitted_events),

to_nt(read_requests),

to_nt(new_commitments),
to_nt(new_nullifiers),

Expand Down Expand Up @@ -139,6 +146,8 @@ template <typename NCT> class PrivateCircuitPublicInputs {

spread_arr_into_vec(emitted_events, inputs);

spread_arr_into_vec(read_requests, inputs);

spread_arr_into_vec(new_commitments, inputs);
spread_arr_into_vec(new_nullifiers, inputs);

Expand Down Expand Up @@ -172,6 +181,7 @@ template <typename NCT> void read(uint8_t const*& it, PrivateCircuitPublicInputs
read(it, pis.args);
read(it, pis.return_values);
read(it, pis.emitted_events);
read(it, pis.read_requests);
read(it, pis.new_commitments);
read(it, pis.new_nullifiers);
read(it, pis.private_call_stack);
Expand All @@ -195,6 +205,7 @@ void write(std::vector<uint8_t>& buf, PrivateCircuitPublicInputs<NCT> const& pri
write(buf, pis.args);
write(buf, pis.return_values);
write(buf, pis.emitted_events);
write(buf, pis.read_requests);
write(buf, pis.new_commitments);
write(buf, pis.new_nullifiers);
write(buf, pis.private_call_stack);
Expand All @@ -217,6 +228,7 @@ std::ostream& operator<<(std::ostream& os, PrivateCircuitPublicInputs<NCT> const
<< "args: " << pis.args << "\n"
<< "return_values: " << pis.return_values << "\n"
<< "emitted_events: " << pis.emitted_events << "\n"
<< "read_requests: " << pis.read_requests << "\n"
<< "new_commitments: " << pis.new_commitments << "\n"
<< "new_nullifiers: " << pis.new_nullifiers << "\n"
<< "private_call_stack: " << pis.private_call_stack << "\n"
Expand Down Expand Up @@ -245,6 +257,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

std::array<opt_fr, EMITTED_EVENTS_LENGTH> emitted_events;

std::array<opt_fr, READ_REQUESTS_LENGTH> read_requests;

std::array<opt_fr, NEW_COMMITMENTS_LENGTH> new_commitments;
std::array<opt_fr, NEW_NULLIFIERS_LENGTH> new_nullifiers;

Expand All @@ -268,6 +282,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

std::array<opt_fr, EMITTED_EVENTS_LENGTH> const& emitted_events,

std::array<opt_fr, READ_REQUESTS_LENGTH> const& read_requests,

std::array<opt_fr, NEW_COMMITMENTS_LENGTH> const& new_commitments,
std::array<opt_fr, NEW_NULLIFIERS_LENGTH> const& new_nullifiers,

Expand All @@ -285,6 +301,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
, args(args)
, return_values(return_values)
, emitted_events(emitted_events)
, read_requests(read_requests)
, new_commitments(new_commitments)
, new_nullifiers(new_nullifiers)
, private_call_stack(private_call_stack)
Expand All @@ -309,6 +326,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

new_inputs.emitted_events.fill(std::nullopt);

new_inputs.read_requests.fill(std::nullopt);

new_inputs.new_commitments.fill(std::nullopt);
new_inputs.new_nullifiers.fill(std::nullopt);

Expand Down Expand Up @@ -357,6 +376,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

make_unused_array_elements_zero(composer, emitted_events);

make_unused_array_elements_zero(composer, read_requests);

make_unused_array_elements_zero(composer, new_commitments);
make_unused_array_elements_zero(composer, new_nullifiers);

Expand Down Expand Up @@ -389,6 +410,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

set_array_public(emitted_events);

set_array_public(read_requests);

set_array_public(new_commitments);
set_array_public(new_nullifiers);

Expand Down Expand Up @@ -423,6 +446,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

to_ct(emitted_events),

to_ct(read_requests),

to_ct(new_commitments),
to_ct(new_nullifiers),

Expand Down Expand Up @@ -458,6 +483,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

to_nt(emitted_events),

to_nt(read_requests),

to_nt(new_commitments),
to_nt(new_nullifiers),

Expand Down Expand Up @@ -494,6 +521,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

spread_arr_opt_into_vec(emitted_events, inputs);

spread_arr_opt_into_vec(read_requests, inputs);

spread_arr_opt_into_vec(new_commitments, inputs);
spread_arr_opt_into_vec(new_nullifiers, inputs);

Expand Down Expand Up @@ -524,6 +553,8 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {

.emitted_events = map(emitted_events, get_value),

.read_requests = map(read_requests, get_value),

.new_commitments = map(new_commitments, get_value),
.new_nullifiers = map(new_nullifiers, get_value),

Expand Down Expand Up @@ -618,6 +649,7 @@ void read(uint8_t const*& it, OptionalPrivateCircuitPublicInputs<NCT>& private_c
read(it, pis.args);
read(it, pis.return_values);
read(it, pis.emitted_events);
read(it, pis.read_requests);
read(it, pis.new_commitments);
read(it, pis.new_nullifiers);
read(it, pis.private_call_stack);
Expand All @@ -641,6 +673,7 @@ void write(std::vector<uint8_t>& buf, OptionalPrivateCircuitPublicInputs<NCT> co
write(buf, pis.args);
write(buf, pis.return_values);
write(buf, pis.emitted_events);
write(buf, pis.read_requests);
write(buf, pis.new_commitments);
write(buf, pis.new_nullifiers);
write(buf, pis.private_call_stack);
Expand All @@ -662,6 +695,7 @@ std::ostream& operator<<(std::ostream& os, OptionalPrivateCircuitPublicInputs<NC
<< "args: " << pis.args << "\n"
<< "return_values: " << pis.return_values << "\n"
<< "emitted_events: " << pis.emitted_events << "\n"
<< "read_requests: " << pis.read_requests << "\n"
<< "new_commitments: " << pis.new_commitments << "\n"
<< "new_nullifiers: " << pis.new_nullifiers << "\n"
<< "private_call_stack: " << pis.private_call_stack << "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "../types.hpp"

#include "aztec3/constants.hpp"
#include "aztec3/utils/array.hpp"
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/native_types.hpp>
Expand All @@ -18,7 +17,6 @@ namespace aztec3::circuits::abis::private_kernel {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using plonk::stdlib::witness_t;
using std::is_same;

template <typename NCT> struct PrivateCallData {
Expand All @@ -39,6 +37,9 @@ template <typename NCT> struct PrivateCallData {
MembershipWitness<NCT, FUNCTION_TREE_HEIGHT> function_leaf_membership_witness{};
MembershipWitness<NCT, CONTRACT_TREE_HEIGHT> contract_leaf_membership_witness{};

std::array<MembershipWitness<NCT, PRIVATE_DATA_TREE_HEIGHT>, READ_REQUESTS_LENGTH>
read_request_membership_witnesses{};

fr portal_contract_address = 0; // an ETH address
fr acir_hash = 0;

Expand All @@ -49,6 +50,7 @@ template <typename NCT> struct PrivateCallData {
private_call_stack_preimages == other.private_call_stack_preimages && vk == other.vk &&
function_leaf_membership_witness == other.function_leaf_membership_witness &&
contract_leaf_membership_witness == other.contract_leaf_membership_witness &&
read_request_membership_witnesses == other.read_request_membership_witnesses &&
portal_contract_address == other.portal_contract_address && acir_hash == other.acir_hash;
};

Expand All @@ -75,6 +77,9 @@ template <typename NCT> struct PrivateCallData {
to_circuit_type(function_leaf_membership_witness),
to_circuit_type(contract_leaf_membership_witness),

aztec3::utils::types::to_ct<Composer, MembershipWitness<CT, PRIVATE_DATA_TREE_HEIGHT>>(
composer, read_request_membership_witnesses),

to_ct(portal_contract_address),
to_ct(acir_hash),
};
Expand All @@ -93,6 +98,7 @@ template <typename NCT> void read(uint8_t const*& it, PrivateCallData<NCT>& obj)
read(it, obj.vk);
read(it, obj.function_leaf_membership_witness);
read(it, obj.contract_leaf_membership_witness);
read(it, obj.read_request_membership_witnesses);
read(it, obj.portal_contract_address);
read(it, obj.acir_hash);
};
Expand All @@ -107,6 +113,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, PrivateCallData<NC
write(buf, *obj.vk);
write(buf, obj.function_leaf_membership_witness);
write(buf, obj.contract_leaf_membership_witness);
write(buf, obj.read_request_membership_witnesses);
write(buf, obj.portal_contract_address);
write(buf, obj.acir_hash);
};
Expand All @@ -125,6 +132,8 @@ template <typename NCT> std::ostream& operator<<(std::ostream& os, PrivateCallDa
<< obj.function_leaf_membership_witness << "\n"
<< "contract_leaf_membership_witness:\n"
<< obj.contract_leaf_membership_witness << "\n"
<< "read_request_membership_witnesses:\n"
<< obj.read_request_membership_witnesses << "\n"
<< "portal_contract_address: " << obj.portal_contract_address << "\n"
<< "acir_hash: " << obj.acir_hash << "\n";
}
Expand Down
19 changes: 19 additions & 0 deletions circuits/cpp/src/aztec3/circuits/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <aztec3/utils/circuit_errors.hpp>

#include "barretenberg/crypto/sha256/sha256.hpp"
#include <barretenberg/stdlib/merkle_tree/memory_tree.hpp>

#include <array>

Expand All @@ -15,6 +16,7 @@ namespace aztec3::circuits {
using abis::FunctionData;
using aztec3::circuits::abis::ContractLeafPreimage;
using aztec3::circuits::abis::FunctionLeafPreimage;
using MerkleTree = stdlib::merkle_tree::MemoryTree;

template <typename NCT> typename NCT::fr compute_args_hash(std::array<typename NCT::fr, ARGS_LENGTH> args)
{
Expand Down Expand Up @@ -151,6 +153,23 @@ typename NCT::fr root_from_sibling_path(typename NCT::fr const& leaf,
return node; // root
}

template <size_t N>
std::array<fr, N> get_sibling_path(MerkleTree& tree, size_t leafIndex, size_t const& subtree_depth_to_skip)
{
std::array<fr, N> siblingPath;
auto path = tree.get_hash_path(leafIndex);
// slice out the skip
leafIndex = leafIndex >> (subtree_depth_to_skip);
for (size_t i = 0; i < N; i++) {
dbanks12 marked this conversation as resolved.
Show resolved Hide resolved
if (leafIndex & (1 << i)) {
siblingPath[i] = path[subtree_depth_to_skip + i].first;
} else {
siblingPath[i] = path[subtree_depth_to_skip + i].second;
}
}
return siblingPath;
dbanks12 marked this conversation as resolved.
Show resolved Hide resolved
}

template <typename NCT, typename Composer, size_t SIZE>
void check_membership(Composer& composer,
typename NCT::fr const& value,
Expand Down
Loading