diamondCut is not protected in case of governor’s key leakage
The diamondCut upgrade mechanism allows the governor to change the upgrade calldata after the proposal has been approved or the notice period has passed. If the governor's key is leaked, an attacker can front-run the governor and execute the proposal with malicious calldata at the last moment, bypassing the timelock protection.
HE1M Follow with codehacker
Originally disclosed on Code4rena
Submitted by HE1M, also found by codehacker
When the governor proposes a diamondCut, governor must wait for upgradeNoticePeriod to be passed, or security council members have to approve the proposal to bypass the notice period, so that the governor can execute the proposal.
require(approvedBySecurityCouncil || upgradeNoticePeriodPassed, "a6"); // notice period should expire
require(approvedBySecurityCouncil || !diamondStorage.isFrozen, "f3");
If the governor’s key is leaked and noticed by zkSync, the attacker must wait for the notice period to execute the already proposed diamondCut with the malicious _calldata based on the note below from zkSync, or to propose a new malicious diamondCut. For, both cases, the attacker loses time.
NOTE: proposeDiamondCut - commits data associated with an upgrade but does not execute it. While the upgrade is associated with facetCuts and (address _initAddress, bytes _calldata) the upgrade will be committed to the facetCuts and _initAddress. This is done on purpose, to leave some freedom to the governor to change calldata for the upgrade between proposing and executing it.
Since, there is a notice period (as zkSync noticed the key leakage, security council member will not approve the proposal, so bypassing the notice period is not possible), there is enough time for zkSync to apply security measures (pausing any deposit/withdraw, reporting in media to not execute any transaction in zkSync, and so on).
But, the attacker can be smarter, just before the proposal be executed by the governor (i.e. the notice period is passed or security council members approved it), the attacker executes the proposal earlier than governor with the malicious _calldata. In other words, the attacker front runs the governor.
Therefore, if zkSync notices the governor’s key leakage beforehand, there is enough time to protect the project. But, if zkSync does not notice the governor’s key leakage, the attacker can change the _calldata into a malicious one in the last moment so that it is not possible to protect the project.
Proof of Concept
Diamond.sol#L277 DiamondCut.sol#L46
Recommended Mitigation Steps
_calldata should be included in the proposed diamondCut:DiamondCut.sol#L27.
Or, at least one of the security council members should approve the _calldata during execution of the proposal.
miladpiri (zkSync) confirmed and commented:
It is a valid issue, and the fix is going to be implemented, so we confirm the issue as medium! Thanks.
Alex the Entreprenerd (judge) commented:
In contrast to other reports, this shows how a malicious proposal could be injected, bypassing the timelock protection, for this reason (after consulting with a second Judge), I agree with marking it as a distinct finding and agree with Medium Severity.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The proposed upgrade does not commit to the `_calldata`, so the governor can change it between proposal and execution, and an attacker with the governor's key can front-run the execution with malicious calldata.
Impact
If the governor's key is leaked and zkSync does not notice in time, an attacker could execute a malicious upgrade at the last moment, bypassing the timelock protection; if the leak is noticed beforehand, there is enough time to apply security measures.
What the attacker needed
Governor's private key is leaked; attacker can submit transactions to the network; zkSync does not notice the leak in time
The fix
The `_calldata` should be included in the proposed diamondCut, or at least one security council member should approve the `_calldata` during execution; zkSync confirmed the issue and said the fix is going to be implemented.
How it was found
- Governor proposes a diamondCut with a target address and calldata, but the calldata is not fixed in the proposal.
- The notice period passes or the security council approves the proposal.
- An attacker who has leaked the governor's key front-runs the governor by executing the proposal with malicious calldata.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract upgrade system lets a privileged account (the governor) propose changes, wait a notice period, then execute them. The proposal only commits to the target address, not the exact data that will be run. If someone steals the governor's key, they can wait until the last moment and submit the execution with harmful data before the real governor does, so the safety delay does not help.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.