Skip to content

Commit

Permalink
make upgrade validation more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Jan 8, 2024
1 parent 2e0734b commit 6998958
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
30 changes: 27 additions & 3 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 @@ -104,13 +120,15 @@ abstract contract BaseZkSyncUpgrade is Base {
/// @notice Change the address of the verifier smart contract
/// @param _newVerifier Verifier smart contract address
function _setVerifier(IVerifier _newVerifier) private {
if (_newVerifier == IVerifier(address(0))) {
return;
}

// An upgrade to the verifier 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 will fail. Ensure all commited batches are finalized before the
// verifier is upgraded.
if (_newVerifier == IVerifier(address(0))) {
return;
}
require(s.totalBatchesCommitted == s.totalBatchesVerified, "All committed batches must be verified first");

IVerifier oldVerifier = s.verifier;
s.verifier = _newVerifier;
Expand All @@ -128,6 +146,12 @@ abstract contract BaseZkSyncUpgrade is Base {
return;
}

// 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 verifier are 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.
require(s.totalBatchesCommitted == s.totalBatchesVerified, "All committed batches must be verified first");

VerifierParams memory oldVerifierParams = s.verifierParams;
s.verifierParams = _newVerifierParams;
emit NewVerifierParams(oldVerifierParams, _newVerifierParams);
Expand Down
17 changes: 0 additions & 17 deletions ethereum/contracts/upgrades/DefaultUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ contract DefaultUpgrade is BaseZkSyncUpgrade {
/// @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;
}
}

0 comments on commit 6998958

Please sign in to comment.