Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gas optimization (OZ N-02) #938

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity ^0.7.6;

import { SafeMathUpgradeable } from "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";

import { Governed } from "../governance/Governed.sol";
import { IRewardsManager } from "../rewards/IRewardsManager.sol";

Expand All @@ -17,8 +15,6 @@ import { IRewardsManager } from "../rewards/IRewardsManager.sol";
* Governor can transfer ownership to a new governor.
*/
contract SubgraphAvailabilityManager is Governed {
using SafeMathUpgradeable for uint256;

// -- Immutable --

/// @notice Number of oracles
Expand Down Expand Up @@ -106,14 +102,11 @@ contract SubgraphAvailabilityManager is Governed {
) {
require(_governor != address(0), "SAM: governor must be set");
require(_rewardsManager != address(0), "SAM: rewardsManager must be set");
require(
_executionThreshold >= NUM_ORACLES.div(2).add(1),
"SAM: executionThreshold too low"
);
require(_executionThreshold >= (NUM_ORACLES / 2) + 1, "SAM: executionThreshold too low");
require(_executionThreshold <= NUM_ORACLES, "SAM: executionThreshold too high");

// Oracles should not be address zero
for (uint256 i = 0; i < _oracles.length; i++) {
for (uint256 i; i < _oracles.length; i++) {
address oracle = _oracles[i];
require(oracle != address(0), "SAM: oracle cannot be address zero");
oracles[i] = oracle;
Expand Down Expand Up @@ -183,7 +176,7 @@ contract SubgraphAvailabilityManager is Governed {
uint256 _oracleIndex
) external onlyOracle(_oracleIndex) {
require(_subgraphDeploymentID.length == _deny.length, "!length");
for (uint256 i = 0; i < _subgraphDeploymentID.length; i++) {
for (uint256 i; i < _subgraphDeploymentID.length; i++) {
_vote(_subgraphDeploymentID[i], _deny[i], _oracleIndex);
}
}
Expand Down Expand Up @@ -226,7 +219,7 @@ contract SubgraphAvailabilityManager is Governed {
* @return True if execution threshold is reached
*/
function checkVotes(bytes32 _subgraphDeploymentID, bool _deny) public view returns (bool) {
uint256 votes = 0;
uint256 votes;

// timeframe for a vote to be valid
uint256 voteTimeValidity = block.timestamp - voteTimeLimit;
Expand All @@ -236,7 +229,7 @@ contract SubgraphAvailabilityManager is Governed {
? lastDenyVote[currentNonce][_subgraphDeploymentID]
: lastAllowVote[currentNonce][_subgraphDeploymentID];

for (uint256 i = 0; i < NUM_ORACLES; i++) {
for (uint256 i; i < NUM_ORACLES; i++) {
// check if vote is within the vote time limit
if (lastVoteForSubgraph[i] > voteTimeValidity) {
votes++;
Expand Down