Skip to content

Commit

Permalink
fix: issue with run_nargo_fmt.sh + minor yellow paper naming improv…
Browse files Browse the repository at this point in the history
…ements (AztecProtocol#3833)

When input param was not set (which is expected when we want to apply
the changes) the script failed with

> ./run_nargo_fmt.sh: line 31: $1: unbound variable

I decided to solve this by allowing for unbound vars.

Other than this I sneaked in a few changes I discussed with Lasse:

1. Renamed content hash as body hash because we have a struct called
body and the hash is hash of body so it makes it a bit more clear of
what the hash is.
2. Renamed `l1_to_l2_message_tree` as `l1_to_l2_messages_tree` in the
yellow paper to make it consistent with our codebase.
  • Loading branch information
benesjan authored Jan 4, 2024
1 parent 1f5b2c6 commit 8e692c1
Show file tree
Hide file tree
Showing 63 changed files with 256 additions and 256 deletions.
26 changes: 13 additions & 13 deletions circuits/cpp/src/aztec3/circuits/abis/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <typename NCT> struct BlockHeader {
fr note_hash_tree_root = 0;
fr nullifier_tree_root = 0;
fr contract_tree_root = 0;
fr l1_to_l2_messages_tree_root = 0;
fr l1_to_l2_message_tree_root = 0;
fr archive_root = 0;
fr private_kernel_vk_tree_root = 0; // TODO: future enhancement

Expand All @@ -37,7 +37,7 @@ template <typename NCT> struct BlockHeader {
MSGPACK_FIELDS(note_hash_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
l1_to_l2_message_tree_root,
archive_root,
private_kernel_vk_tree_root,
public_data_tree_root,
Expand All @@ -47,7 +47,7 @@ template <typename NCT> struct BlockHeader {
{
return note_hash_tree_root == other.note_hash_tree_root && nullifier_tree_root == other.nullifier_tree_root &&
contract_tree_root == other.contract_tree_root &&
l1_to_l2_messages_tree_root == other.l1_to_l2_messages_tree_root && archive_root == other.archive_root &&
l1_to_l2_message_tree_root == other.l1_to_l2_message_tree_root && archive_root == other.archive_root &&
private_kernel_vk_tree_root == other.private_kernel_vk_tree_root &&
public_data_tree_root == other.public_data_tree_root &&
global_variables_hash == other.global_variables_hash;
Expand All @@ -60,7 +60,7 @@ template <typename NCT> struct BlockHeader {
note_hash_tree_root.assert_is_zero();
nullifier_tree_root.assert_is_zero();
contract_tree_root.assert_is_zero();
l1_to_l2_messages_tree_root.assert_is_zero();
l1_to_l2_message_tree_root.assert_is_zero();
archive_root.assert_is_zero();
private_kernel_vk_tree_root.assert_is_zero();
public_data_tree_root.assert_is_zero();
Expand All @@ -75,9 +75,9 @@ template <typename NCT> struct BlockHeader {
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); };

BlockHeader<CircuitTypes<Builder>> data = {
to_ct(note_hash_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
to_ct(l1_to_l2_messages_tree_root), to_ct(archive_root), to_ct(private_kernel_vk_tree_root),
to_ct(public_data_tree_root), to_ct(global_variables_hash),
to_ct(note_hash_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
to_ct(l1_to_l2_message_tree_root), to_ct(archive_root), to_ct(private_kernel_vk_tree_root),
to_ct(public_data_tree_root), to_ct(global_variables_hash),
};

return data;
Expand All @@ -89,9 +89,9 @@ template <typename NCT> struct BlockHeader {
auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt<Builder>(e); };

BlockHeader<NativeTypes> data = {
to_nt(note_hash_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
to_nt(l1_to_l2_messages_tree_root), to_nt(archive_root), to_nt(private_kernel_vk_tree_root),
to_nt(public_data_tree_root), to_nt(global_variables_hash),
to_nt(note_hash_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
to_nt(l1_to_l2_message_tree_root), to_nt(archive_root), to_nt(private_kernel_vk_tree_root),
to_nt(public_data_tree_root), to_nt(global_variables_hash),
};

return data;
Expand All @@ -104,7 +104,7 @@ template <typename NCT> struct BlockHeader {
note_hash_tree_root.set_public();
nullifier_tree_root.set_public();
contract_tree_root.set_public();
l1_to_l2_messages_tree_root.set_public();
l1_to_l2_message_tree_root.set_public();
archive_root.set_public();
private_kernel_vk_tree_root.set_public();
public_data_tree_root.set_public();
Expand All @@ -116,7 +116,7 @@ template <typename NCT> struct BlockHeader {
return { note_hash_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
l1_to_l2_message_tree_root,
archive_root, // TODO(#3441) Note private_kernel_vk_tree_root, is not included yet as
// it is not present in noir,
public_data_tree_root,
Expand All @@ -130,7 +130,7 @@ template <typename NCT> struct BlockHeader {
note_hash_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
l1_to_l2_message_tree_root,
public_data_tree_root);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ template <typename NCT> struct RootRollupInputs {

// inputs required to process l1 to l2 messages
std::array<fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP> new_l1_to_l2_messages{};
std::array<fr, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH> new_l1_to_l2_messages_tree_root_sibling_path{};
std::array<fr, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH> new_l1_to_l2_message_tree_root_sibling_path{};

AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_messages_tree_snapshot{};
AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_message_tree_snapshot{};

// inputs required to add the block hash
AppendOnlyTreeSnapshot<NCT> start_archive_snapshot{};
Expand All @@ -31,8 +31,8 @@ template <typename NCT> struct RootRollupInputs {
// For serialization, update with new fields
MSGPACK_FIELDS(previous_rollup_data,
new_l1_to_l2_messages,
new_l1_to_l2_messages_tree_root_sibling_path,
start_l1_to_l2_messages_tree_snapshot,
new_l1_to_l2_message_tree_root_sibling_path,
start_l1_to_l2_message_tree_snapshot,
start_archive_snapshot,
new_archive_sibling_path);
bool operator==(RootRollupInputs<NCT> const&) const = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ template <typename NCT> struct RootRollupPublicInputs {
AppendOnlyTreeSnapshot<NCT> start_tree_of_historical_contract_tree_roots_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_tree_of_historical_contract_tree_roots_snapshot{};

AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_messages_tree_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_l1_to_l2_messages_tree_snapshot{};
AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_message_tree_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_l1_to_l2_message_tree_snapshot{};

AppendOnlyTreeSnapshot<NCT> start_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot{};
AppendOnlyTreeSnapshot<NCT> start_tree_of_historical_l1_to_l2_message_tree_roots_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_tree_of_historical_l1_to_l2_message_tree_roots_snapshot{};

AppendOnlyTreeSnapshot<NCT> start_archive_snapshot{};
AppendOnlyTreeSnapshot<NCT> end_archive_snapshot{};
Expand All @@ -64,10 +64,10 @@ template <typename NCT> struct RootRollupPublicInputs {
end_tree_of_historical_note_hash_tree_roots_snapshot,
start_tree_of_historical_contract_tree_roots_snapshot,
end_tree_of_historical_contract_tree_roots_snapshot,
start_l1_to_l2_messages_tree_snapshot,
end_l1_to_l2_messages_tree_snapshot,
start_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot,
end_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot,
start_l1_to_l2_message_tree_snapshot,
end_l1_to_l2_message_tree_snapshot,
start_tree_of_historical_l1_to_l2_message_tree_roots_snapshot,
end_tree_of_historical_l1_to_l2_message_tree_roots_snapshot,
start_archive_snapshot,
end_archive_snapshot,
calldata_hash,
Expand All @@ -86,17 +86,17 @@ template <typename NCT> struct RootRollupPublicInputs {
write(buf, start_tree_of_historical_note_hash_tree_roots_snapshot);
write(buf, start_tree_of_historical_contract_tree_roots_snapshot);
write(buf, start_public_data_tree_root);
write(buf, start_l1_to_l2_messages_tree_snapshot);
write(buf, start_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot);
write(buf, start_l1_to_l2_message_tree_snapshot);
write(buf, start_tree_of_historical_l1_to_l2_message_tree_roots_snapshot);
write(buf, start_archive_snapshot);
write(buf, end_note_hash_tree_snapshot);
write(buf, end_nullifier_tree_snapshot);
write(buf, end_contract_tree_snapshot);
write(buf, end_tree_of_historical_note_hash_tree_roots_snapshot);
write(buf, end_tree_of_historical_contract_tree_roots_snapshot);
write(buf, end_public_data_tree_root);
write(buf, end_l1_to_l2_messages_tree_snapshot);
write(buf, end_tree_of_historical_l1_to_l2_messages_tree_roots_snapshot);
write(buf, end_l1_to_l2_message_tree_snapshot);
write(buf, end_tree_of_historical_l1_to_l2_message_tree_roots_snapshot);
write(buf, end_archive_snapshot);

// Stitching calldata hash together
Expand Down
12 changes: 6 additions & 6 deletions circuits/cpp/src/aztec3/circuits/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ template <typename NCT> typename NCT::fr compute_block_hash(typename NCT::fr con
typename NCT::fr const& note_hash_tree_root,
typename NCT::fr const& nullifier_tree_root,
typename NCT::fr const& contract_tree_root,
typename NCT::fr const& l1_to_l2_messages_tree_root,
typename NCT::fr const& l1_to_l2_message_tree_root,
typename NCT::fr const& public_data_tree_root)
{
using fr = typename NCT::fr;

std::vector<fr> const inputs = {
globals_hash, note_hash_tree_root, nullifier_tree_root,
contract_tree_root, l1_to_l2_messages_tree_root, public_data_tree_root,
globals_hash, note_hash_tree_root, nullifier_tree_root,
contract_tree_root, l1_to_l2_message_tree_root, public_data_tree_root,
};

return NCT::hash(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
Expand All @@ -148,14 +148,14 @@ typename NCT::fr compute_block_hash_with_globals(abis::GlobalVariables<NCT> cons
typename NCT::fr const& note_hash_tree_root,
typename NCT::fr const& nullifier_tree_root,
typename NCT::fr const& contract_tree_root,
typename NCT::fr const& l1_to_l2_messages_tree_root,
typename NCT::fr const& l1_to_l2_message_tree_root,
typename NCT::fr const& public_data_tree_root)
{
using fr = typename NCT::fr;

std::vector<fr> const inputs = {
globals.hash(), note_hash_tree_root, nullifier_tree_root,
contract_tree_root, l1_to_l2_messages_tree_root, public_data_tree_root,
globals.hash(), note_hash_tree_root, nullifier_tree_root,
contract_tree_root, l1_to_l2_message_tree_root, public_data_tree_root,
};

return NCT::hash(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
Expand Down
4 changes: 2 additions & 2 deletions circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ PublicKernelInputs<NT> get_kernel_inputs_with_previous_kernel(NT::boolean privat
.note_hash_tree_root = ++seed,
.nullifier_tree_root = ++seed,
.contract_tree_root = ++seed,
.l1_to_l2_messages_tree_root = ++seed,
.l1_to_l2_message_tree_root = ++seed,
.archive_root = ++seed,
.private_kernel_vk_tree_root = ++seed,
.public_data_tree_root = ++seed,
Expand Down Expand Up @@ -372,7 +372,7 @@ PublicKernelInputs<NT> get_kernel_inputs_with_previous_kernel(NT::boolean privat
[[maybe_unused]] BlockHeader<NT> const historical_tree_roots = {
.note_hash_tree_root = 1000,
.contract_tree_root = 2000,
.l1_to_l2_messages_tree_root = 3000,
.l1_to_l2_message_tree_root = 3000,
.private_kernel_vk_tree_root = 4000,
};

Expand Down
24 changes: 12 additions & 12 deletions circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ TEST_F(base_rollup_tests, native_single_public_state_read)
MemoryStore public_data_tree_store;
MerkleTree public_data_tree(public_data_tree_store, PUBLIC_DATA_TREE_HEIGHT);

MemoryStore l1_to_l2_messages_tree_store;
MerkleTree l1_to_l2_messages_tree(l1_to_l2_messages_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);
MemoryStore l1_to_l2_message_tree_store;
MerkleTree l1_to_l2_message_tree(l1_to_l2_message_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);

auto data_read = abis::PublicDataRead<NT>{
.leaf_index = fr(1),
Expand All @@ -752,7 +752,7 @@ TEST_F(base_rollup_tests, native_single_public_state_read)
std::array<PreviousKernelData<NT>, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() };
kernel_data[0].public_inputs.end.public_data_reads[0] = data_read;
auto inputs = test_utils::utils::base_rollup_inputs_from_kernels(
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree);
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_message_tree);

BaseOrMergeRollupPublicInputs outputs =
aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs);
Expand All @@ -777,8 +777,8 @@ TEST_F(base_rollup_tests, native_single_public_state_write)
MemoryStore public_data_tree_store;
MerkleTree public_data_tree(public_data_tree_store, PUBLIC_DATA_TREE_HEIGHT);

MemoryStore l1_to_l2_messages_tree_store;
MerkleTree l1_to_l2_messages_tree(l1_to_l2_messages_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);
MemoryStore l1_to_l2_message_tree_store;
MerkleTree l1_to_l2_message_tree(l1_to_l2_message_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);


auto data_write = abis::PublicDataUpdateRequest<NT>{
Expand All @@ -791,7 +791,7 @@ TEST_F(base_rollup_tests, native_single_public_state_write)
kernel_data[0].public_inputs.end.public_data_update_requests[0] = data_write;

auto inputs = test_utils::utils::base_rollup_inputs_from_kernels(
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree);
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_message_tree);

BaseOrMergeRollupPublicInputs outputs =
aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs);
Expand All @@ -816,8 +816,8 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes)
MemoryStore public_data_tree_store;
MerkleTree public_data_tree(public_data_tree_store, PUBLIC_DATA_TREE_HEIGHT);

MemoryStore l1_to_l2_messages_tree_store;
MerkleTree l1_to_l2_messages_tree(l1_to_l2_messages_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);
MemoryStore l1_to_l2_message_tree_store;
MerkleTree l1_to_l2_message_tree(l1_to_l2_message_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);

std::array<PreviousKernelData<NT>, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() };

Expand All @@ -840,7 +840,7 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes)
make_public_data_update_request(fr(4), fr(204), fr(304));

auto inputs = test_utils::utils::base_rollup_inputs_from_kernels(
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree);
kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_message_tree);

BaseOrMergeRollupPublicInputs outputs =
aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs);
Expand Down Expand Up @@ -868,8 +868,8 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes)
// MemoryStore public_data_tree_store;
// MerkleTree public_data_tree(public_data_tree_store, PUBLIC_DATA_TREE_HEIGHT);

// MemoryStore l1_to_l2_messages_tree_store;
// MerkleTree l1_to_l2_messages_tree(l1_to_l2_messages_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);
// MemoryStore l1_to_l2_message_tree_store;
// MerkleTree l1_to_l2_message_tree(l1_to_l2_message_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);

// auto data_read = abis::PublicDataRead<NT>{
// .leaf_index = fr(1),
Expand All @@ -879,7 +879,7 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes)
// std::array<PreviousKernelData<NT>, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() };
// kernel_data[0].public_inputs.end.public_data_reads[0] = data_read;
// auto inputs = test_utils::utils::base_rollup_inputs_from_kernels(
// kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree);
// kernel_data, note_hash_tree, contract_tree, public_data_tree, l1_to_l2_message_tree);

// // We change the initial tree root so the read value does not match
// public_data_tree.update_element(1, fr(43));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ void perform_archive_membership_checks(DummyBuilder& builder, BaseRollupInputs c
auto note_hash_tree_root = historical_block.note_hash_tree_root;
auto nullifier_tree_root = historical_block.nullifier_tree_root;
auto contract_tree_root = historical_block.contract_tree_root;
auto l1_to_l2_messages_tree_root = historical_block.l1_to_l2_messages_tree_root;
auto l1_to_l2_message_tree_root = historical_block.l1_to_l2_message_tree_root;
auto public_data_tree_root = historical_block.public_data_tree_root;

auto previous_block_hash = compute_block_hash<NT>(historical_block.global_variables_hash,
note_hash_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
l1_to_l2_message_tree_root,
public_data_tree_root);

abis::MembershipWitness<NT, ARCHIVE_HEIGHT> const historical_root_witness =
Expand Down
Loading

0 comments on commit 8e692c1

Please sign in to comment.