Redundant parameter amountToRefill duplicates the functionality of msg.value.
slightly higher gas usage and function call complexity.
Description
-
The refillSepEth() function allows the owner to deposit Sepolia ETH into the contract, ensuring the sent value matches the declared amount.
-
The parameter amountToRefill is redundant since msg.value already represents the transferred amount, slightly increasing gas usage and code complexity.
function refillSepEth(uint256 amountToRefill) external payable onlyOwner {
@> require(amountToRefill > 0, "invalid eth amount");
@> require(msg.value == amountToRefill, "Refill amount must be same as value sent.");
emit SepEthRefilled(msg.sender, amountToRefill);
}
Risk
Likelihood:
-
This occurs every time the owner calls refillSepEth(), as the redundant parameter is always processed.
-
The issue consistently adds minor but unnecessary gas overhead on each execution.
Impact:
-
Slight increase in gas consumption and transaction cost due to redundant parameter handling.
-
Minor code inefficiency and deviation from Solidity best practices for minimal, clean contract design.
Proof of Concept
function refillSepEth(uint256 amountToRefill) external payable onlyOwner {
require(amountToRefill > 0, "invalid eth amount");
require(msg.value == amountToRefill, "Refill amount must be same as value sent.");
emit SepEthRefilled(msg.sender, amountToRefill);
}
refillSepEth | 24292 | 24748 | 24292 | 25662 | 3 |
function refillSepEth() external payable onlyOwner {
emit SepEthRefilled(msg.sender, msg.value);
}
| refillSepEth | 23815 | 24252 | 23815 | 25126 | 3 |
Recommended Mitigation
- function refillSepEth(uint256 amountToRefill) external payable onlyOwner {
- require(amountToRefill > 0, "invalid eth amount");
- require(msg.value == amountToRefill, "Refill amount must be same as value sent.");
- emit SepEthRefilled(msg.sender, amountToRefill);
- }
+ function refillSepEth() external payable onlyOwner {
+ emit SepEthRefilled(msg.sender, msg.value);
+ }