Skip to content

Commit

Permalink
Merge 9f162cb into c48ae90
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaWang authored Nov 28, 2024
2 parents c48ae90 + 9f162cb commit f028efd
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::abis::constant_rollup_data::ConstantRollupData;
use dep::types::{
abis::constant_rollup_data::ConstantRollupData,
constants::BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH,
partial_state_reference::PartialStateReference,
traits::{Deserialize, Empty, Serialize},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub(crate) mod constant_rollup_data;
pub(crate) mod base_or_merge_rollup_public_inputs;
pub(crate) mod block_root_or_block_merge_public_inputs;
pub(crate) mod previous_rollup_data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::abis::constant_rollup_data::ConstantRollupData;
use types::abis::combined_constant_data::CombinedConstantData;
use types::abis::{
combined_constant_data::CombinedConstantData, constant_rollup_data::ConstantRollupData,
};

pub(crate) fn validate_combined_constant_data(
constants: CombinedConstantData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ pub(crate) mod constants;
pub(crate) mod fees;
pub(crate) mod nullifier_tree;
pub(crate) mod public_data_tree;

mod private_tube_data_validator;
mod public_tube_data_validator;
pub(crate) mod validate_tube_data;

pub(crate) use private_tube_data_validator::PrivateTubeDataValidator;
pub(crate) use public_tube_data_validator::PublicTubeDataValidator;
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.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,
);
}
}
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,
);
}
}
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),
"max fee_per_da_gas in settings must not be less than the global value",
);
assert(
!max_fees_per_gas.fee_per_l2_gas.lt(gas_fees.fee_per_l2_gas),
"max fee_per_l2_gas in settings must not be less than the global value",
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub(crate) mod components;
pub(crate) mod state_diff_hints;
mod private_base_rollup;
mod public_base_rollup;
mod tests;

pub use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
pub use private_base_rollup::PrivateBaseRollupInputs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use crate::{
abis::{
base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs},
constant_rollup_data::ConstantRollupData,
},
abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs},
base::{
components::{
archive::perform_archive_membership_check, constants::validate_combined_constant_data,
fees::compute_fee_payer_fee_juice_balance_leaf_slot,
nullifier_tree::nullifier_tree_batch_insert, public_data_tree::public_data_tree_insert,
nullifier_tree::nullifier_tree_batch_insert, PrivateTubeDataValidator,
public_data_tree::public_data_tree_insert,
},
state_diff_hints::PrivateBaseStateDiffHints,
},
components::{compute_kernel_out_hash, compute_tx_effects_hash},
};
use dep::types::{
abis::{
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
append_only_tree_snapshot::AppendOnlyTreeSnapshot, constant_rollup_data::ConstantRollupData,
nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite,
tube::PrivateTubeData,
},
Expand Down Expand Up @@ -55,11 +53,9 @@ impl PrivateBaseRollupInputs {
}

pub fn execute(self) -> BaseOrMergeRollupPublicInputs {
if !dep::std::runtime::is_unconstrained() {
self.tube_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);
}
let tube_data_validator = PrivateTubeDataValidator::new(self.tube_data);
tube_data_validator.verify_proof(ALLOWED_PREVIOUS_CIRCUITS);
tube_data_validator.validate_with_rollup_data(self.constants);

let transaction_fee = self.compute_transaction_fee();

Expand Down Expand Up @@ -221,10 +217,7 @@ impl PrivateBaseRollupInputs {

mod tests {
use crate::{
abis::{
base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs,
constant_rollup_data::ConstantRollupData,
},
abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs,
base::{
components::fees::compute_fee_payer_fee_juice_balance_leaf_slot,
private_base_rollup::PrivateBaseRollupInputs,
Expand All @@ -234,7 +227,8 @@ mod tests {
};
use dep::types::{
abis::{
append_only_tree_snapshot::AppendOnlyTreeSnapshot, gas::Gas, gas_fees::GasFees,
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
constant_rollup_data::ConstantRollupData, gas::Gas, gas_fees::GasFees,
kernel_circuit_public_inputs::KernelCircuitPublicInputs,
nullifier_leaf_preimage::NullifierLeafPreimage,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::{
abis::{
base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs},
constant_rollup_data::ConstantRollupData,
},
abis::base_or_merge_rollup_public_inputs::{BASE_ROLLUP_TYPE, BaseOrMergeRollupPublicInputs},
base::{
components::{
archive::perform_archive_membership_check, constants::validate_combined_constant_data,
fees::compute_fee_payer_fee_juice_balance_leaf_slot,
nullifier_tree::nullifier_tree_batch_insert, public_data_tree::public_data_tree_insert,
PublicTubeDataValidator,
},
state_diff_hints::PublicBaseStateDiffHints,
},
Expand All @@ -19,6 +17,7 @@ use dep::types::{
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
avm_circuit_public_inputs::AvmProofData,
combined_constant_data::CombinedConstantData,
constant_rollup_data::ConstantRollupData,
log_hash::{LogHash, ScopedLogHash},
nullifier_leaf_preimage::NullifierLeafPreimage,
public_data_write::PublicDataWrite,
Expand Down Expand Up @@ -109,11 +108,9 @@ impl PublicBaseRollupInputs {
}

pub fn execute(self) -> BaseOrMergeRollupPublicInputs {
if !dep::std::runtime::is_unconstrained() {
self.tube_data.verify();
// TODO(#7410)
// self.tube_data.vk_data.validate_in_vk_tree([TUBE_VK_INDEX]);
}
let tube_data_validator = PublicTubeDataValidator::new(self.tube_data);
tube_data_validator.verify_proof();
tube_data_validator.validate_with_rollup_data(self.constants);

// TODO(#8470)
// if !dep::std::runtime::is_unconstrained() {
Expand Down Expand Up @@ -363,10 +360,7 @@ impl PublicBaseRollupInputs {

mod tests {
use crate::{
abis::{
base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs,
constant_rollup_data::ConstantRollupData,
},
abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs,
base::{
components::fees::compute_fee_payer_fee_juice_balance_leaf_slot,
public_base_rollup::PublicBaseRollupInputs, state_diff_hints::PublicBaseStateDiffHints,
Expand All @@ -376,6 +370,7 @@ mod tests {
use dep::types::{
abis::{
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
constant_rollup_data::ConstantRollupData,
nullifier_leaf_preimage::NullifierLeafPreimage, public_data_write::PublicDataWrite,
},
address::{AztecAddress, EthAddress},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod private_tube_data_validator_builder;
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);
}
}
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 = "max fee_per_da_gas in settings must not be less than the global value")]
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 = "max fee_per_l2_gas in settings must not be less than the global value")]
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();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::types::{
use crate::{
abis::{append_only_tree_snapshot::AppendOnlyTreeSnapshot, global_variables::GlobalVariables},
constants::CONSTANT_ROLLUP_DATA_LENGTH,
traits::{Deserialize, Empty, Serialize},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
abis::{gas::Gas, gas_fees::GasFees},
constants::{DEFAULT_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT, GAS_SETTINGS_LENGTH},
constants::GAS_SETTINGS_LENGTH,
traits::{Deserialize, Empty, Serialize},
utils::reader::Reader,
};

pub struct GasSettings {
gas_limits: Gas,
teardown_gas_limits: Gas,
max_fees_per_gas: GasFees,
pub gas_limits: Gas,
pub teardown_gas_limits: Gas,
pub max_fees_per_gas: GasFees,
}

impl GasSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod nullifier_leaf_preimage;

pub mod tx_constant_data;
pub mod combined_constant_data;
pub mod constant_rollup_data;

pub mod side_effect;
pub mod read_request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Verifiable for PublicTubeData {
}

pub struct PrivateTubeData {
public_inputs: KernelCircuitPublicInputs,
pub public_inputs: KernelCircuitPublicInputs,
proof: TubeProof,
vk_data: VkData<HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use crate::{
avm_accumulated_data::AvmAccumulatedData, CombinedAccumulatedData,
PrivateAccumulatedData, PrivateAccumulatedDataBuilder, PrivateToPublicAccumulatedData,
},
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
avm_circuit_public_inputs::AvmProofData,
call_context::CallContext,
combined_constant_data::CombinedConstantData,
constant_rollup_data::ConstantRollupData,
function_data::FunctionData,
gas::Gas,
gas_settings::GasSettings,
Expand Down Expand Up @@ -159,6 +161,9 @@ pub struct FixtureBuilder {
pub protocol_contract_tree_root: Field,
pub protocol_contract_sibling_path: [Field; PROTOCOL_CONTRACT_TREE_HEIGHT],

// Tree snapshots.
pub archive_tree: AppendOnlyTreeSnapshot,

// Counters.
pub min_revertible_side_effect_counter: u32,
pub counter_start: u32,
Expand Down Expand Up @@ -291,6 +296,15 @@ impl FixtureBuilder {
}
}

pub fn to_constant_rollup_data(self) -> ConstantRollupData {
ConstantRollupData {
last_archive: self.archive_tree,
vk_tree_root: self.vk_tree_root,
protocol_contract_tree_root: self.protocol_contract_tree_root,
global_variables: self.global_variables,
}
}

pub fn build_tx_request(self) -> TxRequest {
TxRequest {
origin: self.contract_address,
Expand Down Expand Up @@ -1047,13 +1061,13 @@ impl FixtureBuilder {
fixtures::vk_tree::get_vk_merkle_tree().get_root()
}

fn to_private_tube_data(self) -> PrivateTubeData {
pub fn to_private_tube_data(self) -> PrivateTubeData {
let mut result: PrivateTubeData = std::mem::zeroed();
result.public_inputs = self.to_kernel_circuit_public_inputs();
result
}

fn to_public_tube_data(self) -> PublicTubeData {
pub fn to_public_tube_data(self) -> PublicTubeData {
let mut result: PublicTubeData = std::mem::zeroed();
result.public_inputs = self.to_private_to_public_kernel_circuit_public_inputs(true);
result
Expand Down Expand Up @@ -1133,6 +1147,7 @@ impl Empty for FixtureBuilder {
vk_tree_root: FixtureBuilder::vk_tree_root(),
protocol_contract_tree_root: 0,
protocol_contract_sibling_path: [0; PROTOCOL_CONTRACT_TREE_HEIGHT],
archive_tree: AppendOnlyTreeSnapshot::zero(),
revert_code: 0,
min_revertible_side_effect_counter: 0,
counter_start: 0,
Expand Down
Loading

0 comments on commit f028efd

Please sign in to comment.