Repository navigation
Mitigate griefing caused by unauthorized third party bonding - #670
SidestreamCrunchyCarrot wants to merge 15 commits into
Conversation
…mic contract addresses
fix: Winning ticket dust griefing
* feat: implement third-party bonding approval system in BondingManager * test: add tests for third-party bonding scenarios in BondingManager * test: add unit test functions for third-party bonding approval and revocation in BondingManager * fix: failing tests in BondingManager unit tests * refactor: rename third-party bonding functions for clarity and consistency + add additional unit tests * refactor: rename third-party bonding functions and events for clarity and consistency * fix: clarify notice fo rallowThirdPartyBondinge in BondingManager * fix: dev annotation for `_authorizeClaimEarnings` * fix: update notice for third-party bonding in BondingManager * fix: prevent third-party forced claims before delegator rewards are claimed * enh: PoC and fix tests * doc: enhance natspec * test: enhance the fix test file * enh: unit tests * test: add remaining unit tests for complete coverage * enh: use only camel case for functions names * test: enhance comments for clarity in third party bonding tests * refactor: rename ThirdPartyBondingAllowance event to ThirdPartyBondingAuthorization * refactor: rename third-party bonding functions and event * refactor: renaming * refactor: rename third-party bonding functions to setThirdPartyBondingAuthorization * refactor: improve parameter documentation for setThirdPartyBondingAuthorization function * refactor: rename third-party bonding functions and events to use "Bonder" instead of "Bonding" * refactor: pin block number in poc and fix files * refactor: add explanatory comment to `_authorizeClaimEarnings` * refactor: remove zero address validation from `setThirdPartyBonderAuthorization` * refactor: update error messages for unauthorized bonder claims * refactor: enhance documentation for third-party bonder authorization requirements * refactor: clarify authorization requirements for third-party bonders in comments * fix: account for unauthorized pre-planted bonds * fix: failing unit tests * format * fix: add test for zero address receiver in transferBond by L2Migrator * refact: exempt a legit DelegatorPool from the authorization check * fix: coverage * refact: improve _isDelegatorPool check * enh: add tests for third-party bonding with inactive transcoders * docs: update documentation * enh: improve _isDelegatorPool function to return early for a 0 address l2Migrator * test: add missing unit test to check for unregistered l2migrator * rearrange the checks to prevent reward griefing by the DelegatorPool * increase test coverage * update comments to match the code * rename _owner -> _delegator for the transferBond --------- Co-authored-by: SidestreamCrunchyCarrot <crunchycarrot@sidestream.tech>
There was a problem hiding this comment.
🟡 Changes recommended
Existing regression tests omit third-party bonder authorization, causing unexpected reverts and preventing them from exercising the intended reward and delegate restrictions.
1 open issue
What changed in this PR
This PR adds recipient-controlled authorization for third-party bonding and stake transfers to mitigate forced earnings claims and delegate pre-planting, while preserving migration access.
Changes:
- Adds authorization controls and an event, while retaining reward-timing restrictions.
- Recognizes migration DelegatorPools through a shared
IL2Migratorinterface. - Adds exploit demonstrations, fix regression tests, and expanded unit coverage.
| File | Description |
|---|---|
test/unit/helpers/Fixture.js |
Registers the L2Migrator mock. |
test/unit/BondingManager.js |
Expands authorization and migration-exception coverage. |
src/test/BondingVotesStateInitialization.sol |
Updates the migrator interface import. |
src/test/BondingManagerTransferBondFix.sol |
Updates the migrator interface import. |
src/test/BondingManagerRewardsGriefingPoC.sol |
Updates the migrator interface import. |
src/test/BondingManagerRewardsGriefingFix.sol |
Updates the migrator interface import. |
src/test/BondingManagerNullDelegateTransferBondFix.sol |
Updates the migrator interface import. |
src/test/BondingManagerForceSelfDelegationFix.sol |
Updates the migrator interface import. |
src/test/BondingManagerForcedClaimLateFeePoC.sol |
Demonstrates forced claims and delegate pre-planting. |
src/test/BondingManagerForcedClaimLateFeeFix.sol |
Tests authorization enforcement and migration compatibility. |
src/test/BondingManagerForceChangeDelegateFix.sol |
Updates the migrator interface import. |
contracts/test/mocks/L2MigratorMock.sol |
Adds configurable DelegatorPool registrations for tests. |
contracts/IL2Migrator.sol |
Relocates the shared interface and exposes pool lookup. |
contracts/bonding/IBondingManager.sol |
Exposes authorization functions and event. |
contracts/bonding/BondingManager.sol |
Enforces authorization with migration exceptions. |
Review effort: Balanced
| msg.sender == l2Migrator() || _isDelegatorPool() || authorizedThirdPartyBonders[_owner][msg.sender], | ||
| "UNAUTHORIZED_BONDER" |
There was a problem hiding this comment.
Non-blocking but would be a nice thing to fix. Not required tho as those fork tests are more historical anyway.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## delta #670 +/- ##
===============================================
Coverage 100.00000% 100.00000%
===============================================
Files 29 29
Lines 1349 1365 +16
Branches 226 229 +3
===============================================
+ Hits 1349 1365 +16
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|

