Skip to content

perf: decommission() O(N²) → O(N) by batching member transfers#147

Open
Tranquil-Flow wants to merge 1 commit into
devfrom
perf/decommission-gas-optimization
Open

perf: decommission() O(N²) → O(N) by batching member transfers#147
Tranquil-Flow wants to merge 1 commit into
devfrom
perf/decommission-gas-optimization

Conversation

@Tranquil-Flow
Copy link
Copy Markdown

Summary

Closes #120

decommission() previously made one safeTransfer call per member per unclaimed round — O(N²) external calls in the worst case. Each call costs ~20k gas overhead.

This refactors the refund loop to aggregate all owed amounts per depositor into a memory array, then executes a single transfer per member.

Changes

  • Accumulate refunds in a uint256[] memory array indexed by member position
  • Single safeTransfer per member after aggregation
  • Removed per-round SSTORE zeroing of roundDeposits (circle is deactivated, data is dead)

Test plan

  • forge test passes (140 tests)
  • Verify decommission refunds are correct with multi-round scenarios

Refactor decommission() to aggregate refunds per depositor across all
unclaimed rounds before executing transfers. Reduces external safeTransfer
calls from O(N²) worst case to at most N (one per member).

- Consolidate per-member refunds in memory before executing transfers
- Remove unnecessary SSTORE zeroing of roundDeposits
- Closes: #120
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.

Optimize decommission() refund logic to avoid gas blowups

1 participant