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

diamondCut doesn't validate _init and _calldata #159

Closed
code423n4 opened this issue Jun 19, 2022 · 2 comments
Closed

diamondCut doesn't validate _init and _calldata #159

code423n4 opened this issue Jun 19, 2022 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/libraries/LibDiamond.sol#L95-L118

Vulnerability details

Malicious or compromised governance can send a different _init and _calldata payload than the one that was proposed. This is dangerous as they will be used for a delegatecall operation. An attacker can pretend to propose a safe upgrade and later execute a delegatecall to steal funds or selfdestruct the system.

Proof of Concept

  • Malicious governor proposed a normal update with empty payload for _init and _calldata.
  • After the update delay has passed, the governor executes the update with _init pointing to a malicious contract, stealing funds from the system.

Recommended Mitigation Steps

Consider hashing _init and _calldata alongside _diamondCut as the acceptanceTimes key, to ensure the execution will use the same payload.

// @audit Apply to rescindDiamondCut() and diamondCut() as well.
function proposeDiamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
) internal {
    uint256 acceptance = block.timestamp + _delay;
    diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut, _init, _calldata))] = acceptance;
    emit DiamondCutProposed(_diamondCut, _init, _calldata, acceptance);
} 
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jun 19, 2022
code423n4 added a commit that referenced this issue Jun 19, 2022
@jakekidd
Copy link
Collaborator

Malicious or compromised governance can send a different _init and _calldata payload than the one that was proposed. This is dangerous as they will be used for a delegatecall operation.

Right now, "governance" is just an Owner role. However, I am still concerned with whether there is, hypothetically, a security issue here when governance is deployed for the protocol in the future.

Additionally worth noting that the implementation here differs from the boilerplate EIP-2535 by adding the propose route, so this isn't a redundant issue with the core proposal.

Because of this, marking as valid. The mitigation step works fine for this.

@jakekidd jakekidd added sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") duplicate This issue or pull request already exists and removed sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Jun 25, 2022
@jakekidd
Copy link
Collaborator

Duplicate of #241

@jakekidd jakekidd marked this as a duplicate of #241 Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants