Skip to content

Commit 4711ef7

Browse files
authored
feat: public data tree as indexed tree (AztecProtocol#3566)
Resolves AztecProtocol#501 This PR changes the Public Data tree to an indexed tree of height 40. This optimizes insertions at the base rollup, reducing hashing and allowing batch insertion. In order to do this: - Now blocks use a snapshot for the public data tree, not just a root - Now indexed leaves have an updateTo method that allows updates. Nullifiers disallow updates. - The standard indexed tree realizes when a low leaf is an exact match and updates the low leaf instead. - The base rollup does indexed tree insertions for the public data tree, applying the update logic. - When fetching a slot from the public data tree, we get the low leaf for the given slot. If the low leaf is not an exact match, the value hasn't been inserted and the stored value is zero. If it's an exact match, the latest value is contained in the leaf.
1 parent 260c7c3 commit 4711ef7

File tree

78 files changed

+2175
-789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2175
-789
lines changed

l1-contracts/src/core/libraries/ConstantsGen.sol

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ library Constants {
4747
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
4848
uint256 internal constant CONTRACT_TREE_HEIGHT = 16;
4949
uint256 internal constant NOTE_HASH_TREE_HEIGHT = 32;
50-
uint256 internal constant PUBLIC_DATA_TREE_HEIGHT = 254;
50+
uint256 internal constant PUBLIC_DATA_TREE_HEIGHT = 40;
5151
uint256 internal constant NULLIFIER_TREE_HEIGHT = 20;
5252
uint256 internal constant L1_TO_L2_MSG_TREE_HEIGHT = 16;
5353
uint256 internal constant ROLLUP_VK_TREE_HEIGHT = 8;
@@ -56,8 +56,10 @@ library Constants {
5656
uint256 internal constant NOTE_HASH_SUBTREE_HEIGHT = 7;
5757
uint256 internal constant NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 25;
5858
uint256 internal constant NULLIFIER_SUBTREE_HEIGHT = 7;
59+
uint256 internal constant PUBLIC_DATA_SUBTREE_HEIGHT = 4;
5960
uint256 internal constant ARCHIVE_HEIGHT = 16;
6061
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 13;
62+
uint256 internal constant PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 36;
6163
uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
6264
uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
6365
uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4;

l1-contracts/src/core/libraries/Decoder.sol

+36-34
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,41 @@ import {Hash} from "./Hash.sol";
3232
* | 0x00c4 | 0x04 | startNullifierTreeSnapshot.nextAvailableLeafIndex
3333
* | 0x00c8 | 0x20 | startContractTreeSnapshot.root
3434
* | 0x00e8 | 0x04 | startContractTreeSnapshot.nextAvailableLeafIndex
35-
* | 0x00ec | 0x20 | startPublicDataTreeRoot
36-
* | 0x010c | 0x20 | startL1ToL2MessageTreeSnapshot.root
37-
* | 0x012c | 0x04 | startL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex
38-
* | 0x0130 | 0x20 | startArchiveSnapshot.root
39-
* | 0x0150 | 0x04 | startArchiveSnapshot.nextAvailableLeafIndex
40-
* | 0x0154 | 0x20 | endNoteHashTreeSnapshot.root
41-
* | 0x0174 | 0x04 | endNoteHashTreeSnapshot.nextAvailableLeafIndex
42-
* | 0x0178 | 0x20 | endNullifierTreeSnapshot.root
43-
* | 0x0198 | 0x04 | endNullifierTreeSnapshot.nextAvailableLeafIndex
44-
* | 0x019c | 0x20 | endContractTreeSnapshot.root
45-
* | 0x01bc | 0x04 | endContractTreeSnapshot.nextAvailableLeafIndex
46-
* | 0x01c0 | 0x20 | endPublicDataTreeRoot
47-
* | 0x01e0 | 0x20 | endL1ToL2MessageTreeSnapshot.root
48-
* | 0x0200 | 0x04 | endL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex
49-
* | 0x0204 | 0x20 | endArchiveSnapshot.root
50-
* | 0x0224 | 0x04 | endArchiveSnapshot.nextAvailableLeafIndex
51-
* | 0x0228 | 0x04 | len(newCommitments) (denoted a)
52-
* | 0x022c | a * 0x20 | newCommitments
53-
* | 0x022c + a * 0x20 | 0x04 | len(newNullifiers) (denoted b)
54-
* | 0x0230 + a * 0x20 | b * 0x20 | newNullifiers
55-
* | 0x0230 + a * 0x20 + b * 0x20 | 0x04 | len(newPublicDataWrites) (denoted c)
56-
* | 0x0234 + a * 0x20 + b * 0x20 | c * 0x40 | newPublicDataWrites
57-
* | 0x0234 + a * 0x20 + b * 0x20 + c * 0x40 | 0x04 | len(newL2ToL1Msgs) (denoted d)
58-
* | 0x0238 + a * 0x20 + b * 0x20 + c * 0x40 | d * 0x20 | newL2ToL1Msgs
59-
* | 0x0238 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 | 0x04 | len(contracts) (denoted e)
60-
* | 0x023c + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 | e * 0x20 | newContracts
61-
* | 0x023c + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x20 | e * 0x34 | newContractsData
62-
* | 0x023c + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 | 0x04 | len(newL1ToL2Msgs) (denoted f)
63-
* | 0x0240 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 | f * 0x20 | newL1ToL2Msgs
64-
* | 0x0240 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 | 0x04 | byteLen(newEncryptedLogs) (denoted g)
65-
* | 0x0244 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 | g | newEncryptedLogs
66-
* | 0x0244 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 + g | 0x04 | byteLen(newUnencryptedLogs) (denoted h)
67-
* | 0x0248 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 + g | h | newUnencryptedLogs
35+
* | 0x00ec | 0x20 | startPublicDataTreeSnapshot.root
36+
* | 0x010c | 0x04 | startPublicDataTreeSnapshot.nextAvailableLeafIndex
37+
* | 0x0110 | 0x20 | startL1ToL2MessageTreeSnapshot.root
38+
* | 0x0130 | 0x04 | startL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex
39+
* | 0x0134 | 0x20 | startArchiveSnapshot.root
40+
* | 0x0154 | 0x04 | startArchiveSnapshot.nextAvailableLeafIndex
41+
* | 0x0158 | 0x20 | endNoteHashTreeSnapshot.root
42+
* | 0x0178 | 0x04 | endNoteHashTreeSnapshot.nextAvailableLeafIndex
43+
* | 0x017c | 0x20 | endNullifierTreeSnapshot.root
44+
* | 0x019c | 0x04 | endNullifierTreeSnapshot.nextAvailableLeafIndex
45+
* | 0x01a0 | 0x20 | endContractTreeSnapshot.root
46+
* | 0x01c0 | 0x04 | endContractTreeSnapshot.nextAvailableLeafIndex
47+
* | 0x01c4 | 0x20 | endPublicDataTreeSnapshot.root
48+
* | 0x01e4 | 0x04 | endPublicDataTreeSnapshot.nextAvailableLeafIndex
49+
* | 0x01e8 | 0x20 | endL1ToL2MessageTreeSnapshot.root
50+
* | 0x0208 | 0x04 | endL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex
51+
* | 0x020c | 0x20 | endArchiveSnapshot.root
52+
* | 0x022c | 0x04 | endArchiveSnapshot.nextAvailableLeafIndex
53+
* | 0x0230 | 0x04 | len(newCommitments) (denoted a)
54+
* | 0x0234 | a * 0x20 | newCommitments
55+
* | 0x0234 + a * 0x20 | 0x04 | len(newNullifiers) (denoted b)
56+
* | 0x0238 + a * 0x20 | b * 0x20 | newNullifiers
57+
* | 0x0238 + a * 0x20 + b * 0x20 | 0x04 | len(newPublicDataWrites) (denoted c)
58+
* | 0x023c + a * 0x20 + b * 0x20 | c * 0x40 | newPublicDataWrites
59+
* | 0x023c + a * 0x20 + b * 0x20 + c * 0x40 | 0x04 | len(newL2ToL1Msgs) (denoted d)
60+
* | 0x0240 + a * 0x20 + b * 0x20 + c * 0x40 | d * 0x20 | newL2ToL1Msgs
61+
* | 0x0240 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 | 0x04 | len(contracts) (denoted e)
62+
* | 0x0244 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 | e * 0x20 | newContracts
63+
* | 0x0244 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x20 | e * 0x34 | newContractsData
64+
* | 0x0244 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 | 0x04 | len(newL1ToL2Msgs) (denoted f)
65+
* | 0x0248 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 | f * 0x20 | newL1ToL2Msgs
66+
* | 0x0248 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 | 0x04 | byteLen(newEncryptedLogs) (denoted g)
67+
* | 0x024c + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 | g | newEncryptedLogs
68+
* | 0x024c + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 + g | 0x04 | byteLen(newUnencryptedLogs) (denoted h)
69+
* | 0x0250 + a * 0x20 + b * 0x20 + c * 0x40 + d * 0x20 + e * 0x54 + f * 0x20 + g | h | newUnencryptedLogs
6870
* | --- | --- | ---
6971
*/
7072
library Decoder {
@@ -97,7 +99,7 @@ library Decoder {
9799
uint256 private constant START_TREES_BLOCK_HEADER_OFFSET = 0x80;
98100

99101
// The size of the block header elements
100-
uint256 private constant TREES_BLOCK_HEADER_SIZE = 0xd4;
102+
uint256 private constant TREES_BLOCK_HEADER_SIZE = 0xd8;
101103

102104
// Where the end of trees metadata begins in the block
103105
uint256 private constant END_TREES_BLOCK_HEADER_OFFSET =

0 commit comments

Comments
 (0)