Skip to content

Conversation

@zZoMROT
Copy link
Contributor

@zZoMROT zZoMROT commented Jul 4, 2025

What Was Wrong

In FarmAccounting.startFarming(...), when starting a new farming period before the previous one ends, the leftover from the previous reward is added to amount. Then, the full amount (which now includes the leftover) is added to info.balance:

The Problem

info.balance should reflect only the actual tokens transferred to the contract via safeTransferFrom in startFarming.
However, leftover was already on the contract and previously accounted for in the last reward.

As a result:

  • info.balance becomes inflated, it includes both the newly transferred amount and already existing leftover
  • an inconsistency arises between internal accounting (info.balance) and the actual token balance of the contract

Why It Matters

  • rescueFunds() may allow withdrawal of “excess” tokens that are still needed for payouts
  • claim() may unexpectedly revert if the inflated balance doesn’t match the actual token balance

What Was Fixed

Now, info.balance is increased only by the amount passed to startFarming, which matches the actual safeTransferFrom.
The leftover is still used to increase reward, but it’s no longer double-counted in the internal balance

@codecov
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.40%. Comparing base (4579b9b) to head (e347f13).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #94      +/-   ##
==========================================
+ Coverage   92.36%   92.40%   +0.03%     
==========================================
  Files           7        7              
  Lines         249      250       +1     
  Branches       60       60              
==========================================
+ Hits          230      231       +1     
  Misses         19       19              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@k06a
Copy link
Member

k06a commented Sep 11, 2025

But this was desired behavior, why do you think it should be fixed?

This balance is being used exclusively in rescueFunds() which lets distributor to withdraw some rewards - that's bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants