Sparkn

CodeFox Inc.
DeFiFoundryProxy
15,000 USDC
View results
Submission Details
Severity: low

Gas optimization calldata

Summary

Use calldata Instead of Memory for Function Parameters

Vulnerability Details

The "calldata" keyword is used for data that is sent as part of the transaction and is not stored in the contract's state. It is read-only, and its main advantage is that it is cheaper in terms of gas costs compared to "memory".
So, by changing "memory" to "calldata" in the function parameters, we can optimize the contract for lower gas usage.

Impact

Gas optimization:
Memory:
Running 1 test for test/uint/OnlyDistributorTest.t.sol:DistributionTest
[PASS] testCallingdistributeWillFail() (gas: 15945)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.69ms

Running 1 test for test/integration/ProxyFactoryTest.t.sol:ProxyFactoryTest
[PASS] testRevertsIfCalledByNonOwnerdistributeByOwner() (gas: 239325)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 6.78ms
Ran 2 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests)
Calldata:
Running 1 test for test/uint/OnlyDistributorTest.t.sol:DistributionTest
[PASS] testCallingdistributeWillFail() (gas: 14723)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.61ms

Running 1 test for test/integration/ProxyFactoryTest.t.sol:ProxyFactoryTest
[PASS] testRevertsIfCalledByNonOwnerdistributeByOwner() (gas: 238925)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 4.74ms
Ran 2 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests)

Tools Used

Manual

Recommendations

To resolve this issue, you should change the "memory" keyword to "calldata" in the function parameters

Support

FAQs

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