Skip to content

Commit 586006d

Browse files
committed
refactor: renamed RNG into IRNG
1 parent 1ff6097 commit 586006d

10 files changed

+27
-25
lines changed

contracts/src/arbitration/SortitionModule.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract SortitionModule is SortitionModuleBase, UUPSProxiable, Initializable {
3737
KlerosCore _core,
3838
uint256 _minStakingTime,
3939
uint256 _maxDrawingTime,
40-
RNG _rng
40+
IRNG _rng
4141
) external reinitializer(1) {
4242
super._initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng);
4343
}

contracts/src/arbitration/SortitionModuleBase.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pragma solidity 0.8.24;
1313
import "./KlerosCore.sol";
1414
import "./interfaces/ISortitionModule.sol";
1515
import "./interfaces/IDisputeKit.sol";
16-
import "../rng/RNG.sol";
16+
import "../rng/IRNG.sol";
1717
import "../libraries/Constants.sol";
1818

1919
/// @title SortitionModuleBase
@@ -64,7 +64,7 @@ abstract contract SortitionModuleBase is ISortitionModule {
6464
uint256 public maxDrawingTime; // The time after which the phase can be switched back to Staking.
6565
uint256 public lastPhaseChange; // The last time the phase was changed.
6666
uint256 public disputesWithoutJurors; // The number of disputes that have not finished drawing jurors.
67-
RNG public rng; // The random number generator.
67+
IRNG public rng; // The random number generator.
6868
uint256 public randomNumber; // Random number returned by RNG.
6969
uint256 public rngLookahead; // DEPRECATED
7070
uint256 public delayedStakeWriteIndex; // The index of the last `delayedStake` item that was written to the array. 0 index is skipped.
@@ -93,7 +93,7 @@ abstract contract SortitionModuleBase is ISortitionModule {
9393
KlerosCore _core,
9494
uint256 _minStakingTime,
9595
uint256 _maxDrawingTime,
96-
RNG _rng
96+
IRNG _rng
9797
) internal {
9898
governor = _governor;
9999
core = _core;
@@ -136,7 +136,7 @@ abstract contract SortitionModuleBase is ISortitionModule {
136136

137137
/// @dev Changes the `rng` storage variable.
138138
/// @param _rng The new random number generator.
139-
function changeRandomNumberGenerator(RNG _rng) external onlyByGovernor {
139+
function changeRandomNumberGenerator(IRNG _rng) external onlyByGovernor {
140140
rng = _rng;
141141
if (phase == Phase.generating) {
142142
rng.requestRandomness();

contracts/src/arbitration/SortitionModuleNeo.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contract SortitionModuleNeo is SortitionModuleBase, UUPSProxiable, Initializable
4747
KlerosCore _core,
4848
uint256 _minStakingTime,
4949
uint256 _maxDrawingTime,
50-
RNG _rng,
50+
IRNG _rng,
5151
uint256 _maxStakePerJuror,
5252
uint256 _maxTotalStaked
5353
) external reinitializer(2) {

contracts/src/rng/BlockhashRNG.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
pragma solidity 0.8.24;
44

5-
import "./RNG.sol";
5+
import "./IRNG.sol";
66

77
/// @title Random Number Generator using blockhash with fallback.
88
/// @dev
99
/// Random Number Generator returning the blockhash with a fallback behaviour.
1010
/// In case no one called it within the 256 blocks, it returns the previous blockhash.
1111
/// This contract must be used when returning 0 is a worse failure mode than returning another blockhash.
1212
/// Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.
13-
contract BlockHashRNG is RNG {
13+
contract BlockHashRNG is IRNG {
1414
uint256 public immutable lookahead; // Minimal block distance between requesting and obtaining a random number.
1515
uint256 public requestBlock; // Block number of the current request
1616
mapping(uint256 block => uint256 number) public randomNumbers; // randomNumbers[block] is the random number for this block, 0 otherwise.

contracts/src/rng/ChainlinkRNG.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pragma solidity 0.8.24;
55
import {VRFConsumerBaseV2Plus, IVRFCoordinatorV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol";
66
import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol";
77

8-
import "./RNG.sol";
8+
import "./IRNG.sol";
99

1010
/// @title Random Number Generator that uses Chainlink VRF v2.5
1111
/// https://blog.chain.link/introducing-vrf-v2-5/
12-
contract ChainlinkRNG is RNG, VRFConsumerBaseV2Plus {
12+
contract ChainlinkRNG is IRNG, VRFConsumerBaseV2Plus {
1313
// ************************************* //
1414
// * Storage * //
1515
// ************************************* //

contracts/src/rng/RNG.sol contracts/src/rng/IRNG.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
pragma solidity 0.8.24;
44

5-
interface RNG {
5+
/// @title Random Number Generator interface
6+
interface IRNG {
67
/// @dev Request a random number.
78
function requestRandomness() external;
89

contracts/src/rng/IncrementalNG.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/// @dev A Random Number Generator which returns a number incremented by 1 each time. Useful as a fallback method.
66

77
pragma solidity 0.8.24;
8-
import "./RNG.sol";
8+
import "./IRNG.sol";
99

10-
contract IncrementalNG is RNG {
10+
contract IncrementalNG is IRNG {
1111
uint256 public number;
1212

1313
constructor(uint256 _start) {

contracts/src/rng/RNGWithFallback.sol

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.24;
33

4-
import "./RNG.sol";
4+
import "./IRNG.sol";
55

66
/// @title RNG with fallback mechanism
77
/// @notice Uses multiple RNG implementations with automatic fallback if default RNG does not respond passed a timeout.
8-
contract RNGWithFallback is RNG {
8+
contract RNGWithFallback is IRNG {
99
uint256 public constant DEFAULT_RNG = 0;
1010

1111
// ************************************* //
1212
// * Storage * //
1313
// ************************************* //
1414

1515
address public governor; // Governor address
16-
RNG[] public rngs; // List of RNG implementations
16+
IRNG[] public rngs; // List of RNG implementations
1717
uint256 public fallbackTimeout; // Number of blocks to wait before falling back to next RNG
1818
uint256 public requestBlock; // Block number of the current request
1919
uint256 public currentRngIndex; // Index of the current RNG
@@ -35,14 +35,14 @@ contract RNGWithFallback is RNG {
3535

3636
/// @param _governor Governor address
3737
/// @param _fallbackTimeout Number of blocks to wait before falling back to next RNG
38-
/// @param _initialRng The default RNG
39-
constructor(address _governor, uint256 _fallbackTimeout, RNG _initialRng) {
40-
require(address(_initialRng) != address(0), "Invalid default RNG");
38+
/// @param _defaultRng The default RNG
39+
constructor(address _governor, uint256 _fallbackTimeout, IRNG _defaultRng) {
40+
require(address(_defaultRng) != address(0), "Invalid default RNG");
4141
require(_fallbackTimeout > 0, "Invalid fallback timeout");
4242

4343
governor = _governor;
4444
fallbackTimeout = _fallbackTimeout;
45-
rngs.push(_initialRng);
45+
rngs.push(_defaultRng);
4646
}
4747

4848
// ************************************* //
@@ -110,7 +110,7 @@ contract RNGWithFallback is RNG {
110110

111111
/// @dev Change the default RNG
112112
/// @param _newDefaultRng Address of the new default RNG
113-
function changeDefaultRng(RNG _newDefaultRng) external onlyByGovernor {
113+
function changeDefaultRng(IRNG _newDefaultRng) external onlyByGovernor {
114114
require(address(_newDefaultRng) != address(0), "Invalid RNG");
115115
rngs[DEFAULT_RNG] = _newDefaultRng;
116116
emit RNGDefaultChanged(address(_newDefaultRng));
@@ -121,7 +121,7 @@ contract RNGWithFallback is RNG {
121121

122122
/// @dev Add a new RNG fallback
123123
/// @param _newFallbackRng Address of the new RNG fallback
124-
function addRngFallback(RNG _newFallbackRng) external onlyByGovernor {
124+
function addRngFallback(IRNG _newFallbackRng) external onlyByGovernor {
125125
require(address(_newFallbackRng) != address(0), "Invalid RNG");
126126
rngs.push(_newFallbackRng);
127127
emit RNGFallbackAdded(address(_newFallbackRng));
@@ -136,7 +136,7 @@ contract RNGWithFallback is RNG {
136136
currentRngIndex = DEFAULT_RNG;
137137
}
138138

139-
RNG removedRng = rngs[rngs.length - 1];
139+
IRNG removedRng = rngs[rngs.length - 1];
140140
rngs.pop();
141141
emit RNGFallbackRemoved(address(removedRng));
142142
}

contracts/src/rng/RandomizerRNG.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
pragma solidity 0.8.24;
44

5-
import "./RNG.sol";
5+
import "./IRNG.sol";
66
import "./IRandomizer.sol";
77
import "../proxy/UUPSProxiable.sol";
88
import "../proxy/Initializable.sol";
99

1010
/// @title Random Number Generator that uses Randomizer.ai
1111
/// https://randomizer.ai/
12-
contract RandomizerRNG is RNG, UUPSProxiable, Initializable {
12+
contract RandomizerRNG is IRNG, UUPSProxiable, Initializable {
1313
// ************************************* //
1414
// * Storage * //
1515
// ************************************* //

cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"IERC",
3535
"Initializable",
3636
"ipfs",
37+
"IRNG",
3738
"kleros",
3839
"linguo",
3940
"Numberish",

0 commit comments

Comments
 (0)