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

DO NOT MERGE feat: attempting to implement sideeffect counting #1646

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions circuits/cpp/src/aztec3/circuits/abis/call_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ template <typename NCT> struct CallContext {
boolean is_static_call = false;
boolean is_contract_deployment = false;

fr start_side_effect_counter = 0;

// for serialization, update with new fields
MSGPACK_FIELDS(msg_sender,
storage_contract_address,
portal_contract_address,
function_selector,
is_delegate_call,
is_static_call,
is_contract_deployment);
is_contract_deployment,
start_side_effect_counter);
boolean operator==(CallContext<NCT> const& other) const
{
// we can't use =default with a custom boolean, but we can use a msgpack-derived utility
Expand All @@ -60,6 +63,7 @@ template <typename NCT> struct CallContext {
to_ct(is_delegate_call),
to_ct(is_static_call),
to_ct(is_contract_deployment),
to_ct(start_side_effect_counter),

};

Expand All @@ -80,6 +84,7 @@ template <typename NCT> struct CallContext {
to_nt(is_delegate_call),
to_nt(is_static_call),
to_nt(is_contract_deployment),
to_nt(start_side_effect_counter),
};

return call_context;
Expand All @@ -91,7 +96,7 @@ template <typename NCT> struct CallContext {
msg_sender.to_field(), storage_contract_address.to_field(),
portal_contract_address, function_selector.to_field(),
fr(is_delegate_call), fr(is_static_call),
fr(is_contract_deployment),
fr(is_contract_deployment), start_side_effect_counter,
};

return NCT::hash(inputs, GeneratorIndex::CALL_CONTEXT);
Expand All @@ -108,6 +113,7 @@ template <typename NCT> struct CallContext {
fr(is_delegate_call).assert_is_zero();
fr(is_static_call).assert_is_zero();
fr(is_contract_deployment).assert_is_zero();
start_side_effect_counter.assert_is_zero();
}

void set_public()
Expand All @@ -121,6 +127,7 @@ template <typename NCT> struct CallContext {
fr(is_delegate_call).set_public();
fr(is_static_call).set_public();
fr(is_contract_deployment).set_public();
start_side_effect_counter.set_public();
}
};

Expand Down
121 changes: 72 additions & 49 deletions circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "optionally_revealed_data.hpp"
#include "public_data_read.hpp"
#include "public_data_update_request.hpp"
#include "side_effects.hpp"

