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

Landlords who locked tokens before LandManager deployment have uninitialized plotMetadata, so renters stake at 0% tax and farm untaxed until metadata is triggered.

- Payout: Audit contest
- Severity: medium
- Program: Munchables
- Found by: merlinboii
- Disclosed: 2024-08-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-munchables-findings/issues/30
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-munchables%3AM-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:legacy-endpoint technique:source-review vuln:accounting-error vuln:business-logic vuln:fee-bypass

**Target:** LandManager.stakeMunchable / _farmPlots tax accounting
**Root cause:** stakeMunchable does not verify plotMetadata[landlord] is initialized; toilerState.latestTaxRate is snapshotted as 0 and used for tax at harvest even after landlord updates rate.
**Steps:**
1. Landlord locks tokens in LockManager before LandManager deployment, so plotMetadata[landlord].lastUpdated == 0.
2. Renter calls `stakeMunchable(landlord, tokenId, plotId)`; toilerState.latestTaxRate = plotMetadata[landlord].currentTaxRate = 0.
3. Landlord later calls triggerPlotMetadata/updatePlotMetadata setting DEFAULT_TAX_RATE.
4. Renter calls harvest; `_farmPlots` computes schnibblesLandlord = schnibblesTotal * _toiler.latestTaxRate / 1e18 = 0, renter keeps full schnibblesTotal.
5. Only after this harvest does toilerState.latestTaxRate refresh to the new rate.
**How found:** Code reading of stakeMunchable noting no check on plotMetadata initialization, combined with on-chain observation that LockManager was live 55 days before LandManager with >$1M locked, and that the deployed AccountManager.forceHarvest does not call landManager.updatePlotMetadata.
**Exploitation:** Attacker stakes MunchNFTs onto plots of landlords whose metadata was never initialized (pre-deployment lockers), then farms schnibbles paying zero tax to the landlord for the entire accrual window until first harvest after rate update.
**Insight:** When a new accounting module is deployed against an already-live state contract, check whether pre-existing state entries get lazily initialized; snapshot values (like tax rate) taken at stake time can bypass later updates until the next harvest.

## Proof of concept (copied exactly from the original report)

**PoC steps: Alice stakes on Bob's uninitialized land**

```
1. **`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,
```

**PoC: Bob updates plotMetadata at block-12**

```
2. **`block-12`**: Bob triggers an update to his `plotMetadata`.

    plotMetadata[Bob Account] = PlotMetadata({
            lastUpdated: block-12,
            currentTaxRate: DEFAULT_TAX_RATE
        });
```

**PoC: Alice farms at block-31 paying zero tax**

```
3. **`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.
```

