Skip to content

Commit ef22657

Browse files
committed
Restrict _sinceTime to uint64 and add assertion for checkpointExists
1 parent b4d61ae commit ef22657

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

contracts/contract/megapool/RocketMegapoolDelegate.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ contract RocketMegapoolDelegate is RocketMegapoolDelegateBase, RocketMegapoolDel
507507
if (lastDistributionTime == 0) return (_amount, 0, 0, 0);
508508
// Calculate split based on capital ratio and average commission since last distribute
509509
RocketNetworkRevenuesInterface rocketNetworkRevenues = RocketNetworkRevenuesInterface(getContractAddress("rocketNetworkRevenues"));
510-
(, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare) = rocketNetworkRevenues.calculateSplit(lastDistributionTime);
511-
uint256 averageCapitalRatio = rocketNetworkRevenues.getNodeAverageCapitalRatioSince(nodeAddress, lastDistributionTime);
510+
uint64 lastDistributionTime64 = uint64(lastDistributionTime);
511+
(, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare) = rocketNetworkRevenues.calculateSplit(lastDistributionTime64);
512+
uint256 averageCapitalRatio = rocketNetworkRevenues.getNodeAverageCapitalRatioSince(nodeAddress, lastDistributionTime64);
512513
// Sanity check input values
513514
require(averageCapitalRatio >= calcBase, "Invalid average capital ratio");
514515
require(voterShare + protocolDAOShare + rethShare <= calcBase, "Invalid shares");

contracts/contract/megapool/RocketMegapoolPenalties.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ contract RocketMegapoolPenalties is RocketBase, RocketMegapoolPenaltiesInterface
137137
if (block.timestamp > penaltyMaximumPeriod) {
138138
earlierTime = block.timestamp - penaltyMaximumPeriod;
139139
}
140-
uint256 earlierRunningTotal = rocketNetworkSnapshotsTime.lookup(penaltyKey, uint32(earlierTime));
140+
uint256 earlierRunningTotal = rocketNetworkSnapshotsTime.lookup(penaltyKey, uint64(earlierTime));
141141
// Get current running total
142142
(,, uint192 currentRunningTotal) = rocketNetworkSnapshotsTime.latest(penaltyKey);
143143
// Prevent the running penalty total from exceeding the maximum amount

contracts/contract/network/RocketNetworkRevenues.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ contract RocketNetworkRevenues is RocketBase, RocketNetworkRevenuesInterface {
105105

106106
/// @notice Calculates the time-weighted average revenue split values between the supplied timestamp and now
107107
/// @param _sinceTime The starting block timestamp for the calculation
108-
function calculateSplit(uint256 _sinceTime) external override view returns (uint256 nodeShare, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare) {
108+
function calculateSplit(uint64 _sinceTime) external override view returns (uint256 nodeShare, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare) {
109109
RocketNetworkSnapshotsTimeInterface rocketNetworkSnapshotsTime = RocketNetworkSnapshotsTimeInterface(getContractAddress("rocketNetworkSnapshotsTime"));
110110
if (_sinceTime == block.timestamp) {
111111
nodeShare = _getCurrentShare(rocketNetworkSnapshotsTime, nodeShareKey, true);
@@ -150,7 +150,7 @@ contract RocketNetworkRevenues is RocketBase, RocketNetworkRevenuesInterface {
150150
/// @notice Returns the average capital ratio of the given node operator since a given block
151151
/// @param _nodeAddress Address of the node operator to query the value for
152152
/// @param _sinceTime The timestamp to calculate the average since
153-
function getNodeAverageCapitalRatioSince(address _nodeAddress, uint256 _sinceTime) external override view returns (uint256) {
153+
function getNodeAverageCapitalRatioSince(address _nodeAddress, uint64 _sinceTime) external override view returns (uint256) {
154154
RocketNetworkSnapshotsTimeInterface rocketNetworkSnapshotsTime = RocketNetworkSnapshotsTimeInterface(getContractAddress("rocketNetworkSnapshotsTime"));
155155
bytes32 key = keccak256(abi.encodePacked("node.capital.ratio", _nodeAddress));
156156
if (_sinceTime == block.timestamp) {
@@ -162,7 +162,7 @@ contract RocketNetworkRevenues is RocketBase, RocketNetworkRevenuesInterface {
162162
}
163163

164164
/// @notice Calculates the time-weighted average since a given block
165-
function _getAverageSince(RocketNetworkSnapshotsTimeInterface _rocketNetworkSnapshotsTime, uint256 _sinceTime, bytes32 _key, bool _mustExist) internal view returns (uint256) {
165+
function _getAverageSince(RocketNetworkSnapshotsTimeInterface _rocketNetworkSnapshotsTime, uint64 _sinceTime, bytes32 _key, bool _mustExist) internal view returns (uint256) {
166166
(bool checkpointExists, uint64 checkpointTime, uint192 checkpointValue) = _rocketNetworkSnapshotsTime.latest(_key);
167167
require(!_mustExist || checkpointExists, "Snapshot does not exist");
168168
if (!checkpointExists) return 0;
@@ -178,6 +178,7 @@ contract RocketNetworkRevenues is RocketBase, RocketNetworkRevenuesInterface {
178178
uint256 currentAccum = uint256(checkpointValue) + (valueAtTime * durationSinceCheckpoint);
179179
// Calculate the accumulator at _sinceTime
180180
(checkpointExists, checkpointTime, checkpointValue) = _rocketNetworkSnapshotsTime.lookupCheckpoint(_key, uint64(_sinceTime));
181+
require(!_mustExist || checkpointExists, "Snapshot does not exist");
181182
valueKey = bytes32(uint256(_key) + checkpointTime);
182183
valueAtTime = getUint(valueKey);
183184
durationSinceCheckpoint = (_sinceTime - checkpointTime);

contracts/interface/network/RocketNetworkRevenuesInterface.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface RocketNetworkRevenuesInterface {
99
function setNodeShare(uint256 _newShare) external;
1010
function setVoterShare(uint256 _newShare) external;
1111
function setProtocolDAOShare(uint256 _newShare) external;
12-
function calculateSplit(uint256 _sinceBlock) external view returns (uint256 nodeShare, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare);
12+
function calculateSplit(uint64 _sinceTime) external view returns (uint256 nodeShare, uint256 voterShare, uint256 protocolDAOShare, uint256 rethShare);
1313
function setNodeCapitalRatio(address _nodeAddress, uint256 _value) external;
1414
function getNodeCapitalRatio(address _nodeAddress) external view returns (uint256);
15-
function getNodeAverageCapitalRatioSince(address _nodeAddress, uint256 _sinceBlock) external view returns (uint256);
15+
function getNodeAverageCapitalRatioSince(address _nodeAddress, uint64 _sinceTime) external view returns (uint256);
1616
}

0 commit comments

Comments
 (0)