Closed code423n4 closed 2 years ago
hyh
Gas is overspent on storage access.
https://github.com/code-423n4/2021-11-overlay/blob/main/contracts/collateral/OverlayV1OVLCollateral.sol#L177
Access exact part of storage that is needed.
Now:
mapping(uint=>uint) storage _currentBlockPositions = _isLong ? currentBlockPositionsLong[_market] : currentBlockPositionsShort[_market]; positionId_ = _currentBlockPositions[_leverage]; ... _currentBlockPositions[_leverage] = positionId_;
To be:
uint storage _currentBlockPosition = _isLong ? currentBlockPositionsLong[_market][_leverage] : currentBlockPositionsShort[_market][_leverage]; positionId_ = _currentBlockPosition; ... _currentBlockPosition = positionId_;
sponsor disputed reason - suggested change seems to actually be more gas intensive
When I tried this the way proposed, I actually encountered a greater gas expenditure.
Handle
hyh
Vulnerability details
Impact
Gas is overspent on storage access.
Proof of Concept
https://github.com/code-423n4/2021-11-overlay/blob/main/contracts/collateral/OverlayV1OVLCollateral.sol#L177
Recommended Mitigation Steps
Access exact part of storage that is needed.
Now:
To be: