Skip to content

feat: protect against reentrancy attacks in smart contracts#421

Open
od-hunter wants to merge 1 commit into
Smartdevs17:mainfrom
od-hunter:feat/reentrancy-protection
Open

feat: protect against reentrancy attacks in smart contracts#421
od-hunter wants to merge 1 commit into
Smartdevs17:mainfrom
od-hunter:feat/reentrancy-protection

Conversation

@od-hunter
Copy link
Copy Markdown
Contributor

@od-hunter od-hunter commented May 28, 2026

Closes #397


#397

- Add reentrancy latch (_acquire_lock/_release_lock) to all mutative
  functions in contracts/src/lib.rs: create_project, batch_create_projects,
  fund_project, submit_work, approve_work, raise_dispute, resolve_dispute,
  check_deadline, set_metadata, remove_metadata, pause, unpause

- Enforce checks-effects-interactions (CEI) pattern across all functions:
  deposited is zeroed and status committed to storage before any event
  emission or token transfer interaction in approve_work, resolve_dispute,
  and check_deadline

- Add emergency circuit breaker: pause(admin) / unpause(admin) / is_paused()
  backed by DataKey::Paused; all mutative functions call _require_not_paused
  first; upgrade intentionally exempt so security patches can deploy while paused

- Add nonReentrant modifier to BatchSplitter.batchTransfer (was the only
  EVM contract missing a reentrancy guard)

- Add cross-contract reentrancy protection via shared latch that blocks
  all mutative entry points simultaneously

- Add fuzz and invariant tests in contracts/test/foundry/ReentrancyFuzz.t.sol
  covering: direct reentrancy, cross-function reentrancy, read-only reentrancy,
  constructor reentrancy, BatchSplitter guard, forwarder nonce replay,
  balance invariant, no-double-payment, over-withdraw prevention

- Add formal verification spec contracts/certora/specs/ReentrancySafety.spec
  with 10 rules: latch zero at entry/exit, latch released on revert,
  no direct/cross-function reentrancy, balance bounds, only-owner withdraw,
  platformFeeBps bounded

- Expand contracts/src/security_properties.rs with 14 new proptest properties
  covering latch mutual-exclusion, read-only reentrancy, cross-function
  reentrancy, constructor reentrancy, CEI invariants, circuit-breaker
  state machine

All 39 Rust tests pass. Solidity files compile clean.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@od-hunter is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@od-hunter Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Protect against reentrancy attacks in smart contracts

1 participant