|
| 1 | +// ▓▓▌ ▓▓ ▐▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄ |
| 2 | +// ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▌▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ |
| 3 | +// ▓▓▓▓▓▓ ▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓ ▐▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓ |
| 4 | +// ▓▓▓▓▓▓▄▄▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▄▄▄▄ ▓▓▓▓▓▓▄▄▄▄ ▐▓▓▓▓▓▌ ▐▓▓▓▓▓▓ |
| 5 | +// ▓▓▓▓▓▓▓▓▓▓▓▓▓▀ ▐▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ |
| 6 | +// ▓▓▓▓▓▓▀▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓▀▀▀▀ ▓▓▓▓▓▓▀▀▀▀ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀ |
| 7 | +// ▓▓▓▓▓▓ ▀▓▓▓▓▓▓▄ ▐▓▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓ ▐▓▓▓▓▓▌ |
| 8 | +// ▓▓▓▓▓▓▓▓▓▓ █▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ |
| 9 | +// ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ |
| 10 | +// |
| 11 | +// Trust math, not hardware. |
| 12 | + |
| 13 | +// SPDX-License-Identifier: MIT |
| 14 | + |
| 15 | +pragma solidity ^0.8.6; |
| 16 | + |
| 17 | +import "@openzeppelin/contracts/access/Ownable.sol"; |
| 18 | + |
| 19 | +/// @title Random beacon |
| 20 | +/// @notice Random beacon contract which represents the on-chain part of the |
| 21 | +/// random beacon functionality |
| 22 | +/// @dev Should be owned by the random beacon governance contract |
| 23 | +contract RandomBeacon is Ownable { |
| 24 | + /// @notice Relay request fee in T |
| 25 | + uint256 public relayRequestFee; |
| 26 | + |
| 27 | + /// @notice The number of blocks for a member to become eligible to submit |
| 28 | + /// relay entry |
| 29 | + uint256 public relayEntrySubmissionEligibilityDelay; |
| 30 | + |
| 31 | + /// @notice Hard timeout for a relay entry |
| 32 | + uint256 public relayEntryHardTimeout; |
| 33 | + |
| 34 | + /// @notice Callback gas limit |
| 35 | + uint256 public callbackGasLimit; |
| 36 | + |
| 37 | + /// @notice The frequency of a new group creation |
| 38 | + uint256 public groupCreationFrequency; |
| 39 | + |
| 40 | + /// @notice Group lifetime |
| 41 | + uint256 public groupLifetime; |
| 42 | + |
| 43 | + /// @notice The number of blocks for which a DKG result can be challenged |
| 44 | + uint256 public dkgResultChallengePeriodLength; |
| 45 | + |
| 46 | + /// @notice The number of blocks for a member to become eligible to submit |
| 47 | + /// DKG result |
| 48 | + uint256 public dkgSubmissionEligibilityDelay; |
| 49 | + |
| 50 | + /// @notice Reward for submitting DKG result |
| 51 | + uint256 public dkgResultSubmissionReward; |
| 52 | + |
| 53 | + /// @notice Reward for unlocking the sortition pool if DKG timed out |
| 54 | + uint256 public sortitionPoolUnlockingReward; |
| 55 | + |
| 56 | + /// @notice Slashing amount for not submitting relay entry |
| 57 | + uint256 public relayEntrySubmissionFailureSlashingAmount; |
| 58 | + |
| 59 | + /// @notice Slashing amount for submitting malicious DKG result |
| 60 | + uint256 public maliciousDkgResultSlashingAmount; |
| 61 | + |
| 62 | + event RelayEntryParametersUpdated( |
| 63 | + uint256 relayRequestFee, |
| 64 | + uint256 relayEntrySubmissionEligibilityDelay, |
| 65 | + uint256 RelayEntryHardTimeout, |
| 66 | + uint256 callbackGasLimit |
| 67 | + ); |
| 68 | + |
| 69 | + event GroupCreationParametersUpdated( |
| 70 | + uint256 groupCreationFrequency, |
| 71 | + uint256 groupLifetime, |
| 72 | + uint256 dkgResultChallengePeriodLength, |
| 73 | + uint256 dkgSubmissionEligibilityDelay |
| 74 | + ); |
| 75 | + |
| 76 | + event RewardParametersUpdated( |
| 77 | + uint256 dkgResultSubmissionReward, |
| 78 | + uint256 sortitionPoolUnlockingReward |
| 79 | + ); |
| 80 | + |
| 81 | + event SlashingParametersUpdated( |
| 82 | + uint256 relayEntrySubmissionFailureSlashingAmount, |
| 83 | + uint256 maliciousDkgResultSlashingAmount |
| 84 | + ); |
| 85 | + |
| 86 | + /// @notice Updates the values of relay entry parameters |
| 87 | + /// @dev Can be called only by the contract owner, which should be the |
| 88 | + /// random beacon governance contract |
| 89 | + /// @param _relayRequestFee New relay request fee |
| 90 | + /// @param _relayEntrySubmissionEligibilityDelay New relay entry submission |
| 91 | + /// eligibility delay |
| 92 | + /// @param _relayEntryHardTimeout New relay entry hard timeout |
| 93 | + /// @param _callbackGasLimit New callback gas limit |
| 94 | + function updateRelayEntryParameters( |
| 95 | + uint256 _relayRequestFee, |
| 96 | + uint256 _relayEntrySubmissionEligibilityDelay, |
| 97 | + uint256 _relayEntryHardTimeout, |
| 98 | + uint256 _callbackGasLimit |
| 99 | + ) external onlyOwner { |
| 100 | + relayRequestFee = _relayRequestFee; |
| 101 | + relayEntrySubmissionEligibilityDelay = _relayEntrySubmissionEligibilityDelay; |
| 102 | + relayEntryHardTimeout = _relayEntryHardTimeout; |
| 103 | + callbackGasLimit = _callbackGasLimit; |
| 104 | + emit RelayEntryParametersUpdated( |
| 105 | + relayRequestFee, |
| 106 | + relayEntrySubmissionEligibilityDelay, |
| 107 | + relayEntryHardTimeout, |
| 108 | + callbackGasLimit |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + /// @notice Updates the values of group creation parameters |
| 113 | + /// @dev Can be called only by the contract owner, which should be the |
| 114 | + /// random beacon governance contract |
| 115 | + /// @param _groupCreationFrequency New group creation frequency |
| 116 | + /// @param _groupLifetime New group lifetime |
| 117 | + /// @param _dkgResultChallengePeriodLength New DKG result challenge period |
| 118 | + /// length |
| 119 | + /// @param _dkgSubmissionEligibilityDelay New DKG submission eligibility |
| 120 | + /// delay |
| 121 | + function updateGroupCreationParameters( |
| 122 | + uint256 _groupCreationFrequency, |
| 123 | + uint256 _groupLifetime, |
| 124 | + uint256 _dkgResultChallengePeriodLength, |
| 125 | + uint256 _dkgSubmissionEligibilityDelay |
| 126 | + ) external onlyOwner { |
| 127 | + groupCreationFrequency = _groupCreationFrequency; |
| 128 | + groupLifetime = _groupLifetime; |
| 129 | + dkgResultChallengePeriodLength = _dkgResultChallengePeriodLength; |
| 130 | + dkgSubmissionEligibilityDelay = _dkgSubmissionEligibilityDelay; |
| 131 | + emit GroupCreationParametersUpdated( |
| 132 | + groupCreationFrequency, |
| 133 | + groupLifetime, |
| 134 | + dkgResultChallengePeriodLength, |
| 135 | + dkgSubmissionEligibilityDelay |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + /// @notice Updates the values of reward parameters |
| 140 | + /// @dev Can be called only by the contract owner, which should be the |
| 141 | + /// random beacon governance contract |
| 142 | + /// @param _dkgResultSubmissionReward New DKG result submission reward |
| 143 | + /// @param _sortitionPoolUnlockingReward New sortition pool unlocking reward |
| 144 | + function updateRewardParameters( |
| 145 | + uint256 _dkgResultSubmissionReward, |
| 146 | + uint256 _sortitionPoolUnlockingReward |
| 147 | + ) external onlyOwner { |
| 148 | + dkgResultSubmissionReward = _dkgResultSubmissionReward; |
| 149 | + sortitionPoolUnlockingReward = _sortitionPoolUnlockingReward; |
| 150 | + emit RewardParametersUpdated( |
| 151 | + dkgResultSubmissionReward, |
| 152 | + sortitionPoolUnlockingReward |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + /// @notice Updates the values of slashing parameters |
| 157 | + /// @dev Can be called only by the contract owner, which should be the |
| 158 | + /// random beacon governance contract |
| 159 | + /// @param _relayEntrySubmissionFailureSlashingAmount New relay entry |
| 160 | + /// submission failure amount |
| 161 | + /// @param _maliciousDkgResultSlashingAmount New malicious DKG result |
| 162 | + /// slashing amount |
| 163 | + function updateSlashingParameters( |
| 164 | + uint256 _relayEntrySubmissionFailureSlashingAmount, |
| 165 | + uint256 _maliciousDkgResultSlashingAmount |
| 166 | + ) external onlyOwner { |
| 167 | + relayEntrySubmissionFailureSlashingAmount = _relayEntrySubmissionFailureSlashingAmount; |
| 168 | + maliciousDkgResultSlashingAmount = _maliciousDkgResultSlashingAmount; |
| 169 | + emit SlashingParametersUpdated( |
| 170 | + relayEntrySubmissionFailureSlashingAmount, |
| 171 | + maliciousDkgResultSlashingAmount |
| 172 | + ); |
| 173 | + } |
| 174 | +} |
0 commit comments