Skip to content

Conversation

@dmrdvn
Copy link

@dmrdvn dmrdvn commented Dec 26, 2025

Overview

This PR fixes a critical bug in the epoch reward calculation and adds comprehensive test coverage to improve contract security and reliability.

Changes

Contract Improvements

  • Fixed critical bug: Epoch reward calculation now correctly uses upperLookup() for each epoch
  • Custom error support: Converted require() statements to if + revert pattern
  • Gas optimization: Added unchecked blocks to 9 loops (~3 gas saved per iteration)
  • Code cleanup: Removed unused imports (Arrays, Math)
  • Version consistency: Updated Solidity version to 0.8.27

Test Enhancements

  • Added 18 new test cases covering:
    • Security (reentrancy protection, overflow/underflow)
    • Edge cases (epoch boundaries, zero balances)
    • Multi-user scenarios
    • Access control
  • Added gas benchmark suite for tracking optimization impact
  • Test coverage increased from 49 to 67 tests (+37%)

Gas Impact

  • stake(): -24 gas (-0.007%)
  • unstake(): -32 gas (-0.017%)
  • withdrawReward(30 epochs): -90 gas (-0.017%)

Testing

All 67 tests passing ✅

- fix critical bug in reward calculation using upperLookup correctly
- convert require statements to if+revert for custom error support
- add unchecked blocks to loops for gas optimization (~3 gas per iteration)
- remove unused imports (Arrays, Math)
- update solidity version to 0.8.27 for consistency

gas improvements:
- stake: -24 gas (-0.007%)
- unstake: -32 gas (-0.017%)
- withdrawReward(30 epochs): -90 gas (-0.017%)
- add 18 new test cases covering security, edge cases, and multi-user scenarios
- add reentrancy protection tests
- add maximum value handling tests
- add gas benchmark suite for tracking optimization impact
- test coverage increased from 49 to 67 tests (+37%)

all tests passing
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.

1 participant