code4rena-2022-08-nounsdao-g20
[G‑20] Division by two should use bit shifting
Summary
2의 배수로 나누기 하는 것은 / 연산자보다 shift를 이용하는 것이 저렴하다.
Keyword
shift, safemath
Vulnerability
File: contracts/base/ERC721Checkpointable.sol
184: uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflowFile: contracts/governance/NounsDAOLogicV2.sol
951: uint256 center = upper - (upper - lower) / 2;2의 배수로 나누기 하는 것은 / 연산자보다 shift를 이용하는 것이 저렴하다. / 로 계산 시 JUMP 연산이 들어가고, SafeMath 체크를 하기 때문이다. (SafeMath는 unchecked로 해제 가능하다)
Impact
gas가 낭비된다.
Mitigation
2의 배수로 나누기 하는 것은 shift로 연산한다.
tags: bughunting, nouns dao, smart contract, solidity, gas optimization, severity gas