fix: aderyn static analysis for contracts#1542
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughThis PR pins Solidity version to 0.8.28 across all contracts, adds comprehensive state-change events for observability throughout interfaces and implementations, introduces a ChangesSolidity 0.8.28 Compiler Pinning and State Change Events
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/enclave-contracts/contracts/Enclave.sol`:
- Around line 252-253: The max-duration guard currently uses
require(totalDuration < maxDuration, InvalidDuration(totalDuration)) which
rejects requests equal to maxDuration; update the check in Enclave.sol to allow
durations up to and including maxDuration by changing the condition to use <=
for totalDuration (keep the same InvalidDuration error payload).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 26a98783-11b2-4bb6-97a0-4839754aa72b
📒 Files selected for processing (35)
packages/enclave-contracts/artifacts/contracts/Enclave.sol/Enclave.jsonpackages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.jsonpackages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.jsonpackages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.jsonpackages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.jsonpackages/enclave-contracts/artifacts/contracts/registry/CiphernodeRegistryOwnable.sol/CiphernodeRegistryOwnable.jsonpackages/enclave-contracts/artifacts/contracts/token/EnclaveTicketToken.sol/EnclaveTicketToken.jsonpackages/enclave-contracts/contracts/E3RefundManager.solpackages/enclave-contracts/contracts/Enclave.solpackages/enclave-contracts/contracts/interfaces/IBondingRegistry.solpackages/enclave-contracts/contracts/interfaces/ICiphernodeRegistry.solpackages/enclave-contracts/contracts/interfaces/ICircuitVerifier.solpackages/enclave-contracts/contracts/interfaces/IComputeProvider.solpackages/enclave-contracts/contracts/interfaces/IDecryptionVerifier.solpackages/enclave-contracts/contracts/interfaces/IE3.solpackages/enclave-contracts/contracts/interfaces/IE3Program.solpackages/enclave-contracts/contracts/interfaces/IE3RefundManager.solpackages/enclave-contracts/contracts/interfaces/IEnclave.solpackages/enclave-contracts/contracts/interfaces/IPkVerifier.solpackages/enclave-contracts/contracts/interfaces/ISlashingManager.solpackages/enclave-contracts/contracts/lib/ExitQueueLib.solpackages/enclave-contracts/contracts/registry/BondingRegistry.solpackages/enclave-contracts/contracts/registry/CiphernodeRegistryOwnable.solpackages/enclave-contracts/contracts/slashing/SlashingManager.solpackages/enclave-contracts/contracts/test/MockCiphernodeRegistry.solpackages/enclave-contracts/contracts/test/MockComputeProvider.solpackages/enclave-contracts/contracts/test/MockDecryptionVerifier.solpackages/enclave-contracts/contracts/test/MockE3Program.solpackages/enclave-contracts/contracts/test/MockPkVerifier.solpackages/enclave-contracts/contracts/test/MockSlashingVerifier.solpackages/enclave-contracts/contracts/test/MockStableToken.solpackages/enclave-contracts/contracts/token/EnclaveTicketToken.solpackages/enclave-contracts/contracts/token/EnclaveToken.solpackages/enclave-contracts/contracts/verifiers/bfv/BfvDecryptionVerifier.solpackages/enclave-contracts/contracts/verifiers/bfv/BfvPkVerifier.sol
close #1541
Summary
Fixes actionable findings from the Aderyn static analysis over all 30 Solidity
contracts (8,985 nSLOC). Builds clean, lints clean, all 234 tests pass.
Fixed Issues
🔴 H-1 — Reentrancy: State change after external call (17 instances)
Fix: Restructured
Enclave.request()to follow checks-effects-interactions.Moved
e3s[e3Id] = e3beforeciphernodeRegistry.requestCommittee(), andfeeToken.safeTransferFrom()to after all validations and state writes.Remaining 16 instances are in OZ
initializer-guarded functions or trusted viewcalls (
enclave.getRequester(),bondingRegistry.numActiveOperators()) wherereentrancy is not exploitable.
🔴 H-3 — Weak Randomness (1 instance)
Fix: Added documentation comment at
Enclave.solexplaining thatblock.prevrandaois combined with the unique, incrementinge3Idforsortition seeding only — not for cryptographic key generation.
🟡 L-5 — Large Numeric Literal (14 instances)
Fix: Replaced all raw
10000withBPS_BASEconstant inE3RefundManager.solacrosscalculateRefund,calculateWorkValue,distributeSlashedFundsOnSuccess, andsetWorkAllocation.🟡 L-6 — Literal Instead of Constant (71 instances)
Fix: Added
uint16 internal constant BPS_BASE = 10000toE3RefundManager.sol.Enclave.solandBondingRegistry.solalready had thisconstant. Verifier hex literals are auto-generated and left as-is.
🟡 L-7 — Local Variable Shadows State Variable (1 instance)
Fix: Renamed constructor parameter
_owner→initialOwner_inEnclaveToken.solto stop shadowing OpenZeppelin'sOwnable._owner.🟡 L-10 — Redundant Statement (1 instance)
Fix: Removed bare
data;expression statement inMockE3Program.verify().Replaced with a descriptive comment.
🟡 L-12 — State Change Without Event (21 instances)
Fix: Added events to 12 setter functions across 6 contracts that previously
mutated state without emitting:
EnclavePkVerifierSetE3RefundManagerEnclaveSet,TreasurySetBondingRegistryTicketTokenSet,LicenseTokenSet,RegistrySet,SlashingManagerSet,SlashedFundsTreasurySetSlashingManagerBondingRegistrySet,CiphernodeRegistrySet,EnclaveSet,E3RefundManagerSetCiphernodeRegistryOwnableSlashingManagerSetEnclaveTicketTokenRegistrySet,PayoutCorresponding event declarations added to
IEnclave,IE3RefundManager,IBondingRegistry,ISlashingManager, andCiphernodeRegistryOwnable.🟡 L-14 — State Variable Could Be Immutable (1 instance)
Fix: Changed
uint8 private _decimals→uint8 private immutable _decimalsin
MockStableToken.sol.🟡 L-15 — Contract has TODO Comments (2 instances)
Fix: Converted 3 TODO markers to proper NatSpec documentation in
Enclave.solandCiphernodeRegistryOwnable.sol.🟡 L-18 — Unspecific Solidity Pragma (27 instances)
Fix: Pinned all 28
.solfiles from>=0.8.27/^0.8.27topragma solidity 0.8.28;matching the hardhat compiler config.Not Fixed (by design / won't fix)
initialize()with deferred zero-address config_grantRole/_revokeRolerevert internally on failurepublicneeded for internal calls frominitialize()and other pathsSummary by CodeRabbit
Release Notes
New Features
Bug Fixes
Chores