refactor: Replace inline auth checks with named modifiers (gas optimisation)#247
Conversation
…ings
Two inline ownership/access-control checks were duplicated as ad-hoc
if-revert blocks inside function bodies. This pattern:
1. Costs slightly more gas than a modifier because it runs after other
function body setup (stack frame already allocated).
2. Obscures the access-control intent from the function signature.
Changes:
- Election.sol: add onlyFactory modifier; apply to ccipVote() replacing
the inline check. This also moves auth to modifier position (before
the function body), which is the Solidity convention and fails faster.
- ElectionFactory.sol: add onlyElectionOwner(uint) modifier; apply to
deleteElection() replacing the inline check. The parameterised modifier
pattern follows the existing onlyOwner() in the same contract.
Closes AOSSIE-Org#231
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Replaces two ad-hoc inline
if (...) revertownership checks inside function bodies with dedicated named modifiers, reducing gas and improving code clarity.Closes #231
Problem
Two contracts contained inline access-control checks embedded in function bodies instead of using modifiers:
Election.sol—ccipVote()ElectionFactory.sol—deleteElection()Issues with this pattern:
Fix
Election.sol— addedonlyFactorymodifier, applied toccipVote():ElectionFactory.sol— added parameterisedonlyElectionOwner(uint)modifier, applied todeleteElection():Both patterns follow the conventions already established in their respective contracts (
onlyOwnerinElection.sol,onlyOwnerinElectionFactory.sol).Files Changed
blockchain/contracts/Election.solonlyFactorymodifier; applied toccipVote()blockchain/contracts/ElectionFactory.solonlyElectionOwner(uint)modifier; applied todeleteElection()Checklist
ccipVotemodifier order (electionInactivebeforeonlyFactory) is intentional — time-gate first, then authupstream/main