forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vm): Make utils version-dependent (matter-labs#809)
## What ❔ In the new 1.4.1 version, the fee formulas as well as max txs per batch will change. We'll prepare the main branch for it first to reduce the diff ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `cargo spellcheck --cfg=./spellcheck/era.cfg --code 1`.
- Loading branch information
1 parent
39f2d50
commit e5fbcb5
Showing
40 changed files
with
482 additions
and
222 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
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
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,164 @@ | ||
use zksync_types::{VmVersion, U256}; | ||
|
||
/// Calculates the base fee and gas per pubdata for the given L1 gas price. | ||
pub fn derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price: u64, | ||
fair_gas_price: u64, | ||
vm_version: VmVersion, | ||
) -> (u64, u64) { | ||
match vm_version { | ||
VmVersion::M5WithRefunds | VmVersion::M5WithoutRefunds => { | ||
crate::vm_m5::vm_with_bootloader::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
VmVersion::M6Initial | VmVersion::M6BugWithCompressionFixed => { | ||
crate::vm_m6::vm_with_bootloader::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
VmVersion::Vm1_3_2 => { | ||
crate::vm_1_3_2::vm_with_bootloader::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
VmVersion::VmVirtualBlocks => { | ||
crate::vm_virtual_blocks::utils::fee::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
VmVersion::VmVirtualBlocksRefundsEnhancement => { | ||
crate::vm_refunds_enhancement::utils::fee::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
VmVersion::VmBoojumIntegration => { | ||
crate::vm_boojum_integration::utils::fee::derive_base_fee_and_gas_per_pubdata( | ||
l1_gas_price, | ||
fair_gas_price, | ||
) | ||
} | ||
} | ||
} | ||
|
||
/// Changes the fee model output so that the expected gas per pubdata is smaller than or the `tx_gas_per_pubdata_limit`. | ||
pub fn adjust_l1_gas_price_for_tx( | ||
l1_gas_price: u64, | ||
fair_l2_gas_price: u64, | ||
tx_gas_per_pubdata_limit: U256, | ||
vm_version: VmVersion, | ||
) -> u64 { | ||
if U256::from( | ||
derive_base_fee_and_gas_per_pubdata(l1_gas_price, fair_l2_gas_price, vm_version).1, | ||
) <= tx_gas_per_pubdata_limit | ||
{ | ||
return l1_gas_price; | ||
} | ||
|
||
// The latest VM supports adjusting the pubdata price for all the types of the fee models. | ||
crate::vm_latest::utils::fee::adjust_l1_gas_price_for_tx( | ||
fair_l2_gas_price, | ||
tx_gas_per_pubdata_limit, | ||
) | ||
} | ||
|
||
pub fn derive_overhead( | ||
gas_limit: u32, | ||
gas_price_per_pubdata: u32, | ||
encoded_len: usize, | ||
tx_type: u8, | ||
vm_version: VmVersion, | ||
) -> u32 { | ||
match vm_version { | ||
VmVersion::M5WithRefunds | VmVersion::M5WithoutRefunds => { | ||
crate::vm_m5::transaction_data::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
) | ||
} | ||
VmVersion::M6Initial | VmVersion::M6BugWithCompressionFixed => { | ||
crate::vm_m6::transaction_data::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
crate::vm_m6::transaction_data::OverheadCoefficients::from_tx_type(tx_type), | ||
) | ||
} | ||
VmVersion::Vm1_3_2 => crate::vm_1_3_2::transaction_data::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
crate::vm_1_3_2::transaction_data::OverheadCoefficients::from_tx_type(tx_type), | ||
), | ||
VmVersion::VmVirtualBlocks => crate::vm_virtual_blocks::utils::overhead::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
crate::vm_virtual_blocks::utils::overhead::OverheadCoefficients::from_tx_type(tx_type), | ||
), | ||
VmVersion::VmVirtualBlocksRefundsEnhancement => { | ||
crate::vm_refunds_enhancement::utils::overhead::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
crate::vm_refunds_enhancement::utils::overhead::OverheadCoefficients::from_tx_type( | ||
tx_type, | ||
), | ||
) | ||
} | ||
VmVersion::VmBoojumIntegration => { | ||
crate::vm_boojum_integration::utils::overhead::derive_overhead( | ||
gas_limit, | ||
gas_price_per_pubdata, | ||
encoded_len, | ||
crate::vm_boojum_integration::utils::overhead::OverheadCoefficients::from_tx_type( | ||
tx_type, | ||
), | ||
) | ||
} | ||
} | ||
} | ||
|
||
pub fn get_bootloader_encoding_space(version: VmVersion) -> u32 { | ||
match version { | ||
VmVersion::M5WithRefunds | VmVersion::M5WithoutRefunds => { | ||
crate::vm_m5::vm_with_bootloader::BOOTLOADER_TX_ENCODING_SPACE | ||
} | ||
VmVersion::M6Initial | VmVersion::M6BugWithCompressionFixed => { | ||
crate::vm_m6::vm_with_bootloader::BOOTLOADER_TX_ENCODING_SPACE | ||
} | ||
VmVersion::Vm1_3_2 => crate::vm_1_3_2::vm_with_bootloader::BOOTLOADER_TX_ENCODING_SPACE, | ||
VmVersion::VmVirtualBlocks => { | ||
crate::vm_virtual_blocks::constants::BOOTLOADER_TX_ENCODING_SPACE | ||
} | ||
VmVersion::VmVirtualBlocksRefundsEnhancement => { | ||
crate::vm_refunds_enhancement::constants::BOOTLOADER_TX_ENCODING_SPACE | ||
} | ||
VmVersion::VmBoojumIntegration => { | ||
crate::vm_boojum_integration::constants::BOOTLOADER_TX_ENCODING_SPACE | ||
} | ||
} | ||
} | ||
|
||
pub fn get_bootloader_max_txs_in_batch(version: VmVersion) -> usize { | ||
match version { | ||
VmVersion::M5WithRefunds | VmVersion::M5WithoutRefunds => { | ||
crate::vm_m5::vm_with_bootloader::MAX_TXS_IN_BLOCK | ||
} | ||
VmVersion::M6Initial | VmVersion::M6BugWithCompressionFixed => { | ||
crate::vm_m6::vm_with_bootloader::MAX_TXS_IN_BLOCK | ||
} | ||
VmVersion::Vm1_3_2 => crate::vm_1_3_2::vm_with_bootloader::MAX_TXS_IN_BLOCK, | ||
VmVersion::VmVirtualBlocks => crate::vm_virtual_blocks::constants::MAX_TXS_IN_BLOCK, | ||
VmVersion::VmVirtualBlocksRefundsEnhancement => { | ||
crate::vm_refunds_enhancement::constants::MAX_TXS_IN_BLOCK | ||
} | ||
VmVersion::VmBoojumIntegration => crate::vm_boojum_integration::constants::MAX_TXS_IN_BLOCK, | ||
} | ||
} |
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
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
6 changes: 3 additions & 3 deletions
6
core/lib/multivm/src/versions/vm_boojum_integration/utils/overhead.rs
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.