Skip to content

Commit

Permalink
chore!: Add Side effect counter struct for ordering (AztecProtocol#3608)
Browse files Browse the repository at this point in the history
For ordering, we need to keep track of the sequence in which notes were
created/read. This modifies the Protocol Circuit input structs to add a
"counter" value in addition to the raw "value" of a commitment, read
request, and nullifier.

This PR is a breaking but nonfunctional change - just adds 0 values for
counters everywhere, values are set in `context.nr` but will not be
validated inside the ordering kernel until a follow up PR.

also removes all references to "pending_read_requests", which we've
decided not to support for now due to high complexity.

This is a continuation of
https://github.com/AztecProtocol/aztec-packages/pull/1646/files , but
for noir protocol circuits instead of the CPP ones.

---------

Co-authored-by: sirasistant <sirasistant@gmail.com>
Co-authored-by: Dan Lee <dan-aztec@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 3, 2024
1 parent 44458be commit c58b197
Show file tree
Hide file tree
Showing 90 changed files with 70,273 additions and 48,657 deletions.
4 changes: 1 addition & 3 deletions barretenberg/cpp/.clang-format
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
PointerAlignment: Left
ColumnLimit: 120
BreakBeforeBraces: Allman
IndentWidth: 4
BinPackArguments: false
BinPackParameters: false
AllowShortFunctionsOnASingleLine: None
Cpp11BracedListStyle: false
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
Expand All @@ -25,4 +23,4 @@ BraceWrapping:
SplitEmptyRecord: false
SplitEmptyNamespace: false
AllowShortFunctionsOnASingleLine : Inline
SortIncludes: true
SortIncludes: true
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 @@ -61,7 +60,6 @@ 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 @@ -100,7 +98,6 @@ 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 @@ -141,7 +138,6 @@ 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 @@ -172,7 +168,6 @@ 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
6 changes: 3 additions & 3 deletions circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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 @@ -37,8 +36,7 @@ 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_PENDING_READ_REQUESTS_PER_TX),
MAX_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 Expand Up @@ -132,6 +130,7 @@ struct GeneratorIndexPacker {
int GLOBAL_VARIABLES = GeneratorIndex::GLOBAL_VARIABLES;
int PARTIAL_ADDRESS = GeneratorIndex::PARTIAL_ADDRESS;
int BLOCK_HASH = GeneratorIndex::BLOCK_HASH;
int SIDE_EFFECT = GeneratorIndex::SIDE_EFFECT;
int TX_REQUEST = GeneratorIndex::TX_REQUEST;
int SIGNATURE_PAYLOAD = GeneratorIndex::SIGNATURE_PAYLOAD;
int VK = GeneratorIndex::VK;
Expand Down Expand Up @@ -170,6 +169,7 @@ struct GeneratorIndexPacker {
GLOBAL_VARIABLES,
PARTIAL_ADDRESS,
BLOCK_HASH,
SIDE_EFFECT,
TX_REQUEST,
SIGNATURE_PAYLOAD,
VK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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 @@ -58,7 +57,6 @@ template <typename NCT> class PrivateCircuitPublicInputs {
args_hash,
return_values,
read_requests,
pending_read_requests,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand All @@ -78,7 +76,7 @@ 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 &&
pending_read_requests == other.pending_read_requests && new_commitments == other.new_commitments &&
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 &&
Expand All @@ -105,7 +103,6 @@ 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 @@ -145,7 +142,6 @@ 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 @@ -184,7 +180,6 @@ 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 @@ -235,7 +230,6 @@ 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 @@ -263,7 +257,6 @@ template <typename NCT> class OptionalPrivateCircuitPublicInputs {
args_hash,
return_values,
read_requests,
pending_read_requests,
new_commitments,
new_nullifiers,
nullified_commitments,
Expand All @@ -288,7 +281,6 @@ 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 @@ -314,7 +306,6 @@ 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 @@ -342,7 +333,6 @@ 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 @@ -408,7 +398,6 @@ 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 @@ -448,7 +437,6 @@ 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 @@ -490,7 +478,6 @@ 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 @@ -532,7 +519,6 @@ 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 @@ -575,7 +561,6 @@ 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 @@ -613,7 +598,6 @@ 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
3 changes: 0 additions & 3 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ 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 @@ -152,7 +151,6 @@ 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 @@ -183,7 +181,6 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ 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
7 changes: 2 additions & 5 deletions circuits/cpp/src/aztec3/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ 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 @@ -66,8 +65,6 @@ 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 @@ -324,15 +321,15 @@ 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_PENDING_READ_REQUESTS_PER_CALL +
+ 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
+ BLOCK_HEADER_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_PENDING_READ_REQUESTS_PER_CALL +
+ 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
Expand Down
13 changes: 5 additions & 8 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 @@ -35,7 +34,6 @@ 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 @@ -69,19 +67,18 @@ library Constants {
uint256 internal constant GET_NOTE_ORACLE_RETURN_LENGTH = 23;
uint256 internal constant MAX_NOTES_PER_PAGE = 10;
uint256 internal constant VIEW_NOTE_ORACLE_RETURN_LENGTH = 212;
uint256 internal constant CALL_CONTEXT_LENGTH = 7;
uint256 internal constant CALL_CONTEXT_LENGTH = 8;
uint256 internal constant BLOCK_HEADER_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 = 155;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 189;
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 PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 190;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
uint256 internal constant EMPTY_NULLIFIED_COMMITMENT = 1000000;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 161;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 195;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 87;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 144;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 177;
uint256 internal constant COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 1024;
Expand Down

0 comments on commit c58b197

Please sign in to comment.