Skip to content

Commit 77fd88c

Browse files
committed
Add Arbitration reputation penalties
1 parent c888778 commit 77fd88c

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

contracts/colony/Colony.sol

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ contract Colony is ColonyStorage, PatriciaTreeProofs {
117117
return token;
118118
}
119119

120+
function emitDomainReputationPenalty(
121+
uint256 _permissionDomainId,
122+
uint256 _childSkillIndex,
123+
uint256 _domainId,
124+
address _user,
125+
int256 _amount
126+
) public stoppable authDomain(_permissionDomainId, _childSkillIndex, _domainId)
127+
{
128+
require(_amount <= 0, "colony-penalty-cannot-be-positive");
129+
IColonyNetwork(colonyNetworkAddress).appendReputationUpdateLog(_user, _amount, domains[_domainId].skillId);
130+
}
131+
132+
function emitSkillReputationPenalty(uint256 _permissionDomainId, uint256 _skillId, address _user, int256 _amount)
133+
public stoppable validGlobalSkill(_skillId)
134+
{
135+
require(_amount <= 0, "colony-penalty-cannot-be-positive");
136+
require(isAuthorized(msg.sender, _permissionDomainId, msg.sig), "ds-auth-unauthorized");
137+
IColonyNetwork(colonyNetworkAddress).appendReputationUpdateLog(_user, _amount, _skillId);
138+
}
139+
120140
function initialiseColony(address _colonyNetworkAddress, address _token) public stoppable {
121141
require(colonyNetworkAddress == address(0x0), "colony-already-initialised-network");
122142
require(token == address(0x0), "colony-already-initialised-token");

contracts/colony/ColonyAuthority.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ contract ColonyAuthority is CommonAuthority {
8585
addRoleCapability(ARBITRATION_ROLE, "setExpenditurePayoutModifier(uint256,uint256,uint256,uint256,int256)");
8686
addRoleCapability(ARBITRATION_ROLE, "setExpenditureClaimDelay(uint256,uint256,uint256,uint256,uint256)");
8787

88-
// Added in colony v5
88+
// Added in colony v5 (current version)
8989
addRoleCapability(ARBITRATION_ROLE, "transferStake(uint256,uint256,address,address,uint256,uint256,address)");
90+
addRoleCapability(ARBITRATION_ROLE, "emitDomainReputationPenalty(uint256,uint256,uint256,address,int256)");
91+
addRoleCapability(ARBITRATION_ROLE, "emitSkillReputationPenalty(uint256,uint256,address,int256)");
9092
}
9193

9294
function addRoleCapability(uint8 role, bytes memory sig) private {

contracts/colony/IColony.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,28 @@ contract IColony is ColonyDataTypes, IRecovery {
127127
/// @return roles bytes32 representation of the roles
128128
function getUserRoles(address who, uint256 where) public view returns (bytes32 roles);
129129

130+
/// @notice Emit a negative domain reputation update. Available only to Arbitration role holders.
131+
/// @param _permissionDomainId The domainId in which I hold the Arbitration role.
132+
/// @param _childSkillIndex The index that the `_domainId` is relative to `_permissionDomainId`,
133+
/// (only used if `_permissionDomainId` is different to `_domainId`)
134+
/// @param _domainId The domain where the user will lose reputation.
135+
/// @param _user The user who will lose reputation.
136+
/// @param _amount The (negative) amount of reputation to lose.
137+
function emitDomainReputationPenalty(
138+
uint256 _permissionDomainId,
139+
uint256 _childSkillIndex,
140+
uint256 _domainId,
141+
address _user,
142+
int256 _amount
143+
) public;
144+
145+
/// @notice Emit a negative skill reputation update. Available only to Arbitration role holders.
146+
/// @param _permissionDomainId The domainId in which I hold the Arbitration role.
147+
/// @param _skillId The skill where the user will lose reputation.
148+
/// @param _user The user who will lose reputation.
149+
/// @param _amount The (negative) amount of reputation to lose.
150+
function emitSkillReputationPenalty(uint256 _permissionDomainId, uint256 _skillId, address _user, int256 _amount) public;
151+
130152
/// @notice Called once when the colony is created to initialise certain storage slot values.
131153
/// @dev Sets the reward inverse to the uint max 2**256 - 1.
132154
/// @param _colonyNetworkAddress Address of the colony network

docs/_Interface_IColony.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,37 @@ Deobligate the user some amount of tokens, releasing the stake.
206206
|_amount|uint256|Amount of internal token we are deobligating.
207207

208208

209+
### `emitDomainReputationPenalty`
210+
211+
Emit a negative domain reputation update. Available only to Arbitration role holders.
212+
213+
214+
**Parameters**
215+
216+
|Name|Type|Description|
217+
|---|---|---|
218+
|_permissionDomainId|uint256|The domainId in which I hold the Arbitration role.
219+
|_childSkillIndex|uint256|The index that the `_domainId` is relative to `_permissionDomainId`, (only used if `_permissionDomainId` is different to `_domainId`)
220+
|_domainId|uint256|The domain where the user will lose reputation.
221+
|_user|address|The user who will lose reputation.
222+
|_amount|int256|The (negative) amount of reputation to lose.
223+
224+
225+
### `emitSkillReputationPenalty`
226+
227+
Emit a negative skill reputation update. Available only to Arbitration role holders.
228+
229+
230+
**Parameters**
231+
232+
|Name|Type|Description|
233+
|---|---|---|
234+
|_permissionDomainId|uint256|The domainId in which I hold the Arbitration role.
235+
|_skillId|uint256|The skill where the user will lose reputation.
236+
|_user|address|The user who will lose reputation.
237+
|_amount|int256|The (negative) amount of reputation to lose.
238+
239+
209240
### `executeTaskChange`
210241

211242
Executes a task update transaction `_data` which is approved and signed by two of its roles (e.g. manager and worker) using the detached signatures for these users.

test/contracts-network/colony-permissions.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ADMINISTRATION_ROLE,
1313
INITIAL_FUNDING,
1414
SPECIFICATION_HASH,
15+
GLOBAL_SKILL_ID,
1516
} from "../../helpers/constants";
1617

1718
import { fundColonyWithTokens, makeTask, setupRandomColony } from "../../helpers/test-data-generator";
@@ -278,6 +279,19 @@ contract("ColonyPermissions", (accounts) => {
278279
await colony.setAdministrationRole(1, 1, USER2, 3, true, { from: USER1 });
279280
});
280281

282+
it("should allow users with arbitration permission to emit negative reputation penalties", async () => {
283+
await colony.setArbitrationRole(1, 0, USER1, 1, true);
284+
285+
// Domain penalties
286+
await colony.emitDomainReputationPenalty(1, 1, 3, USER2, -100, { from: USER1 });
287+
await checkErrorRevert(colony.emitDomainReputationPenalty(1, 1, 3, USER2, 100, { from: USER1 }), "colony-penalty-cannot-be-positive");
288+
289+
// Skill penalties
290+
await colony.emitSkillReputationPenalty(1, GLOBAL_SKILL_ID, USER2, -100, { from: USER1 });
291+
await checkErrorRevert(colony.emitSkillReputationPenalty(1, GLOBAL_SKILL_ID, USER2, 100, { from: USER1 }), "colony-penalty-cannot-be-positive");
292+
await checkErrorRevert(colony.emitSkillReputationPenalty(2, GLOBAL_SKILL_ID, USER2, -100, { from: USER1 }), "ds-auth-unauthorized");
293+
});
294+
281295
it("should allow permissions to propagate to subdomains", async () => {
282296
// Give User 2 funding permissions in domain 1
283297
await colony.setFundingRole(1, UINT256_MAX, USER2, 1, true);

0 commit comments

Comments
 (0)