Skip to content

Commit

Permalink
plumb da_gas_used through kernel and rollup. Basic computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Mar 28, 2024
1 parent a066544 commit 61fb9d3
Show file tree
Hide file tree
Showing 54 changed files with 1,307 additions and 209 deletions.
3 changes: 3 additions & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ library Constants {
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant DA_GAS_PER_BYTE = 16;
uint256 internal constant FIXED_DA_GAS = 272;
uint256 internal constant DA_BYTES_PER_FIELD = 32;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
uint256 internal constant VK_TREE_HEIGHT = 3;
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
Expand Down
58 changes: 33 additions & 25 deletions l1-contracts/src/core/libraries/decoders/TxsDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@ import {Hash} from "../Hash.sol";
* -------------------
* L2 Body Data Specification
* -------------------
* | byte start | num bytes | name
* | --- | --- | ---
* | 0x0 | 0x4 | len(numTxs) (denoted t)
* | | | TxEffect 0 {
* | 0x4 | 0x1 | len(newNoteHashes) (denoted b)
* | 0x4 + 0x1 | b * 0x20 | newNoteHashes
* | 0x4 + 0x1 + b * 0x20 | 0x1 | len(newNullifiers) (denoted c)
* | 0x4 + 0x1 + b * 0x20 + 0x1 | c * 0x20 | newNullifiers
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 | 0x1 | len(newL2ToL1Msgs) (denoted d)
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 | d * 0x20 | newL2ToL1Msgs
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 | 0x1 | len(newPublicDataWrites) (denoted e)
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 | e * 0x40 | newPublicDataWrites
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 | 0x04 | byteLen(newEncryptedLogs) (denoted f)
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 | f | newEncryptedLogs
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 + f | 0x04 | byteLen(newUnencryptedLogs) (denoted g)
* | 0x4 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 + f + 0x4 | g | newUnencryptedLogs
* | | | },
* | | | TxEffect 1 {
* | | | ...
* | | | },
* | | | ...
* | | | TxEffect (t - 1) {
* | | | ...
* | | | },
* | byte start | num bytes | name
* | --- | --- | ---
* | 0x0 | 0x4 | len(numTxs) (denoted t)
* | | | TxEffect 0 {
* | 0x4 | 0x8 | daGasUsed
* | 0x4 + 0x8 | 0x1 | revertCode
* | 0x4 + 0x8 + 0x1 | 0x1 | len(newNoteHashes) (denoted b)
* | 0x4 + 0x8 + 0x1 + 0x1 | b * 0x20 | newNoteHashes
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 | 0x1 | len(newNullifiers) (denoted c)
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 | c * 0x20 | newNullifiers
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 | 0x1 | len(newL2ToL1Msgs) (denoted d)
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 | d * 0x20 | newL2ToL1Msgs
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 | 0x1 | len(newPublicDataWrites) (denoted e)
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 | e * 0x40 | newPublicDataWrites
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 | 0x04 | byteLen(newEncryptedLogs) (denoted f)
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 | f | newEncryptedLogs
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 + f | 0x04 | byteLen(newUnencryptedLogs) (denoted g)
* | 0x4 + 0x8 + 0x1 + 0x1 + b * 0x20 + 0x1 + c * 0x20 + 0x1 + d * 0x20 + 0x01 + e * 0x40 + 0x4 + f + 0x4 | g | newUnencryptedLogs
* | | | },
* | | | TxEffect 1 {
* | | | ...
* | | | },
* | | | ...
* | | | TxEffect (t - 1) {
* | | | ...
* | | | },
*/
library TxsDecoder {
struct ArrayOffsets {
uint256 daGasUsed;
uint256 revertCode;
uint256 noteHash;
uint256 nullifier;
Expand Down Expand Up @@ -105,6 +108,10 @@ library TxsDecoder {
* Zero values.
*/

// daGasUsed
offsets.daGasUsed = offset;
offset += 0x8;

// Revert Code
offsets.revertCode = offset;
offset += 0x1;
Expand Down Expand Up @@ -146,7 +153,8 @@ library TxsDecoder {

// Insertions are split into multiple `bytes.concat` to work around stack too deep.
vars.baseLeaf = bytes.concat(
// pad the revert code to 32 bytes to match the hash preimage
// pad these values to 32 bytes to match the hash preimage
sliceAndPadLeft(_body, offsets.daGasUsed, 0x8, 0x20),
sliceAndPadLeft(_body, offsets.revertCode, 0x1, 0x20),
bytes.concat(
sliceAndPadRight(
Expand Down
16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/empty_block_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
]
},
"block": {
"archive": "0x29598370fa40a50b7fbb99e501f11527a69e104a43c8eefbfe66888f137e7e49",
"body": "0x0000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5",
"archive": "0x0d46b75aab05566e1c725d2e3fd396625e7e68063b393501140c92b2f8d61481",
"body": "0x00000004000000000000019000000000000000000000000000000000000000019000000000000000000000000000000000000000019000000000000000000000000000000000000000019000000000000000000000000000",
"txsEffectsHash": "0x00b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a400123",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa4316",
"txTreeHeight": 2,
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5"
"txsEffectsHash": "0x00b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a400123"
},
"globalVariables": {
"blockNumber": 1,
"chainId": 31337,
"timestamp": 0,
"version": 1,
"coinbase": "0x5e65711eaf5606f1f42dd36579261833e54595ee",
"feeRecipient": "0x00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e"
"coinbase": "0x27204f71247c4b9a95aa1b191c2983b1734cb861",
"feeRecipient": "0x1887e79146cc1e84707003c5b9d9fdaf3cfe2bcf07d682a032fdba97cc98b97e"
},
"lastArchive": {
"nextAvailableLeafIndex": 1,
Expand All @@ -60,7 +60,7 @@
}
}
},
"header": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd130000000010000000000000000000000000000000000000000000000000000000000000002008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd500089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa43161864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000005e65711eaf5606f1f42dd36579261833e54595ee00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e",
"publicInputsHash": "0x009e67eb54715bba61c94f475f6d4bf81b775da316c2c9a6a12506851f760bf0"
"header": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd13000000001000000000000000000000000000000000000000000000000000000000000000200b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a40012300089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa43161864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000027204f71247c4b9a95aa1b191c2983b1734cb8611887e79146cc1e84707003c5b9d9fdaf3cfe2bcf07d682a032fdba97cc98b97e",
"publicInputsHash": "0x00e871424d9f28f7086909abbf5863791205778e437e8a19d9ee0a72eb7baa0e"
}
}
20 changes: 10 additions & 10 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
]
},
"block": {
"archive": "0x045487d0ec498eb3f7f027715db8d67cc060604058bc5dd3e2e39fb47fe0ea17",
"body": "0x0000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5",
"archive": "0x15739377b1844c78d29e3a560c31fc4fc966d80f5ee8886c900a825afb49a56a",
"body": "0x00000004000000000000019000000000000000000000000000000000000000019000000000000000000000000000000000000000019000000000000000000000000000000000000000019000000000000000000000000000",
"txsEffectsHash": "0x00b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a400123",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa4316",
"txTreeHeight": 2,
"txsEffectsHash": "0x008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd5"
"txsEffectsHash": "0x00b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a400123"
},
"globalVariables": {
"blockNumber": 2,
"chainId": 31337,
"timestamp": 1711036059,
"timestamp": 1711569782,
"version": 1,
"coinbase": "0x5e65711eaf5606f1f42dd36579261833e54595ee",
"feeRecipient": "0x00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e"
"coinbase": "0x27204f71247c4b9a95aa1b191c2983b1734cb861",
"feeRecipient": "0x1887e79146cc1e84707003c5b9d9fdaf3cfe2bcf07d682a032fdba97cc98b97e"
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x29598370fa40a50b7fbb99e501f11527a69e104a43c8eefbfe66888f137e7e49"
"root": "0x0d46b75aab05566e1c725d2e3fd396625e7e68063b393501140c92b2f8d61481"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -60,7 +60,7 @@
}
}
},
"header": "0x29598370fa40a50b7fbb99e501f11527a69e104a43c8eefbfe66888f137e7e49000000020000000000000000000000000000000000000000000000000000000000000002008194e3dd375d5d878dcf9546bb5c2c77e165c6b1bef9aead8ceb35c3762bd500089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa43161864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000002000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000002800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000001400000000000000000000000000000000000000000000000000000000000007a69000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000065fc569b5e65711eaf5606f1f42dd36579261833e54595ee00eafbad09eab548a89726e2a735bdcadc37aa4c318ed7a12d9be6a7542e517e",
"publicInputsHash": "0x00e9cfdd839060c90c216e1cecd24c5570a84e380e2bc640fd9dbbb5b2dd0718"
"header": "0x0d46b75aab05566e1c725d2e3fd396625e7e68063b393501140c92b2f8d6148100000002000000000000000000000000000000000000000000000000000000000000000200b255173dfd4d694f1cda6750950244cb2efdc1c80176a61675779f5a40012300089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00efcbdb79553ae6863646bf36441755bc344a9a4af335fadc6659594faa43161864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000002000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000002800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000001400000000000000000000000000000000000000000000000000000000000007a69000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000066047b7627204f71247c4b9a95aa1b191c2983b1734cb8611887e79146cc1e84707003c5b9d9fdaf3cfe2bcf07d682a032fdba97cc98b97e",
"publicInputsHash": "0x000d3792c334226f40d2d19fd433172dceb4202d337b9a8b0cd01c71c72ee262"
}
}
16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/mixed_block_0.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions l1-contracts/test/fixtures/mixed_block_1.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn initialize_emitted_end_values(
}

let start_non_revertible = previous_kernel.public_inputs.end_non_revertible;
circuit_outputs.end_non_revertible.da_gas_used = start_non_revertible.da_gas_used;
circuit_outputs.end_non_revertible.new_note_hashes = array_to_bounded_vec(start_non_revertible.new_note_hashes);
circuit_outputs.end_non_revertible.new_nullifiers = array_to_bounded_vec(start_non_revertible.new_nullifiers);
circuit_outputs.end_non_revertible.public_data_update_requests = array_to_bounded_vec(start_non_revertible.public_data_update_requests);
Expand All @@ -92,18 +93,19 @@ pub fn initialize_end_values(
initialize_emitted_end_values(previous_kernel, circuit_outputs);

if circuit_outputs.end_non_revertible.revert_code == 0 {
let start = previous_kernel.public_inputs.end;
let prev_end = previous_kernel.public_inputs.end;
// circuit_outputs.end.private_call_stack = array_to_bounded_vec(start.private_call_stack); // This is enforced in the private tail to always be empty.
circuit_outputs.end.public_call_stack = array_to_bounded_vec(start.public_call_stack);
circuit_outputs.end.public_call_stack = array_to_bounded_vec(prev_end.public_call_stack);
}

let start_non_revertible = previous_kernel.public_inputs.end_non_revertible;
circuit_outputs.end_non_revertible.public_call_stack = array_to_bounded_vec(start_non_revertible.public_call_stack);
let prev_non_revertible = previous_kernel.public_inputs.end_non_revertible;
circuit_outputs.end_non_revertible.public_call_stack = array_to_bounded_vec(prev_non_revertible.public_call_stack);
circuit_outputs.end_non_revertible.da_gas_used = prev_non_revertible.da_gas_used;

let start = previous_kernel.public_inputs.validation_requests;
circuit_outputs.validation_requests.max_block_number = previous_kernel.public_inputs.validation_requests.for_rollup.max_block_number;
circuit_outputs.validation_requests.nullifier_read_requests = array_to_bounded_vec(start.nullifier_read_requests);
circuit_outputs.validation_requests.nullifier_non_existent_read_requests = array_to_bounded_vec(start.nullifier_non_existent_read_requests);
let prev_validation_requests = previous_kernel.public_inputs.validation_requests;
circuit_outputs.validation_requests.max_block_number = prev_validation_requests.for_rollup.max_block_number;
circuit_outputs.validation_requests.nullifier_read_requests = array_to_bounded_vec(prev_validation_requests.nullifier_read_requests);
circuit_outputs.validation_requests.nullifier_non_existent_read_requests = array_to_bounded_vec(prev_validation_requests.nullifier_non_existent_read_requests);
}

fn perform_static_call_checks(public_call: PublicCallData) {
Expand Down
Loading

0 comments on commit 61fb9d3

Please sign in to comment.