ProtocolDAO: upgradeExistingContract deletes the new contract address making protocol inoperable #275
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
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 theStaking
contract.The function takes
newAddr
,newName
andexistingAddr
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:However the
ProtocolDAO.upgradeExistingContract
function callsregisterContract
first and thenunregisterContract
. Because both the new and the old contract have the same name, thecontract.address
entry of the new contract gets deleted again whenunregisterContract
is called.Proof of Concept
ProtocolDAO.upgradeExistingContract
is called to upgrade theStaking
contract with these arguments:newAddr=0x02
,newName="Staking"
,existingAddr=0x01
.registerContract
works fineunregisterContract(0x01)
is called which executes this line:deleteAddress(keccak256(abi.encodePacked("contract.address", name)));
. This deletes thecontract.address
entry for theStaking
contract. So other contracts in the protocol cannot find theStaking
contract which makes the protocol inoperableTools Used
VSCode
Recommended Mitigation Steps
Call
unregisterContract
first and thenregisterContract
such that theProtocolDAO.upgradeExistingContract
looks like this:The text was updated successfully, but these errors were encountered: