Skip to content

feat: audit fixes - #225

Merged
dDevAhmed merged 1 commit into
DigiNodes:mainfrom
Mkalbani:feat/audit-fixes-180-184-185-186
May 30, 2026
Merged

feat: audit fixes #225
dDevAhmed merged 1 commit into
DigiNodes:mainfrom
Mkalbani:feat/audit-fixes-180-184-185-186

Conversation

@Mkalbani

Copy link
Copy Markdown
Contributor

#180 - Cap unbounded loops in createSnapshot

  • Replace constant MAX_SNAPSHOT_SIZE with configurable maxSnapshotSize (default 200)
  • Add setMaxSnapshotSize() admin function with ABSOLUTE_MAX_SNAPSHOT_SIZE (1000) hard cap

#184 - Add sqrt implementation on-chain (WeightedStaking)

  • Add Babylonian _sqrt() for 18-decimal fixed-point numbers
  • Enable useSqrtWeighting flag (default true) to match API behaviour
  • Add setSqrtWeighting() governance toggle

#185 - Prevent slashCooldown bypass via same-block slashing

  • Add lastSlashBlock mapping tracking last slash block per verifier
  • Revert with SlashSameBlock if verifier already slashed in current block
  • Applied to slash(), _slashInternal(), and criticalSlash()

#186 - Allow 100% slash for critical failures

  • Add CRITICAL_SLASHER_ROLE with grantCriticalSlasherRole()/revokeCriticalSlasherRole()
  • Add criticalSlash() that bypasses maxSlashPercentage (up to MAX_SLASH_PERCENTAGE=100)
  • Still respects same-block protection

Tests: 22 new tests in test/AuditFixes.test.ts, 0 regressions in existing suites.
closes #180
closes #184
closes #185
closes #186

…#186

DigiNodes#180 - Cap unbounded loops in createSnapshot
  - Replace constant MAX_SNAPSHOT_SIZE with configurable maxSnapshotSize (default 200)
  - Add setMaxSnapshotSize() admin function with ABSOLUTE_MAX_SNAPSHOT_SIZE (1000) hard cap

DigiNodes#184 - Add sqrt implementation on-chain (WeightedStaking)
  - Add Babylonian _sqrt() for 18-decimal fixed-point numbers
  - Enable useSqrtWeighting flag (default true) to match API behaviour
  - Add setSqrtWeighting() governance toggle

DigiNodes#185 - Prevent slashCooldown bypass via same-block slashing
  - Add lastSlashBlock mapping tracking last slash block per verifier
  - Revert with SlashSameBlock if verifier already slashed in current block
  - Applied to slash(), _slashInternal(), and criticalSlash()

DigiNodes#186 - Allow 100% slash for critical failures
  - Add CRITICAL_SLASHER_ROLE with grantCriticalSlasherRole()/revokeCriticalSlasherRole()
  - Add criticalSlash() that bypasses maxSlashPercentage (up to MAX_SLASH_PERCENTAGE=100)
  - Still respects same-block protection

Tests: 22 new tests in test/AuditFixes.test.ts, 0 regressions in existing suites.
@dDevAhmed
dDevAhmed merged commit f2c7ca9 into DigiNodes:main May 30, 2026
5 of 8 checks passed
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.

maxSlashPercentage too restrictive slashCooldown bypass Missing sqrt implementation on-chain Unbounded loops in createSnapshot

2 participants