Skip to content

Commit 2478d19

Browse files
authored
feat: add total mana used to header (#9868)
1 parent 3c623fc commit 2478d19

File tree

50 files changed

+349
-269
lines changed

Some content is hidden

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

50 files changed

+349
-269
lines changed

barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
#define PUBLIC_INNER_CALL_REQUEST_LENGTH 13
3939
#define STATE_REFERENCE_LENGTH 8
4040
#define TOTAL_FEES_LENGTH 1
41-
#define HEADER_LENGTH 24
42-
#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 866
41+
#define HEADER_LENGTH 25
42+
#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 867
4343
#define AVM_ACCUMULATED_DATA_LENGTH 318
4444
#define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1006
4545
#define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86
4646
#define AVM_PROOF_LENGTH_IN_FIELDS 4166
4747
#define AVM_PUBLIC_COLUMN_MAX_SIZE 1024
48-
#define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2914
48+
#define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2915
4949
#define MEM_TAG_FF 0
5050
#define MEM_TAG_U1 1
5151
#define MEM_TAG_U8 2

barretenberg/cpp/src/barretenberg/world_state/world_state.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,8 @@ bb::fr WorldState::compute_initial_archive(const StateReference& initial_state_r
828828
0,
829829
0,
830830
// total fees
831+
0,
832+
// total mana used
831833
0 });
832834
}
833835

barretenberg/cpp/src/barretenberg/world_state/world_state.test.cpp

+30-28
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ class WorldStateTest : public testing::Test {
3030
static std::string data_dir;
3131
uint64_t map_size = 10240;
3232
uint64_t thread_pool_size = 1;
33+
34+
// TODO(): https://github.com/AztecProtocol/aztec-packages/issues/8084
3335
std::unordered_map<MerkleTreeId, uint32_t> tree_heights{
34-
{ MerkleTreeId::NULLIFIER_TREE, 20 }, { MerkleTreeId::NOTE_HASH_TREE, 32 },
35-
{ MerkleTreeId::PUBLIC_DATA_TREE, 40 }, { MerkleTreeId::L1_TO_L2_MESSAGE_TREE, 16 },
36-
{ MerkleTreeId::ARCHIVE, 16 },
36+
{ MerkleTreeId::NULLIFIER_TREE, 40 }, { MerkleTreeId::NOTE_HASH_TREE, 40 },
37+
{ MerkleTreeId::PUBLIC_DATA_TREE, 40 }, { MerkleTreeId::L1_TO_L2_MESSAGE_TREE, 39 },
38+
{ MerkleTreeId::ARCHIVE, 29 },
3739
};
3840
std::unordered_map<MerkleTreeId, index_t> tree_prefill{
3941
{ MerkleTreeId::NULLIFIER_TREE, 128 },
@@ -141,14 +143,14 @@ TEST_F(WorldStateTest, GetInitialTreeInfoForAllTrees)
141143
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::NULLIFIER_TREE);
142144
EXPECT_EQ(info.meta.size, 128);
143145
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::NULLIFIER_TREE));
144-
EXPECT_EQ(info.meta.root, bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"));
146+
EXPECT_EQ(info.meta.root, bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"));
145147
}
146148

147149
{
148150
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::NOTE_HASH_TREE);
149151
EXPECT_EQ(info.meta.size, 0);
150152
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::NOTE_HASH_TREE));
151-
EXPECT_EQ(info.meta.root, bb::fr("0x0b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d"));
153+
EXPECT_EQ(info.meta.root, bb::fr("0x1fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb"));
152154
}
153155

154156
{
@@ -162,15 +164,15 @@ TEST_F(WorldStateTest, GetInitialTreeInfoForAllTrees)
162164
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
163165
EXPECT_EQ(info.meta.size, 0);
164166
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE));
165-
EXPECT_EQ(info.meta.root, bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"));
167+
EXPECT_EQ(info.meta.root, bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"));
166168
}
167169

168170
{
169171
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::ARCHIVE);
170172
EXPECT_EQ(info.meta.size, 1);
171173
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::ARCHIVE));
172174
// this is the expected archive tree root at genesis
173-
EXPECT_EQ(info.meta.root, bb::fr("0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e"));
175+
EXPECT_EQ(info.meta.root, bb::fr("0x0237797d6a2c04d20d4fa06b74482bd970ccd51a43d9b05b57e9b91fa1ae1cae"));
174176
}
175177
}
176178

