Incorrect timestamp updating for invalid plots due to USD price fluctuation #37
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-76
🤖_60_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-munchables/blob/main/src/managers/LandManager.sol#L258-L282
https://github.com/code-423n4/2024-07-munchables/blob/main/src/managers/LockManager.sol#L484-L492
https://github.com/code-423n4/2024-07-munchables/blob/main/src/managers/LockManager.sol#L523-L524
Vulnerability details
Description
Varying by USD price of the locked tokens proposed by oracle can make the Plot smaller and dirty, but the landlord's
plotMetadata.timestamp
does not update when the price changes.As the
_getNumPlots()
can vary due to two factors:lock size
(landlord) andUSD price
of the locked token (proposed by a trusted oracle), the USD price could lower the return oflockManager::getLockedWeightedValue()
for the same lock amount.As a result of not updating the landlord's
plotMetadata.timestamp
when the USD price changes, theplotMetadata.timestamp
that reflects the timestamp for when the plots become dirty is incorrect. This causes the user to unfairly gain schnibbles form an incorrect time tracking.Impact
Users gain schnibbles based on an incorrect time period due to outdated timestamps, leading to potential unfair.
Severity Clarification Aspects:
Likelihood: Can be considered
Medium
orHigh
since the tokens that can be locked may have fluctuations in USD price. Although the locked assets listed on-chain includeUSDB
(a stablecoin), they also allow fluctuating assets likeWETH
,BLAST
, so price fluctuation is a concern.Impact: Can be considered
High
. The issue significantly impacts users by leading to incorrect schnibbles calculations and unfair rewards.Proof of Concept
For the
tokenId
that stakes on the last available plotId of the landlord, this issue could potentially occur.Revert on Farming due to Underflow in Use Lesser Timestamp
Landlord has 10 plots available. =>
plotMetadata.lastUpdated: block 9
.User stakes at
plot 9
(the maximum available plotId).User farms to gain schnibbles and pays tax to the landlord as expected. =>
lastToilDate: block 19
.Assuming the proposed USD price change occurs at
block 30
, and the USD price in theLockManager
has decreased. The landlord still locks 10 plots and does not perform any activity to update theirplotMetadata
.User attempts to farm again, but
_getNumPlots()
returns a smaller value, causing thattokenId
to become dirty.timestamp: plotMetadata.lastUpdated = block 9
.schnibblesTotal = (timestamp(block 9) - lastToilDate (block 19)) * BASE_SCHNIBBLE_RATE
.Not Revert but Only Use Lesser Timestamp for Calculation
Landlord has 10 plots available. =>
plotMetadata.lastUpdated: block 9
.User stakes at plot 9 (the maximum available plotId).
User farms to gain schnibbles and pays tax to the landlord as expected. =>
lastToilDate: block 19
.Landlord calls
LockManager::setLockDuration
atblock 20
(without changing any lock amount). =>plotMetadata.lastUpdated: block 20
.Assuming the proposed USD price change occurs at
block 30
, and the USD price in theLockManager
has decreased. The landlord still locks 10 plots and does not perform any activity to update theirplotMetadata
.User attempts to farm again, but
_getNumPlots()
returns a smaller value, causing thattokenId
to become dirty.timestamp: plotMetadata.lastUpdated = block 20
.schnibblesTotal = (timestamp(block 20) - lastToilDate (block 19)) * BASE_SCHNIBBLE_RATE
.In both cases, the invalid plot seems to use the wrong
timestamp
retrieved fromplotMetadata.lastUpdated
, which should actually reflect the action that made them invalid.Tools Used
Recommended Mitigation Steps
Update
plotMetadata.lastUpdated
whenever there is a change in the USD price that impacts the number of plots (numPlots
). This ensures that the timestamp reflects the correct state of the plots.However, since the
LockManager
is already deployed, handling the configuration off-chain might be required. To propose the price, it requires an actor that holds thePriceFeed
Role. When the new price is applied, they should update the related landlord.Currently, there are three tokens available for locking, and the number of plots is retrieved from three different quantities of locked tokens, depending on each landlord. When updating the landlord's
plotMetadata
, ensure that the token price updates are related to the landlord's locked tokens that is used in calculated the number of plots.Assessed type
Context
The text was updated successfully, but these errors were encountered: