Skip to content

Instantly share code, notes, and snippets.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract TWASigUtils {
bytes32 internal DOMAIN_SEPARATOR;
constructor(bytes32 _DOMAIN_SEPARATOR) {
DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR;
}
@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

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
// 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 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

The first file above shows the process of setting supported institutions twice and the second file is the stack trace that validated the duplication of institution in the array of institution

The first file is a foundry test that run on a state for setting paycrest admin functionalities, which allow users to create order and in turn allow aggregator to settle part payment in order to validate the POC of the bug in question the second file is a full stack traces of all the transactions involved in the test file.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
import {Test, console2} from "forge-std/Test.sol";
import {Curves} from "../contracts/Curves.sol";
import {FeeSplitter} from "../contracts/FeeSplitter.sol";
import {CurvesERC20Factory} from "../contracts/CurvesERC20Factory.sol";
contract testCurve is Test {
FeeSplitter feespliter;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
import {Test, console2} from "forge-std/Test.sol";
import {Curves} from "../contracts/Curves.sol";
import {FeeSplitter} from "../contracts/FeeSplitter.sol";
import {CurvesERC20Factory} from "../contracts/CurvesERC20Factory.sol";
contract testCurve is Test {
FeeSplitter feespliter;