What does this pull request do? Explain your changes. (required)
This PR reduces the attack surface of two known vulnerabilities. Both rely on any third party being able to call
bondForWithHint()ortransferBond()for another account:reward(). This triggers an early earnings claim, and the delegator loses the fees added to the rest of that round.transferBond(), such as an LIP-73 stake claim or a wallet-to-wallet transfer, keeps that delegate of the attacker's choice.The mitigation requires the receiving account to authorize every third party that bonds or transfers stake on its behalf. There are three exceptions: the account itself, the
L2Migrator, and the DelegatorPools created by theL2Migrator. TheL2Migratorand the DelegatorPools exceptions keep the migration paths working. An authorized third party is still held to the existing reward-griefing rule: if the receiver delegates to an active transcoder and has not claimed this round, the call waits until the transcoder has calledreward().Specific updates (required)
contracts/bonding/BondingManager.sol: Changed_authorizeClaimEarningsso that every caller other than theowner, theL2Migratoror aDelegatorPoolmust be authorized by the receiving account. Otherwise the call reverts withUNAUTHORIZED_BONDER. This applies whether or not the receiver is bonded. For an authorized caller, the call still reverts withILLEGAL_CLAIM_EARNINGSif the receiver delegates to an active transcoder and the transcoder has not calledreward()yet._isDelegatorPool(). It recognises aDelegatorPoolcaller by checking thatL2Migrator.delegatorPools(delegate) == msg.sender, where delegate is the caller's own delegate.contracts/bonding/BondingManager.sol: AddedsetThirdPartyBonderAuthorization(address _bonder, bool _authorized)so delegators can authorize (or revoke) trusted addresses that may bond on their behalf (and therefore trigger an earnings claim).contracts/bonding/BondingManager.sol: Added theisThirdPartyBonderAuthorized(address _delegator, address _bonder)view function and the privateauthorizedThirdPartyBondersmapping.contracts/bonding/IBondingManager.sol: Exposed the two new functions and addedThirdPartyBonderAuthorizationevent.contracts/IL2Migrator.sol: moved the interface fromsrc/test/interfaces/and addeddelegatorPools(address). The Foundry tests that used the old path now import it from here.How did you test each of these updates (required)
src/test/BondingManagerForcedClaimLateFeePoC.solforks Arbitrum mainnet and shows both vulnerabilities on the live protocol:bondForWithHint()andtransferBond(), with the delegator losing the late fees.bondForWithHint()/transferBond()and end to end through a realDelegatorPoolclaimtransferBond()src/test/BondingManagerForcedClaimLateFeeFix.solto prove the fix works. It deploys the upgraded contract via the Governor and tests that:DelegatorPoolclaim succeeds without authorizationtest/unit/BondingManager.jsto support the new bonding authorization logicDoes this pull request close any open issues?
It partially mitigates two vulnerability reported through Immunefi and evaluated in these Security Advisories:
Checklist:
ℹ️ There is no relevant section in the README file
yarn testpass