Skip to content

Commit

Permalink
Cheaper L1->L2 txs + upgrade implementation (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless authored Jan 15, 2024
1 parent f44e405 commit d8ed1d7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions SystemConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"KECCAK_ROUND_COST_GAS": 40,
"SHA256_ROUND_COST_GAS": 7,
"ECRECOVER_COST_GAS": 7000,
"PRIORITY_TX_MINIMAL_GAS_PRICE": 500000000,
"PRIORITY_TX_MINIMAL_GAS_PRICE": 250000000,
"PRIORITY_TX_MAX_GAS_PER_BATCH": 80000000,
"PRIORITY_TX_PUBDATA_PER_BATCH": 100000,
"PRIORITY_TX_PUBDATA_PER_BATCH": 120000,
"PRIORITY_TX_BATCH_OVERHEAD_L1_GAS": 1000000
}
48 changes: 48 additions & 0 deletions l1-contracts/contracts/upgrades/Upgrade_v1_4_1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

import {Diamond} from "../zksync/libraries/Diamond.sol";
import {BaseZkSyncUpgrade} from "./BaseZkSyncUpgrade.sol";
import {PubdataPricingMode, FeeParams} from "../zksync/Storage.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
contract Upgrade_v1_4_1 is BaseZkSyncUpgrade {
/// This event is an exact copy of the "IAdmin.NewFeeParams" event. Since they have the same name and parameters,
/// these will be tracked by indexers in the same manner.
event NewFeeParams(FeeParams oldFeeParams, FeeParams newFeeParams);

/// This function is a copy of the "Admin.changeFeeParams" function.
/// It is to be used once to set the new fee params for the first time as they needed for the correct functioning of the upgrade.
function changeFeeParams(FeeParams memory _newFeeParams) private {
// Double checking that the new fee params are valid, i.e.
// the maximal pubdata per batch is not less than the maximal pubdata per priority transaction.
require(_newFeeParams.maxPubdataPerBatch >= _newFeeParams.priorityTxMaxPubdata, "n6");

FeeParams memory oldFeeParams = s.feeParams;
s.feeParams = _newFeeParams;

emit NewFeeParams(oldFeeParams, _newFeeParams);
}

/// @notice The main function that will be called by the upgrade proxy.
/// @param _proposedUpgrade The upgrade to be executed.
function upgrade(ProposedUpgrade calldata _proposedUpgrade) public override returns (bytes32) {
// The execution of the next parts of the upgrade does depend on these fee params being already set correctly
changeFeeParams(
FeeParams({
pubdataPricingMode: PubdataPricingMode.Rollup,
batchOverheadL1Gas: $(PRIORITY_TX_BATCH_OVERHEAD_L1_GAS),
maxPubdataPerBatch: $(PRIORITY_TX_PUBDATA_PER_BATCH),
maxL2GasPerBatch: $(PRIORITY_TX_MAX_GAS_PER_BATCH),
priorityTxMaxPubdata: $(PRIORITY_TX_PUBDATA_PER_BATCH),
minimalL2GasPrice: $(PRIORITY_TX_MINIMAL_GAS_PRICE)
})
);

super.upgrade(_proposedUpgrade);

return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE;
}
}
3 changes: 1 addition & 2 deletions l1-contracts/contracts/zksync/facets/Admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ contract AdminFacet is Base, IAdmin {
emit NewPriorityTxMaxGasLimit(oldPriorityTxMaxGasLimit, _newPriorityTxMaxGasLimit);
}

/// @notice Change the fee params for L1->L2 transactions
/// @param _newFeeParams The new fee params
/// @inheritdoc IAdmin
function changeFeeParams(FeeParams calldata _newFeeParams) external onlyGovernor {
// Double checking that the new fee params are valid, i.e.
// the maximal pubdata per batch is not less than the maximal pubdata per priority transaction.
Expand Down
4 changes: 4 additions & 0 deletions l1-contracts/contracts/zksync/interfaces/IAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ interface IAdmin is IBase {
/// @param _newPriorityTxMaxGasLimit The maximum number of L2 gas that a user can request for L1 -> L2 transactions
function setPriorityTxMaxGasLimit(uint256 _newPriorityTxMaxGasLimit) external;

/// @notice Change the fee params for L1->L2 transactions
/// @param _newFeeParams The new fee params
function changeFeeParams(FeeParams calldata _newFeeParams) external;

/// @notice Executes a proposed governor upgrade
/// @dev Only the current governor can execute the upgrade
/// @param _diamondCut The diamond cut parameters to be executed
Expand Down

0 comments on commit d8ed1d7

Please sign in to comment.