Gas: Shift Right instead of Dividing by 2 #131
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Handle
Dravee
Vulnerability details
Impact
A division by 2 can be calculated by shifting one to the right.
While the
DIV
opcode uses 5 gas, theSHR
opcode only uses 3 gas. Furthermore, Solidity's division operation also includes a division-by-0 prevention which is bypassed using shifting.POC
Instances include:
Tools Used
VS Code
Recommended Mitigation Steps
Replace
/ 2
with>> 1
The text was updated successfully, but these errors were encountered: