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(blocks_tree): compute block hashes within root rollup circuit #1214

Merged
merged 24 commits into from
Aug 2, 2023

Conversation

Maddiaa0
Copy link
Member

Description

resolves #1162

Please provide a paragraph or two giving a summary of the change, including relevant motivation and context.

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@netlify
Copy link

netlify bot commented Jul 26, 2023

Deploy Preview for preeminent-bienenstitch-606ad0 canceled.

Name Link
🔨 Latest commit 2942f95
🔍 Latest deploy log https://app.netlify.com/sites/preeminent-bienenstitch-606ad0/deploys/64c1626357bceb0008750eef

@Maddiaa0 Maddiaa0 marked this pull request as ready for review August 1, 2023 10:44
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we really need to add the block hash in the public inputs.

@@ -22,6 +22,8 @@ template <typename NCT> struct RootRollupPublicInputs {

GlobalVariables<NCT> globalVariables;

fr block_hash;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the block_hash as part of the inputs? Using the global variables and the other values you can compute it. What value does it bring to include it directly here?

@@ -378,6 +381,20 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder,
.next_available_leaf_index = 1,
};

// Blocks tree
auto blocks_tree_sibling_path = get_sibling_path<HISTORIC_BLOCKS_TREE_HEIGHT>(historic_blocks_tree, 0, 0);
info("problematic sibling path");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should some of these infos be removed?

.next_available_leaf_index = 0,
};

info("snapshot");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More infos down here.

/**
* The hash of the block being included into the historic block hashes tree.
*/
public blockHash: Fr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As earlier. Not sure you actually need this.

@@ -249,7 +248,7 @@ export class SoloBlockBuilder implements BlockBuilder {

// Run the root rollup with the last two merge rollups (or base, if no merge layers)
const [mergeOutputLeft, mergeOutputRight] = mergeRollupInputs;
return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2Messages);
return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2Messages, globalVariables);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The globalVariables should already be in both mergeOutputLeft and mergeOutputRight, you could just read it from there?

@Maddiaa0 Maddiaa0 force-pushed the md/blocks-tree-circuits branch 2 times, most recently from e9f0626 to dc20631 Compare August 1, 2023 13:16
@Maddiaa0 Maddiaa0 force-pushed the md/blocks-tree-circuits branch from dc20631 to 011a150 Compare August 1, 2023 13:17
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments on indexing of historic trees

circuits/cpp/src/aztec3/circuits/hash.hpp Outdated Show resolved Hide resolved
// Blocks tree snapshots
AppendOnlyTreeSnapshot const start_historic_blocks_tree_snapshot = {
.root = historic_blocks_tree.root(),
.next_available_leaf_index = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next available should probably be one here similarly to how the other historic trees are handled now?

Copy link
Member Author

@Maddiaa0 Maddiaa0 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing in follow up

@@ -378,6 +381,15 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder,
.next_available_leaf_index = 1,
};

// Blocks tree
auto blocks_tree_sibling_path = get_sibling_path<HISTORIC_BLOCKS_TREE_HEIGHT>(historic_blocks_tree, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming wise would add the historic to the name here for clarity. Should probably also be for index 1? As our historic starts there instead of at 0 where the initial was inserted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing in followup

@@ -351,6 +350,9 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder,
MemoryStore l1_to_l2_msg_tree_store;
MerkleTree l1_to_l2_msg_tree(l1_to_l2_msg_tree_store, L1_TO_L2_MSG_TREE_HEIGHT);

MemoryStore historic_blocks_tree_store;
MerkleTree historic_blocks_tree(historic_blocks_tree_store, HISTORIC_BLOCKS_TREE_HEIGHT);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be initialised with empty root for position 0 like we were doing with the others.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing in follow up

Copy link
Contributor

@rahul-kothari rahul-kothari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than lasse's comments lgtm

@@ -16,18 +16,22 @@ template <typename NCT> struct RootRollupInputs {
using fr = typename NCT::fr;

// All below are shared between the base and merge rollups
std::array<PreviousRollupData<NCT>, 2> previous_rollup_data;
std::array<PreviousRollupData<NCT>, 2> previous_rollup_data{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2zo1ki

AppendOnlyTreeSnapshot<NCT> start_historic_tree_l1_to_l2_message_tree_roots_snapshot{};

// inputs required to add the block hash
AppendOnlyTreeSnapshot<NCT> start_historic_blocks_tree_snapshot{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not have to add start_historic_blocks_tree_snapshot and end_historic_blocks_tree_snapshot into the root rollup PublicInputs?

Edit: just realised it was always there in that file lol

baseRollupOutputLeft = makeBaseOrMergeRollupPublicInputs();
baseRollupOutputRight = makeBaseOrMergeRollupPublicInputs();
rootRollupOutput = makeRootRollupPublicInputs();
baseRollupOutputLeft = makeBaseOrMergeRollupPublicInputs(0, blockNumber, globalVariables);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't globalVariables have blockNumber already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point it does, i can refactor this to remove the arg

@Maddiaa0 Maddiaa0 enabled auto-merge (squash) August 2, 2023 13:24
@Maddiaa0 Maddiaa0 merged commit 71dc039 into master Aug 2, 2023
@Maddiaa0 Maddiaa0 deleted the md/blocks-tree-circuits branch August 2, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

feat(blocks_tree): add blocks tree calculations to circuits
4 participants