#include "aztec3/circuits/abis/membership_witness.hpp"
#include "aztec3/circuits/abis/read_request_membership_witness.hpp"
Expand Down Expand Up @@ -30,17 +31,18 @@ template <typename NCT> struct CombinedAccumulatedData {

AggregationObject aggregation_object{};

std::array<fr, MAX_READ_REQUESTS_PER_TX> read_requests{};
std::array<SideEffect<NCT>, MAX_READ_REQUESTS_PER_TX> read_requests{};

std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
std::array<SideEffect<NCT>, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<SideEffectLinkedToNoteHash<NCT>, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
// TODO(dbanks12): remove me!
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> nullified_commitments{};
// For pending nullifiers, we have:
// nullifiedCommitments[j] != 0 <==> newNullifiers[j] nullifies nullifiedCommitments[j]

std::array<fr, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX> private_call_stack{};
std::array<fr, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX> public_call_stack{};
std::array<fr, MAX_NEW_L2_TO_L1_MSGS_PER_TX> new_l2_to_l1_msgs{};
std::array<SideEffectWithRange<NCT>, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX> private_call_stack{};
std::array<SideEffectWithRange<NCT>, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX> public_call_stack{};
std::array<SideEffect<NCT>, MAX_NEW_L2_TO_L1_MSGS_PER_TX> new_l2_to_l1_msgs{};

std::array<fr, NUM_FIELDS_PER_SHA256> encrypted_logs_hash{};
std::array<fr, NUM_FIELDS_PER_SHA256> unencrypted_logs_hash{};
Expand All @@ -62,6 +64,7 @@ template <typename NCT> struct CombinedAccumulatedData {
read_requests,
new_commitments,
new_nullifiers,
// TODO(dbanks12): remove me!
nullified_commitments,
private_call_stack,
public_call_stack,
Expand Down Expand Up @@ -97,15 +100,16 @@ template <typename NCT> struct CombinedAccumulatedData {
aggregation_object.has_data,
},

to_ct(read_requests),
map(read_requests, to_circuit_type),

to_ct(new_commitments),
to_ct(new_nullifiers),
map(new_commitments, to_circuit_type),
map(new_nullifiers, to_circuit_type),
// TODO(dbanks12): remove me!
to_ct(nullified_commitments),

to_ct(private_call_stack),
to_ct(public_call_stack),
to_ct(new_l2_to_l1_msgs),
map(private_call_stack, to_circuit_type),
map(public_call_stack, to_circuit_type),
map(new_l2_to_l1_msgs, to_circuit_type),

to_ct(encrypted_logs_hash),
to_ct(unencrypted_logs_hash),
Expand Down Expand Up @@ -137,15 +141,16 @@ template <typename NCT> struct CombinedAccumulatedData {
aggregation_object.has_data,
},

to_nt(read_requests),
map(read_requests, to_native_type),

to_nt(new_commitments),
to_nt(new_nullifiers),
map(new_commitments, to_native_type),
map(new_nullifiers, to_native_type),
// TODO(dbanks12): remove me!
to_nt(nullified_commitments),

to_nt(private_call_stack),
to_nt(public_call_stack),
to_nt(new_l2_to_l1_msgs),
map(private_call_stack, to_native_type),
map(public_call_stack, to_native_type),
map(new_l2_to_l1_msgs, to_native_type),

to_nt(encrypted_logs_hash),
to_nt(unencrypted_logs_hash),
Expand All @@ -171,6 +176,7 @@ template <typename NCT> struct CombinedAccumulatedData {

set_array_public(new_commitments);
set_array_public(new_nullifiers);
// TODO(dbanks12): remove me!
set_array_public(nullified_commitments);

set_array_public(private_call_stack);
Expand All @@ -190,41 +196,58 @@ template <typename NCT> struct CombinedAccumulatedData {
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (T& e : arr) {
fr(e).set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<OptionallyRevealedData<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<NewContractData<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<PublicDataUpdateRequest<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<PublicDataRead<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.set_public();
}
}
// template <typename T, size_t SIZE> void set_array_public(std::array<T, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (T& e : arr) {
// fr(e).set_public();
// }
// }

// template <size_t SIZE>
// void set_array_public(std::array<ReadRequestMembershipWitness<NCT, PRIVATE_DATA_TREE_HEIGHT>, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (auto& e : arr) {
// e.set_public();
// }
// }

// template <size_t SIZE> void set_array_public(std::array<OptionallyRevealedData<NCT>, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (auto& e : arr) {
// e.set_public();
// }
// }

// template <size_t SIZE> void set_array_public(std::array<NewContractData<NCT>, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (auto& e : arr) {
// e.set_public();
// }
// }

// template <size_t SIZE> void set_array_public(std::array<PublicDataUpdateRequest<NCT>, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (auto& e : arr) {
// e.set_public();
// }
// }

// template <size_t SIZE> void set_array_public(std::array<PublicDataRead<NCT>, SIZE>& arr)
//{
// static_assert(!(std::is_same<NativeTypes, NCT>::value));
// for (auto& e : arr) {
// e.set_public();
// }
// }
};

} // namespace aztec3::circuits::abis
60 changes: 45 additions & 15 deletions circuits/cpp/src/aztec3/circuits/abis/final_accumulated_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "aztec3/circuits/abis/membership_witness.hpp"
#include "aztec3/circuits/abis/read_request_membership_witness.hpp"
#include "aztec3/circuits/abis/side_effects.hpp"
#include "aztec3/constants.hpp"
#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/convert.hpp"
Expand All @@ -30,15 +31,16 @@ template <typename NCT> struct FinalAccumulatedData {

AggregationObject aggregation_object{};

std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
std::array<SideEffect<NCT>, MAX_NEW_COMMITMENTS_PER_TX> new_commitments{};
std::array<SideEffectLinkedToNoteHash<NCT>, MAX_NEW_NULLIFIERS_PER_TX> new_nullifiers{};
// TODO(dbanks12): remove me!
std::array<fr, MAX_NEW_NULLIFIERS_PER_TX> nullified_commitments{};
// For pending nullifiers, we have:
// nullifiedCommitments[j] != 0 <==> newNullifiers[j] nullifies nullifiedCommitments[j]

std::array<fr, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX> private_call_stack{};
std::array<fr, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX> public_call_stack{};
std::array<fr, MAX_NEW_L2_TO_L1_MSGS_PER_TX> new_l2_to_l1_msgs{};
std::array<SideEffectWithRange<NCT>, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX> private_call_stack{};
std::array<SideEffectWithRange<NCT>, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX> public_call_stack{};
std::array<SideEffect<NCT>, MAX_NEW_L2_TO_L1_MSGS_PER_TX> new_l2_to_l1_msgs{};

std::array<fr, NUM_FIELDS_PER_SHA256> encrypted_logs_hash{};
std::array<fr, NUM_FIELDS_PER_SHA256> unencrypted_logs_hash{};
Expand Down Expand Up @@ -89,13 +91,14 @@ template <typename NCT> struct FinalAccumulatedData {
aggregation_object.has_data,
},

to_ct(new_commitments),
to_ct(new_nullifiers),
map(new_commitments, to_circuit_type),
map(new_nullifiers, to_circuit_type),
// TODO(dbanks12): remove me!
to_ct(nullified_commitments),

to_ct(private_call_stack),
to_ct(public_call_stack),
to_ct(new_l2_to_l1_msgs),
map(private_call_stack, to_circuit_type),
map(public_call_stack, to_circuit_type),
map(new_l2_to_l1_msgs, to_circuit_type),

to_ct(encrypted_logs_hash),
to_ct(unencrypted_logs_hash),
Expand Down Expand Up @@ -125,13 +128,14 @@ template <typename NCT> struct FinalAccumulatedData {
aggregation_object.has_data,
},

to_nt(new_commitments),
to_nt(new_nullifiers),
map(new_commitments, to_native_type),
map(new_nullifiers, to_native_type),
// TODO(dbanks12): remove me!
to_nt(nullified_commitments),

to_nt(private_call_stack),
to_nt(public_call_stack),
to_nt(new_l2_to_l1_msgs),
map(private_call_stack, to_native_type),
map(public_call_stack, to_native_type),
map(new_l2_to_l1_msgs, to_native_type),

to_nt(encrypted_logs_hash),
to_nt(unencrypted_logs_hash),
Expand All @@ -153,6 +157,7 @@ template <typename NCT> struct FinalAccumulatedData {

set_array_public(new_commitments);
set_array_public(new_nullifiers);
// TODO(dbanks12): remove me!
set_array_public(nullified_commitments);

set_array_public(private_call_stack);
Expand Down Expand Up @@ -189,6 +194,31 @@ template <typename NCT> struct FinalAccumulatedData {
e.set_public();
}
}

// TODO(suyash): We're only making the value public not the counter. Check if this is okay.
template <size_t SIZE> void set_array_public(std::array<SideEffect<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.value.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<SideEffectWithRange<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.value.set_public();
}
}

template <size_t SIZE> void set_array_public(std::array<SideEffectLinkedToNoteHash<NCT>, SIZE>& arr)
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));
for (auto& e : arr) {
e.value.set_public();
}
}
};

} // namespace aztec3::circuits::abis
14 changes: 9 additions & 5 deletions circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ template <typename NCT> struct NewContractData {
return NCT::compress(inputs, GeneratorIndex::CONTRACT_LEAF);
}

