Skip to content

Refactor: Update pnkPenalties incrementally to improve CEI pattern compliance #2094

@coderabbitai

Description

@coderabbitai

Description

A refactor suggestion was made to improve the Check-Effects-Interactions (CEI) pattern compliance in the penalty execution logic.

Currently, round.pnkPenalties is updated in a batch after external calls (unlock/penalize/setJurorInactive). While the modules are trusted, updating storage incrementally after each penalty reduces reliance on local cache across reentrant paths and ensures state consistency at all times.

Suggested Changes

Update the _executePenalties function to write round.pnkPenalties to storage immediately after each penalty calculation, rather than batching the update after external calls.

Files affected:

Specific changes:

  1. In _executePenalties, update round.pnkPenalties immediately after computing availablePenalty
  2. Adjust the execute function to handle the incremental updates appropriately

Benefits

  • Better CEI pattern compliance
  • Reduced reentrancy surface area
  • More consistent state across function calls
  • Defensive programming against future changes

References

Priority

Low - This is a defensive refactor for improved security patterns, but the current implementation works correctly with trusted modules.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions