😧Gas Saving Technique 18: Redundant code
Introduction
Impact & Details
Example: Removing Redundant Code
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyContract {
uint256 public value;
function setValue(uint256 _value) public {
require(_value > 0, "Value must be positive");
value = _value;
value = value; // Redundant code
// ... rest of the function ...
}
}Recommended Mitigation Steps
Conclusion
PreviousGas Saving Technique 17: Don’t cache value that is used onceNextGas Saving Technique 19: Early Validation before external call
Last updated