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

call upgradeExistingContract in ProtocolDAO.sol with the same name cause inaccurate storage "contract.address"+name #358

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

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jan 1, 2023

Lines of code

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

Vulnerability details

Impact

storage "contract.address"+name is wrongly set to zero when guardian call upgradeExistingContract with the same name

Proof of Concept

It's common that a contract will get updated with the same name, thus calling upgradeExistingContract with the same (newName is the same as the old name).

In this upgradeExistingContract function, it will first call registerContract function, which writes the storage setAddress(keccak256(abi.encodePacked("contract.address", name)), addr);, but afterwards, it calls unregisterContract, which clears the storage: deleteAddress(keccak256(abi.encodePacked("contract.address", name)));.

So after this call, the contract.address+name is wrongly cleared, which makes getContractAddress fails in https://github.com/code-423n4/2022-12-gogopool/blob/1c30b320b7105e57c92232408bc795b6d2dfa208/contracts/contract/BaseAbstract.sol#L90 :

		if (contractAddress == address(0x0)) {
			revert ContractNotFound();
		}

This further makes all functionalities relying on getContractAddress fail

For example, after upgrade Staking contract, isEligible function in https://github.com/code-423n4/2022-12-gogopool/blob/1c30b320b7105e57c92232408bc795b6d2dfa208/contracts/contract/ClaimNodeOp.sol#L47 will fail.

Tools Used

reading code

Recommended Mitigation Steps

change to unregister first.

	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 1, 2023
code423n4 added a commit that referenced this issue Jan 1, 2023
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
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 duplicate-742 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants