Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Penalty for reward as alternative to slashing #254

Merged
merged 5 commits into from
May 3, 2024

Conversation

vzotova
Copy link
Member

@vzotova vzotova commented Apr 12, 2024

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:
Penalize reward as an option when slashing is too much. Penalty decreases reward by penaltyDefault for penaltyDuration. Each penalize restarts time, penalty itself is the same value until end of duration. Initially this event starts on Polygon in child app, where penalize can be called by special role (adjudicator for now)

Issues fixed/closed:

  • Fixes #...

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on?
Is there a particular commit/function/section of your PR that requires more attention from reviewers?

@vzotova vzotova self-assigned this Apr 12, 2024
@vzotova vzotova changed the title [WIP] TACoApplication: reward only penalty Penalty for reward as alternative to slashing Apr 21, 2024
@vzotova vzotova marked this pull request as ready for review April 21, 2024 14:34
Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

Great work here 🙌

contracts/contracts/TACoApplication.sol Outdated Show resolved Hide resolved
contracts/contracts/TACoApplication.sol Show resolved Hide resolved
contracts/contracts/TACoApplication.sol Outdated Show resolved Hide resolved
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸 - nice work!

Copy link
Member

@arjunhassard arjunhassard left a comment

Choose a reason for hiding this comment

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

Nice one! Tried to outline the simplest way for penaltyPercent to scale with violation count.

contracts/contracts/TACoApplication.sol Show resolved Hide resolved
contracts/contracts/TACoApplication.sol Show resolved Hide resolved
* @notice Resets future reward back to 100%
* @param _stakingProvider Staking provider address
*/
function resetReward(address _stakingProvider) external {
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify what happens in resetReward is not called for a penalized staking provider whose penalty ended?

Copy link
Member Author

Choose a reason for hiding this comment

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

resetReward also included in updareReward, so if it none such methods will be called then reward calculation will be looking like staker still has penalty. I know it's not great but with our model - we need active input to update values

Copy link
Member

Choose a reason for hiding this comment

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

In that case, this needs to be stated in the @notice.

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

return effectiveAuthorized(_authorized, _info.penaltyPercent);
}

/// @dev This view should be called after updateReward modifier
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with these @dev comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

updateReward modifier has resetReward inside, so this view will give proper value after that check. Otherwise it will show penalty in cases when they may be reseted

Copy link
Member

Choose a reason for hiding this comment

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

Right, this is related to my previous comment. What about something like:

/// @dev In case that a penalty period already ended, this view method may produce
///      outdated results if the penalty hasn't been reset, either by calling 
///      `resetReward` explicitly or any function with the `updateReward` modifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

✔️

Comment on lines +504 to +513
if (_info.endPenalty == 0) {
return _from - _to;
}
uint96 effectiveFrom = effectiveAuthorized(_from, _info.penaltyPercent);
uint96 effectiveTo = effectiveAuthorized(_to, _info.penaltyPercent);
return effectiveFrom - effectiveTo;
Copy link
Member

Choose a reason for hiding this comment

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

Can you just say return effectiveAuthorized(_from, _to)? When endPenalty == 0, L492 will make sure the result is _from - _to.

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure that I follow you, second value in effectiveAuthorized is penalty percent, can you elaborate?
in general I made this thing to decrease read operations (still costly)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this is what I meant:

Suggested change
if (_info.endPenalty == 0) {
return _from - _to;
}
uint96 effectiveFrom = effectiveAuthorized(_from, _info.penaltyPercent);
uint96 effectiveTo = effectiveAuthorized(_to, _info.penaltyPercent);
return effectiveFrom - effectiveTo;
return effectiveAuthorized(_from - _to);

Copy link
Member Author

Choose a reason for hiding this comment

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

now I see your question, but I didn't do that on purpose, reason is it could produce different result because of rounding errors, for all other places it's division first and then addition/subtraction.

Copy link
Member

Choose a reason for hiding this comment

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

Opened #260

contracts/contracts/TACoApplication.sol Show resolved Hide resolved
Copy link
Member

@cygnusv cygnusv left a comment

Choose a reason for hiding this comment

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

Added some comments, but in general looks good. Just waiting for the small RFCs to merge, IMO.

Co-authored-by: Manuel Montenegro <[email protected]>
Co-authored-by: Derek Pierre <[email protected]>
Co-authored-by: David Núñez <[email protected]>
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