πCode4rena Audit
Overview
About C4
Code4rena (C4) is an open organization consisting of security researchers, auditors, developers, and individuals with domain expertise in smart contracts.
A C4 audit contest is an event in which community participants, referred to as Wardens, review, audit, or analyze smart contract logic in exchange for a bounty provided by sponsoring projects.
During the audit contest outlined in this document, C4 conducted an analysis of the GoGoPool smart contract system written in Solidity. The audit contest took place between December 15βJanuary 3 2023.
Following the C4 audit contest, 3 wardens (hansfriese, RaymondFam, and ladboy233) reviewed the mitigations for all identified issues; the mitigation review report is appended below the audit contest report.
Wardens
114 Wardens contributed reports to the GoGoPool contest:
0xLad
0xbepresent
0xc0ffEE
0xhunter
0xmint
Arbor-Finance (namaskar and bookland)
Atarpara
Bnke0x0
Breeje
HE1M
HollaDieWaldfee
IllIllI
Josiah
KmanOfficial
Lirios
Matin
NoamYakov
PaludoX0
RaymondFam
Rolezn
SEVEN
Saintcode_
SmartSek (0xDjango and hake)
V_B (Barichek and vlad_bochok)
WatchDogs
__141345__
ak1
ast3ros
brgltd
btk
caventa
cccz
chaduke
ck
clems4ever
cozzetti
cryptonue
cryptostellar5
datapunk
dic0de
eierina
enckrish
fs0c
gz627
hihen
imare
immeas
jadezti
kaliberpoziomka8552
kartkhira
koxuan
latt1ce
lukris02
mert_eren
minhtrng
mookimgo
nameruse
neumo
peanuts
peritoflores
rvierdiiev
sces60107
shark
simon135
sk8erboy
slowmoses
tonisives
unforgiven
wagmi
wallstreetvilkas
yixxas
yongskiws
This contest was judged by Alex the Entreprenerd.
Final report assembled by liveactionllama.
Summary
The C4 analysis yielded an aggregated total of 28 unique vulnerabilities. Of these vulnerabilities, 6 received a risk rating in the category of HIGH severity and 22 received a risk rating in the category of MEDIUM severity.
Additionally, C4 analysis included 15 reports detailing issues with a risk rating of LOW severity or non-critical. There were also 12 reports recommending gas optimizations.
All of the issues presented here are linked back to their original finding.
Scope
The code under review can be found within the C4 GoGoPool contest repository, and is composed of 18 smart contracts written in the Solidity programming language and includes 2,040 lines of Solidity code.
Severity Criteria
C4 assesses the severity of disclosed vulnerabilities based on three primary risk categories: high, medium, and low/non-critical.
High-level considerations for vulnerabilities span the following key areas when conducting assessments:
Malicious Input Handling
Escalation of privileges
Arithmetic
Gas use
For more information regarding the severity criteria referenced throughout the submission review process, please refer to the documentation provided on the C4 website, specifically our section on Severity Categorization.
High Risk Findings (6)
Submitted by hansfriese, also found by unforgiven, wagmi, betweenETHlines, Allarious, HollaDieWaldfee, and chaduke
contracts/contract/MinipoolManager.sol#L374
Node operators can manipulate the assigned high water to be higher than the actual.
Proof of Concept
The protocol rewards node operators according to the AVAXAssignedHighWater
that is the maximum amount assigned to the specific staker during the reward cycle.
In the function MinipoolManager.recordStakingStart()
, the AVAXAssignedHighWater
is updated as below.
In the line #373, if the current assigned AVAX is greater than the owner's AVAXAssignedHighWater
, it is increased by avaxLiquidStakerAmt
. But this is supposed to be updated to staking.getAVAXAssigned(owner)
rather than being increased by the amount.
Example: The node operator creates a minipool with 1000AVAX via createMinipool(nodeID, 2 weeks, delegationFee, 1000*1e18)
.
On creation, the assigned AVAX for the operator will be 1000AVAX.
If the Rialtor calls recordStakingStart()
, AVAXAssignedHighWater
will be updated to 1000AVAX. After the validation finishes, the operator creates another minipool with 1500AVAX this time. Then on recordStakingStart()
, AVAXAssignedHighWater
will be updated to 2500AVAX by increasing 1500AVAX because the current assigned AVAX is 1500AVAX which is higher than the current AVAXAssignedHighWater=1000AVAX
.
This is wrong because the actual highest assigned amount is 1500AVAX.
Note that AVAXAssignedHighWater
is reset only through the function calculateAndDistributeRewards
which can be called after RewardsCycleSeconds=28 days
.
Recommended Mitigation Steps
Call staking.resetAVAXAssignedHighWater(owner)
instead of calling increaseAVAXAssignedHighWater()
.
emersoncloud (GoGoPool) confirmed
Can we take some extra considerations here please? Discussed with @0xju1ie (GoGoPool) about this specific issue, and this was the answer:
(it is AVAXAssignedHighWater)
Their example in the proof of concept section is correct, and we have decided that this is not the ideal behavior and thus this is a bug. However, their recommended mitigation steps would create other issues, as highlighted by what @Franfran said. We intend to solve this issue differently than what they suggested.
Alex the Entreprenerd (judge) commented:
The Warden has shown a flaw in the way
increaseAVAXAssignedHighWater
is used, which can be used to:
Inflate the amount of AVAX
With the goal of extracting more rewards than intended
I believe that the finding highlights both a way to extract further rewards as well as broken accounting.
For this reason I agree with High Severity.
emersoncloud (GoGoPool) mitigated:
New variable to track validating avax: multisig-labs/gogopool#25
Status: Mitigation confirmed with comments. Full details in report from RaymondFam.
Submitted by bin2chen, also found by AkshaySrivastav, hansfriese, hansfriese, caventa, shark, RaymondFam, csanuragjain, rvierdiiev, and cozzetti
contracts/contract/Staking.sol#L379-L383
ProtocolDAO implementation does not have a method to take out GGP. So it can't handle ggp unless it updates ProtocolDAO.
Proof of Concept
recordStakingEnd() will pass the rewards of this reward. "If the validator is failing at their duties, their GGP will be slashed and used to compensate the loss to our Liquid Stakers"
At this point slashGGP() will be executed and the GGP will be transferred to "ProtocolDAO"
staking.slashGGP():
But the current ProtocolDAO implementation does not have a method to take out GGP. So it can't handle ggp unless it updates ProtocolDAO
Recommended Mitigation Steps
1.transfer GGP to ClaimProtocolDAO or 2.Similar to ClaimProtocolDAO, add spend method to retrieve GGP
Alex the Entreprenerd (judge) increased severity to High and commented:
The Warden has shown how, due to a lack of
sweep
the default contract for fee handling will be unable to retrieve tokens sent to it.While the issue definitely would have been discovered fairly early in Prod, the in-scope system makes it clear that the funds would have been sent to ProtocolDAO.sol and would have been lost indefinitely.
For this reason, I believe the finding to be of High Severity.
emersoncloud (GoGoPool) commented:
Acknowledged.
Thanks for the report. This is something we're aware of and are not going to fix at the moment.
The funds are transferred to the Vault and the ProtocolDAO contract is upgradeable. Therefore in the future we can upgrade the contract to spend the Vault GGP tokens to return funds to Liquid Stakers.
We expect slashing to be a rare event and might have some manual steps involved in the early days of the protocol to do this process if it occurs.
Submitted by immeas, also found by Allarious, ast3ros, unforgiven, Josiah, SmartSek, Franfran, HollaDieWaldfee, RaymondFam, and 0xdeadbeef0x
contracts/contract/MinipoolManager.sol#L673-L675
A node operator sends in the amount of duration they want to stake for. Behind the scenes Rialto will stake in 14 day cycles and then distribute rewards.
If a node operator doesn't have high enough availability and doesn't get any rewards, the protocol will slash their staked GGP
. For calculating the expected rewards that are missed however, the full duration is used:
This is unfair to the node operator because the expected rewards is from a 14 day cycle.
Also, If they were to be unavailable again, in a later cycle, they would get slashed for the full duration once again.
Impact
A node operator staking for a long time is getting slashed for an unfairly large amount if they aren't available during a 14 day period.
The protocol also wants node operators to stake in longer periods: https://multisiglabs.notion.site/Known-Issues-42e2f733daf24893a93ad31100f4cd98
Team Comment:
This can only be taken advantage of when signing up for 2-4 week validation periods. Our protocol is incentivizing nodes to sign up for 3-12 month validation periods. If the team notices this mechanic being abused, Rialto may update its GGP reward calculation to disincentive this behavior.
This slashing amount calculation incentives the node operator to sign up for the shortest period possible and restake themselves to minimize possible losses.
Proof of Concept
Test in MinipoolManager.t.sol
:
Slashed amount for a 365 days
duration is 100 eth
(10%). However, where they to stake for the minimum time, 14 days
the slashed amount would be only ~3.8 eth
.
Tools Used
vs code, forge
Recommended Mitigation Steps
Either hard code the duration to 14 days for calculating expected rewards or calculate the actual duration using startTime
and endTime
.
Alex the Entreprenerd (judge) increased severity to High and commented:
The Warden has shown an incorrect formula that uses the
duration
of the pool for slashing.The resulting loss can be up to 26 times the yield that should be made up for.
Because the:
Math is incorrect
Based on intended usage
Impact is more than an order of magnitude off
Principal is impacted (not just loss of yield)
I believe the most appropriate severity to be High.
emersoncloud (GoGoPool) mitigated:
Base slash on validation period not full duration: multisig-labs/gogopool#41
Status: Mitigation confirmed by RaymondFam and hansfriese.
Submitted by 0xdeadbeef0x, also found by bin2chen, datapunk, 0xmint, Lirios, AkshaySrivastav, adriro, ak1, IllIllI, pauliax, imare, imare, immeas, sces60107, peritoflores, wagmi, Jeiwan, sk8erboy, unforgiven, caventa, yixxas, Franfran, clems4ever, Ch_301, Allarious, 0xc0ffEE, 0Kage, kaliberpoziomka8552, kaliberpoziomka8552, HollaDieWaldfee, wallstreetvilkas, stealthyz, cozzetti, rvierdiiev, ladboy233, chaduke, chaduke, and Manboy
A malicious actor can hijack a minipool of any node operator that finished the validation period or had an error.
The impacts:
Node operators staked funds will be lost (Loss of funds)
Hacker can hijack the minipool and retrieve rewards without hosting a node. (Theft of yield)
2.1 See scenario #2 comment for dependencies
Proof of Concept
Background description
The protocol created a state machine that validates transitions between minipool states. For this exploit it is important to understand three states:
Prelaunch
- This state is the initial state when a minipool is created. The created minipool will have a status ofPrelaunch
until liquid stakers funds are matched andrialto
stakes 2000 AVAX into Avalanche.Withdrawable
- This state is set when the 14 days validation period is over. In this state: 2.1.rialto
returned 1000 AVAX to the liquid stakers and handled reward distribution. 2.2. Node operators can withdraw their staked funds and rewards. 2.3. If the node operator signed up for a duration longer than 14 daysrialto
will recreate the minipool and stake it for another 14 days.Error
- This state is set whenrialto
has an issue to stake the funds in Avalanche
The state machine allows transitions according the requireValidStateTransition
function: https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L164
In the above restrictions, we can see that the following transitions are allowed:
From
Withdrawable
state toPrelaunch
state. This transition enablesrialto
to callrecreateMinipool
From
Finished
state toPrelaunch
state. This transition allows a node operator to re-use their nodeID to stake again in the protocol.From
Error
state toPrelaunch
state. This transition allows a node operator to re-use their nodeID to stake again in the protocol after an error.
#2 is a needed capability, therefore createMinipool
allows overriding a minipool record if: nodeID
already exists and transition to Prelaunch
is permitted
createMinipool
:
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L242
THE BUG: createMinipool
can be called by Anyone with the nodeID
of any node operator.
If createMinipool
is called at the Withdrawable
state or Error
state:
The transaction will be allowed
The owner of the minipool will be switched to the caller.
Therefore, the minipool is hijacked and the node operator will not be able to withdraw their funds.
Exploit scenarios
As shown above, an attacker can always hijack the minipool and lock the node operators funds.
Cancel the minipool
Earn rewards on behalf of original NodeOp
Scenario #1 - Cancel the minipool
A hacker can hijack the minipool and immediately cancel the pool after a 14 day period is finished or an error state. Results:
Node operator will lose all his staked AVAX 1.1. This can be done by a malicious actor to ALL GoGoPool stakers to lose their funds in a period of 14 days.
Hacker will not lose anything and not gain anything.
Consider the following steps:
Hacker creates a node and creates a minipool
node-1337
.NodeOp registers a nodeID
node-123
and finished the 14 days stake period. State isWithdrawable
.Hacker calls
createMinipool
withnode-123
and deposits 1000 AVAX. Hacker is now owner of the minipoolHacker calls
cancelMinipool
ofnode-123
and receives his staked 1000 AVAX.NodeOp cannot withdraw his staked AVAX as NodeOp is no longer the owner.
Hacker can withdraw staked AVAX for both
node-1337
andnode-123
The above step #1 is not necessary but allow the hacker to immediately cancel the minipool without waiting 5 days. (See other submitted bug #211: "Anti griefing mechanism can be bypassed")
Scenario #2 - Use node of node operator
In this scenario the NodeOp registers for a duration longer then 14 days. The hacker will hijack the minipool after 14 days and earn rewards on behalf of the node operators node for the rest of the duration. As the NodeOp registers for a longer period of time, it is likely he will not notice he is not the owner of the minipool and continue to use his node to validate Avalanche.
Results:
Node operator will lose all his staked AVAX
Hacker will gain rewards for staking without hosting a node
Important to note:
This scenario is only possible if
recordStakingEnd
andrecreateMinipool
are not called in the same transaction byrialto
.During the research the sponsor has elaborated that they plan to perform the calls in the same transaction.
The sponsor requested to submit issues related to
recordStakingEnd
andrecreateMinipool
single/multi transactions for information and clarity anyway.
Consider the following steps:
Hacker creates a node and creates a minipool
node-1337
.NodeOp registers a nodeID
node-123
for 28 days duration and finished the 14 days stake period. State isWithdrawable
.Hacker calls
createMinipool
withnode-1234
and deposits 1000 AVAX. Hacker is now owner of minipoolRialto calls
recreateMinipool
to restake the minipool in Avalanche. (This time: the owner is the hacker, the hardware is NodeOp)14 days have passed, hacker can withdraw the rewards and 1000 staked AVAX
NodeOps cannot withdraw staked AVAX.
Foundry POC
The POC will demonstrate scenario #1.
Add the following test to MinipoolManager.t.sol
:
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/test/unit/MinipoolManager.t.sol#L175
To run the POC, execute:
Expected output:
Tools Used
VS Code, Foundry
Recommended Mitigation Steps
Fortunately, the fix is very simple.
The reason createMinipool
is called with an existing nodeID
is to re-use the nodeID
again with the protocol. GoGoPool can validate that the owner is the same address as the calling address. GoGoPool have already implemented a function that does this: onlyOwner(index)
.
Consider placing onlyOwner(index)
in the following area:
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L243
Alex the Entreprenerd (judge) commented:
The Warden has shown how, due to a lax check for State Transition, a Pool ID can be hijacked, causing the loss of the original deposit
Because the attack is contingent on a logic flaw and can cause a complete loss of Principal, I agree with High Severity.
Separate note: I created issue 904. For the Finding 2 of this report, please refrain from grouping findings especially when they use different functions and relate to different issues.
emersoncloud (GoGoPool) mitigated:
Atomically recreate minipool to not allow hijack: multisig-labs/gogopool#23
Status: Mitigation confirmed, but a new medium severity issue was found. Full details in report from hansfriese, and also included in Mitigation Review section below.
Submitted by 0xdeadbeef0x, also found by eierina, ak1, datapunk, 0xNazgul, Qeew, Breeje, SamGMK, IllIllI, TomJ, sces60107, WatchDogs, Arbor-Finance, SmartSek, hansfriese, tonisives, peanuts, unforgiven, 0xSmartContract, fs0c, ck, 0xbepresent, yongskiws, 0xLad, btk, rvierdiiev, koxuan, ladboy233, Rolezn, HE1M, yongskiws, SEVEN, and dic0de
Inflation of ggAVAX
share price can be done by depositing as soon as the vault is created.
Impact:
Early depositor will be able steal other depositors funds
Exchange rate is inflated. As a result depositors are not able to deposit small funds.
Proof of Concept
If ggAVAX
is not seeded as soon as it is created, a malicious depositor can deposit 1 WEI of AVAX to receive 1 share.
The depositor can donate WAVAX to the vault and call syncRewards
. This will start inflating the price.
When the attacker front-runs the creation of the vault, the attacker:
Calls
depositAVAX
to receive 1 shareTransfers
WAVAX
toggAVAX
Calls
syncRewards
to inflate exchange rate
The issue exists because the exchange rate is calculated as the ratio between the totalSupply
of shares and the totalAssets()
.
When the attacker transfers WAVAX
and calls syncRewards()
, the totalAssets()
increases gradually and therefore the exchange rate also increases.
convertToShares
: https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L123
Its important to note that while it is true that cycle length is 14 days, in practice time between cycles can very between 0-14 days. This is because syncRewards validates that the next reward cycle is evenly divided by the length (14 days).
Therefore:
The closer the call to
syncRewards
is to the next evenly divisible value ofrewardsCycleLength
, the closer the nextrewardsCycleEnd
will be.The closer the delta between
syncRewards
calls is, the higher revenue the attacker will get.
Edge case example:
syncRewards
is called with the timestamp 1672876799, syncRewards
will be able to be called again 1 second later. (1672876799 + 14 days) / 14 days) * 14 days) = 1672876800
Additionally, the price inflation causes a revert for users who want to deposit less then the donation (WAVAX transfer) amount, due to precision rounding when depositing.
previewDeposit
and convertToShares
:
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L133
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L123
Foundry POC
The POC will demonstrate the below scenario:
Bob front-runs the vault creation.
Bob deposits 1 WEI of AVAX to the vault.
Bob transfers 1000 WAVAX to the vault.
Bob calls
syncRewards
when block.timestamp =1672876799
.Bob waits 1 second.
Bob calls
syncRewards
again. Share price fully inflated.Alice deposits 2000 AVAX to vault.
Bob withdraws 1500 AVAX (steals 500 AVAX from Alice).
Alice share earns her 1500 AVAX (although she deposited 2000).
Additionally, the POC will show that depositors trying to deposit less then the donation amount will revert.
Add the following test to TokenggAVAX.t.sol
: https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/test/unit/TokenggAVAX.t.sol#L108
To run the POC, execute:
Expected output:
Tools Used
VS Code, Foundry
Recommended Mitigation Steps
When creating the vault add initial funds in order to make it harder to inflate the price. Best practice would add initial funds as part of the initialization of the contract (to prevent front-running).
emersoncloud (GoGoPool) confirmed
Alex the Entreprenerd (judge) commented:
The Warden has shown how, by performing a small deposit, followed by a transfer, shares can be rebased, causing a grief in the best case, and complete fund loss in the worst case for every subsequent depositor.
While the finding is fairly known, it's impact should not be understated, and because of this I agree with High Severity.
I recommend watching this presentation by Riley Holterhus which shows possible mitigations for the attack: https://youtu.be/_pO2jDgL0XE?t=601
emersoncloud (GoGoPool) mitigated:
Initialize ggAVAX with a deposit: multisig-labs/gogopool#49
Status: Mitigation confirmed by RaymondFam and hansfriese.
Submitted by HollaDieWaldfee, also found by enckrish, imare, bin2chen, danyams, 0xdeadbeef0x, cozzetti, and ladboy233
When staking is done, a Rialto multisig calls MinipoolManager.recordStakingEnd
(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L385-L440).
If the avaxTotalRewardAmt
has the value zero, the MinipoolManager
will slash the node operator's GGP.
The issue is that the amount to slash can be greater than the GGP balance the node operator has staked.
This will cause the call to MinipoolManager.recordStakingEnd
to revert because an underflow is detected.
This means a node operator can create a minipool that cannot be slashed.
A node operator must provide at least 10% of avaxAssigned
as collateral by staking GGP.
It is assumed that a node operator earns AVAX at a rate of 10% per year.
So if a Minipool is created with a duration of > 365 days
, the 10% collateral is not sufficient to pay the expected rewards.
This causes the function call to revert.
Another cause of the revert can be that the GGP price in AVAX changes. Specifically if the GGP price falls, there needs to be slashed more GGP.
Therefore if the GGP price drops enough it can cause the call to slash to revert.
I think it is important to say that with any collateralization ratio this can happen. The price of GGP must just drop enough or one must use a long enough duration.
The exact impact of this also depends on how the Rialto multisig handles failed calls to MinipoolManager.recordStakingEnd
.
It looks like if this happens, MinipoolManager.recordStakingError
(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L484-L515) is called.
This allows the node operator to withdraw his GGP stake.
So in summary a node operator can create a Minipool that cannot be slashed and probably remove his GGP stake when it should have been slashed.
Proof of Concept
When calling MinipoolManager.recordStakingEnd
(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L385-L440) and the avaxTotalRewardAmt
parameter is zero, the node operator is slashed:
The MinipoolManager.slash
function (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L670-L683) then calculates expectedAVAXRewardsAmt
and from this slashGGPAmt
:
Downstream there is then a revert due to underflow because of the following line in Staking.decreaseGGPStake
(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/Staking.sol#L94-L97):
You can add the following foundry test to MinipoolManager.t.sol
:
See that it runs successfully with duration = 365 days
and fails with duration = 366 days
.
The similar issue occurs when the GGP price drops. I chose to implement the test with duration
as the cause for the underflow because your tests use a fixed AVAX/GGP price.
Tools Used
VSCode, Foundry
Recommended Mitigation Steps
You should check if the amount to be slashed is greater than the node operator's GGP balance. If this is the case, the amount to be slashed should be set to the node operator's GGP balance.
I believe this check can be implemented within the MinipoolManager.slash
function without breaking any of the existing accounting logic.
emersoncloud (GoGoPool) confirmed, but commented:
This is a combination of two other issues from other wardens
Slash amount shouldn't depend on duration: https://github.com/code-423n4/2022-12-gogopool-findings/issues/694
GGP Slash shouldn't revert: https://github.com/code-423n4/2022-12-gogopool-findings/issues/743
Alex the Entreprenerd (judge) commented:
This finding combines 2 issues:
If price drops Slash can revert -> Medium
Attacker can set Duration to too high to cause a revert -> High
Am going to dedupe this and the rest, but ultimately I think these are different findings, that should have been filed separately.
Alex the Entreprenerd (judge) commented:
The Warden has shown how a malicious staker could bypass slashing, by inputting a duration that is beyond the intended amount.
Other reports have shown how to sidestep the slash or reduce it, however, this report shows how the bypass can be enacted maliciously to break the protocol functionality, to the attacker's potential gain.
Because slashing is sidestepped in it's entirety, I believe this finding to be of High Severity.
emersoncloud (GoGoPool) mitigated:
If staked GGP doesn't cover slash amount, slash it all: multisig-labs/gogopool#41
Status: Original finding mitigated, but a medium severity economical risk is still present. Full details in reports from RaymondFam, ladboy233 and hansfriese. Also included in Mitigation Review section below.
Medium Risk Findings (22)
Submitted by ak1, also found by sces60107
When the contract is paused , allowing startRewardsCycle would inflate the token value which might not be safe.
Rewards should not be claimed by anyone when all other operations are paused.
I saw that the witdrawGGP
has this WhenNotPaused
modifier.
Inflate should not consider the paused duration.
Let's say, when the contract is paused for the duration of 2 months, then the dao, protocol, and node validator would enjoy the rewards. This is not good for a healthy protocol.
Proof of Concept
startRewardsCycle does not have the WhenNotPaused modifier.
Recommended Mitigation Steps
We suggest to use WhenNotPaused
modifier.
emersoncloud (GoGoPool) confirmed
Alex the Entreprenerd (judge) commented:
The Warden has shown an inconsistency as to how Pausing is used.
While other aspects of the code are pausable and under the control of the
guardian
, a call tostartRewardsCycle
can be performed by anyone, and in the case of a system-wide pause may create unfair gains or lost rewards.For this reason I agree with Medium Severity.
emersoncloud (GoGoPool) mitigated:
Pause startRewardsCycle when protocol is paused: multisig-labs/gogopool#22
Status: Mitigation confirmed with comments. Full details in report from RaymondFam.
Submitted by gz627, also found by Allarious, ast3ros, bin2chen, brgltd, hihen, adriro, unforgiven, Czar102, nogo, nogo, imare, HE1M, KmanOfficial, neumo, AkshaySrivastav, betweenETHlines, peanuts, mookimgo, cccz, chaduke, and HollaDieWaldfee
Function ProtocolDAO.upgradeExistingContract
handles contract upgrading. However, there are multiple implicaitons of the coding logic in the function, which render the contract upgrading impractical.
Implication 1:
The above function upgradeExistingContract
registers the upgraded contract first, then unregisters the existing contract. This leads to the requirement that the upgraded contract name must be different from the existing contract name. Otherwise the updated contract address returned by Storage.getAddress(keccak256(abi.encodePacked("contract.address", contractName)))
will be address(0)
(please refer to the below POC Testcase 1). This is because if the upgraded contract uses the original name (i.e. the contract name is not changed), function call unregisterContract(existingAddr)
in the upgradeExistingContract
will override the registered contract address in Storage
to address(0) due to the use of the same contract name.
Since using the same name after upgrading will run into trouble with current coding logic, a safeguard should be in place to make sure two names are really different. For example, put this statement in the upgradeExistingContract
function:
require(newName != existingName, "Name not changed");
, where existingName
can be obtained using:
string memory existingName = store.getString(keccak256(abi.encodePacked("contract.name", existingAddr)));
.
Implication 2:
If we really want a different name for an upgraded contract, we then get into more serious troubles: We have to upgrade other contracts that reference the upgraded contract since contract names are referenced mostly hardcoded (for security considerations). This may lead to a very complicated issue because contracts are cross-referenced.
For example, contract ClaimNodeOp
references contracts RewardsPool
, ProtocolDAO
and Staking
. At the same time, contract ClaimNodeOp
is referenced by contracts RewardsPool
and Staking
. This means that:
If contract
ClaimNodeOp
was upgraded, which means the contract nameClaimNodeOp
was changed;This requires contracts
RewardsPool
andStaking
to be upgraded (with new names) in order to correctly reference to newly namedClaimNodeOp
contract;This further requires those contracts that reference
RewardsPool
orStaking
to be upgraded in order to correctly reference them;and this further requires those contracts that reference the above upgraded contracts to be upgraded ...
This may lead to complicated code management issue and expose new vulnerabilites due to possible incomplete code adaptation.
This may render the contracts upgrading impractical.
I rate this issue as high severity due to the fact that:
Contract upgradability is one of the main features of the whole system design (all other contracts are designed upgradable except for TokenGGP
, Storage
and Vault
). However, the current upgradeExistingContract
function's coding logic requires the upgraded contract must change its name (refer to the below Testcase 1). This inturn requires to upgrade all relevant cross-referenced contracts (refer to the below Testcase 2). Thus leading to a quite serous code management issue while upgrading contracts, and renders upgrading contracts impractical.
Proof of Concept
Testcase 1:
This testcase demonstrates that current coding logic of upgrading contracts requires: the upgraded contract must change its name. Otherwise contract upgrading will run into issue. Put the below test case in file ProtocolDAO.t.sol
. The test case demonstrates that ProtocolDAO.upgradeExistingContract
does not function properly if the upgraded contract does not change the name. That is: the upgraded contract address returned by Storage.getAddress(keccak256(abi.encodePacked("contract.address", contractName)))
will be address(0)
if its name unchanged.
Testcase 2:
This testcase demonstrates that current coding logic of upgrading contracts requires: in order to upgrade a single contract, all cross-referenced contracts have to be upgraded and change their names. Otherwise, other contracts will run into issues.
If the upgraded contract does change its name, contract upgrading will succeed. However, other contracts' functions that reference the upgraded contract will fail due to referencing hardcoded contract name.
The below testcase upgrades contract ClaimNodeOp
to ClaimNodeOpV2
. Then, contract Staking
calls increaseGGPRewards
which references hardcoded contract name ClaimNodeOp
in its modifier. The call is failed.
Test steps:
Copy contract file
ClaimNodeOp.sol
toClaimNodeOpV2.sol
, and rename the contract name fromClaimNodeOp
toClaimNodeOpV2
in fileClaimNodeOpV2.sol
;Put the below test file
UpgradeContractIssue.t.sol
under foldertest/unit/
;Run the test.
Note: In order to test actual function call after upgrading contract, this testcase upgrades a real contract ClaimNodeOp
. This is different from the above Testcase 1 which uses a random address to simulate a contract.
Recommended Mitigation Steps
Upgrading contract does not have to change contranct names especially in such a complicated system wherein contracts are cross-referenced in a hardcoded way. I would suggest not to change contract names when upgrading contracts.
In function
upgradeExistingContract
definition, swap fucnction call sequence betweenregisterContract()
andunregisterContract()
so that contract names can keep unchanged after upgrading. That is, the modified function would be:
POC of Mitigation:
After the above recommended mitigation, the below Testcase verifies that after upgrading contracts, other contract's functions, which reference the hardcoded contract name, can still opetate correctly.
Make the above recommended mitigation in function
ProtocolDAO.upgradeExistingContract
;Put the below test file
UpgradeContractImproved.t.sol
under foldertest/unit/
;Run the test.
Note: Since we don't change the upgraded contract name, for testing purpose, we just need to create a new contract instance (so that the contract instance address is changed) to simulate the contract upgrading.