Conversation
Cantina audit finding #7: _decreasePeData unconditionally reset lastUpdate on every decrease, penalizing partial unstakers by resetting their staking weight. Now lastUpdate is only reset when effectiveStake reaches zero. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cantina audit finding #8: transferOwnership now nominates a pending owner who must call acceptOwnership() to finalize the transfer, preventing irrevocable ownership loss from incorrect addresses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…edStaker Cantina audit finding #10: when a beneficiary removes a staker from their allowlist, the staker's lastUpdate is reset via _increasePeData, losing accumulated staking weight. Document this as an inherent trust assumption of the delegation model. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughImplements a two-step ownership transfer in PolicyEngineStaking: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.sol">
<violation number="1" location="packages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.sol:198">
P1: Custom agent: **Solidity Standards**
Bug: `_owner` is already overwritten to `msg.sender` before the event is emitted, so `OwnershipTransferred` will log `previousOwner == newOwner == msg.sender`, losing the actual previous owner. Cache the old owner before mutating state.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.sol (1)
183-201: Consider clearing_pendingOwnerwhen nominating a new one.If
transferOwnershipis called multiple times with different addresses, the previous pending owner is silently overwritten. This is likely intentional but worth noting. Additionally, if ownership needs to be canceled, there's no explicit mechanism (though callingtransferOwnership(address(0))would revert).If cancellation is desired, consider allowing
transferOwnershipto acceptaddress(0)to clear pending state, or add a separatecancelOwnershipTransfer()function.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.sol` around lines 183 - 201, transferOwnership currently overwrites _pendingOwner without a way to cancel a pending nomination; update the logic to allow clearing a pending owner or add an explicit cancel function: either (A) permit transferOwnership(address(0)) to clear _pendingOwner by removing the revert on zero address and set _pendingOwner = address(0) with an emitted event (e.g., OwnershipTransferCancelled) so callers can cancel a nomination, or (B) add a new onlyOwner function cancelOwnershipTransfer() that sets _pendingOwner = address(0) and emits a cancellation event; ensure acceptOwnership still checks _pendingOwner and behavior around emitting OwnershipTransferStarted/OwnershipTransferred remains consistent.packages/contracts-bedrock/test/periphery/staking/PolicyEngineStaking.t.sol (1)
23-31: MissingOwnershipTransferredevent declaration.
OwnershipTransferStartedwas added butOwnershipTransferredis used intest_acceptOwnership_succeeds(line 90) without being declared locally in the test init contract. While it compiles (inherited from interface), other events are declared locally for consistency.Proposed fix
event Paused(); event Unpaused(); event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/contracts-bedrock/test/periphery/staking/PolicyEngineStaking.t.sol` around lines 23 - 31, The test contract is missing a local declaration for the OwnershipTransferred event used in test_acceptOwnership_succeeds; add a matching event declaration (e.g., event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);) alongside the existing OwnershipTransferStarted, BeneficiarySet, etc., so the test and local declarations are consistent with the inherited interface and the test_acceptOwnership_succeeds assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.sol`:
- Around line 183-201: transferOwnership currently overwrites _pendingOwner
without a way to cancel a pending nomination; update the logic to allow clearing
a pending owner or add an explicit cancel function: either (A) permit
transferOwnership(address(0)) to clear _pendingOwner by removing the revert on
zero address and set _pendingOwner = address(0) with an emitted event (e.g.,
OwnershipTransferCancelled) so callers can cancel a nomination, or (B) add a new
onlyOwner function cancelOwnershipTransfer() that sets _pendingOwner =
address(0) and emits a cancellation event; ensure acceptOwnership still checks
_pendingOwner and behavior around emitting
OwnershipTransferStarted/OwnershipTransferred remains consistent.
In `@packages/contracts-bedrock/test/periphery/staking/PolicyEngineStaking.t.sol`:
- Around line 23-31: The test contract is missing a local declaration for the
OwnershipTransferred event used in test_acceptOwnership_succeeds; add a matching
event declaration (e.g., event OwnershipTransferred(address indexed
previousOwner, address indexed newOwner);) alongside the existing
OwnershipTransferStarted, BeneficiarySet, etc., so the test and local
declarations are consistent with the inherited interface and the
test_acceptOwnership_succeeds assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: defi-wonderland/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2faa8a23-1365-477e-bb8b-b5bc9eb139bd
📒 Files selected for processing (3)
packages/contracts-bedrock/interfaces/periphery/staking/IPolicyEngineStaking.solpackages/contracts-bedrock/src/periphery/staking/PolicyEngineStaking.solpackages/contracts-bedrock/test/periphery/staking/PolicyEngineStaking.t.sol
|
Closing to be opened as external PR. |
Fixes some findings from the Cantina's audit
setAllowedStakercallable during pause (documented as intentional)lastUpdateunnecessarily reset on partial unstake (now only resets on fullunstake)transferOwnershiprisks permanent loss (now two-step withacceptOwnership)lastUpdatevia allowlist removal (documented trust assumption)