Skip to content

[PERF] Refactor Classic ReentrancyGuard to Transient-Ready Boolean Flags #652

Description

@mijinummi

Labels: good-first-issue, solidity, gas-saving, gasguard
Difficulty: Easy
Module: contracts/security/


🧠 Concept

Update standard boolean status flags (uint256 private _status) in local reentrancy guards to use uint256 values $1$ and $2$ instead of $0$ and $1$.

⚠️ Problem

Setting a storage slot from $0$ to $1$ incurs a cold-write cost ($20,000\text{ gas}$), whereas changing from $1$ to $2$ operates on a warm slot ($2,900\text{ gas}$).

📁 Implementation Scope

  • contracts/security/GasOptimizedReentrancyGuard.sol
  • test/security/GasOptimizedReentrancyGuard.test.ts

🛠️ Requirements

  1. Define uint256 private constant _NOT_ENTERED = 1; and uint256 private constant _ENTERED = 2;.
  2. Initialize _status = _NOT_ENTERED in constructor / declaration.

🎯 Acceptance Criteria

  • Execution costs for protected endpoints decrease significantly after deployment.
  • Unit tests verify reentrancy protection remains fully functional.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions