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: Update circuits structs with gas info #5677

Merged
merged 1 commit into from
Apr 11, 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
22 changes: 13 additions & 9 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ library Constants {
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant NESTED_CALL_L2_GAS_BUFFER = 20000;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 15000;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 16000;
uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000;
uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000;
uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19;
Expand All @@ -83,36 +83,40 @@ library Constants {
uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
uint256 internal constant DEPLOYER_CONTRACT_ADDRESS =
0x00eadf9f983d265e8f496dec4172e75b4a98fe00a99a1b80042a7257b63a3a56;
0x1df42e0457430b8d294d920181cc72ae0e3c5f8afd8d62d461bd26773cfdf3c1;
uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17;
uint256 internal constant MAX_NOTE_FIELDS_LENGTH = 20;
uint256 internal constant GET_NOTE_ORACLE_RETURN_LENGTH = 23;
uint256 internal constant MAX_NOTES_PER_PAGE = 10;
uint256 internal constant VIEW_NOTE_ORACLE_RETURN_LENGTH = 212;
uint256 internal constant AZTEC_ADDRESS_LENGTH = 1;
uint256 internal constant CALL_CONTEXT_LENGTH = 7;
uint256 internal constant CALL_CONTEXT_LENGTH = 18;
uint256 internal constant GAS_SETTINGS_LENGTH = 10;
uint256 internal constant DIMENSION_GAS_SETTINGS_LENGTH = 3;
uint256 internal constant GAS_FEES_LENGTH = 3;
uint256 internal constant GAS_USED_LENGTH = 3;
uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4;
uint256 internal constant CONTRACT_INSTANCE_LENGTH = 6;
uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2;
uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 2;
uint256 internal constant ETH_ADDRESS_LENGTH = 1;
uint256 internal constant FUNCTION_DATA_LENGTH = 2;
uint256 internal constant FUNCTION_LEAF_PREIMAGE_LENGTH = 5;
uint256 internal constant GLOBAL_VARIABLES_LENGTH = 6;
uint256 internal constant HEADER_LENGTH = 20;
uint256 internal constant GLOBAL_VARIABLES_LENGTH = 9;
uint256 internal constant HEADER_LENGTH = 23;
uint256 internal constant L1_TO_L2_MESSAGE_LENGTH = 6;
uint256 internal constant L2_TO_L1_MESSAGE_LENGTH = 2;
uint256 internal constant MAX_BLOCK_NUMBER_LENGTH = 2;
uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 4;
uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 5;
uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 6;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 207;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 195;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 221;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 218;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 209;
uint256 internal constant STATE_REFERENCE_LENGTH = 8;
uint256 internal constant TX_CONTEXT_DATA_LENGTH = 4;
uint256 internal constant TX_REQUEST_LENGTH = 8;
uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 11;
uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 22;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
uint256 internal constant NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
Expand Down
17 changes: 15 additions & 2 deletions l1-contracts/src/core/libraries/HeaderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import {Hash} from "./Hash.sol";
* | 0x0194 | 0x20 | timestamp
* | 0x01b4 | 0x14 | coinbase
* | 0x01c8 | 0x20 | feeRecipient
* | 0x01e8 | 0x20 | gasFees.feePerDaGas
* | 0x0208 | 0x20 | gasFees.feePerL1Gas
* | 0x0228 | 0x20 | gasFees.feePerL2Gas
* | | | }
* | | | }
* | --- | --- | ---
Expand All @@ -71,13 +74,20 @@ library HeaderLib {
PartialStateReference partialStateReference;
}

struct GasFees {
uint256 feePerDaGas;
uint256 feePerL1Gas;
uint256 feePerL2Gas;
}

struct GlobalVariables {
uint256 chainId;
uint256 version;
uint256 blockNumber;
uint256 timestamp;
address coinbase;
bytes32 feeRecipient;
GasFees gasFees;
}

struct ContentCommitment {
Expand All @@ -94,7 +104,7 @@ library HeaderLib {
GlobalVariables globalVariables;
}

uint256 private constant HEADER_LENGTH = 0x1e8; // Header byte length
uint256 private constant HEADER_LENGTH = 0x248; // Header byte length

/**
* @notice Validates the header
Expand Down Expand Up @@ -178,7 +188,10 @@ library HeaderLib {
header.globalVariables.blockNumber = uint256(bytes32(_header[0x0174:0x0194]));
header.globalVariables.timestamp = uint256(bytes32(_header[0x0194:0x01b4]));
header.globalVariables.coinbase = address(bytes20(_header[0x01b4:0x01c8]));
header.globalVariables.feeRecipient = bytes32(_header[0x01c8:HEADER_LENGTH]);
header.globalVariables.feeRecipient = bytes32(_header[0x01c8:0x01e8]);
header.globalVariables.gasFees.feePerDaGas = uint256(bytes32(_header[0x01e8:0x0208]));
header.globalVariables.gasFees.feePerL1Gas = uint256(bytes32(_header[0x0208:0x0228]));
header.globalVariables.gasFees.feePerL2Gas = uint256(bytes32(_header[0x0228:0x0248]));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
header.globalVariables.gasFees.feePerL2Gas = uint256(bytes32(_header[0x0228:0x0248]));
header.globalVariables.gasFees.feePerL2Gas = uint256(bytes32(_header[0x0228:HEADER_LENGTH]));


return header;
}
Expand Down
7 changes: 7 additions & 0 deletions l1-contracts/test/decoders/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ contract DecoderBase is Test {
StateReference stateReference;
}

struct GasFees {
uint256 feePerDaGas;
uint256 feePerL1Gas;
uint256 feePerL2Gas;
}

struct GlobalVariables {
uint256 blockNumber;
uint256 chainId;
address coinbase;
bytes32 feeRecipient;
GasFees gasFees;
uint256 timestamp;
uint256 version;
}
Expand Down
11 changes: 11 additions & 0 deletions l1-contracts/test/decoders/Decoders.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ contract DecodersTest is DecoderBase {
assertEq(
header.globalVariables.feeRecipient, globalVariables.feeRecipient, "Invalid feeRecipient"
);
assertEq(
header.globalVariables.gasFees.feePerDaGas,
globalVariables.gasFees.feePerDaGas,
"Invalid gasFees.feePerDaGas"
);
assertEq(
header.globalVariables.feeRecipient, globalVariables.feeRecipient, "Invalid feeRecipient"
);
assertEq(
header.globalVariables.feeRecipient, globalVariables.feeRecipient, "Invalid feeRecipient"
);
}

// ContentCommitment
Expand Down
17 changes: 11 additions & 6 deletions l1-contracts/test/fixtures/empty_block_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x0335fb6ef6a421a73ba4b4f124f6bf1101333cdb1ade05bc7cac1e83885a8df4",
"archive": "0x2ea0c3d3ffef649532de4fb75c9135681ef65b926876b5ff37a4bacfb679f558",
"body": "0x00000000",
"txsEffectsHash": "0x00df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d2493896",
"decodedHeader": {
Expand All @@ -23,12 +23,17 @@
"chainId": 31337,
"timestamp": 0,
"version": 1,
"coinbase": "0x89c70d339816591366d159b0ea442faf8af62682",
"feeRecipient": "0x0ff93b075ef4b1480ce807a2c3c0b9ca9b3bca8de09a33ae658acb21e8107f50"
"coinbase": "0xf6a7844f33ced45fbfeaa9ba463a706b30d4c454",
"feeRecipient": "0x115f6d9664fe6497dec1741573007fcd96fc24124e05b2d415fe4e43e0de4d6e",
"gasFees": {
"feePerDaGas": 0,
"feePerL1Gas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 1,
"root": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd130"
"root": "0x05b0b6df52f1d47d0406318558052c89a174fbc9d615def82b3cc9ccc1937db8"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -51,8 +56,8 @@
}
}
},
"header": "0x1e3523d3bd50ae6204e1ec2ee1bdf8af4c6217ec80900052d2cf4259379dd13000000001000000000000000000000000000000000000000000000000000000000000000100df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d249389600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000000800bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001000572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000800000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000089c70d339816591366d159b0ea442faf8af626820ff93b075ef4b1480ce807a2c3c0b9ca9b3bca8de09a33ae658acb21e8107f50",
"publicInputsHash": "0x00e2216979cc60a156f5a3ed2270286ad640960492fce44e17abc29d154bb01b",
"header": "0x05b0b6df52f1d47d0406318558052c89a174fbc9d615def82b3cc9ccc1937db800000001000000000000000000000000000000000000000000000000000000000000000100df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d249389600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000001016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000000800bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001000572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000800000000000000000000000000000000000000000000000000000000000007a69000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000f6a7844f33ced45fbfeaa9ba463a706b30d4c454115f6d9664fe6497dec1741573007fcd96fc24124e05b2d415fe4e43e0de4d6e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x000150a504a83df5a4a24f26081fb7397809f2ef5976b687fbdeefb5d42da7f3",
"numTxs": 0
}
}
19 changes: 12 additions & 7 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x220677d238ea4407e12e9c0caa76bf6753ecfa88d10a80107f73f6005b5d5c3b",
"archive": "0x20411bada543bf4a76e1e2b96c15059c7c81b81b4dec36b15102bcc72dfdebff",
"body": "0x00000000",
"txsEffectsHash": "0x00df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d2493896",
"decodedHeader": {
Expand All @@ -21,14 +21,19 @@
"globalVariables": {
"blockNumber": 2,
"chainId": 31337,
"timestamp": 1712154039,
"timestamp": 1712782698,
"version": 1,
"coinbase": "0x89c70d339816591366d159b0ea442faf8af62682",
"feeRecipient": "0x0ff93b075ef4b1480ce807a2c3c0b9ca9b3bca8de09a33ae658acb21e8107f50"
"coinbase": "0xf6a7844f33ced45fbfeaa9ba463a706b30d4c454",
"feeRecipient": "0x115f6d9664fe6497dec1741573007fcd96fc24124e05b2d415fe4e43e0de4d6e",
"gasFees": {
"feePerDaGas": 0,
"feePerL1Gas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x0335fb6ef6a421a73ba4b4f124f6bf1101333cdb1ade05bc7cac1e83885a8df4"
"root": "0x2ea0c3d3ffef649532de4fb75c9135681ef65b926876b5ff37a4bacfb679f558"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -51,8 +56,8 @@
}
}
},
"header": "0x0335fb6ef6a421a73ba4b4f124f6bf1101333cdb1ade05bc7cac1e83885a8df400000002000000000000000000000000000000000000000000000000000000000000000100df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d249389600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000660d65b789c70d339816591366d159b0ea442faf8af626820ff93b075ef4b1480ce807a2c3c0b9ca9b3bca8de09a33ae658acb21e8107f50",
"publicInputsHash": "0x00dbd8f31a147084243681f36208343c03b5415482040df2682a6ad175c3de0c",
"header": "0x2ea0c3d3ffef649532de4fb75c9135681ef65b926876b5ff37a4bacfb679f55800000002000000000000000000000000000000000000000000000000000000000000000100df6b1c97b9e01113fa0363d9ff71c85addc74e92b22d433b2fb082d249389600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c0007638bb56b6dda2b64b8f76841114ac3a87a1820030e2e16772c4d294879c31864fcdaa80ff2719154fa7c8a9050662972707168d69eac9db6fd3110829f800000002016642d9ccd8346c403aa4c3fa451178b22534a27035cdaa6ec34ae53b29c50cb000001000bcfa3e9f1a8922ee92c6dc964d6595907c1804a86753774322b468f69d4f278000001800572c8db882674dd026b8877fbba1b700a4407da3ae9ce5fa43215a28163362b000000c00000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000006616fd6af6a7844f33ced45fbfeaa9ba463a706b30d4c454115f6d9664fe6497dec1741573007fcd96fc24124e05b2d415fe4e43e0de4d6e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00da6d809b78297d6f97202d0679da5a45cfbc2c6594eaeb3f0ac4deba7c6b2e",
"numTxs": 0
}
}
17 changes: 11 additions & 6 deletions l1-contracts/test/fixtures/mixed_block_0.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions l1-contracts/test/fixtures/mixed_block_1.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ impl PublicContextInterface for AvmContext {
AztecAddress::zero()
}

fn fee_per_da_gas(self) -> Field {
assert(false, "'fee_per_da_gas' not implemented!");
0
}

fn fee_per_l1_gas(self) -> Field {
assert(false, "'fee_per_l1_gas' not implemented!");
0
}

fn fee_per_l2_gas(self) -> Field {
assert(false, "'fee_per_l2_gas' not implemented!");
0
}

fn nullifier_exists(self, unsiloed_nullifier: Field, address: AztecAddress) -> bool {
nullifier_exists(unsiloed_nullifier, address.to_field()) == 1
}
Expand Down
3 changes: 3 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/interface.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ trait PublicContextInterface {
fn timestamp(self) -> u64;
fn coinbase(self) -> EthAddress;
fn fee_recipient(self) -> AztecAddress;
fn fee_per_da_gas(self) -> Field;
fn fee_per_l1_gas(self) -> Field;
fn fee_per_l2_gas(self) -> Field;
fn push_nullifier_read_request(&mut self, nullifier: Field);
fn push_nullifier_non_existent_read_request(&mut self, nullifier: Field);
fn message_portal(&mut self, recipient: EthAddress, content: Field);
Expand Down
12 changes: 12 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ impl PublicContextInterface for PublicContext {
self.inputs.public_global_variables.fee_recipient
}

fn fee_per_da_gas(self) -> Field {
self.inputs.public_global_variables.gas_fees.fee_per_da_gas
}

fn fee_per_l1_gas(self) -> Field {
self.inputs.public_global_variables.gas_fees.fee_per_l1_gas
}

fn fee_per_l2_gas(self) -> Field {
self.inputs.public_global_variables.gas_fees.fee_per_l2_gas
}

fn nullifier_exists(self, unsiloed_nullifier: Field, address: AztecAddress) -> bool {
// Current public can only check for settled nullifiers, so we always silo.
let siloed_nullifier = silo_nullifier(address, unsiloed_nullifier);
Expand Down
Loading
Loading