code-423n4 / 2023-11-shellprotocol-findings

7 stars 7 forks source link

Potential Gas Inefficiency due to Unnecessary abi.encode Usage #301

Closed c4-bot-1 closed 8 months ago

c4-bot-1 commented 8 months ago

Lines of code

https://github.com/code-423n4/2023-11-shellprotocol/blob/main/src/adapters/OceanAdapter.sol#L99

Vulnerability details

Impact

The function unnecessarily uses abi.encode to convert a uint256 to bytes32, incurring additional gas costs. This doesn't affect correctness but may lead to suboptimal gas usage.

Proof of Concept

By modifying the _fetchInteractionId function to directly cast the packed value (uint256) to bytes32 without using abi.encode, gas costs can potentially be reduced.

Tools Used

Recommended Mitigation Steps

function _fetchInteractionId(address token, uint256 interactionType) internal pure returns (bytes32) { uint256 packedValue = uint256(uint160(token)); packedValue |= interactionType << 248; return bytes32(packedValue); // Direct casting without abi.encode }

Assessed type

Other

c4-pre-sort commented 8 months ago

raymondfam marked the issue as insufficient quality report

c4-pre-sort commented 8 months ago

raymondfam marked the issue as primary issue

raymondfam commented 8 months ago

An FP reported also by the bot: G-01

c4-judge commented 8 months ago

0xA5DF marked the issue as unsatisfactory: Overinflated severity

c4-judge commented 8 months ago

0xA5DF marked the issue as unsatisfactory: Invalid

c4-judge commented 8 months ago

0xA5DF marked the issue as unsatisfactory: Invalid

c4-judge commented 8 months ago

0xA5DF marked the issue as unsatisfactory: Invalid