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

Create a balanced merkle tree for L2 to L1 Messages #7218

Open
MirandaWood opened this issue Jun 27, 2024 · 0 comments
Open

Create a balanced merkle tree for L2 to L1 Messages #7218

MirandaWood opened this issue Jun 27, 2024 · 0 comments

Comments

@MirandaWood
Copy link
Contributor

Currently, L2 to L1 messages are hashed into a merkle tree at the tx level, with the root of this tree being the out_hash calculated and output from the base rollup.

From the base upwards, each merge and root circuit accumulates this as out_hash = H(left.out_hash, right.out_hash).

Previously, each transaction was limited to just 2 messages, which meant the tx's out_hash = H(msg_0, msg_1). However, transactions with just 1 message (=> out_hash = H(msg_0, 0)) caused issues as methods in ts to recreate the out_hash were not padding with empty messages. This was fixed in #6959, but introduced a variable size tree for the tx's out_hash. With the possibility of wonky rollups, this tree would be very unbalanced and messy to keep track of.

A solution is to ensure all L2 to L1 messages in a block are formed into a balanced tree. We could:

  • Keep track of the tree's state in the rollups like note and nullifier trees, using PartialStateReference to accumulate them
  • Add L2 to L1 messages to the parity circuits

A rollup just provides the final out_hash (the root of the message tree) and the height (currently a height range since the tree has variable height) to the Outbox. Consuming this message requires a valid message preimage and path, which is checked against the stored out_hash using sha256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant