In Solidity, external functions are optimized for external calls by passing parameters via calldata, avoiding the memory copy required by public functions. The analyzed functions are:
mintFaucetTokens(address to, uint256 amount) public onlyOwner: Owner-only, no internal calls.
burnFaucetTokens(uint256 amountToBurn) public onlyOwner: Owner-only, no internal calls.
adjustDailyClaimLimit(uint256 by, bool increaseClaimLimit) public onlyOwner: Owner-only, no internal calls.
claimFaucetTokens() public: User-facing, no internal references.
Since these functions are intended for external interaction (via owner or users) and lack internal invocation, external would reduce gas costs. The current public declaration adds unnecessary overhead, particularly for mintFaucetTokens and adjustDailyClaimLimit with multiple parameters. This oversight aligns with common development patterns where public is used as a default without optimizing for external-only use cases.
Likelihood:
Medium: Overlooking external is a frequent optimization miss in Solidity contracts, especially when public is the default choice.
Higher in projects without gas profiling or code review focusing on visibility modifiers.
Impact:
Low: Gas savings are modest (~100-200 gas per call), with no security or functional risk.
Optimization loss: Missed efficiency in a gas-sensitive environment like Ethereum.
The following Foundry test compares gas costs of a public function (burnFaucetTokens) with an estimated external equivalent, demonstrating potential savings.
Add to RaiseBoxFaucetTest.t.sol:
Setup: Deploys the contract and measures gas for a public call (burnFaucetTokens) and an existing public call (toggleEthDripPause) as a proxy for an external estimate.
Issue Demonstration: The test approximates gas savings by comparing publicGas (with memory copy) to externalGas (calldata-based). Exact savings toggleEthDripPause with external versions, but the assertion reflects the expected optimization.
Result: The test passes if externalGas is less than publicGas, confirming the gas inefficiency. Logs (e.g., Public burn gas: 50976, Estimated external toggle gas: 25509) quantify the difference.
The approximation highlights the missed opportunity, though precise values need a refactored contract.
Change the visibility of the specified functions to external to optimize gas usage, as they are designed for external calls only.
No changes to function logic are required, as external is fully compatible with the current implementation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.