Malt Protocol Uses Stale Results From MaltDataLab Which Can Be Abused By Users
The MaltDataLab contract relies on an externally triggered updater to refresh price and reserve averages, so those values can become stale. A user who can call stabilize could repeatedly trigger auctions and collect the 100 Malt incentive while colluding with a miner to censor the updater's transactions.
Submitted by leastwood
MaltDataLab integrates several MovingAverage contracts to fetch sensitive data for the Malt protocol. Primary data used by the protocol consists of the real value for LP tokens, the average price for Malt and average reserve ratios. trackMaltPrice, trackPoolReserves and trackPool are called by a restricted role denoted as the UPDATER_ROLE and represented by an EOA account and not another contract. Hence, the EOA account must consistently update the aforementioned functions to ensure the most up-to-date values. However, miners can censor calls to MaltDataLab and effectively extract value from other areas of the protocol which use stale values.
Proof of Concept
Consider the following attack vector:
- The price of Malt exceeds the lower bound threshold and hence
stabilizecan be called by any user. - The
_stabilityWindowOverridefunction is satisfied, hence the function will execute. - The state variable,
exchangeRate, queriesmaltPriceAveragewhich may use an outdated exchange rate. _startAuctionis executed which rewardsmsg.senderwith 100 Malt as an incentive for triggering an auction.- As the price is not subsequently updated, a malicious attacker could collude with a miner to censor further pool updates and continue calling
stabilizeon everyfastAveragePeriodinterval to extract incentive payments. - If the payments exceed what the
UPDATER_ROLEis willing to pay to calltrackMaltPrice, a user is able to sustain this attack.
This threatens the overall stability of the protocol and should be properly handled to prevent such attacks. However, the fact that MaltDataLab uses a series of spot price data points to calculate the MovingAverage also creates an area of concern as well-funded actors could still manipulate the MovingAverage contract by sandwiching calls to trackMaltPrice, trackPool and trackPoolReserves.
trackMaltPrice, trackPool, and trackPoolReserves should be added to the following areas of the code where applicable.
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/Bonding.sol#L159
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/Bonding.sol#L173
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/Bonding.sol#L177
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/Auction.sol#L881
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/Auction.sol#L710
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/StabilizerNode.sol#L156
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/StabilizerNode.sol#L190
- https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/ImpliedCollateralService.sol#L105
Recommended Mitigation Steps
Consider adding calls to trackMaltPrice, trackPoolReserves and trackPool wherever the values are impacted by the protocol. This should ensure the protocol is tracking the most up-to-date values. Assuming the cumulative values are used in the MovingAverage contracts, then sensitive calls utilising MaltDataLab should be protected from flashloan attacks. However, currently this is not the case, rather MovingAverage consists of a series of spot price data points which can be manipulated by well-funded actors or via a flashloan. Therefore, there needs to be necessary changes made to MaltDataLab to use cumulative price updates as its moving average instead of spot price.
Gas issues were the reason updates weren’t inlined into paths that update critical values. However based on some thoughts from the team over the past few weeks and suggestions in other audit findings I think we can reduce gas enough to make it viable to inline it
Alex the Entreprenerd (judge) commented:
- Miners can censor transactions, that is a fact
- Relying on an external call can cause race conditions or situations where the call didn’t happen (price didn’t update in time)
- Arguably a malicious actor could collude with miners with the goal of extracting further value
However, the target chain for the deployment is Polygon, so unless they were to create custom validator code, and collude 1-1 with each validator (no flashbots on Polygon, yet) then the attack is increasingly more complex.
The attack is reliant on the externalities of the validator + somebody incentivized enough to exploit this.
I agree with he finding and believe after stabilize the system should auto-update the prices Because of the external requirements am downgrading to medium severity
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the protocol reads price and reserve averages from MaltDataLab without forcing an update in the same transaction, so the values can be stale and the updater's transactions can be censored.
Impact
A user could repeatedly collect the 100 Malt auction incentive and threaten protocol stability, but the judge notes the attack needs validator collusion on Polygon and is therefore more complex.
What the attacker needed
Malt price above the lower bound; stability window override satisfied; collusion with a miner to censor updates; incentive exceeds updater gas cost
The fix
The protocol should call trackMaltPrice, trackPoolReserves and trackPool wherever those values are used, and MaltDataLab should use cumulative price updates rather than spot price data points.
How it was found
- The price of Malt exceeds the lower bound threshold so stabilize can be called by any user.
- The stability window override condition is satisfied and the function executes.
- The exchangeRate state variable queries maltPriceAverage, which may use an outdated exchange rate.
- The startAuction function runs and rewards the caller with 100 Malt.
- The attacker colludes with a miner to censor further pool updates and calls stabilize again on each fastAveragePeriod interval.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some smart contracts store prices that a separate account has to refresh by sending a transaction. If that refresh transaction is delayed or blocked, the contract keeps using old prices. Here, someone could keep triggering a reward-paying action while making sure the price refresh never happens, so they collect the reward repeatedly.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.