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

upgradeExistingContract will fail to register the new address when newName == oldName. #315

Closed
code423n4 opened this issue Dec 30, 2022 · 3 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 downgraded by judge Judge downgraded the risk level of this issue duplicate-742 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Dec 30, 2022

Lines of code

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

Vulnerability details

Impact

Detailed description of the impact of this finding.
when the new name of the contract is the same as the old name of a contract (which is necessary to move funding from old contracts to upgraded ones), the function upgradeExistingContract() will fail to register the new address of the contract and in particular, getContractAddress(newName) will return zero after the upgrade. The whole system will not work after that since modifiers guardianOrSpecificRegisteredContract() and onlySpecificRegisteredContract() will always revert for this contract.

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ProtocolDAO.sol#L209-L217
The main problem of upgradeExistingContract() is that it performs registerContract() first and then performs unregisterContract(). The order should be reversed. Because of this, the following statement of registerContract()

setAddress(keccak256(abi.encodePacked("contract.address", name)), addr);

is overwritten by the following statement of unregisteredContract():

deleteAddress(keccak256(abi.encodePacked("contract.address", name)));

as a result, the registration of the address of the contract under the name is lost when oldName == newName.
Moreover, getContractAddress(newName) will return zero after the upgrade. The whole system might fail after that.

Tools Used

Remix

Recommended Mitigation Steps

The fix is simple, just exchange the order of registerContract() and unregisterContract() in function upgradeExistingContract():


function upgradeExistingContract(
		address newAddr,
		string memory newName,
		address existingAddr
	) external onlyGuardian {
		unregisterContract(existingAddr);
		registerContract(newAddr, newName);
}

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 30, 2022
code423n4 added a commit that referenced this issue Dec 30, 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 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Feb 2, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 2, 2023

GalloDaSballo changed the severity to 2 (Med Risk)

@c4-judge
Copy link
Contributor

c4-judge commented Feb 8, 2023

GalloDaSballo marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 8, 2023
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-742 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants