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: add total mana used to header #9868

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
#define PUBLIC_INNER_CALL_REQUEST_LENGTH 13
#define STATE_REFERENCE_LENGTH 8
#define TOTAL_FEES_LENGTH 1
#define HEADER_LENGTH 24
#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 866
#define HEADER_LENGTH 25
#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 867
#define AVM_ACCUMULATED_DATA_LENGTH 318
#define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1006
#define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86
#define AVM_PROOF_LENGTH_IN_FIELDS 4166
#define AVM_PUBLIC_COLUMN_MAX_SIZE 1024
#define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2914
#define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2915
#define MEM_TAG_FF 0
#define MEM_TAG_U1 1
#define MEM_TAG_U8 2
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/world_state/world_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ bb::fr WorldState::compute_initial_archive(const StateReference& initial_state_r
0,
0,
// total fees
0,
// total mana used
0 });
}

Expand Down
58 changes: 30 additions & 28 deletions barretenberg/cpp/src/barretenberg/world_state/world_state.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class WorldStateTest : public testing::Test {
static std::string data_dir;
uint64_t map_size = 10240;
uint64_t thread_pool_size = 1;

// TODO(): https://github.com/AztecProtocol/aztec-packages/issues/8084
std::unordered_map<MerkleTreeId, uint32_t> tree_heights{
{ MerkleTreeId::NULLIFIER_TREE, 20 }, { MerkleTreeId::NOTE_HASH_TREE, 32 },
{ MerkleTreeId::PUBLIC_DATA_TREE, 40 }, { MerkleTreeId::L1_TO_L2_MESSAGE_TREE, 16 },
{ MerkleTreeId::ARCHIVE, 16 },
{ MerkleTreeId::NULLIFIER_TREE, 40 }, { MerkleTreeId::NOTE_HASH_TREE, 40 },
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
{ MerkleTreeId::PUBLIC_DATA_TREE, 40 }, { MerkleTreeId::L1_TO_L2_MESSAGE_TREE, 39 },
{ MerkleTreeId::ARCHIVE, 29 },
};
std::unordered_map<MerkleTreeId, index_t> tree_prefill{
{ MerkleTreeId::NULLIFIER_TREE, 128 },
Expand Down Expand Up @@ -141,14 +143,14 @@ TEST_F(WorldStateTest, GetInitialTreeInfoForAllTrees)
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::NULLIFIER_TREE);
EXPECT_EQ(info.meta.size, 128);
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::NULLIFIER_TREE));
EXPECT_EQ(info.meta.root, bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"));
EXPECT_EQ(info.meta.root, bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"));
}

{
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::NOTE_HASH_TREE);
EXPECT_EQ(info.meta.size, 0);
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::NOTE_HASH_TREE));
EXPECT_EQ(info.meta.root, bb::fr("0x0b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d"));
EXPECT_EQ(info.meta.root, bb::fr("0x1fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb"));
}

{
Expand All @@ -162,15 +164,15 @@ TEST_F(WorldStateTest, GetInitialTreeInfoForAllTrees)
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
EXPECT_EQ(info.meta.size, 0);
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE));
EXPECT_EQ(info.meta.root, bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"));
EXPECT_EQ(info.meta.root, bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"));
}

{
auto info = ws.get_tree_info(WorldStateRevision::committed(), MerkleTreeId::ARCHIVE);
EXPECT_EQ(info.meta.size, 1);
EXPECT_EQ(info.meta.depth, tree_heights.at(MerkleTreeId::ARCHIVE));
// this is the expected archive tree root at genesis
EXPECT_EQ(info.meta.root, bb::fr("0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e"));
EXPECT_EQ(info.meta.root, bb::fr("0x0237797d6a2c04d20d4fa06b74482bd970ccd51a43d9b05b57e9b91fa1ae1cae"));
}
}

Expand All @@ -184,14 +186,14 @@ TEST_F(WorldStateTest, GetStateReference)
auto snapshot = state_ref.at(MerkleTreeId::NULLIFIER_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"), 128UL));
std::make_pair(bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"), 128UL));
}

{
auto snapshot = state_ref.at(MerkleTreeId::NOTE_HASH_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x0b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d"), 0UL));
std::make_pair(bb::fr("0x1fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb"), 0UL));
}

{
Expand All @@ -205,7 +207,7 @@ TEST_F(WorldStateTest, GetStateReference)
auto snapshot = state_ref.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"), 0UL));
std::make_pair(bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"), 0UL));
}
}

Expand All @@ -217,14 +219,14 @@ TEST_F(WorldStateTest, GetStateReference)
auto snapshot = state_ref.at(MerkleTreeId::NULLIFIER_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x19a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc"), 128UL));
std::make_pair(bb::fr("0x0c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d639073"), 128UL));
}

{
auto snapshot = state_ref.at(MerkleTreeId::NOTE_HASH_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x12dbc0ae893e0aa914df8ed20837148c89d78fbef9471ede1d39416d9660c169"), 1UL));
std::make_pair(bb::fr("0x0f031292dfc64353244dfc38871cbeac74ddbd03df4a0856c411bb1ddfb494f0"), 1UL));
}

{
Expand All @@ -238,7 +240,7 @@ TEST_F(WorldStateTest, GetStateReference)
auto snapshot = state_ref.at(MerkleTreeId::L1_TO_L2_MESSAGE_TREE);
EXPECT_EQ(
snapshot,
std::make_pair(bb::fr("0x14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3"), 0UL));
std::make_pair(bb::fr("0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"), 0UL));
}
}
}
Expand Down Expand Up @@ -497,13 +499,13 @@ TEST_F(WorldStateTest, SyncExternalBlockFromEmpty)
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
StateReference block_state_ref = {
{ MerkleTreeId::NULLIFIER_TREE,
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
{ MerkleTreeId::NOTE_HASH_TREE,
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
{ MerkleTreeId::PUBLIC_DATA_TREE,
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
};

WorldStateStatusFull status = ws.sync_block(
Expand All @@ -529,13 +531,13 @@ TEST_F(WorldStateTest, SyncBlockFromDirtyState)
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
StateReference block_state_ref = {
{ MerkleTreeId::NULLIFIER_TREE,
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
{ MerkleTreeId::NOTE_HASH_TREE,
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
{ MerkleTreeId::PUBLIC_DATA_TREE,
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
};

ws.append_leaves<fr>(MerkleTreeId::NOTE_HASH_TREE, { fr(142) });
Expand Down Expand Up @@ -572,13 +574,13 @@ TEST_F(WorldStateTest, SyncCurrentBlock)
bb::fr block_hash(1);
StateReference block_state_ref = {
{ MerkleTreeId::NULLIFIER_TREE,
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
{ MerkleTreeId::NOTE_HASH_TREE,
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
{ MerkleTreeId::PUBLIC_DATA_TREE,
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
};

ws.append_leaves<fr>(MerkleTreeId::NOTE_HASH_TREE, { 42 });
Expand Down Expand Up @@ -610,13 +612,13 @@ TEST_F(WorldStateTest, RejectSyncBlockWithBadPublicWriteBatches)
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
StateReference block_state_ref = {
{ MerkleTreeId::NULLIFIER_TREE,
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
{ MerkleTreeId::NOTE_HASH_TREE,
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
{ MerkleTreeId::PUBLIC_DATA_TREE,
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
};

auto sync = [&]() {
Expand All @@ -637,13 +639,13 @@ TEST_F(WorldStateTest, RejectSyncBlockWithInvalidStateRef)
WorldState ws(thread_pool_size, data_dir, map_size, tree_heights, tree_prefill, initial_header_generator_point);
StateReference block_state_ref = {
{ MerkleTreeId::NULLIFIER_TREE,
{ fr("0x0342578609a7358092788d0eed7d1ee0ec8e0c596c0b1e85ba980ddd5cc79d04"), 129 } },
{ fr("0x187a19972150cd1e76d8201d720da7682fcf4d93ec6a3c7b0d84bbefde5bd927"), 129 } },
{ MerkleTreeId::NOTE_HASH_TREE,
{ fr("0x15dad063953d8d216c1db77739d6fb27e1b73a5beef748a1208898b3428781eb"), 1 } },
{ fr("0x2467e5f90736b4ea977e7d21cfb3714181e16b7d6cd867768b59e2ea90fa3eaf"), 1 } },
{ MerkleTreeId::PUBLIC_DATA_TREE,
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
{ fr("0x20ea8ca97f96508aaed2d6cdc4198a41c77c640bfa8785a51bb905b9a672ba0b"), 1 } },
{ fr("0x24ffd0fab86555ab2e86cffc706d4cfb4b8c405c3966af805de954504ffc27ac"), 1 } },
};

auto sync = [&]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ classDiagram
class Header {
+GlobalVariables globalVariables
+Fr totalFees
+Fr totalManaUsed
}

class GlobalVariables {
Expand All @@ -100,6 +101,8 @@ The `feePerGas` is presently held constant at `1` for both dimensions, but may b

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

`totalManaUsed` is the total mana used in the block and used to update the base fee.

`coinbase` is the L1 address that receives the fees.

## Transaction Fee
Expand Down
23 changes: 12 additions & 11 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ library Constants {
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant AZTEC_MAX_EPOCH_DURATION = 32;
uint256 internal constant GENESIS_ARCHIVE_ROOT =
19007378675971183768036762391356802220352606103602592933942074152320327194720;
1002640778211850180189505934749257244705296832326768971348723156503780793518;
uint256 internal constant FEE_JUICE_INITIAL_MINT = 20000000000000000000;
uint256 internal constant FEE_FUNDING_FOR_TESTER_ACCOUNT = 100000000000000000000;
uint256 internal constant PUBLIC_DISPATCH_SELECTOR = 3578010381;
Expand Down Expand Up @@ -201,27 +201,28 @@ library Constants {
uint256 internal constant TX_CONTEXT_LENGTH = 8;
uint256 internal constant TX_REQUEST_LENGTH = 12;
uint256 internal constant TOTAL_FEES_LENGTH = 1;
uint256 internal constant HEADER_LENGTH = 24;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 490;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 866;
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 37;
uint256 internal constant TOTAL_MANA_USED_LENGTH = 1;
uint256 internal constant HEADER_LENGTH = 25;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 491;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 867;
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 38;
uint256 internal constant FEE_RECIPIENT_LENGTH = 2;
uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16;
uint256 internal constant SCOPED_READ_REQUEST_LEN = 3;
uint256 internal constant PUBLIC_DATA_READ_LENGTH = 3;
uint256 internal constant PRIVATE_VALIDATION_REQUESTS_LENGTH = 772;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 550;
uint256 internal constant TX_CONSTANT_DATA_LENGTH = 34;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 43;
uint256 internal constant TX_CONSTANT_DATA_LENGTH = 35;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 44;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1036;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1849;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1850;
uint256 internal constant PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH = 548;
uint256 internal constant PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160;
uint256 internal constant NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3;
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1140;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 605;
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1141;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 606;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 30;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31;
uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 90;
uint256 internal constant ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH = 76;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
Expand Down
Loading
Loading