Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make upgrade validation more strict #158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ethereum/contracts/dev-contracts/test/CustomUpgradeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ contract CustomUpgradeTest is BaseZkSyncUpgrade {
/// @notice Placeholder function for custom logic for upgrading L1 contract.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for upgrade, which may be interpreted differently for each upgrade.
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal {
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal override {
emit Test();
}

/// @notice placeholder function for custom logic for post-upgrade logic.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
/// upgrade.
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal virtual {}
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal override {}

/// @notice The main function that will be called by the upgrade proxy.
/// @param _proposedUpgrade The upgrade to be executed.
Expand Down
32 changes: 32 additions & 0 deletions ethereum/contracts/upgrades/BaseZkSyncUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ abstract contract BaseZkSyncUpgrade is Base {
// on the L2 side would be inaccurate. The effects of this "back-dating" of L2 upgrade batches will be reduced
// as the permitted delay window is reduced in the future.
require(block.timestamp >= _proposedUpgrade.upgradeTimestamp, "Upgrade is not ready yet");

_setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash);

bytes32 txHash;
txHash = _setL2SystemContractUpgrade(
_proposedUpgrade.l2ProtocolUpgradeTx,
_proposedUpgrade.factoryDeps,
_proposedUpgrade.newProtocolVersion
);

_postUpgrade(_proposedUpgrade.postUpgradeCalldata);

emit UpgradeComplete(_proposedUpgrade.newProtocolVersion, txHash, _proposedUpgrade);
}

/// @notice Change default account bytecode hash, that is used on L2
Expand Down Expand Up @@ -120,6 +136,10 @@ abstract contract BaseZkSyncUpgrade is Base {
/// @notice Change the verifier parameters
/// @param _newVerifierParams New parameters for the verifier
function _setVerifierParams(VerifierParams calldata _newVerifierParams) private {
// An upgrade to the verifier params must be done carefully to ensure there aren't batches in the committed state
// during the transition. If verifier is upgraded, it will immediately be used to prove all committed batches.
// Batches committed expecting the old verifier params will fail. Ensure all commited batches are finalized before the
// verifier is upgraded.
if (
_newVerifierParams.recursionNodeLevelVkHash == bytes32(0) &&
_newVerifierParams.recursionLeafLevelVkHash == bytes32(0) &&
Expand Down Expand Up @@ -228,4 +248,16 @@ abstract contract BaseZkSyncUpgrade is Base {
s.protocolVersion = _newProtocolVersion;
emit NewProtocolVersion(previousProtocolVersion, _newProtocolVersion);
}

/// @notice Placeholder function for custom logic for upgrading L1 contract.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
/// upgrade.
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal virtual {}

/// @notice placeholder function for custom logic for post-upgrade logic.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
/// upgrade.
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal virtual {}
}
29 changes: 0 additions & 29 deletions ethereum/contracts/upgrades/DefaultUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,10 @@ import "./BaseZkSyncUpgrade.sol";
/// @author Matter Labs
/// @custom:security-contact [email protected]
contract DefaultUpgrade is BaseZkSyncUpgrade {
/// @notice Placeholder function for custom logic for upgrading L1 contract.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
/// upgrade.
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal virtual {}

/// @notice placeholder function for custom logic for post-upgrade logic.
/// Typically this function will never be used.
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
/// upgrade.
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal virtual {}

/// @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) {
super.upgrade(_proposedUpgrade);

_setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash);

bytes32 txHash;
txHash = _setL2SystemContractUpgrade(
_proposedUpgrade.l2ProtocolUpgradeTx,
_proposedUpgrade.factoryDeps,
_proposedUpgrade.newProtocolVersion
);

_postUpgrade(_proposedUpgrade.postUpgradeCalldata);

emit UpgradeComplete(_proposedUpgrade.newProtocolVersion, txHash, _proposedUpgrade);

return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE;
}
}
Loading