Use calldata instead of memory in function parameter declarations #75
Labels
bug
Warden finding
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
chasemartin01
Vulnerability details
Impact
Gas optimisation
Example
As an example, you can change the declaration of
inputTokens
,inputWeights
,outputTokens
,outputWeights
to becalldata
as a gas optimisationhttps://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Auction.sol#L69-L75
There's other instances of this in
Basket.sol
andFactory.sol
Explanation
When you specify
memory
for a function param for an external function, the following happens: the compiler copies elements fromcalldata
tomemory
(using the opcodecalldatacopy
.) Note that there is also the opcodecalldataload
to read an offset fromcalldata
. By changing the location frommemory
tocalldata
, you avoid this expensive copy fromcalldata
tomemory
, while managing to do exactly what's needed.Tools Used
Manual analysis
Recommended Mitigation Steps
Change all instances of
memory
tocalldata
where the function parameter isn't being modifiedThe text was updated successfully, but these errors were encountered: