⏱️Gas Saving Techniques 25: Redundant Access Control Checks
solidityCopy codepragma solidity ^0.8.0;
contract RedundantChecks {
address public owner;
modifier onlyAuthorized() {
require(msg.sender == owner, "Not authorized");
_;
}
constructor() {
owner = msg.sender;
}
function setProposal(string memory proposal) public onlyAuthorized {
// Proposal setting logic
}
function setProposals(string[] memory proposals) public onlyAuthorized {
for (uint i = 0; i < proposals.length; i++) {
setProposal(proposals[i]);
}
}
}PreviousGas Saving Technique 24: Make unchanged variables constant/immutableNextGas Saving Technique 26: Shift Right instead of Dividing by 2
Last updated