Skip to content

Commit 8dec5d6

Browse files
authored
Merge pull request #2960 from keep-network/authorization-stuff-2
Introduced authorization decrease change period parameter to the beacon See threshold-network/solidity-contracts#99 Introduced authorization decrease change period parameter to the beacon This value protect against malicious operators who manipulate their weight by overwriting authorization decrease request, and lowering or increasing their eligible stake this way. Authorization decrease change period is the time period before the authorization decrease delay end, during which the authorization decrease request can be overwritten. When the request is overwritten, the authorization decrease delay is reset. For example, if `authorizationDecraseChangePeriod` is set to 4 days, `authorizationDecreaseDelay` is set to 14 days, and someone requested authorization decrease, it means they can not request another decrease for the first 10 days. After 10 days pass, they can request again and overwrite the previous authorization decrease request. The delay time will reset for them and they will have to wait another 10 days to alter it and 14 days to approve it. If set to a value equal to `authorizationDecreaseDelay, it means that authorization decrease request can be always overwritten. If set to zero, it means authorization decrease request can not be overwritten until the delay end, and one needs to wait for the entire authorization decrease delay to approve their decrease or to alter it. ``` (1) authorization decrease requested timestamp (2) from this moment authorization decrease request can be overwritten (3) from this moment authorization decrease request can be approved, assuming it was NOT overwritten in (2) (1) (2) (3) --x------------------------------x--------------------------x----> | \________________________/ | authorizationDecreaseChangePeriod \______________________________________________________/ authorizationDecreaseDelay ```
2 parents 8bd6f60 + cd5f0da commit 8dec5d6

File tree

7 files changed

+1011
-97
lines changed

7 files changed

+1011
-97
lines changed

solidity/random-beacon/contracts/RandomBeacon.sol

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
164164

165165
event AuthorizationParametersUpdated(
166166
uint96 minimumAuthorization,
167-
uint64 authorizationDecreaseDelay
167+
uint64 authorizationDecreaseDelay,
168+
uint64 authorizationDecreaseChangePeriod
168169
);
169170

170171
event RelayEntryParametersUpdated(
@@ -383,10 +384,12 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
383384
_relayEntryTimeoutNotificationRewardMultiplier = 40;
384385
_unauthorizedSigningNotificationRewardMultiplier = 50;
385386
_dkgMaliciousResultNotificationRewardMultiplier = 100;
386-
// Minimum authorization: 100k T
387-
// Authorization decrease delay: ~10 weeks assuming 15s block time
387+
// Minimum authorization: 100k T
388+
// Authorization decrease delay: ~10 weeks assuming 15s block time
389+
// Authorization decrease change period: equal to the delay
388390
// slither-disable-next-line too-many-digits
389-
authorization.setParameters(100000e18, 403200);
391+
authorization.setParameters(100000e18, 403200, 403200);
392+
390393
dkg.init(_sortitionPool, _dkgValidator);
391394
// DKG result challenge period length: ~48h assuming 15s block time
392395
// DKG result submission timeout: 64 members * 20 blocks = 1280 blocks
@@ -424,18 +427,23 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
424427
/// @param _minimumAuthorization New minimum authorization amount
425428
/// @param _authorizationDecreaseDelay New authorization decrease delay in
426429
/// seconds
430+
/// @param _authorizationDecreaseChangePeriod New authorization decrease
431+
/// change period in seconds
427432
function updateAuthorizationParameters(
428433
uint96 _minimumAuthorization,
429-
uint64 _authorizationDecreaseDelay
434+
uint64 _authorizationDecreaseDelay,
435+
uint64 _authorizationDecreaseChangePeriod
430436
) external onlyGovernance {
431437
authorization.setParameters(
432438
_minimumAuthorization,
433-
_authorizationDecreaseDelay
439+
_authorizationDecreaseDelay,
440+
_authorizationDecreaseChangePeriod
434441
);
435442

436443
emit AuthorizationParametersUpdated(
437444
_minimumAuthorization,
438-
_authorizationDecreaseDelay
445+
_authorizationDecreaseDelay,
446+
_authorizationDecreaseChangePeriod
439447
);
440448
}
441449

@@ -683,6 +691,10 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
683691
/// Reverts if the amount after deauthorization would be non-zero
684692
/// and lower than the minimum authorization.
685693
///
694+
/// Reverts if another authorization decrease request is pending for
695+
/// the staking provider and not enough time passed since the
696+
/// original request (see `authorizationDecreaseChangePeriod`).
697+
///
686698
/// If the operator is not known (`registerOperator` was not called)
687699
/// it lets to `approveAuthorizationDecrease` immediately. If the
688700
/// operator is known (`registerOperator` was called), the operator
@@ -696,7 +708,8 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
696708
/// `approveAuthorizationDecrease` function.
697709
///
698710
/// If there is a pending authorization decrease request, it is
699-
/// overwritten.
711+
/// overwritten, but only if enough time passed since the original
712+
/// request. Otherwise, the function reverts.
700713
///
701714
/// @dev Can only be called by T staking contract.
702715
function authorizationDecreaseRequested(
@@ -1236,14 +1249,6 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
12361249
return authorization.parameters.minimumAuthorization;
12371250
}
12381251

1239-
/// @notice Delay in seconds that needs to pass between the time
1240-
/// authorization decrease is requested and the time that request
1241-
/// gets approved. Protects against free-riders earning rewards and
1242-
/// not being active in the network.
1243-
function authorizationDecreaseDelay() external view returns (uint64) {
1244-
return authorization.parameters.authorizationDecreaseDelay;
1245-
}
1246-
12471252
/// @return Flag indicating whether a relay entry request is currently
12481253
/// in progress.
12491254
function isRelayRequestInProgress() external view returns (bool) {
@@ -1344,6 +1349,41 @@ contract RandomBeacon is IRandomBeacon, IApplication, Governable, Reimbursable {
13441349
return sortitionPool.selectGroup(DKG.groupSize, bytes32(dkg.seed));
13451350
}
13461351

1352+
/// @notice Returns authorization-related parameters of the beacon.
1353+
/// @dev The minimum authorization is also returned by `minimumAuthorization()`
1354+
/// function, as a requirement of `IApplication` interface.
1355+
/// @return minimumAuthorization The minimum authorization amount required
1356+
/// so that operator can participate in the random beacon. This
1357+
/// amount is required to execute slashing for providing a malicious
1358+
/// DKG result or when a relay entry times out.
1359+
/// @return authorizationDecreaseDelay Delay in seconds that needs to pass
1360+
/// between the time authorization decrease is requested and the
1361+
/// time that request gets approved. Protects against free-riders
1362+
/// earning rewards and not being active in the network.
1363+
/// @return authorizationDecreaseChangePeriod Authorization decrease change
1364+
/// period in seconds. It is the time, before authorization decrease
1365+
/// delay end, during which the pending authorization decrease
1366+
/// request can be overwritten.
1367+
/// If set to 0, pending authorization decrease request can not be
1368+
/// overwritten until the endire `authorizationDecreaseDelay` ends.
1369+
/// If set to value equal `authorizationDecreaseDelay`, request can
1370+
/// always be overwritten.
1371+
function authorizationParameters()
1372+
external
1373+
view
1374+
returns (
1375+
uint96 minimumAuthorization,
1376+
uint64 authorizationDecreaseDelay,
1377+
uint64 authorizationDecreaseChangePeriod
1378+
)
1379+
{
1380+
return (
1381+
authorization.parameters.minimumAuthorization,
1382+
authorization.parameters.authorizationDecreaseDelay,
1383+
authorization.parameters.authorizationDecreaseChangePeriod
1384+
);
1385+
}
1386+
13471387
/// @notice Returns relay-entry-related parameters of the beacon.
13481388
/// @return relayEntrySoftTimeout Soft timeout in blocks for a group to
13491389
/// submit the relay entry. If the soft timeout is reached for

solidity/random-beacon/contracts/RandomBeaconGovernance.sol

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ contract RandomBeaconGovernance is Ownable {
7777
uint64 public newAuthorizationDecreaseDelay;
7878
uint256 public authorizationDecreaseDelayChangeInitiated;
7979

80+
uint64 public newAuthorizationDecreaseChangePeriod;
81+
uint256 public authorizationDecreaseChangePeriodChangeInitiated;
82+
8083
uint256 public newDkgMaliciousResultNotificationRewardMultiplier;
8184
uint256
8285
public dkgMaliciousResultNotificationRewardMultiplierChangeInitiated;
@@ -218,6 +221,15 @@ contract RandomBeaconGovernance is Ownable {
218221
);
219222
event AuthorizationDecreaseDelayUpdated(uint64 authorizationDecreaseDelay);
220223

224+
event AuthorizationDecreaseChangePeriodUpdateStarted(
225+
uint64 authorizationDecreaseChangePeriod,
226+
uint256 timestamp
227+
);
228+
229+
event AuthorizationDecreaseChangePeriodUpdated(
230+
uint64 authorizationDecreaseChangePeriod
231+
);
232+
221233
event DkgMaliciousResultNotificationRewardMultiplierUpdateStarted(
222234
uint256 dkgMaliciousResultNotificationRewardMultiplier,
223235
uint256 timestamp
@@ -1270,10 +1282,16 @@ contract RandomBeaconGovernance is Ownable {
12701282
onlyAfterGovernanceDelay(minimumAuthorizationChangeInitiated)
12711283
{
12721284
emit MinimumAuthorizationUpdated(newMinimumAuthorization);
1285+
(
1286+
,
1287+
uint64 authorizationDecreaseDelay,
1288+
uint64 authorizationDecreaseChangePeriod
1289+
) = randomBeacon.authorizationParameters();
12731290
// slither-disable-next-line reentrancy-no-eth
12741291
randomBeacon.updateAuthorizationParameters(
12751292
newMinimumAuthorization,
1276-
randomBeacon.authorizationDecreaseDelay()
1293+
authorizationDecreaseDelay,
1294+
authorizationDecreaseChangePeriod
12771295
);
12781296
minimumAuthorizationChangeInitiated = 0;
12791297
newMinimumAuthorization = 0;
@@ -1304,15 +1322,65 @@ contract RandomBeaconGovernance is Ownable {
13041322
onlyAfterGovernanceDelay(authorizationDecreaseDelayChangeInitiated)
13051323
{
13061324
emit AuthorizationDecreaseDelayUpdated(newAuthorizationDecreaseDelay);
1325+
(
1326+
uint96 minimumAuthorization,
1327+
uint64 authorizationDecreaseChangePeriod,
1328+
1329+
) = randomBeacon.authorizationParameters();
13071330
// slither-disable-next-line reentrancy-no-eth
13081331
randomBeacon.updateAuthorizationParameters(
1309-
randomBeacon.minimumAuthorization(),
1310-
newAuthorizationDecreaseDelay
1332+
minimumAuthorization,
1333+
newAuthorizationDecreaseDelay,
1334+
authorizationDecreaseChangePeriod
13111335
);
13121336
authorizationDecreaseDelayChangeInitiated = 0;
13131337
newAuthorizationDecreaseDelay = 0;
13141338
}
13151339

1340+
/// @notice Begins the authorization decrease change period update process.
1341+
/// @dev Can be called only by the contract owner.
1342+
/// @param _newAuthorizationDecreaseChangePeriod New authorization decrease change period
1343+
function beginAuthorizationDecreaseChangePeriodUpdate(
1344+
uint64 _newAuthorizationDecreaseChangePeriod
1345+
) external onlyOwner {
1346+
/* solhint-disable not-rely-on-time */
1347+
newAuthorizationDecreaseChangePeriod = _newAuthorizationDecreaseChangePeriod;
1348+
authorizationDecreaseChangePeriodChangeInitiated = block.timestamp;
1349+
emit AuthorizationDecreaseChangePeriodUpdateStarted(
1350+
_newAuthorizationDecreaseChangePeriod,
1351+
block.timestamp
1352+
);
1353+
/* solhint-enable not-rely-on-time */
1354+
}
1355+
1356+
/// @notice Finalizes the authorization decrease change period update process.
1357+
/// @dev Can be called only by the contract owner, after the governance
1358+
/// delay elapses.
1359+
function finalizeAuthorizationDecreaseChangePeriodUpdate()
1360+
external
1361+
onlyOwner
1362+
onlyAfterGovernanceDelay(
1363+
authorizationDecreaseChangePeriodChangeInitiated
1364+
)
1365+
{
1366+
emit AuthorizationDecreaseChangePeriodUpdated(
1367+
newAuthorizationDecreaseChangePeriod
1368+
);
1369+
(
1370+
uint96 minimumAuthorization,
1371+
uint64 authorizationDecreaseDelay,
1372+
1373+
) = randomBeacon.authorizationParameters();
1374+
// slither-disable-next-line reentrancy-no-eth
1375+
randomBeacon.updateAuthorizationParameters(
1376+
minimumAuthorization,
1377+
authorizationDecreaseDelay,
1378+
newAuthorizationDecreaseChangePeriod
1379+
);
1380+
authorizationDecreaseChangePeriodChangeInitiated = 0;
1381+
newAuthorizationDecreaseChangePeriod = 0;
1382+
}
1383+
13161384
/// @notice Set authorization for requesters that can request a relay
13171385
/// entry. It can be done by the governance only.
13181386
/// @param requester Requester, can be a contract or EOA
@@ -1499,6 +1567,9 @@ contract RandomBeaconGovernance is Ownable {
14991567
return getRemainingChangeTime(minimumAuthorizationChangeInitiated);
15001568
}
15011569

1570+
/// @notice Get the time remaining until the authorization decrease delay
1571+
/// can be updated.
1572+
/// @return Remaining time in seconds.
15021573
function getRemainingAuthorizationDecreaseDelayUpdateTime()
15031574
external
15041575
view
@@ -1508,6 +1579,20 @@ contract RandomBeaconGovernance is Ownable {
15081579
getRemainingChangeTime(authorizationDecreaseDelayChangeInitiated);
15091580
}
15101581

1582+
/// @notice Get the time remaining until the authorization decrease change
1583+
/// period can be updated.
1584+
/// @return Remaining time in seconds.
1585+
function getRemainingAuthorizationDecreaseChangePeriodUpdateTime()
1586+
external
1587+
view
1588+
returns (uint256)
1589+
{
1590+
return
1591+
getRemainingChangeTime(
1592+
authorizationDecreaseChangePeriodChangeInitiated
1593+
);
1594+
}
1595+
15111596
/// @notice Get the time remaining until the sortition pool rewards ban
15121597
/// duration can be updated.
15131598
/// @return Remaining time in seconds.

0 commit comments

Comments
 (0)