Skip to content
Business logic Audit finding Intermediate

Users can farm on zero-tax land if the landlord locked tokens before the LandManager deployment

merlinboii Follow with Abdessamed, dontonka and 11 others

Originally disclosed on Code4rena

Submitted by merlinboii, also found by Abdessamed, dontonka, araj, Utsav, MrPotatoMagic, dhank, prapandey031, DemoreX, santipu_, 0xCiphky, 0xrex, ke1caM, and dimulski

The LandManager::stakeMunchable() does not verify whether the plotMetadata[landlord] is set or not.

Since the LockManager contract is already deployed on-chain (0xEA091311Fc07139d753A6BBfcA27aB0224854Bae (Blast)), accounts that have locked their tokens before the LandManager deployment will need to trigger LandManager::triggerPlotMetadata() to update their LandManager.plotMetadata after the LandManager is deployed.

The current AccountManager interacts with the LockManager on-chain but does not introduce interaction with the LandManager during AccountManager::forceHarvest().

As a result, users can stake their tokens on land with a 0% tax rate if the landlord has not updated their plotMetadata and farm schnibbles without paying tax to the landlord until the landlord’s plot metadata is initialized in the LandManager contract (via triggerPlotMetadata() and updatePlotMetadata()).

File: src/managers/LandManager.sol

131:     function stakeMunchable(
132:         address landlord,
133:         uint256 tokenId,
134:         uint256 plotId
135:     ) external override forceFarmPlots(msg.sender) notPaused {
136:         (address mainAccount, ) = _getMainAccountRequireRegistered(msg.sender);
137:         if (landlord == mainAccount) revert CantStakeToSelfError();
138:         if (plotOccupied[landlord][plotId].occupied)
139:             revert OccupiedPlotError(landlord, plotId);
140:         if (munchablesStaked[mainAccount].length > 10)
141:             revert TooManyStakedMunchiesError();
142:         if (munchNFT.ownerOf(tokenId) != mainAccount)
143:             revert InvalidOwnerError();
144:
145:         uint256 totalPlotsAvail = _getNumPlots(landlord);
146:         if (plotId >= totalPlotsAvail) revert PlotTooHighError();
147:
148:         if (
149:             !munchNFT.isApprovedForAll(mainAccount, address(this)) &&
150:             munchNFT.getApproved(tokenId) != address(this)
151:         ) revert NotApprovedError();
152:         munchNFT.transferFrom(mainAccount, address(this), tokenId);
153:
154:         plotOccupied[landlord][plotId] = Plot({
155:             occupied: true,
156:             tokenId: tokenId
157:         });
158:
159:         munchablesStaked[mainAccount].push(tokenId);
160:         munchableOwner[tokenId] = mainAccount;
161:
162:         toilerState[tokenId] = ToilerState({
163:             lastToilDate: block.timestamp,
164:             plotId: plotId,
165:             landlord: landlord,
166:@>           latestTaxRate: plotMetadata[landlord].currentTaxRate,
167:             dirty: false
168:         });
169:
170:         emit FarmPlotTaken(toilerState[tokenId], tokenId);
171:     }
File: src/managers/LandManager.sol

232:     function _farmPlots(address _sender) internal {
233:         (
234:             address mainAccount,
235:             MunchablesCommonLib.Player memory renterMetadata
236:         ) = _getMainAccountRequireRegistered(_sender);
237:
                --- SNIPPED ---

247:         for (uint8 i = 0; i < staked.length; i++) {
                --- SNIPPED ---

280:             schnibblesTotal =
281:                 (timestamp - _toiler.lastToilDate) *
282:                 BASE_SCHNIBBLE_RATE;
283:             schnibblesTotal = uint256(
284:                 (int256(schnibblesTotal) +
285:                     (int256(schnibblesTotal) * finalBonus)) / 100
286:             );
287:             schnibblesLandlord =
288:@>           (schnibblesTotal * _toiler.latestTaxRate) / //@audit _toiler.latestTaxRate will be 0
289:                 1e18;
290:
291:             toilerState[tokenId].lastToilDate = timestamp;
292:@>           toilerState[tokenId].latestTaxRate = plotMetadata[_toiler.landlord]    //@audit update toilerState's latestTaxRate
293:                 .currentTaxRate;
294:
295:@>          renterMetadata.unfedSchnibbles += (schnibblesTotal -
296:                 schnibblesLandlord);
297:
298:             landlordMetadata.unfedSchnibbles += schnibblesLandlord;
299:             landlordMetadata.lastPetMunchable = uint32(timestamp);
300:             accountManager.updatePlayer(landlord, landlordMetadata);
301:             emit FarmedSchnibbles(
302:                 _toiler.landlord,
303:                 tokenId,
304:                 _toiler.plotId,
305:                 schnibblesTotal - schnibblesLandlord,
306:                 schnibblesLandlord
307:             );
308:         }
309:@>       accountManager.updatePlayer(mainAccount, renterMetadata);
310:     }

Impact

Users can farm schnibbles on plots with a 0% tax rate without paying any tax to the landlord, which disrupts the platform’s revenue model and incentives.

Severity Clarification Aspects

  • Likelihood: Can be considered Medium as there are many accounts that have locked tokens in the LandManager. This is evident from the fact that it was deployed over 55 days ago and the locked tokens are worth more than $1 million (On-chain: LandManager).
  • Impact: Can be considered Medium as it does not directly affect the landlord’s assets but results in a loss of benefits for landlords. Renters can exploit the issue by paying no tax on farming if the landlord’s tax rate is not updated. Although landlords can eventually update their rates, renters can continue farming at the previous 0% tax rate until they farm again after the update.

Proof of Concept

Prerequisites:

  • Bob has locked tokens at the LockManager, with enough tokens for 10 plots.
  • The AccountManager contract is upgraded to support the LandManager when forceHarvest() is called.
  • The LandManager is deployed at block-10.
  • block-11: Alice stakes her MunchNFT on Bob’s land with a 0% tax rate, as Bob has not triggered LandManager::triggerPlotMetadata() or interacted with the LockManager to trigger forceHarvest() after the LandManager deployment.
    toilerState[Alice's tokenId: 10] = ToilerState({
            lastToilDate: `block-11`,
            plotId: 0,
            landlord: Bob Account,
            latestTaxRate: plotMetadata[landlord].currentTaxRate => 0,
            dirty: false
        });
  1. block-12: Bob triggers an update to his plotMetadata.
    plotMetadata[Bob Account] = PlotMetadata({
            lastUpdated: block-12,
            currentTaxRate: DEFAULT_TAX_RATE
        });

This currentTaxRate will not apply to Alice’s toilerState until Alice farms.

  1. block-31: Alice farms.

During the schnibblesLandlord calculation, Alice’s _toiler.latestTaxRate (which was 0) will be used, even though Bob updated the currentTaxRate at block-12.

File: src/managers/LandManager.sol

232:     function _farmPlots(address _sender) internal {
233:         (
234:             address mainAccount,
235:             MunchablesCommonLib.Player memory renterMetadata
236:         ) = _getMainAccountRequireRegistered(_sender);
237:
                --- SNIPPED ---

247:         for (uint8 i = 0; i < staked.length; i++) {
                --- SNIPPED ---

280:@>           schnibblesTotal =
281:               (timestamp - _toiler.lastToilDate) *   //@audit `block-31` - `block-11`
282:                 BASE_SCHNIBBLE_RATE;
283:             schnibblesTotal = uint256(
284:                 (int256(schnibblesTotal) +
285:                     (int256(schnibblesTotal) * finalBonus)) / 100
286:             );
287:             schnibblesLandlord =
288:@>           (schnibblesTotal * _toiler.latestTaxRate) / //@audit _toiler.latestTaxRate will be 0
289:                 1e18;
290:
291:             toilerState[tokenId].lastToilDate = timestamp;
292:@>           toilerState[tokenId].latestTaxRate = plotMetadata[_toiler.landlord]    //@audit update toilerState's latestTaxRate
293:                 .currentTaxRate;
294:
295:@>          renterMetadata.unfedSchnibbles += (schnibblesTotal -
296:                 schnibblesLandlord);
297:
298:             landlordMetadata.unfedSchnibbles += schnibblesLandlord;
299:             landlordMetadata.lastPetMunchable = uint32(timestamp);
300:             accountManager.updatePlayer(landlord, landlordMetadata);
301:             emit FarmedSchnibbles(
302:                 _toiler.landlord,
303:                 tokenId,
304:                 _toiler.plotId,
305:                 schnibblesTotal - schnibblesLandlord,
306:                 schnibblesLandlord
307:             );
308:         }
309:@>       accountManager.updatePlayer(mainAccount, renterMetadata);
310:     }

Result: Alice benefits by retrieving the full schnibblesTotal from block-11 until block-31, even though Bob updated his plotMetadata immediately after Alice staked.

Recommended Mitigation Steps

Apply unset plotMetadata.currentTaxRate checks in the LandManager::stakeMunchable():

File: src/managers/LandManager.sol

131:     function stakeMunchable(
132:         address landlord,
133:         uint256 tokenId,
134:         uint256 plotId
135:     ) external override forceFarmPlots(msg.sender) notPaused {
136:         (address mainAccount, ) = _getMainAccountRequireRegistered(msg.sender);
137:         if (landlord == mainAccount) revert CantStakeToSelfError();
+138:        if (plotMetadata[landlord].lastUpdated == 0)
+139              revert PlotMetadataNotUpdatedError();
            --- SNIPPED ---
171:     }

Assessed type

Invalid Validation

0xsomeone (judge) commented:

As with other tax-related submissions, I do not consider edge conditions around tax configurations to be valid submissions in line with the validator’s assessment.

merlinboii (warden) commented:

@0xsomeone - I agree with this statement in validation-289, which misses out on the crucial point of the issue. I also agree with the other duplicates.

To specify further from the validator’s comment in the CSV:

While Landlords’ first locking of funds, updatePlotMetadata() will be called to init tax rate, please refer to L154 and L341; otherwise, there will be no valid plots to stake due to zero value locked.

The validator pointed out that the code at AccountManager.sol#L154 updates the plotMetadata right away when AccountManager.forceHarvest() is triggered, which is incorrect.

Noted that the all deployment addresses are listed in deployment-2024-06-01T21-33-57.416Z.json

The LockManager is currently live here and has stakers (or landlords in terms of the LandManager) who locked their tokens before the LandManager was deployed.

The oversight is that the current version of the AccountManager in the audit repository is not the one being used on-chain. Instead, it is an upgraded version prepared for use once the LandManager goes live.

This can be proven by accessing the live AccountManager contract here:

Below is the actual code currently used for the LockManager that has not integrated with LandManager (that have not deployed):

function forceHarvest(
    address _player
)
    external
    onlyConfiguredContract2(
        StorageKey.LockManager,
        StorageKey.MunchadexManager
    )
{
    (, MunchablesCommonLib.Player memory player) = this.getPlayer(_player);
    if (player.registrationDate != 0) {
        _harvest(_player);
        if (
            msg.sender == configStorage.getAddress(StorageKey.LockManager)
        ) {
@>          //landManager.updatePlotMetadata(_player);
        }
    }
}

This on-chain contract can prove that there is a significant amount of tokens locked and stakers in the LockManager before the introduction of the LandManager, allowing them to become landlords.

Malicious actors can stake to the non-triggered metadata landlord who has staked in the LockManager so far, immediately after the LandManager is deployed and gain rewards without paying tax rates.

Even if the landlord sets their tax rate right after the staking occurs, stakers will farm on the current tax rate at the time they staked until they farm again (proof of concept provided in this issue).

Moreover, another proof that the missing update timestamp of the landlord can occur is the triggerPlotMetadata() that is truly intended for this case.

In conclusion, I believe this issue, including other duplicates, should be reconsidered as per the statement above. The severity is also clearly described in this report and others.

0xsomeone (judge) commented:

@merlinboii, after a closer re-examination of the vulnerability described, I believe that it represents a borderline Medium severity submission.

My initial train of thought was that a landlord can simply relock their tokens to a different account or transfer their lock which is impossible per the implementation, meaning that they cannot force users to re-stake and thus acquire the updated tax rate.

The maximum impact of the submission is a single reward claim at a 0% tax rate which we can argue can last until the end of the landlord’s lock time or the time the plot would become dirty due to a price decrease, so a medium severity is appropriate for this submission.

0xinsanity (Munchables) acknowledged and commented:

I would not consider this medium. If a user sees land that has zero tax, they just won’t go to it. We’re gonna make it extremely apparent in the UI what tax rates are at for a given farm. We’re also gonna run the landmanager deployer contract atomatically with the configstorage updates. At most that’s a low-risk.


The original report as published on Code4rena, by merlinboii. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A medium-severity business logic bug in Munchables. Code4rena made it public on 16 August 2024. Found in the 2024-07-munchables audit contest (finding M-01), also found by 13 other wardens.

About Business logic

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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.

More by merlinboii

View all

9 more disclosed reports, best first.

More from Munchables

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.