Skip to content

Commit 86b0722

Browse files
authored
feat(AVM): Implement l2 gas limit maximum and remove clamping (#16500)
- Removes gas limit clamping - Reworks the gas limit constants - Improves gas estimation - Adds a transaction validator to check that l2 gas limit is within AVM provable bounds - Adds l2 gas limit check to public base, pending move to private kernels - Adds a check in the avm simulator that the actual **consumed** gas is not more than the provable gas.
2 parents 4577292 + c093997 commit 86b0722

File tree

42 files changed

+1567
-1537
lines changed

Some content is hidden

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

42 files changed

+1567
-1537
lines changed

barretenberg/cpp/src/barretenberg/vm2/common/aztec_constants.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
#define AVM_V2_PUBLIC_INPUTS_FLATTENED_SIZE 1
170170
#define AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED 20000
171171
#define AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED 1000
172-
#define MAX_L2_GAS_PER_TX_PUBLIC_PORTION 6000000
172+
#define AVM_MAX_PROCESSABLE_L2_GAS 6000000
173173
#define AVM_GAS_PER_ROW 3
174174
#define AVM_MERKLE_CHECK_ROWS_PUBLIC_WRITE 80
175175
#define AVM_MERKLE_CHECK_ROWS_PUBLIC_READ 40
Binary file not shown.
Binary file not shown.

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use dep::types::{
1111
gas::Gas, gas_fees::GasFees, gas_settings::GasSettings,
1212
kernel_circuit_public_inputs::PrivateToRollupKernelCircuitPublicInputs,
1313
},
14-
constants::{DEFAULT_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT},
14+
constants::{
15+
DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT, DEFAULT_TEARDOWN_DA_GAS_LIMIT,
16+
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
17+
},
1518
tests::fixture_builder::FixtureBuilder,
1619
};
1720

@@ -24,8 +27,8 @@ pub struct TailOutputValidatorBuilder {
2427
impl TailOutputValidatorBuilder {
2528
pub fn new() -> Self {
2629
let gas_settings = GasSettings::new(
27-
Gas::new(DEFAULT_GAS_LIMIT, DEFAULT_GAS_LIMIT),
28-
Gas::new(DEFAULT_TEARDOWN_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT),
30+
Gas::new(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT),
31+
Gas::new(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT),
2932
GasFees::new(10, 10),
3033
GasFees::new(3, 3),
3134
);

noir-projects/noir-protocol-circuits/crates/rollup-base-private/Prover.toml

Lines changed: 174 additions & 174 deletions
Large diffs are not rendered by default.

noir-projects/noir-protocol-circuits/crates/rollup-base-public/Prover.toml

Lines changed: 1089 additions & 1089 deletions
Large diffs are not rendered by default.

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/gas.nr

Lines changed: 0 additions & 29 deletions
This file was deleted.

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/mod.nr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub(crate) mod archive;
22
pub(crate) mod constants;
33
pub(crate) mod fees;
4-
pub(crate) mod gas;
54
pub(crate) mod include_by_timestamp;
65
pub(crate) mod nullifier_tree;
76
pub(crate) mod public_data_tree;

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/private_tube_data_validator.nr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::base::components::{
33
};
44
use dep::types::{
55
abis::{block_constant_data::BlockConstantData, tube::PrivateTubeData},
6-
constants::ARCHIVE_HEIGHT,
6+
constants::{ARCHIVE_HEIGHT, AVM_MAX_PROCESSABLE_L2_GAS},
77
merkle_tree::MembershipWitness,
88
proof::traits::Verifiable,
99
};
@@ -17,6 +17,15 @@ impl PrivateTubeDataValidator {
1717
PrivateTubeDataValidator { data }
1818
}
1919

20+
// TODO: This should be moved to the private kernels once they are not used for gas estimation anymore.
21+
pub fn validate_gas_settings(self) {
22+
let gas_settings = self.data.public_inputs.constants.tx_context.gas_settings;
23+
assert(
24+
gas_settings.gas_limits.l2_gas <= AVM_MAX_PROCESSABLE_L2_GAS,
25+
"l2 gas limit exceeds max processable l2 gas",
26+
);
27+
}
28+
2029
pub fn validate_proof_and_vk(self) {
2130
if !dep::std::runtime::is_unconstrained() {
2231
self.data.verify();

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/public_tube_data_validator.nr

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::base::components::{
2-
constants::validate_tx_constant_data, gas::clamp_gas_settings_for_avm,
3-
include_by_timestamp::validate_include_by_timestamp,
2+
constants::validate_tx_constant_data, include_by_timestamp::validate_include_by_timestamp,
43
};
54
use super::fees::compute_effective_gas_fees;
65
use dep::types::{
76
abis::{
87
avm_circuit_public_inputs::AvmCircuitPublicInputs, block_constant_data::BlockConstantData,
98
tube::PublicTubeData,
109
},
11-
constants::ARCHIVE_HEIGHT,
10+
constants::{ARCHIVE_HEIGHT, AVM_MAX_PROCESSABLE_L2_GAS},
1211
merkle_tree::MembershipWitness,
1312
proof::traits::Verifiable,
1413
traits::Empty,
@@ -39,6 +38,15 @@ impl PublicTubeDataValidator {
3938
PublicTubeDataValidator { data }
4039
}
4140

41+
// TODO: This should be moved to the private kernels once they are not used for gas estimation anymore.
42+
pub fn validate_gas_settings(self) {
43+
let gas_settings = self.data.public_inputs.constants.tx_context.gas_settings;
44+
assert(
45+
gas_settings.gas_limits.l2_gas <= AVM_MAX_PROCESSABLE_L2_GAS,
46+
"l2 gas limit exceeds max processable l2 gas",
47+
);
48+
}
49+
4250
pub fn validate_proof_and_vk(self) {
4351
if !dep::std::runtime::is_unconstrained() {
4452
self.data.verify();
@@ -84,10 +92,7 @@ impl PublicTubeDataValidator {
8492
);
8593

8694
assert_eq(
87-
clamp_gas_settings_for_avm(
88-
tube_data.constants.tx_context.gas_settings,
89-
tube_data.gas_used,
90-
),
95+
tube_data.constants.tx_context.gas_settings,
9196
avm_data.gas_settings,
9297
"unexpected gas settings used in the AVM",
9398
);

0 commit comments

Comments
 (0)