Skip to content

Instantly share code, notes, and snippets.

Report

Gas Optimizations

Issue Instances
GAS-1 Using bools for storage incurs overhead 1
GAS-2 For Operations that will not overflow, you could use unchecked 64
GAS-3 Use Custom Errors 12
GAS-4 Don't initialize variables with default value 2
// SPDX-License-Identifier: MIT
pragma solidity =0.8.17;
import "forge-std/console.sol";
import "forge-std/Test.sol";
import {DNft} from "../../src/core/DNft.sol";
import {DeployV2, Contracts} from "../../script/deploy/Deploy.V2.s.sol";
import {Licenser} from "../../src/core/Licenser.sol";
// SPDX-License-Identifier: MIT
pragma solidity =0.8.17;
import "forge-std/console.sol";
import "forge-std/Test.sol";
import {DNft} from "../../src/core/DNft.sol";
import {DeployV2, Contracts} from "../../script/deploy/Deploy.V2.s.sol";
import {Licenser} from "../../src/core/Licenser.sol";

Report

Gas Optimizations

Issue Instances
GAS-1 a = a + b is more gas effective than a += b for state variables (excluding arrays and mappings) 3
GAS-2 Cache array length outside of loop 1
@Falilah
Falilah / gas.md
Created November 19, 2024 12:45
Understanding Gas in Ethereum: The Fuel of Smart Contracts

Ethereum smart contracts are powerful tools for decentralized applications (dApps), but they come with a critical concept: gas. Gas ensures that computational resources on the Ethereum network are used efficiently and fairly. Whether you're a developer or a user, understanding gas is essential to navigating the Ethereum ecosystem.

What is Gas?

Gas is a unit that measures the amount of computational effort required to execute operations on Ethereum. Think of gas like fuel for a car: the more complex the operation, the more fuel (or gas) it consumes. For instance, transferring Ether is simple and requires little gas, but deploying a smart contract or interacting with decentralized finance (DeFi) protocols involves more computation and thus more gas.

"In Ethereum terms, because understanding gas consumption is crucial for optimizing contracts and saving costs.

How Gas Works

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract TWASigUtils {
bytes32 internal DOMAIN_SEPARATOR;
constructor(bytes32 _DOMAIN_SEPARATOR) {
DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR;
}