THE FIRST AMM STAKER WILL HAVE CONTROL OVER HOW THE SHARES ARE CALCULATED #100
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
disagree with severity
Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L147
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L154
Vulnerability details
Impact
The first staker can take control of how the subsequent shares are going to be distributed by simply staking 1wei amount of the token and frontrunning future stakers. The reasons of this are related on how the variables are updated and with the amounts that the Gauge allows users to stake (anything but zero). The origin of this vulnerability relies on the evaluation of the
totalStaked
variable on its inception.Proof of Concept
To illustrate this attack an environment of testing was made in order to track the token flows and how the variables are being updated and read.
The initial or border conditions taken into account are the same as the used by the team to perform the tests and just a few assumptions and simplifications were taken.
0.001
). This is valid within a short period of time because it is not a function of how the tokens are distributed or their flows. By tracking how the inflation rate is calculated an updated, we see that it is managed by thecurrentInflationAmountAmm
within theMinter.sol
contract, which value is modified by_executeInflationRateUpdate()
three lines below the last code permalink. Its value depends on non-token balance related parameters (such as inflation decays and annual rates).Each user state is updated whenever he calls either
stake
,unstake
orclaimRewards
.Steps:
10 * 10**decimals()
).Both cases were evaluated (with and without staking 1 wei first). The attack scenario outputs a 100% more shares to Alice than Bob in comparison with the ethical/non-attack situation.
The code used to perform this test is the following:
The simulation was both made for the attacked and non attacked situations.
The values that are shown represent how the contract updates them (the
totalStaked
variable is 0 when first Alice calls the stake function after_userCheckpoint()
rans)WITH 1WEI STAKE (ATTACK)
WITHOUT THE 1WEI STAKE (No "first staker hijack")
Recommended Mitigation Steps
Further evaluation on how the variables are updated and how does the
Integral
(both each users and global one) is calculated on the pool inception is needed to patch this issue.The text was updated successfully, but these errors were encountered: