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

Upgrading existing contract in storage can result in unwanted state #621

Closed
code423n4 opened this issue Jan 3, 2023 · 2 comments
Closed
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 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jan 3, 2023

Lines of code

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

Vulnerability details

Impact

If there is a need to upgrade an existing contract due to vulnerability or added functionality, upgradeExistingContract could be called to simplify unregistering and registering a new contract in one transaction. However, registering a new contract before unregistering the previous address can leave keccak256(abi.encodePacked("contract.address", name) without the correct value in addressStorage if newAddr and existingAddr's name in storage is equal to the function parameter newName. This would be the assumed case given the fact that the underlying contract address is being upgraded for that name so that other areas of the GoGoPool protocol can interact with the newly upgraded contract at that name which is hardcoded and used throughout the protocol.

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

## Proof of concept
For example, if the contract you was replacing was named "RewardsPool" with an existing address of 0x0000000000000000000000000000000000000001 and upgradingExistingContract is called with newName "rewardsPool" and address 0x0000000000000000000000000000000000000002 it would call registerContract setting the values required in storage correctly. Next, unregisterContract would be called with the existing address in which the contract.exists bool and contract.name string would be removed correctly. However, the contract.address field which is packed and hashed with the same name "RewardsPool" would be removed although that mapping in storage was already updated to the new address already in registerContract.

Tools Used

VSCode

Recommended Mitigation Steps

If unregisterContract(existingAddr); is called before registerContract(newAddr, newName); in upgradeExistingContract, this would resolve that issue where the addressStorage mapped value is set and stays changed to newAddr.

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 Jan 3, 2023
code423n4 added a commit that referenced this issue Jan 3, 2023
C4-Staff added a commit that referenced this issue Jan 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jan 9, 2023

GalloDaSballo marked the issue as duplicate of #742

@c4-judge c4-judge closed this as completed Jan 9, 2023
@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 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants