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

ProtocolDAO: upgradeExistingContract deletes the new contract address making protocol inoperable #275

Closed
code423n4 opened this issue Dec 29, 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-742 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ProtocolDAO.sol#L209-L216

Vulnerability details

Impact

The ProtocolDAO.upgradeExistingContract function (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ProtocolDAO.sol#L209-L216) allows to upgrade an existing contract in the protocol. E.g. it can be used to upgrade the Staking contract.

The function takes newAddr, newName and existingAddr as arguments.

It only really makes sense to upgrade an existing contract to a new contract that has the same name as the old contract. E.g. the staking contract must be called Staking before and after the upgrade. This is because other contracts look up the contract address by the contract's name:

Staking(getContractAddress("Staking"))

However the ProtocolDAO.upgradeExistingContract function calls registerContract first and then unregisterContract. Because both the new and the old contract have the same name, the contract.address entry of the new contract gets deleted again when unregisterContract is called.

Proof of Concept

  1. ProtocolDAO.upgradeExistingContract is called to upgrade the Staking contract with these arguments: newAddr=0x02, newName="Staking", existingAddr=0x01.
  2. The call to registerContract works fine
  3. However after that, unregisterContract(0x01) is called which executes this line: deleteAddress(keccak256(abi.encodePacked("contract.address", name)));. This deletes the contract.address entry for the Staking contract. So other contracts in the protocol cannot find the Staking contract which makes the protocol inoperable

Tools Used

VSCode

Recommended Mitigation Steps

Call unregisterContract first and then registerContract such that the ProtocolDAO.upgradeExistingContract looks like this:

function upgradeExistingContract(
    address newAddr,
    string memory newName,
    address existingAddr
) external onlyGuardian {
    unregisterContract(existingAddr);
    registerContract(newAddr, newName);
}
@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 Dec 29, 2022
code423n4 added a commit that referenced this issue Dec 29, 2022
C4-Staff added a commit that referenced this issue Jan 6, 2023
@c4-judge c4-judge closed this as completed Jan 9, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jan 9, 2023

GalloDaSballo marked the issue as duplicate of #742

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 8, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 8, 2023

GalloDaSballo marked the issue as satisfactory

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-742 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants