Skip to content

Update reporter delegated amount during slashing#11572

Open
pahor167 wants to merge 1 commit intorelease/core-contracts/16from
pahor/fixDelegationDuringSlashing
Open

Update reporter delegated amount during slashing#11572
pahor167 wants to merge 1 commit intorelease/core-contracts/16from
pahor/fixDelegationDuringSlashing

Conversation

@pahor167
Copy link
Copy Markdown
Collaborator

@pahor167 pahor167 commented Nov 13, 2025

Description

Enhance LockedGold contract to update delegated amounts for reporter when slashed and receiving rewards. Add unit tests to verify correct behavior for both reporter and account delegation scenarios.

Tested

Unit tests


Note

Update LockedGold.slash to recalculate reporter’s delegated amount when reward is granted and add unit tests covering reporter/account delegation updates.

  • Contracts:
    • contracts/governance/LockedGold.sol:
      • In slash, after balance adjustments, also call _updateDelegatedAmount(reporter) to refresh reporter delegation state.
  • Tests:
    • test-sol/unit/governance/voting/LockedGold.t.sol:
      • Add tests ensuring reporter’s delegated amount and delegatee voting power update when reporter is delegating and receives reward.
      • Add tests validating both slashed account and reporter delegations are updated when both are delegating.

Written by Cursor Bugbot for commit 62adde1. This will update automatically on new commits. Configure here.

… when slashed and receiving rewards. Add unit tests to verify correct behavior for both reporter and account delegation scenarios.
@pahor167 pahor167 requested a review from a team as a code owner November 13, 2025 16:52
}

_updateDelegatedAmount(account);
_updateDelegatedAmount(reporter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When slashing through GovernanceSlasher the reporter is 0x0 so I would add this exclusion:

Suggested change
_updateDelegatedAmount(reporter);
if (reporter != address(0)) {
_updateDelegatedAmount(reporter);
}

and appropriate test case for it in LockedGold.t.sol

Copy link
Copy Markdown
Contributor

@Mc01 Mc01 Nov 25, 2025

Choose a reason for hiding this comment

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

Additionally 👉 how about the found issue within unlock function?

function unlock(uint256 value) external nonReentrant {
  ...
  _decrementNonvotingAccountBalance(msg.sender, value);
  _updateDelegatedAmount(msg.sender); // fix for storage
  ...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When slashing through GovernanceSlasher the reporter is 0x0 so I would add this exclusion

Yes, this is probably even necessary, otherwise the call to voteSignerToAccount inside _updateDelegatedAmount would revert, making Governance slashings impossible.

}

_updateDelegatedAmount(account);
_updateDelegatedAmount(reporter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just noting: if I remember correctly, the point of having an updateDelegatedAmount function was that we'd allow the stored delegated amount to diverge from the expected amount (in particular, when the delegator accrues epoch rewards). So this change isn't strictly necessary, more of a convenience that adds gas costs to the slash function.

In fact, even the above call with _updateDelegatedAmount(account) isn't really necessary - since the only slashable actors are validators and validator groups, and those are not allowed to delegate.

}

_updateDelegatedAmount(account);
_updateDelegatedAmount(reporter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When slashing through GovernanceSlasher the reporter is 0x0 so I would add this exclusion

Yes, this is probably even necessary, otherwise the call to voteSignerToAccount inside _updateDelegatedAmount would revert, making Governance slashings impossible.

@martinvol martinvol changed the base branch from release/core-contracts/15 to release/core-contracts/16 February 9, 2026 11:14
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.

3 participants