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

Use of constant keccak variables results in extra hashing (and so gas) #17

Closed
code423n4 opened this issue Nov 25, 2021 · 2 comments
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) invalid This doesn't seem right

Comments

@code423n4
Copy link
Contributor

Handle

defsec

Vulnerability details

Impact

That would Increase gas costs on all privileged operations.

Proof of Concept

The following role variables are marked as constant.

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/MiningService.sol#L20

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/RewardSystem/RewardDistributor.sol#L37

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/AbstractRewardMine.sol#L16

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/AuctionParticipant.sol#L15

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/MaltDataLab.sol#L28

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/MovingAverage.sol#L25

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/Auction.sol#L72

This results in the keccak operation being performed whenever the variable is used, increasing gas costs relative to just storing the output hash. Changing to immutable will only perform hashing on contract deployment which will save gas.

See: ethereum/solidity#9232 (ethereum/solidity#9232 (comment))

Tools Used

Code Review

Recommended Mitigation Steps

Consider to change the variable to be immutable rather than constant.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 25, 2021
code423n4 added a commit that referenced this issue Nov 25, 2021
@0xScotch 0xScotch added the duplicate This issue or pull request already exists label Dec 8, 2021
@0xScotch
Copy link
Collaborator

0xScotch commented Dec 8, 2021

#105

@0xScotch 0xScotch closed this as completed Dec 8, 2021
@GalloDaSballo
Copy link
Collaborator

Not true anmore, invalid

@GalloDaSballo GalloDaSballo added the invalid This doesn't seem right label Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants