-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check max fees per gas (#10283)
Please read [contributing guidelines](CONTRIBUTING.md) and remove this line.
- Loading branch information
Showing
27 changed files
with
398 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...s/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/components/constants.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ir-protocol-circuits/crates/rollup-lib/src/base/components/private_tube_data_validator.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::validate_tube_data::validate_max_fees_per_gas; | ||
use dep::types::abis::{constant_rollup_data::ConstantRollupData, tube::PrivateTubeData}; | ||
|
||
pub struct PrivateTubeDataValidator { | ||
pub data: PrivateTubeData, | ||
} | ||
|
||
// TODO: Move relevant verifications here. | ||
impl PrivateTubeDataValidator { | ||
pub fn new(data: PrivateTubeData) -> Self { | ||
PrivateTubeDataValidator { data } | ||
} | ||
|
||
pub fn verify_proof<let N: u32>(self, _allowed_previous_circuits: [u32; N]) { | ||
if !dep::std::runtime::is_unconstrained() { | ||
self.data.verify(); | ||
// TODO(#7410) | ||
// self.data.vk_data.validate_in_vk_tree(self.data.public_inputs.constants.vk_tree_root, allowed_previous_circuits); | ||
} | ||
} | ||
|
||
pub fn validate_with_rollup_data(self, constants: ConstantRollupData) { | ||
validate_max_fees_per_gas( | ||
self.data.public_inputs.constants.tx_context.gas_settings.max_fees_per_gas, | ||
constants.global_variables.gas_fees, | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...oir-protocol-circuits/crates/rollup-lib/src/base/components/public_tube_data_validator.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::validate_tube_data::validate_max_fees_per_gas; | ||
use dep::types::abis::{constant_rollup_data::ConstantRollupData, tube::PublicTubeData}; | ||
|
||
pub struct PublicTubeDataValidator { | ||
pub data: PublicTubeData, | ||
} | ||
|
||
// TODO: Move relevant verifications here. | ||
impl PublicTubeDataValidator { | ||
pub fn new(data: PublicTubeData) -> Self { | ||
PublicTubeDataValidator { data } | ||
} | ||
|
||
pub fn verify_proof(self) { | ||
if !dep::std::runtime::is_unconstrained() { | ||
self.data.verify(); | ||
// TODO(#7410) | ||
// self.tube_data.vk_data.validate_in_vk_tree(self.tube_data.public_inputs.constants.vk_tree_root, ALLOWED_PREVIOUS_CIRCUITS); | ||
} | ||
} | ||
|
||
pub fn validate_with_rollup_data(self, constants: ConstantRollupData) { | ||
validate_max_fees_per_gas( | ||
self.data.public_inputs.constants.tx_context.gas_settings.max_fees_per_gas, | ||
constants.global_variables.gas_fees, | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ojects/noir-protocol-circuits/crates/rollup-lib/src/base/components/validate_tube_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use dep::types::abis::gas_fees::GasFees; | ||
|
||
pub fn validate_max_fees_per_gas(max_fees_per_gas: GasFees, gas_fees: GasFees) { | ||
assert( | ||
!max_fees_per_gas.fee_per_da_gas.lt(gas_fees.fee_per_da_gas), | ||
"da gas is higher than the maximum specified by the tx", | ||
); | ||
assert( | ||
!max_fees_per_gas.fee_per_l2_gas.lt(gas_fees.fee_per_l2_gas), | ||
"l2 gas is higher than the maximum specified by the tx", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/tests/mod.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod private_tube_data_validator_builder; |
24 changes: 24 additions & 0 deletions
24
...ocol-circuits/crates/rollup-lib/src/base/tests/private_tube_data_validator_builder/mod.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
mod validate_with_rollup_data; | ||
|
||
use crate::base::components::PrivateTubeDataValidator; | ||
use dep::types::tests::fixture_builder::FixtureBuilder; | ||
|
||
pub struct PrivateTubeDataValidatorBuilder { | ||
pub tube_data: FixtureBuilder, | ||
pub rollup_data: FixtureBuilder, | ||
} | ||
|
||
impl PrivateTubeDataValidatorBuilder { | ||
pub fn new() -> Self { | ||
PrivateTubeDataValidatorBuilder { | ||
tube_data: FixtureBuilder::new(), | ||
rollup_data: FixtureBuilder::new(), | ||
} | ||
} | ||
|
||
pub fn validate_with_rollup_data(self) { | ||
let tube_data = self.tube_data.to_private_tube_data(); | ||
let rollup_data = self.rollup_data.to_constant_rollup_data(); | ||
PrivateTubeDataValidator::new(tube_data).validate_with_rollup_data(rollup_data); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ollup-lib/src/base/tests/private_tube_data_validator_builder/validate_with_rollup_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use super::PrivateTubeDataValidatorBuilder; | ||
|
||
#[test] | ||
fn validate_with_rollup_data_success() { | ||
let builder = PrivateTubeDataValidatorBuilder::new(); | ||
builder.validate_with_rollup_data(); | ||
} | ||
|
||
#[test(should_fail_with = "da gas is higher than the maximum specified by the tx")] | ||
fn validate_with_rollup_data_not_enough_fee_per_da_gas_fails() { | ||
let mut builder = PrivateTubeDataValidatorBuilder::new(); | ||
|
||
builder.tube_data.tx_context.gas_settings.max_fees_per_gas.fee_per_da_gas = 3; | ||
builder.rollup_data.global_variables.gas_fees.fee_per_da_gas = 4; | ||
|
||
builder.validate_with_rollup_data(); | ||
} | ||
|
||
#[test(should_fail_with = "l2 gas is higher than the maximum specified by the tx")] | ||
fn validate_with_rollup_data_not_enough_fee_per_l2_gas_fails() { | ||
let mut builder = PrivateTubeDataValidatorBuilder::new(); | ||
|
||
builder.tube_data.tx_context.gas_settings.max_fees_per_gas.fee_per_l2_gas = 3; | ||
builder.rollup_data.global_variables.gas_fees.fee_per_l2_gas = 4; | ||
|
||
builder.validate_with_rollup_data(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...llup-lib/src/abis/constant_rollup_data.nr → ...es/types/src/abis/constant_rollup_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.