Skip to content

fix: prevent front-running attack in GenericHarvester - #15

Open
Joh077 wants to merge 19 commits into
devfrom
fix/harvester-vulnerability
Open

Joh077 wants to merge 19 commits into
devfrom
fix/harvester-vulnerability

Conversation

@Joh077

@Joh077 Joh077 commented Feb 6, 2026

Copy link
Copy Markdown
Collaborator
  • Add leftover token detection in harvest() to protect against router manipulation
  • Revert if router doesn't consume all tokens received from Parallelizer
  • Add RouterDidNotConsumeAllTokens custom error
  • Add tests

Fix compares token balance before receiving from Parallelizer and after router swap. Any leftover triggers revert, protecting user funds on flash loan

@Joh077
Joh077 changed the base branch from main to dev February 6, 2026 11:10
Comment thread tests/units/GenericHarvester.t.sol Resolved
Comment thread tests/units/GenericHarvester.t.sol Outdated
Comment on lines +114 to +116
/// @title GenericHarvester Front-Run Protection Tests
/// @notice Tests for the leftover token detection mechanism that protects against front-running attacks
contract Test_GenericHarvester_FrontRunProtection is Fixture {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to put FrontRunProctection in name, you can test the all contract here not just the FrontRunProctection

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to Test_GenericHarvesterfor units and Test_GenericHarvester_Integration for integrations

Comment thread tests/units/GenericRebalancer.t.sol Resolved
Comment thread tests/units/GenericHarvester.t.sol Resolved
Comment thread tests/units/GenericHarvester.t.sol Resolved
Joh077 and others added 6 commits February 10, 2026 17:39
…r, add tests, utils, split unit/integration (18+3 tests)
Prevents CI from resolving a newer OZ version where
__UUPSUpgradeable_init was removed, breaking the build.
@Joh077

Joh077 commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator Author

Update : fix vulnerability + test coverage

fix(GenericRebalancer): credit budget surplus when amountStableOut exceeds flashloan amount (missing else if)
test(GenericRebalancer): new unit tests (flash loan guards, increase direction, budget underflow) + integration (4 end-to-end scenarios)
fix: lint & ci issues

Comment thread contracts/helpers/GenericRebalancer.sol Outdated
uint256 amountOut =
parallelizer.swapExactInput(amount, 0, address(tokenP), tokenIn, address(this), block.timestamp);

// Swap to tokenIn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment: swap to tokenOut

Comment on lines +165 to +168
// Ensure router consumed all tokens
if (IERC20(tokenIn).balanceOf(address(this)) > tokenInBalanceBefore) {
revert RouterDidNotConsumeAllTokens();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will always revert in case of swapExactOutput with positive slippage

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.

2 participants