Skip to content

Commit

Permalink
feat: add input support for chained transactions ("pending_read_reque…
Browse files Browse the repository at this point in the history
…sts" in private kernel circuit) (#2869)

starting first few task in https://hackmd.io/G0uD0r52Qca89BCINuDByQ

this adds a "non functional" pending_read_requests array to the private
kernel circuit inputs and accumualtors, and updates the typescript
types.

the pending reads are not used though - it is merely a placeholder input
for follow up implementation.
  • Loading branch information
dan-aztec authored Oct 17, 2023
1 parent 20ad577 commit c1dff38
Show file tree
Hide file tree
Showing 29 changed files with 285 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ template <typename NCT> struct CombinedAccumulatedData {
AggregationObject aggregation_object{};

std::array<fr, MAX_READ_REQUESTS_PER_TX> read_requests{};
std::array<fr, MAX_PENDING_READ_REQUESTS_PER_TX> pending_read_requests{};

std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
Expand Down Expand Up @@ -60,6 +61,7 @@ template <typename NCT> struct CombinedAccumulatedData {
// for serialization, update with new fields
MSGPACK_FIELDS(aggregation_object,
read_requests,
pending_read_requests,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand Down Expand Up @@ -98,6 +100,7 @@ template <typename NCT> struct CombinedAccumulatedData {
},

to_ct(read_requests),
to_ct(pending_read_requests),

to_ct(new_commitments),
to_ct(new_nullifiers),
Expand Down Expand Up @@ -138,6 +141,7 @@ template <typename NCT> struct CombinedAccumulatedData {
},

to_nt(read_requests),
to_nt(pending_read_requests),

to_nt(new_commitments),
to_nt(new_nullifiers),
Expand Down Expand Up @@ -168,6 +172,7 @@ template <typename NCT> struct CombinedAccumulatedData {
aggregation_object.add_proof_outputs_as_public_inputs();

set_array_public(read_requests);
set_array_public(pending_read_requests);

set_array_public(new_commitments);
set_array_public(new_nullifiers);
Expand Down
4 changes: 3 additions & 1 deletion circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct ConstantsPacker {
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
MAX_PUBLIC_DATA_READS_PER_CALL,
MAX_READ_REQUESTS_PER_CALL,
MAX_PENDING_READ_REQUESTS_PER_CALL,
MAX_NEW_COMMITMENTS_PER_TX,
MAX_NEW_NULLIFIERS_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX,
Expand All @@ -36,7 +37,8 @@ struct ConstantsPacker {
MAX_PUBLIC_DATA_READS_PER_TX,
MAX_NEW_CONTRACTS_PER_TX,
MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX,
MAX_READ_REQUESTS_PER_TX),
MAX_READ_REQUESTS_PER_TX,
MAX_PENDING_READ_REQUESTS_PER_TX),
NVP(NUM_ENCRYPTED_LOGS_HASHES_PER_TX,
NUM_UNENCRYPTED_LOGS_HASHES_PER_TX,
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template <typename NCT> class PrivateCircuitPublicInputs {
std::array<fr, RETURN_VALUES_LENGTH> return_values{};

std::array<fr, MAX_READ_REQUESTS_PER_CALL> read_requests{};
std::array<fr, MAX_PENDING_READ_REQUESTS_PER_CALL> pending_read_requests{};

std::array<fr, MAX_NEW_COMMITMENTS_PER_CALL> new_commitments{};
std::array<fr, MAX_NEW_NULLIFIERS_PER_CALL> new_nullifiers{};
Expand Down Expand Up @@ -57,6 +58,7 @@ template <typename NCT> class PrivateCircuitPublicInputs {
args_hash,
return_values,
read_requests,
pending_read_requests,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand All @@ -76,10 +78,10 @@ template <typename NCT> class PrivateCircuitPublicInputs {
{
return call_context == other.call_context && args_hash == other.args_hash &&
return_values == other.return_values && read_requests == other.read_requests &&
new_commitments == other.new_commitments && new_nullifiers == other.new_nullifiers &&
nullified_commitments == other.nullified_commitments && 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 &&
encrypted_logs_hash == other.encrypted_logs_hash &&
pending_read_requests == other.pending_read_requests && new_commitments == other.new_commitments &&
new_nullifiers == other.new_nullifiers && nullified_commitments == other.nullified_commitments &&
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 && encrypted_logs_hash == other.encrypted_logs_hash &&
unencrypted_logs_hash == other.unencrypted_logs_hash &&
encrypted_log_preimages_length == other.encrypted_log_preimages_length &&
unencrypted_log_preimages_length == other.unencrypted_log_preimages_length &&
Expand All @@ -104,6 +106,7 @@ template <typename NCT> class PrivateCircuitPublicInputs {
to_ct(return_values),

to_ct(read_requests),
to_ct(pending_read_requests),

to_ct(new_commitments),
to_ct(new_nullifiers),
Expand Down Expand Up @@ -143,6 +146,7 @@ template <typename NCT> class PrivateCircuitPublicInputs {
to_nt(return_values),

to_nt(read_requests),
to_nt(pending_read_requests),

to_nt(new_commitments),
to_nt(new_nullifiers),
Expand Down Expand Up @@ -181,6 +185,7 @@ template <typename NCT> class PrivateCircuitPublicInputs {
spread_arr_into_vec(return_values, inputs);

spread_arr_into_vec(read_requests, inputs);
spread_arr_into_vec(pending_read_requests, inputs);

spread_arr_into_vec(new_commitments, inputs);
spread_arr_into_vec(new_nullifiers, inputs);
Expand Down Expand Up @@ -231,6 +236,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
std::array<opt_fr, RETURN_VALUES_LENGTH> return_values;

std::array<opt_fr, MAX_READ_REQUESTS_PER_CALL> read_requests;
std::array<opt_fr, MAX_PENDING_READ_REQUESTS_PER_CALL> pending_read_requests;

std::array<opt_fr, MAX_NEW_COMMITMENTS_PER_CALL> new_commitments;
std::array<opt_fr, MAX_NEW_NULLIFIERS_PER_CALL> new_nullifiers;
Expand Down Expand Up @@ -258,6 +264,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
args_hash,
return_values,
read_requests,
pending_read_requests,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand All @@ -282,6 +289,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
std::array<opt_fr, RETURN_VALUES_LENGTH> const& return_values,

std::array<opt_fr, MAX_READ_REQUESTS_PER_CALL> const& read_requests,
std::array<opt_fr, MAX_PENDING_READ_REQUESTS_PER_CALL> const& pending_read_requests,

std::array<opt_fr, MAX_NEW_COMMITMENTS_PER_CALL> const& new_commitments,
std::array<opt_fr, MAX_NEW_NULLIFIERS_PER_CALL> const& new_nullifiers,
Expand All @@ -307,6 +315,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
, args_hash(args_hash)
, return_values(return_values)
, read_requests(read_requests)
, pending_read_requests(pending_read_requests)
, new_commitments(new_commitments)
, new_nullifiers(new_nullifiers)
, nullified_commitments(nullified_commitments)
Expand Down Expand Up @@ -334,6 +343,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
new_inputs.return_values.fill(std::nullopt);

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

new_inputs.new_commitments.fill(std::nullopt);
new_inputs.new_nullifiers.fill(std::nullopt);
Expand Down Expand Up @@ -399,6 +409,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
make_unused_array_elements_zero(builder, return_values);

make_unused_array_elements_zero(builder, read_requests);
make_unused_array_elements_zero(builder, pending_read_requests);

make_unused_array_elements_zero(builder, new_commitments);
make_unused_array_elements_zero(builder, new_nullifiers);
Expand Down Expand Up @@ -438,6 +449,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
set_array_public(return_values);

set_array_public(read_requests);
set_array_public(pending_read_requests);

set_array_public(new_commitments);
set_array_public(new_nullifiers);
Expand Down Expand Up @@ -479,6 +491,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
to_ct(return_values),

to_ct(read_requests),
to_ct(pending_read_requests),

to_ct(new_commitments),
to_ct(new_nullifiers),
Expand Down Expand Up @@ -520,6 +533,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
to_nt(return_values),

to_nt(read_requests),
to_nt(pending_read_requests),

to_nt(new_commitments),
to_nt(new_nullifiers),
Expand Down Expand Up @@ -562,6 +576,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
spread_arr_opt_into_vec(return_values, inputs);

spread_arr_opt_into_vec(read_requests, inputs);
spread_arr_opt_into_vec(pending_read_requests, inputs);

spread_arr_opt_into_vec(new_commitments, inputs);
spread_arr_opt_into_vec(new_nullifiers, inputs);
Expand Down Expand Up @@ -599,6 +614,7 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
.return_values = map(return_values, get_value),

.read_requests = map(read_requests, get_value),
.pending_read_requests = map(pending_read_requests, get_value),

.new_commitments = map(new_commitments, get_value),
.new_nullifiers = map(new_nullifiers, get_value),
Expand Down
10 changes: 8 additions & 2 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void common_validate_call_stack(DummyBuilder& builder, PrivateCallData<NT> const
* @param builder
* @param historic_private_data_tree_root This is a reference to the historic root which all
* read requests are checked against here.
* @param read_requests the commitments being read by this private call - 'pending note reads' here are
* @param read_requests the commitments being read by this private call - 'transient note reads' here are
* `inner_note_hashes` (not yet siloed, not unique), but 'pre-existing note reads' are `unique_siloed_note_hashes`
* @param read_request_membership_witnesses used to compute the private data root
* for a given request which is essentially a membership check
Expand All @@ -82,7 +82,9 @@ void common_validate_read_requests(DummyBuilder& builder,
const auto& witness = read_request_membership_witnesses[rr_idx];

// A pending commitment is the one that is not yet added to private data tree
// A transient read is when we try to "read" a pending commitment
// A "transient read" is when we try to "read" a pending commitment within a transaction
// between function calls, as opposed to reading the outputs of a previous transaction
// which is a "pending read".
// We determine if it is a transient read depending on the leaf index from the membership witness
// Note that the Merkle membership proof would be null and void in case of an transient read
// but we use the leaf index as a placeholder to detect a 'pending note read'.
Expand Down Expand Up @@ -130,6 +132,7 @@ void common_validate_arrays(DummyBuilder& builder, PrivateCircuitPublicInputs<NT
// to push_array_to_array() routines which rely on the passed arrays to be well-formed.
validate_array(builder, app_public_inputs.return_values, "App public inputs - Return values");
validate_array(builder, app_public_inputs.read_requests, "App public inputs - Read requests");
validate_array(builder, app_public_inputs.pending_read_requests, "App public inputs - Pending read requests");
validate_array(builder, app_public_inputs.new_commitments, "App public inputs - New commitments");
validate_array(builder, app_public_inputs.new_nullifiers, "App public inputs - New nullifiers");
validate_array(builder, app_public_inputs.nullified_commitments, "App public inputs - Nullified commitments");
Expand All @@ -149,6 +152,7 @@ void common_validate_previous_kernel_arrays(DummyBuilder& builder, CombinedAccum
{
// Each of the following arrays is expected to be zero-padded.
validate_array(builder, end.read_requests, "Accumulated data - Read Requests");
validate_array(builder, end.pending_read_requests, "Accumulated data - Pending read Requests");
validate_array(builder, end.new_commitments, "Accumulated data - New commitments");
validate_array(builder, end.new_nullifiers, "Accumulated data - New nullifiers");
validate_array(builder, end.nullified_commitments, "Accumulated data - Nullified commitments");
Expand Down Expand Up @@ -179,6 +183,8 @@ void common_update_end_values(DummyBuilder& builder,
const auto& read_requests = private_call_public_inputs.read_requests;
const auto& read_request_membership_witnesses = private_call.read_request_membership_witnesses;

// don't update pending_read_requests, because those just get passed through without any change

const auto& new_commitments = private_call_public_inputs.new_commitments;
const auto& new_nullifiers = private_call_public_inputs.new_nullifiers;
const auto& nullified_commitments = private_call_public_inputs.nullified_commitments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ void update_end_values(DummyCircuitBuilder& builder,
builder.do_assert(is_array_empty(public_inputs.end.read_requests),
"public_inputs.end.read_requests must start as empty in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
builder.do_assert(is_array_empty(public_inputs.end.pending_read_requests),
"public_inputs.end.pending_read_requests must start as empty in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
builder.do_assert(public_inputs.end.encrypted_log_preimages_length == NT::fr(0),
"public_inputs.end.encrypted_log_preimages_length must start as 0 in initial kernel iteration",
CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP);
Expand Down
19 changes: 12 additions & 7 deletions circuits/cpp/src/aztec3/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ constexpr size_t MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2;
constexpr size_t MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 16;
constexpr size_t MAX_PUBLIC_DATA_READS_PER_CALL = 16;
constexpr size_t MAX_READ_REQUESTS_PER_CALL = 32;
constexpr size_t MAX_PENDING_READ_REQUESTS_PER_CALL = MAX_READ_REQUESTS_PER_CALL;


// "PER TRANSACTION" CONSTANTS
Expand All @@ -62,6 +63,8 @@ constexpr size_t MAX_PUBLIC_DATA_READS_PER_TX = 16;
constexpr size_t MAX_NEW_CONTRACTS_PER_TX = 1;
constexpr size_t MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX = 4;
constexpr size_t MAX_READ_REQUESTS_PER_TX = MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_READ_REQUESTS_PER_CALL;
constexpr size_t MAX_PENDING_READ_REQUESTS_PER_TX =
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_PENDING_READ_REQUESTS_PER_CALL;
constexpr size_t NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
constexpr size_t NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
// docs:end:constants
Expand Down Expand Up @@ -236,16 +239,18 @@ constexpr size_t CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
// should change this constant as well as the offsets in private_call_stack_item.nr
constexpr size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH =
CALL_CONTEXT_LENGTH + 1 // +1 for args_hash
+ RETURN_VALUES_LENGTH + MAX_READ_REQUESTS_PER_CALL + MAX_NEW_COMMITMENTS_PER_CALL +
2 * MAX_NEW_NULLIFIERS_PER_CALL + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL +
MAX_NEW_L2_TO_L1_MSGS_PER_CALL + NUM_FIELDS_PER_SHA256 + NUM_FIELDS_PER_SHA256 + 2 // + 2 for logs preimage lengths
+ HISTORIC_BLOCK_DATA_LENGTH + CONTRACT_DEPLOYMENT_DATA_LENGTH + 2; // + 2 for chain_id and version
+ RETURN_VALUES_LENGTH + MAX_READ_REQUESTS_PER_CALL + MAX_PENDING_READ_REQUESTS_PER_CALL +
MAX_NEW_COMMITMENTS_PER_CALL + 2 * MAX_NEW_NULLIFIERS_PER_CALL + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL +
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + MAX_NEW_L2_TO_L1_MSGS_PER_CALL + NUM_FIELDS_PER_SHA256 +
NUM_FIELDS_PER_SHA256 + 2 // + 2 for logs preimage lengths
+ HISTORIC_BLOCK_DATA_LENGTH + CONTRACT_DEPLOYMENT_DATA_LENGTH + 2; // + 2 for chain_id and version

constexpr size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH =
1 + 1 // call_context_hash + args_hash
+ RETURN_VALUES_LENGTH + MAX_READ_REQUESTS_PER_CALL + MAX_NEW_COMMITMENTS_PER_CALL +
2 * MAX_NEW_NULLIFIERS_PER_CALL + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL +
MAX_NEW_L2_TO_L1_MSGS_PER_CALL + NUM_FIELDS_PER_SHA256 + NUM_FIELDS_PER_SHA256 + 2 // + 2 for logs preimage lengths
+ RETURN_VALUES_LENGTH + MAX_READ_REQUESTS_PER_CALL + MAX_PENDING_READ_REQUESTS_PER_CALL +
MAX_NEW_COMMITMENTS_PER_CALL + 2 * MAX_NEW_NULLIFIERS_PER_CALL + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL +
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + MAX_NEW_L2_TO_L1_MSGS_PER_CALL + NUM_FIELDS_PER_SHA256 +
NUM_FIELDS_PER_SHA256 + 2 // + 2 for logs preimage lengths
+ HISTORIC_BLOCK_DATA_LENGTH + 3; // + 3 for contract_deployment_data.hash(), chain_id, version

constexpr size_t CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
Expand Down
8 changes: 5 additions & 3 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ library Constants {
uint256 internal constant MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 16;
uint256 internal constant MAX_PUBLIC_DATA_READS_PER_CALL = 16;
uint256 internal constant MAX_READ_REQUESTS_PER_CALL = 32;
uint256 internal constant MAX_PENDING_READ_REQUESTS_PER_CALL = 32;
uint256 internal constant MAX_NEW_COMMITMENTS_PER_TX = 64;
uint256 internal constant MAX_NEW_NULLIFIERS_PER_TX = 64;
uint256 internal constant MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX = 8;
Expand All @@ -34,6 +35,7 @@ library Constants {
uint256 internal constant MAX_NEW_CONTRACTS_PER_TX = 1;
uint256 internal constant MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX = 4;
uint256 internal constant MAX_READ_REQUESTS_PER_TX = 128;
uint256 internal constant MAX_PENDING_READ_REQUESTS_PER_TX = 128;
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
Expand Down Expand Up @@ -71,15 +73,15 @@ library Constants {
uint256 internal constant HISTORIC_BLOCK_DATA_LENGTH = 7;
uint256 internal constant FUNCTION_DATA_LENGTH = 4;
uint256 internal constant CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 123;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 155;
uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 142;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
uint256 internal constant EMPTY_NULLIFIED_COMMITMENT = 1000000;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 129;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 161;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 87;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 112;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 144;
uint256 internal constant COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
uint256 internal constant PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 2048;
Expand Down
Loading

0 comments on commit c1dff38

Please sign in to comment.