@@ -184,14 +186,14 @@ TEST_F(WorldStateTest, GetStateReference)
184186
auto snapshot = state_ref.at(MerkleTreeId::NULLIFIER_TREE);
185187
EXPECT_EQ(
186188
snapshot,
187-
std::make_pair(bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"), 128UL));
189+
std::make_pair(bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"), 128UL));
188190
}
189191

190192
{
191193
auto snapshot = state_ref.at(MerkleTreeId::NOTE_HASH_TREE);
192194
EXPECT_EQ(
193195
snapshot,
194-
std::make_pair(bb::fr("0x0b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d"), 0UL));
196+
std::make_pair(bb::fr("0x1fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb"), 0UL));
195197
}
196198

197199
{
@@ -205,7 +207,7 @@ TEST_F(WorldStateTest, GetStateReference)
205207
auto snapshot = state_ref.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
206208
EXPECT_EQ(
207209
snapshot,
208-
std::make_pair(bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"), 0UL));
210+
std::make_pair(bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"), 0UL));
209211
}
210212
}
211213

@@ -217,14 +219,14 @@ TEST_F(WorldStateTest, GetStateReference)
217219
auto snapshot = state_ref.at(MerkleTreeId::NULLIFIER_TREE);
218220
EXPECT_EQ(
219221
snapshot,
220-
std::make_pair(bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"), 128UL));
222+
std::make_pair(bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"), 128UL));
221223
}
222224

223225
{
224226
auto snapshot = state_ref.at(MerkleTreeId::NOTE_HASH_TREE);
225227
EXPECT_EQ(
226228
snapshot,
227-
std::make_pair(bb::fr("0x12dbc0ae893e0aa914df8ed20837148c89d78fbef9471ede1d39416d9660c169"), 1UL));
229+
std::make_pair(bb::fr("0x0f031292dfc64353244dfc38871cbeac74ddbd03df4a0856c411bb1ddfb494f0"), 1UL));
228230
}
229231

230232
{
@@ -238,7 +240,7 @@ TEST_F(WorldStateTest, GetStateReference)
238240
auto snapshot = state_ref.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
239241
EXPECT_EQ(
240242
snapshot,
241-
std::make_pair(bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"), 0UL));
243+
std::make_pair(bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"), 0UL));
242244
}
243245
}
244246
}
@@ -497,13 +499,13 @@ TEST_F(WorldStateTest, SyncExternalBlockFromEmpty)
497499
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
498500
StateReference block_state_ref = {
499501
{ MerkleTreeId::NULLIFIER_TREE,
500-
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
502+
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
501503
{ MerkleTreeId::NOTE_HASH_TREE,
502-
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
504+
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
503505
{ MerkleTreeId::PUBLIC_DATA_TREE,
504506
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
505507
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
506-
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
508+
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
507509
};
508510

509511
WorldStateStatusFull status = ws.sync_block(
@@ -529,13 +531,13 @@ TEST_F(WorldStateTest, SyncBlockFromDirtyState)
529531
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
530532
StateReference block_state_ref = {
531533
{ MerkleTreeId::NULLIFIER_TREE,
532-
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
534+
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
533535
{ MerkleTreeId::NOTE_HASH_TREE,
534-
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
536+
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
535537
{ MerkleTreeId::PUBLIC_DATA_TREE,
536538
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
537539
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
538-
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
540+
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
539541
};
540542

541543
ws.append_leaves<fr>(MerkleTreeId::NOTE_HASH_TREE, { fr(142) });
@@ -572,13 +574,13 @@ TEST_F(WorldStateTest, SyncCurrentBlock)
572574
bb::fr block_hash(1);
573575
StateReference block_state_ref = {
574576
{ MerkleTreeId::NULLIFIER_TREE,
575-
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
577+
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
576578
{ MerkleTreeId::NOTE_HASH_TREE,
577-
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
579+
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
578580
{ MerkleTreeId::PUBLIC_DATA_TREE,
579581
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
580582
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
581-
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
583+
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
582584
};
583585

584586
ws.append_leaves<fr>(MerkleTreeId::NOTE_HASH_TREE, { 42 });
@@ -610,13 +612,13 @@ TEST_F(WorldStateTest, RejectSyncBlockWithBadPublicWriteBatches)
610612
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
611613
StateReference block_state_ref = {
612614
{ MerkleTreeId::NULLIFIER_TREE,
613-
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
615+
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
614616
{ MerkleTreeId::NOTE_HASH_TREE,
615-
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
617+
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
616618
{ MerkleTreeId::PUBLIC_DATA_TREE,
617619
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
618620
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
619-
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
621+
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
620622
};
621623

622624
auto sync = [&]() {
@@ -637,13 +639,13 @@ TEST_F(WorldStateTest, RejectSyncBlockWithInvalidStateRef)
637639
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
638640
StateReference block_state_ref = {
639641
{ MerkleTreeId::NULLIFIER_TREE,
640-
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
642+
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
641643
{ MerkleTreeId::NOTE_HASH_TREE,
642-
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
644+
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
643645
{ MerkleTreeId::PUBLIC_DATA_TREE,
644646
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
645647
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
646-
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
648+
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
647649
};
648650

649651
auto sync = [&]() {

docs/docs/protocol-specs/gas-and-fees/specifying-gas-fee-info.md

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ classDiagram
7878
class Header {
7979
+GlobalVariables globalVariables
8080
+Fr totalFees
81+
+Fr totalManaUsed
8182
}
8283
8384
class GlobalVariables {
@@ -100,6 +101,8 @@ The `feePerGas` is presently held constant at `1` for both dimensions, but may b
100101

101102
`totalFees` is the total fees collected in the block in FPA.
102103

104+
`totalManaUsed` is the total mana used in the block and used to update the base fee.
105+
103106
`coinbase` is the L1 address that receives the fees.
104107

105108
## Transaction Fee

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ library Constants {
9696
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
9797
uint256 internal constant AZTEC_MAX_EPOCH_DURATION = 32;
9898
uint256 internal constant GENESIS_ARCHIVE_ROOT =
99-
19007378675971183768036762391356802220352606103602592933942074152320327194720;
99+
1002640778211850180189505934749257244705296832326768971348723156503780793518;
100100
uint256 internal constant FEE_JUICE_INITIAL_MINT = 20000000000000000000;
101101
uint256 internal constant FEE_FUNDING_FOR_TESTER_ACCOUNT = 100000000000000000000;
102102
uint256 internal constant PUBLIC_DISPATCH_SELECTOR = 3578010381;
@@ -201,27 +201,28 @@ library Constants {
201201
uint256 internal constant TX_CONTEXT_LENGTH = 8;
202202
uint256 internal constant TX_REQUEST_LENGTH = 12;
203203
uint256 internal constant TOTAL_FEES_LENGTH = 1;
204-
uint256 internal constant HEADER_LENGTH = 24;
205-
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 490;
206-
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 866;
207-
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 37;
204+
uint256 internal constant TOTAL_MANA_USED_LENGTH = 1;
205+
uint256 internal constant HEADER_LENGTH = 25;
206+
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 491;
207+
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 867;
208+
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 38;
208209
uint256 internal constant FEE_RECIPIENT_LENGTH = 2;
209210
uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16;
210211
uint256 internal constant SCOPED_READ_REQUEST_LEN = 3;
211212
uint256 internal constant PUBLIC_DATA_READ_LENGTH = 3;
212213
uint256 internal constant PRIVATE_VALIDATION_REQUESTS_LENGTH = 772;
213214
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 550;
214-
uint256 internal constant TX_CONSTANT_DATA_LENGTH = 34;
215-
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 43;
215+
uint256 internal constant TX_CONSTANT_DATA_LENGTH = 35;
216+
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 44;
216217
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1036;
217-
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1849;
218+
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1850;
218219
uint256 internal constant PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH = 548;
219220
uint256 internal constant PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160;
220221
uint256 internal constant NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3;
221-
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1140;
222-
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 605;
222+
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1141;
223+
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 606;
223224
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13;
224-
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 30;
225+
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31;
225226
uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 90;
226227
uint256 internal constant ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH = 76;
227228
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;

0 commit comments

Comments
 (0)