void conditional_select(const boolean& condition, const NewContractData<NCT>& other)
NewContractData<NCT> static conditional_assign(const boolean& condition,
const NewContractData<NCT>& lhs,
const NewContractData<NCT>& rhs)
{
contract_address = address::conditional_assign(condition, other.contract_address, contract_address);
portal_contract_address =
address::conditional_assign(condition, other.portal_contract_address, portal_contract_address);
function_tree_root = fr::conditional_assign(condition, other.function_tree_root, function_tree_root);
return NewContractData<NCT>{
.contract_address = address::conditional_assign(condition, lhs.contract_address, rhs.contract_address),
.portal_contract_address =
address::conditional_assign(condition, lhs.portal_contract_address, rhs.portal_contract_address),
.function_tree_root = fr::conditional_assign(condition, lhs.function_tree_root, rhs.function_tree_root),
};
}
};

Expand Down
8 changes: 8 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ struct GeneratorIndexPacker {
int SIGNED_TX_REQUEST = GeneratorIndex::SIGNED_TX_REQUEST;
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 SIDE_EFFECT_LINKED_TO_NOTE_HASH = GeneratorIndex::SIDE_EFFECT_LINKED_TO_NOTE_HASH;
int SIDE_EFFECT_WITH_RANGE = GeneratorIndex::SIDE_EFFECT_WITH_RANGE;
int TX_REQUEST = GeneratorIndex::TX_REQUEST;
int SIGNATURE_PAYLOAD = GeneratorIndex::SIGNATURE_PAYLOAD;
int VK = GeneratorIndex::VK;
Expand Down Expand Up @@ -166,6 +170,10 @@ struct GeneratorIndexPacker {
SIGNED_TX_REQUEST,
GLOBAL_VARIABLES,
PARTIAL_ADDRESS,
BLOCK_HASH,
SIDE_EFFECT,
SIDE_EFFECT_LINKED_TO_NOTE_HASH,
SIDE_EFFECT_WITH_RANGE,
TX_REQUEST,
SIGNATURE_PAYLOAD,
VK,
Expand Down
Loading