40,000 USDC
View results
Submission Details
Severity: gas

Using calldata instead of memory for read-only arguments in external functions saves gas

Summary

[G-3] Using calldata instead of memory for read-only arguments in external functions saves gas

When a function with a memory array is called externally, the abi.decode () step has to use a for-loop to copy each index of the calldata to the memory index. Each iteration of this for-loop costs at least 60 gas (i.e. 60 * <mem_array>.length). Using calldata directly, obliviates the need for such a loop in the contract code and runtime execution.

file: /src/EscrowFactory.sol
57 bytes memory byteCode,

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/EscrowFactory.sol#L57

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.