Skip to content

Commit

Permalink
CleaningUp => Preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Barenblat committed Mar 24, 2020
1 parent 5ca4803 commit 4b917c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions contracts/contracts/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ contract UpgradeEvents {
uint64 version
);

/// @notice Upgrade mode cleaning up status event
event UpgradeModeCleaningUpStatusActivated(
/// @notice Upgrade mode preparation status event
event UpgradeModePreparationStatusActivated(
address proxyAddress,
uint64 version
);
Expand Down
24 changes: 12 additions & 12 deletions contracts/contracts/UpgradeGatekeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "./Ownable.sol";
/// @author Matter Labs
contract UpgradeGatekeeper is UpgradeEvents, Ownable {

/// @notice Notice period before activation cleaning up status of upgrade mode (in seconds)
/// @notice Notice period before activation preparation status of upgrade mode (in seconds)
uint256 constant NOTICE_PERIOD = 2 weeks;

/// @notice Versions of proxy contracts
Expand All @@ -21,7 +21,7 @@ contract UpgradeGatekeeper is UpgradeEvents, Ownable {
enum UpgradeStatus {
Idle,
NoticePeriod,
CleaningUp
Preparation
}

/// @notice Info for upgrade proxy
Expand All @@ -37,7 +37,7 @@ contract UpgradeGatekeeper is UpgradeEvents, Ownable {
address nextTarget;

/// @notice Number of priority operations that must be verified by main contract at the time of finishing upgrade
/// @dev Will store zero in case of not active upgrade mode or not active cleaning up status of upgrade mode
/// @dev Will store zero in case of not active upgrade mode or not active preparation status of upgrade mode
uint64 priorityOperationsToProcessBeforeUpgrade;
}

Expand Down Expand Up @@ -80,18 +80,18 @@ contract UpgradeGatekeeper is UpgradeEvents, Ownable {
emit UpgradeCanceled(proxyAddress, version[proxyAddress]);
}

/// @notice Checks that cleaning up status is active and activates it if needed
/// @notice Checks that preparation status is active and activates it if needed
/// @param proxyAddress Address of proxy to process
/// @return Bool flag indicating that cleaning up status is active after this call
function activateCleaningUpStatusOfUpgrade(address proxyAddress) public returns (bool) {
require(upgradeInfo[proxyAddress].upgradeStatus != UpgradeGatekeeper.UpgradeStatus.Idle, "uaf11"); // uaf11 - unable to activate cleaning up status in case of not active upgrade mode
/// @return Bool flag indicating that preparation status is active after this call
function startPreparation(address proxyAddress) public returns (bool) {
require(upgradeInfo[proxyAddress].upgradeStatus != UpgradeGatekeeper.UpgradeStatus.Idle, "uaf11"); // uaf11 - unable to activate preparation status in case of not active upgrade mode

if (upgradeInfo[proxyAddress].upgradeStatus == UpgradeGatekeeper.UpgradeStatus.CleaningUp) {
if (upgradeInfo[proxyAddress].upgradeStatus == UpgradeGatekeeper.UpgradeStatus.Preparation) {
return true;
}

if (now >= upgradeInfo[proxyAddress].activationTime + NOTICE_PERIOD) {
upgradeInfo[proxyAddress].upgradeStatus = UpgradeGatekeeper.UpgradeStatus.CleaningUp;
upgradeInfo[proxyAddress].upgradeStatus = UpgradeGatekeeper.UpgradeStatus.Preparation;

(bool mainContractCallSuccess, bytes memory encodedResult) = mainContractAddress.staticcall(
abi.encodeWithSignature("totalRegisteredPriorityOperations()")
Expand All @@ -100,7 +100,7 @@ contract UpgradeGatekeeper is UpgradeEvents, Ownable {
uint64 totalRegisteredPriorityOperations = abi.decode(encodedResult, (uint64));
upgradeInfo[proxyAddress].priorityOperationsToProcessBeforeUpgrade = totalRegisteredPriorityOperations;

emit UpgradeModeCleaningUpStatusActivated(proxyAddress, version[proxyAddress]);
emit UpgradeModePreparationStatusActivated(proxyAddress, version[proxyAddress]);
return true;
} else {
return false;
Expand All @@ -112,15 +112,15 @@ contract UpgradeGatekeeper is UpgradeEvents, Ownable {
/// @param newTargetInitializationParameters New target initialization parameters
function finishProxyUpgrade(address proxyAddress, bytes calldata newTargetInitializationParameters) external {
requireMaster(msg.sender);
require(upgradeInfo[proxyAddress].upgradeStatus == UpgradeGatekeeper.UpgradeStatus.CleaningUp, "umf11"); // umf11 - unable to finish upgrade without cleaning up status active
require(upgradeInfo[proxyAddress].upgradeStatus == UpgradeGatekeeper.UpgradeStatus.Preparation, "umf11"); // umf11 - unable to finish upgrade without preparation status active

(bool mainContractCallSuccess, bytes memory encodedResult) = mainContractAddress.staticcall(
abi.encodeWithSignature("totalVerifiedPriorityOperations()")
);
require(mainContractCallSuccess, "umf12"); // umf12 - main contract static call failed
uint64 totalVerifiedPriorityOperations = abi.decode(encodedResult, (uint64));

require(totalVerifiedPriorityOperations >= upgradeInfo[proxyAddress].priorityOperationsToProcessBeforeUpgrade, "umf13"); // umf13 - can't finish upgrade before verifing all priority operations received before start of cleaning up status
require(totalVerifiedPriorityOperations >= upgradeInfo[proxyAddress].priorityOperationsToProcessBeforeUpgrade, "umf13"); // umf13 - can't finish upgrade before verifing all priority operations received before start of preparation status

(bool proxyUpgradeCallSuccess, ) = proxyAddress.call(
abi.encodeWithSignature("upgradeTarget(address,bytes)", upgradeInfo[proxyAddress].nextTarget, newTargetInitializationParameters)
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/test-upgrade-franklin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function main() {
await new Promise(r => setTimeout(r, notice_period * 1000 + 10));

// finish upgrade
await (await upgradeGatekeeper.activateCleaningUpStatusOfUpgrade(proxyContract.address)).wait();
await (await upgradeGatekeeper.startPreparation(proxyContract.address)).wait();
await (await upgradeGatekeeper.finishProxyUpgrade(proxyContract.address, [])).wait();

await expect(await proxyContract.getTarget())
Expand Down
10 changes: 5 additions & 5 deletions contracts/test/unit_tests/upgradeGatekeeper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("UpgradeGatekeeper unit tests", function () {

it("checking UpgradeGatekeeper reverts; activation and cancelation upgrade", async () => {
expect((await getCallRevertReason( () => UpgradeGatekeeperContract.cancelProxyUpgrade(proxyTestContract.address) )).revertReason).equal("umc11")
expect((await getCallRevertReason( () => UpgradeGatekeeperContract.activateCleaningUpStatusOfUpgrade(proxyTestContract.address) )).revertReason).equal("uaf11")
expect((await getCallRevertReason( () => UpgradeGatekeeperContract.startPreparation(proxyTestContract.address) )).revertReason).equal("uaf11")
expect((await getCallRevertReason( () => UpgradeGatekeeperContract.finishProxyUpgrade(proxyTestContract.address, []) )).revertReason).equal("umf11")

await expect(UpgradeGatekeeperContract.startProxyUpgrade(proxyTestContract.address, DummySecond.address))
Expand All @@ -72,7 +72,7 @@ describe("UpgradeGatekeeper unit tests", function () {

let activated_time = performance.now();

// wait and activate cleaning up status
// wait and activate preparation status
let all_time_in_sec = parseInt(await UpgradeGatekeeperContract.get_NOTICE_PERIOD());
for (let step = 1; step <= 3; step++) {
if (step != 3) {
Expand All @@ -86,10 +86,10 @@ describe("UpgradeGatekeeper unit tests", function () {
}

if (step != 3) {
await UpgradeGatekeeperContract.activateCleaningUpStatusOfUpgrade(proxyTestContract.address);
await UpgradeGatekeeperContract.startPreparation(proxyTestContract.address);
} else {
await expect(UpgradeGatekeeperContract.activateCleaningUpStatusOfUpgrade(proxyTestContract.address))
.to.emit(UpgradeGatekeeperContract, 'UpgradeModeCleaningUpStatusActivated')
await expect(UpgradeGatekeeperContract.startPreparation(proxyTestContract.address))
.to.emit(UpgradeGatekeeperContract, 'UpgradeModePreparationStatusActivated')
.withArgs(proxyTestContract.address, 0)
}
}
Expand Down

0 comments on commit 4b917c7

Please sign in to comment.