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

[Slashing] Slash locked gold #2317

Merged
merged 19 commits into from
Jan 2, 2020

Conversation

lucasege
Copy link
Contributor

@lucasege lucasege commented Dec 19, 2019

Description

Adds slash function to LockedGold to allow slashing contracts to slash an account's gold.
Adds isSlasher mapping to allow addition of registered slashing addresses for permissioned use of functions.

Tested

Added unit tests.

Related issues

Driveby changes

Changed MockGovernance to be payable to allow testing of sending to community fund.
Changed Election interface and mock to allow LockedGold to test slashing voting gold.
Adds governance slasher as registered slasher in migrations (this will be expanded upon in PR #2347

@lucasege lucasege changed the title Lucasege/slashing slash locked gold [Slashing] Slash locked gold Dec 20, 2019
packages/protocol/contracts/governance/LockedGold.sol Outdated Show resolved Hide resolved
packages/protocol/contracts/governance/LockedGold.sol Outdated Show resolved Hide resolved
packages/protocol/contracts/governance/LockedGold.sol Outdated Show resolved Hide resolved
packages/protocol/test/governance/lockedgold.ts Outdated Show resolved Hide resolved
* has the most votes of any validator group.
* @param indices The indices of the i'th group in `account`'s voting list.
*/
function slash(
Copy link
Contributor

Choose a reason for hiding this comment

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

Emit an event

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I emit one event AccountSlashed(account, penalty, reporter, reward) or two events to split account/penalty and reporter/reward. Or is the reporter/reward not as important

Copy link
Contributor

Choose a reason for hiding this comment

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

one event is ok imo

@asaj asaj assigned lucasege and unassigned asaj Dec 20, 2019
@asaj asaj added the audit label Dec 20, 2019
@lucasege lucasege force-pushed the lucasege/slashing-slash-locked-gold branch from 312bdd4 to 1aac117 Compare December 20, 2019 06:04
@mrsmkl
Copy link
Contributor

mrsmkl commented Dec 20, 2019

I'll try to add a test into test/common/integration.ts

// If not enough nonvoting, revoke the difference
if (nonvotingBalance < penalty) {
difference = penalty.sub(nonvotingBalance);
require(
Copy link
Contributor

Choose a reason for hiding this comment

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

What should we do if there's not enough to slash anymore?

Copy link
Contributor Author

@lucasege lucasege Dec 27, 2019

Choose a reason for hiding this comment

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

I believe we would want to just slash all of the account's gold, I'm assuming this is handled on the caller side (Slasher contract) by passing in for penalty max(normalSlashPenalty, totalGoldOwnedByAccount) where normalSlashPenalty is the default penalty and totalGoldOwnedByAccount is the total balance + voting balance for the account.

Copy link
Contributor

@jfoutts-celo jfoutts-celo Dec 30, 2019

Choose a reason for hiding this comment

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

Now that the other PRs are in, we can update e.g. https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/contracts/governance/SlasherUtil.sol#L81 to do the max(normalSlashPenalty, totalGoldOwnedByAccount).

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it's easier to handle in LockedGold, because the needed balances are stored there.

Copy link
Contributor Author

@lucasege lucasege Jan 1, 2020

Choose a reason for hiding this comment

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

Based on this I am changing LockedGold.slash to only slash min(totalLockedGold, penalty). A problematic implication is that if totalLockedGold is somehow less than the reward passed in to slash, the call will revert. However, without doing a bunch of wasteful calculations (adjusting reward based on its original proportion or something similar) slash doesn't have the right info to change reward properly. Just something to keep in mind

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is OK for now, but i would follow the discussion on this.

My concern is that Given the min() i will be considered "slashed" and thus can't be slashed again for the same thing, but i wouldn't be really paying the penalty that i'm due... i wonder if i can use that to shield me from penalties somehow.

But to analyze this we need to see the bigger picture...

@mrsmkl
Copy link
Contributor

mrsmkl commented Dec 21, 2019

Did you solve the issue with sending to governance? I guess you just need to make MockGovernance able to receive gold like Governance (fallback function).

@lucasege lucasege force-pushed the lucasege/slashing-slash-locked-gold branch from ec84451 to e923f34 Compare December 30, 2019 21:21
@codecov
Copy link

codecov bot commented Dec 30, 2019

Codecov Report

Merging #2317 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #2317    +/-   ##
========================================
  Coverage   74.55%   74.55%            
========================================
  Files         278      278            
  Lines        7777     7777            
  Branches      707      991   +284     
========================================
  Hits         5798     5798            
  Misses       1868     1868            
  Partials      111      111
Flag Coverage Δ
#mobile 74.55% <ø> (ø) ⬆️

Continue to review full report at Codecov.

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

@lucasege lucasege force-pushed the lucasege/slashing-slash-locked-gold branch from b0d3ee3 to 24c0a9e Compare December 31, 2019 20:39
@mrsmkl
Copy link
Contributor

mrsmkl commented Dec 31, 2019

Looks like the integration test broke here. Should be fixed by using the migration from https://github.com/mrsmkl/celo-monorepo/blob/test-slashing2/packages/protocol/migrations/19_governance_slasher.ts

@mrsmkl
Copy link
Contributor

mrsmkl commented Jan 1, 2020

Looks like there was some flakiness in the validators test, perhaps because the epoch number was calculated differently.

@lucasege lucasege force-pushed the lucasege/slashing-slash-locked-gold branch from b744f78 to 65b6d2b Compare January 2, 2020 14:38
Copy link
Contributor

@mcortesi mcortesi left a comment

Choose a reason for hiding this comment

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

left a comment, but approved!

@lucasege lucasege added the automerge Have PR merge automatically when checks pass label Jan 2, 2020
@celo-ci-bot-user celo-ci-bot-user merged commit 97f2f31 into master Jan 2, 2020
lucasege pushed a commit that referenced this pull request Jan 2, 2020
aaronmgdr added a commit that referenced this pull request Jan 2, 2020
* master: (26 commits)
  Added new lint rule (#2349)
  [Slashing] Slash locked gold (#2317)
  [Slashing] Allow voting gold to be slashable (#2302)
  1666 precompiles assembly rewrite (#2324)
  Small fixes to deploy web (#2343)
  Governance, downtime and double signing slasher contracts (#2267)
  Added daily limit for reserve spending (#2303)
  Fixing multisig tests (#2342)
  [Wallet] Implement new send & import flow (#2332)
  Limechain/16xx (#1982)
  Add infinite pagination to Leaderboard (#2339)
  cli: Add rewards:show (#2160)
  Correct broken link formatting
  Celotool command for deploying hotfixes (#2142)
  Governance ContractKit + CLI changes (#2139)
  Complete codependent slashing precompile PRs (#2333)
  Add new and modified precompiles to UsingPrecompiles.sol (#2318)
  Adding error messages to contracts (#1182)
  Upgrade i18next and react-i18next to latest across monorepo (#2311)
  [Wallet] Fix exchange input on iOS and feed item display (#2319)
  ...

# Conflicts:
#	yarn.lock
aaronmgdr added a commit that referenced this pull request Jan 2, 2020
* master: (35 commits)
  Remove rep sentence from brand kit page (#2350)
  Added new lint rule (#2349)
  [Slashing] Slash locked gold (#2317)
  [Slashing] Allow voting gold to be slashable (#2302)
  1666 precompiles assembly rewrite (#2324)
  Small fixes to deploy web (#2343)
  Governance, downtime and double signing slasher contracts (#2267)
  Added daily limit for reserve spending (#2303)
  Fixing multisig tests (#2342)
  [Wallet] Implement new send & import flow (#2332)
  Limechain/16xx (#1982)
  Add infinite pagination to Leaderboard (#2339)
  cli: Add rewards:show (#2160)
  Correct broken link formatting
  Celotool command for deploying hotfixes (#2142)
  Governance ContractKit + CLI changes (#2139)
  Complete codependent slashing precompile PRs (#2333)
  Add new and modified precompiles to UsingPrecompiles.sol (#2318)
  Adding error messages to contracts (#1182)
  Upgrade i18next and react-i18next to latest across monorepo (#2311)
  ...
@aaronmgdr aaronmgdr deleted the lucasege/slashing-slash-locked-gold branch December 16, 2021 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Locked Gold slashable
6 participants