Skip to content

Mitigate griefing caused by unauthorized third party bonding - #670

Open
SidestreamCrunchyCarrot wants to merge 15 commits into
livepeer:deltafrom
sidestream-tech:delta
Open

SidestreamCrunchyCarrot wants to merge 15 commits into
livepeer:deltafrom
sidestream-tech:delta

Conversation

@SidestreamCrunchyCarrot

Copy link
Copy Markdown
Collaborator

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() or transferBond() for another account:

  1. Forced earnings claim: a third party bonds for a delegator mid-round, after the transcoder has called reward(). This triggers an early earnings claim, and the delegator loses the fees added to the rest of that round.
  2. Delegate pre-plant: a third party bonds 1 wei for an account that is not bonded yet, for example one that has not migrated its stake from L1. This sets the account's delegate to an orchestrator of the attacker's choice. Stake that later arrives through 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 the L2Migrator. The L2Migrator and 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 called reward().

Specific updates (required)

  • contracts/bonding/BondingManager.sol: Changed _authorizeClaimEarnings so that every caller other than the owner, the L2Migrator or a DelegatorPool must be authorized by the receiving account. Otherwise the call reverts with UNAUTHORIZED_BONDER. This applies whether or not the receiver is bonded. For an authorized caller, the call still reverts with ILLEGAL_CLAIM_EARNINGS if the receiver delegates to an active transcoder and the transcoder has not called reward() yet.
  • Added _isDelegatorPool(). It recognises a DelegatorPool caller by checking that L2Migrator.delegatorPools(delegate) == msg.sender, where delegate is the caller's own delegate.
  • contracts/bonding/BondingManager.sol: Added setThirdPartyBonderAuthorization(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 the isThirdPartyBonderAuthorized(address _delegator, address _bonder) view function and the private authorizedThirdPartyBonders mapping.
  • contracts/bonding/IBondingManager.sol: Exposed the two new functions and added ThirdPartyBonderAuthorization event.
  • contracts/IL2Migrator.sol: moved the interface from src/test/interfaces/ and added delegatorPools(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.sol forks Arbitrum mainnet and shows both vulnerabilities on the live protocol:
    • the forced claim via bondForWithHint() and transferBond(), with the delegator losing the late fees.
    • the delegate pre-plant via bondForWithHint()/transferBond() and end to end through a real DelegatorPool claim
    • the front-run of a wallet-to-wallet transferBond()
  • Added src/test/BondingManagerForcedClaimLateFeeFix.sol to prove the fix works. It deploys the upgraded contract via the Governor and tests that:
    • all attack paths revert
    • the owner can still bond for themselves
    • an authorized caller can bond only after reward() (or once the receiver has claimed this round), and immediately for a delegator of an inactive transcoder
    • revoking the authorization blocks the caller again
    • a real DelegatorPool claim succeeds without authorization
  • Added new test functions and updated existing ones in test/unit/BondingManager.js to support the new bonding authorization logic

Does this pull request close any open issues?

It partially mitigates two vulnerability reported through Immunefi and evaluated in these Security Advisories:

Checklist:

  • README and other documentation updated
    ℹ️ There is no relevant section in the README file
  • All tests using yarn test pass

SidestreamSweatyPumpkin and others added 15 commits June 5, 2026 11:28
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>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 IL2Migrator interface.
  • 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

Comment on lines +1829 to +1830
msg.sender == l2Migrator() || _isDelegatorPool() || authorizedThirdPartyBonders[_owner][msg.sender],
"UNAUTHORIZED_BONDER"

@victorges victorges Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking but would be a nice thing to fix. Not required tho as those fork tests are more historical anyway.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (46c24fe) to head (b832adc).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##                delta         #670   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files              29           29           
  Lines            1349         1365   +16     
  Branches          226          229    +3     
===============================================
+ Hits             1349         1365   +16     
Files with missing lines Coverage Δ
contracts/bonding/BondingManager.sol 100.00000% <100.00000%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46c24fe...b832adc. Read the comment docs.

Files with missing lines Coverage Δ
contracts/bonding/BondingManager.sol 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@victorges victorges left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

5 participants