Skip to content

Commit 518d8a8

Browse files
committed
fix(hardhat, distributor v5): gracefully handle timestamp underflow
1 parent 5ba8531 commit 518d8a8

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

packages/hardhat/contracts/claim/distributor-v5/ContinuousVestingMerkleDistributor.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.21;
33

4+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
45
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
56
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
67
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -142,7 +143,7 @@ contract ContinuousVestingMerkleDistributor_v_5_0 is Initializable, ContinuousVe
142143
require(answeredInRound > 0, "answer == 0");
143144
require(updatedAt > 0, "round not complete");
144145
require(answeredInRound >= roundID, "stale price");
145-
require(updatedAt < block.timestamp - heartbeat, "stale price");
146+
require(updatedAt > Math.max(block.timestamp, heartbeat) - heartbeat, "stale price");
146147

147148
return uint256(_price);
148149
}

packages/hardhat/contracts/claim/distributor-v5/ContinuousVestingMerkleDistributorFactory.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.21;
33

4+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
45
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
56
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
67
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -186,7 +187,7 @@ contract ContinuousVestingMerkleDistributorFactory_v_5_0 {
186187
require(answeredInRound > 0, "answer == 0");
187188
require(updatedAt > 0, "round not complete");
188189
require(answeredInRound >= roundID, "stale price");
189-
require(updatedAt < block.timestamp - heartbeat, "stale price");
190+
require(updatedAt > Math.max(block.timestamp, heartbeat) - heartbeat, "stale price");
190191

191192
return uint256(_price);
192193
}

packages/hardhat/contracts/claim/distributor-v5/TrancheVestingMerkleDistributor.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.21;
33

4+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
45
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
56
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
67
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -143,7 +144,7 @@ contract TrancheVestingMerkleDistributor_v_5_0 is
143144
require(answeredInRound > 0, "answer == 0");
144145
require(updatedAt > 0, "round not complete");
145146
require(answeredInRound >= roundID, "stale price");
146-
require(updatedAt < block.timestamp - heartbeat, "stale price");
147+
require(updatedAt > Math.max(block.timestamp, heartbeat) - heartbeat, "stale price");
147148

148149
return uint256(_price);
149150
}

packages/hardhat/contracts/claim/distributor-v5/TrancheVestingMerkleDistributorFactory.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.21;
33

4+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
45
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
56
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
67
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -174,7 +175,7 @@ contract TrancheVestingMerkleDistributorFactory_v_5_0 {
174175
require(answeredInRound > 0, "answer == 0");
175176
require(updatedAt > 0, "round not complete");
176177
require(answeredInRound >= roundID, "stale price");
177-
require(updatedAt < block.timestamp - heartbeat, "stale price");
178+
require(updatedAt > Math.max(block.timestamp, heartbeat) - heartbeat, "stale price");
178179

179180
return uint256(_price);
180181
}

0 commit comments

Comments
 (0)