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

Declare keccak variables as immutable #105

Closed
code423n4 opened this issue Nov 29, 2021 · 1 comment
Closed

Declare keccak variables as immutable #105

code423n4 opened this issue Nov 29, 2021 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) invalid This doesn't seem right sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

pmerkleplant

Vulnerability details

Impact

Access roles marked as constant results in computing the keccak operation
each time the variables are used, which increases gas costs.

Changing the variables to immutable results in computing the hash only
once on deployment, leading to gas savings.

For more information, see ethereum/solidity#9232 (comment).

The following declarations could be refactored:

./MovingAverage.sol:25:  bytes32 public constant UPDATER_ROLE = keccak256("UPDATER_ROLE");
./MaltDataLab.sol:28:  bytes32 public constant UPDATER_ROLE = keccak256("UPDATER_ROLE");
./Auction.sol:72:  bytes32 public constant AUCTION_AMENDER_ROLE = keccak256("AUCTION_AMENDER_ROLE");
./ERC20Permit.sol:16:  bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
./ERC20Permit.sol:17:  bytes32 public constant TRANSFER_TYPEHASH = keccak256("Transfer(address owner,address to,uint256 value,uint256 nonce,uint256 deadline)");
./Permissions.sol:17:  bytes32 public constant TIMELOCK_ROLE = keccak256("TIMELOCK_ROLE");
./Permissions.sol:18:  bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
./Permissions.sol:19:  bytes32 public constant GOVERNOR_ROLE = keccak256("GOVERNOR_ROLE");
./Permissions.sol:22:  bytes32 public constant MONETARY_BURNER_ROLE = keccak256("MONETARY_BURNER_ROLE");
./Permissions.sol:23:  bytes32 public constant MONETARY_MINTER_ROLE = keccak256("MONETARY_MINTER_ROLE");
./Permissions.sol:26:  bytes32 public constant STABILIZER_NODE_ROLE = keccak256("STABILIZER_NODE_ROLE");
./Permissions.sol:27:  bytes32 public constant LIQUIDITY_MINE_ROLE = keccak256("LIQUIDITY_MINE_ROLE");
./Permissions.sol:28:  bytes32 public constant AUCTION_ROLE = keccak256("AUCTION_ROLE");
./Permissions.sol:29:  bytes32 public constant REWARD_THROTTLE_ROLE = keccak256("REWARD_THROTTLE_ROLE");
./AuctionParticipant.sol:15:  bytes32 public constant IMPLIED_COLLATERAL_SERVICE_ROLE = keccak256("IMPLIED_COLLATERAL_SERVICE_ROLE");
./AbstractRewardMine.sol:16:  bytes32 public constant REWARD_MANAGER_ROLE = keccak256("REWARD_MANAGER_ROLE");
./AbstractRewardMine.sol:17:  bytes32 public constant MINING_SERVICE_ROLE = keccak256("MINING_SERVICE_ROLE");
./MiningService.sol:20:  bytes32 public constant REINVESTOR_ROLE = keccak256("REINVESTOR_ROLE");
./MiningService.sol:21:  bytes32 public constant BONDING_ROLE = keccak256("BONDING_ROLE");
./RewardSystem/RewardDistributor.sol:36:  bytes32 public constant THROTTLER_ROLE = keccak256("THROTTLER_ROLE");
./RewardSystem/RewardDistributor.sol:37:  bytes32 public constant REWARD_MINE_ROLE = keccak256("REWARD_MINE_ROLE");
./RewardSystem/RewardDistributor.sol:38:  bytes32 public constant FOCAL_LENGTH_UPDATER_ROLE = keccak256("FOCAL_LENGTH_UPDATER_ROLE");
./DexHandlers/UniswapHandler.sol:24:  bytes32 public constant BUYER_ROLE = keccak256("BUYER_ROLE");

Tools used

grep -rn "keccak256(" .

@GalloDaSballo
Copy link
Collaborator

Finding is invalid as per: https://twitter.com/TomFrench_eth/status/1476940064122826756

@GalloDaSballo GalloDaSballo added the invalid This doesn't seem right label Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) invalid This doesn't seem right sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants