code-423n4 / 2021-07-sherlock-findings

0 stars 0 forks source link

Declare dynamic function parameters as `calldata` to save gas #146

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

In general, declaring dynamic function parameters as calldata instead of memory could save gas since the parameters are not copied into the memory but directly read from the call data.

Proof of Concept

Referenced code: Gov.sol#L138 Gov.sol#L165 Manager.sol#L46 Manager.sol#L74-L75 Manager.sol#L95-L97 Manager.sol#L142-L144 Manager.sol#L166 Manager.sol#L168 Manager.sol#L203-L206 Payout.sol#L110-L113 SherX.sol#L193-L194 SherXERC20.sol#L53

Recommended Mitigation Steps

Consider changing the memory keyword to calldata in the referenced functions. However, two of them require local variables to be rearranged or scoped to avoid "stack too deep" compiler errors. Please refer to this link for the detailed implementation.

Evert0x commented 3 years ago

87