Skip to content

fix: add reentrancy guards and dust absorption to distribution (#85)#124

Open
RonTuretzky wants to merge 2 commits into
RonTuretzky/106-vote-with-datafrom
RonTuretzky/108-dust-reentrancy
Open

fix: add reentrancy guards and dust absorption to distribution (#85)#124
RonTuretzky wants to merge 2 commits into
RonTuretzky/106-vote-with-datafrom
RonTuretzky/108-dust-reentrancy

Conversation

@RonTuretzky
Copy link
Copy Markdown
Contributor

Summary

  • Add ReentrancyGuardUpgradeable to distribution contracts
  • Last recipient/strategy absorbs rounding remainder (up to N-1 wei)
  • Remove redundant strategy length check in MultiStrategyDistributionManager
  • 35 new tests covering dust absorption, reentrancy guards, and edge cases

Closes #85
Supersedes #108

Stack: PR 7 of 10 (0.0.2) — stacked on #123

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the distribution flow by adding upgradeable reentrancy guards to distribution managers/strategies and eliminating rounding “dust” by ensuring the full yield amount is always distributed (with the last recipient/strategy absorbing any remainder).

Changes:

  • Add ReentrancyGuardUpgradeable and apply nonReentrant to claimAndDistribute() (managers) and distribute() (strategies), with initializer wiring via __ReentrancyGuard_init().
  • Fix integer-division remainder handling so the last recipient/strategy absorbs rounding remainder instead of leaving tokens stranded.
  • Add a large test suite covering dust behavior and various distribution edge cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/DistributionStrategies.t.sol Adds tests and mocks for dust-absorption and (partially) reentrancy behavior across strategies/managers.
src/abstract/AbstractDistributionStrategy.sol Adds ReentrancyGuardUpgradeable inheritance and initializes it during strategy initialization.
src/implementation/strategies/EqualDistributionStrategy.sol Makes distribute() non-reentrant and ensures last recipient receives remainder.
src/implementation/strategies/VotingDistributionStrategy.sol Makes distribute() non-reentrant and ensures last recipient receives remainder.
src/base/MultiStrategyDistributionManager.sol Makes claimAndDistribute() non-reentrant and ensures last strategy receives remainder.
src/base/BaseDistributionManager.sol Makes claimAndDistribute() non-reentrant and initializes reentrancy guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +21
/// @dev Concrete strategies implement `distribute` to define how yield is allocated.
/// Inherits ReentrancyGuardUpgradeable to protect all distribute() implementations.
abstract contract AbstractDistributionStrategy is
Initializable,
IDistributionStrategy,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
Comment on lines +173 to +179
function burn(uint256 amount, address receiver) external override {
balanceOf[msg.sender] -= amount;
totalSupply -= amount;
emit Transfer(msg.sender, address(0), amount);
totalSupply += amount;
balanceOf[receiver] += amount;
emit Transfer(address(0), receiver, amount);
Comment thread test/DistributionStrategies.t.sol Outdated
Comment on lines +254 to +280
/// @dev Malicious strategy that attempts to re-enter claimAndDistribute during distribute()
contract ReentrantStrategy is IDistributionStrategy {
MultiStrategyDistributionManager public manager;
IERC20 public token;
bool public shouldReenter;

constructor(address _manager, address _token) {
manager = MultiStrategyDistributionManager(_manager);
token = IERC20(_token);
}

function setShouldReenter(bool _shouldReenter) external {
shouldReenter = _shouldReenter;
}

function distribute(uint256) external override {
if (shouldReenter) {
shouldReenter = false;
manager.claimAndDistribute();
}
}

function withdrawToken(address to, uint256 amount) external {
token.transfer(to, amount);
}
}

@RonTuretzky RonTuretzky force-pushed the RonTuretzky/106-vote-with-data branch from 1afcdfe to f51725e Compare April 16, 2026 01:28
- Add ReentrancyGuardUpgradeable to AbstractDistributionStrategy,
  BaseDistributionManager, and MultiStrategyDistributionManager
- Last recipient/strategy absorbs rounding remainder (up to N-1 wei)
- Remove redundant strategy length check in MultiStrategyDM
- Add 35 tests covering dust absorption, reentrancy, and edge cases
@RonTuretzky RonTuretzky force-pushed the RonTuretzky/108-dust-reentrancy branch from 8545c16 to 8f03b58 Compare April 16, 2026 01:28
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