PROPELOO

SMART CONTRACT / GAS OPTIMISATION

Reduce gas costs without reducing security.

PROPELOO engineers smart contract gas optimisation — from storage layout and opcode analysis through assembly optimisation, batching patterns and the benchmarking infrastructure that measures real improvement. Gas optimisation is not code golf. It is systematic engineering that makes your contracts cheaper to use without making them harder to audit.

A 50% reduction in mint gas cost doubles the number of users who can afford to mint at peak Ethereum gas prices.

On Ethereum mainnet, gas cost is a user experience and accessibility problem. A smart contract that costs 200,000 gas to interact with at 50 gwei costs $10 per transaction. Optimising it to 100,000 gas cuts that to $5. For NFT mints during high-demand launches, for DeFi operations that users perform frequently, and for any protocol competing on user adoption, gas efficiency is product quality. Gas optimisation requires understanding: storage slot packing (SSTORE is the most expensive opcode), calldata compression (each non-zero byte costs 16 gas), loop unrolling trade-offs, assembly for hot paths and ERC-721A-style deferred initialisation. PROPELOO delivers measurable, benchmarked gas reductions with no regression in security.

Gas optimisation surface.

System Layers

  • Storage Layer: Slot packing, struct ordering, storage vs memory vs calldata selection, SSTORE elimination
  • Computation Layer: Opcode analysis, loop optimisation, unchecked arithmetic, short-circuit evaluation
  • Architecture Layer: Batching patterns, lazy initialisation, bitmap usage, event vs storage tradeoffs
  • Assembly Layer: Inline assembly for hot paths, custom error selectors, Yul optimisation
  • Measurement Layer: Foundry gas snapshots, function-level benchmarks, pre/post comparison

Core Technical Capabilities

  • Storage Optimisation

    Struct packing to minimise storage slots (uint128 + uint128 in one slot vs two separate slots), replacing mappings with arrays where iteration is needed, using bytes32 instead of string where possible, and eliminating redundant storage writes.

  • Calldata & Input Optimisation

    Using calldata instead of memory for function parameters, compressing multi-call data, ABI encoding optimisation, using bytes calldata over bytes memory for external functions.

  • Arithmetic Optimisation

    unchecked blocks for arithmetic where overflow is provably impossible (loop counters, array index increments), pre-increment vs post-increment, removing redundant zero checks.

  • Architecture Patterns

    ERC-721A for batch NFT minting, EIP-2929 warm/cold access patterns, lazy initialisation of arrays, bitmap usage for boolean flags, multicall patterns for batching user operations.

  • Inline Assembly

    Custom errors via assembly (cheaper than require strings), optimised transfer loops in Yul, low-level staticcall for view functions, custom storage slot access for proxy patterns.

  • Gas Benchmarking

    Foundry gas snapshots for all public functions, function-level gas reports, pre/post optimisation comparison, worst-case scenario testing (full storage writes) and gas profiling with --gas-report.

How we think about gas optimisation.

Gas optimisation is a readability-cost trade-off. Aggressively optimised contracts are harder to audit. The goal is the optimal point — not minimum gas regardless of consequences.

  • SSTORE is the enemy

    Writing to storage (SSTORE) costs 20,000 gas for a new slot, 5,000 for modification. Reads (SLOAD) cost 2,100. Everything else is cheap by comparison. Optimise storage access patterns first — eliminate redundant writes, pack structs, cache storage values in memory within a function. Storage layout changes compound across every transaction for the lifetime of the protocol.

    Axiom:

  • Measure before and after

    "This optimisation should save gas" is not a result. Foundry gas snapshots measure the gas cost of every function call before and after each change. Every optimisation PR includes a gas comparison table. Without measurement, you are guessing.

    Axiom:

  • Readability is a security property

    A contract optimised to the point where auditors cannot follow the logic is a contract that will have undetected vulnerabilities. Inline assembly is powerful but opaque. unchecked blocks remove safety checks that prevent integer overflow. Every optimisation that reduces readability must be justified by a measured gas improvement worth the increased audit risk.

    Axiom:

  • Custom errors over revert strings

    require(condition, "Error message string") costs gas proportional to the string length — the string is stored in the contract bytecode and included in the revert reason. Custom errors (error InsufficientBalance(uint256 available, uint256 required); + revert InsufficientBalance(balance, amount)) cost 4 bytes for the selector versus 32+ bytes for a string. This is one of the easiest, safest and highest-impact optimisations.

    Axiom:

Gas optimisation decisions.

  • Where to start?

    Impact: Profile first. Foundry gas report identifies the most expensive functions. Custom errors are always safe and provide immediate wins. Storage packing for contracts with complex structs. Assembly only for proven hot paths.

    • Profile first — identify highest-gas functions before optimising
    • Storage packing — most impactful single category
    • Custom errors — easy wins, no security tradeoff
    • Assembly — highest impact, lowest readability
  • Storage packing approach?

    Impact: Manual struct ordering first (no readability cost). Automated detection for large contracts. Bitmap patterns for boolean flag arrays. Storage elimination for data that does not need to be queried on-chain.

    • Manual struct ordering — pack small types together
    • Automated tool (slither-detector) — identifies packing opportunities
    • Replace struct with single uint256 bitmap — maximum packing, minimum readability
    • Eliminate storage entirely — use events or calldata
  • unchecked arithmetic scope?

    Impact: Loop counters and index increments in unchecked blocks are universally safe — the upper bound is array length. Wider unchecked use requires case-by-case proof that overflow cannot occur.

    • Loop counters only — safest, most common
    • All arithmetic where overflow is provably impossible — broader savings
    • Everything in unchecked blocks — risky, not recommended
    • No unchecked — safest, leaves gas savings on the table
  • ERC-721 vs ERC-721A?

    Impact: ERC-721A for PFP/batch-mint collections. The gas savings on mint (5x for minting 10 at once) far outweigh the slight increase in transfer cost for most collection types.

    • ERC-721 — standard, higher per-token mint cost
    • ERC-721A — lower batch mint cost, slightly higher per-transfer cost
    • ERC-1155 — multi-edition, different tradeoffs
    • Custom implementation — maximum optimisation, full audit responsibility
  • Inline assembly scope?

    Impact: Custom errors via assembly are universally recommended. Broader assembly use requires explicit audit by someone fluent in EVM opcodes — inline assembly vulnerabilities are the hardest to detect in audit.

    • Never — maximum readability and auditability
    • Custom errors only — safe, high impact
    • Custom errors + optimised loops — moderate
    • Extensive assembly — maximum gas savings, minimum auditability
  • Optimisation vs security tradeoff?

    Impact: Security is not negotiable. Readability is a proxy for security — it affects how well the contract can be audited. Profile-guided optimisation of demonstrably hot paths is the pragmatic production approach.

    • Never sacrifice security for gas savings — always correct
    • Accept minor readability reduction for major gas reduction — pragmatic
    • Maximise gas efficiency regardless of readability — wrong for production
    • Profile-guided: optimise hot paths heavily, leave cold paths readable

What PROPELOO optimises.

  • NFT Mint Gas Reduction

    ERC-721A migration, struct packing, custom errors and calldata optimisation to reduce mint cost by 30-60%.

  • DeFi Protocol Optimisation

    Storage layout redesign, loop optimisation and assembly for hot paths in AMM, lending or staking contracts.

  • Token Contract Optimisation

    Transfer, approve and transferFrom gas reduction — critical for tokens with high daily transaction volume.

  • Gas Benchmarking Report

    Comprehensive gas report for all contract functions — current cost, optimisation opportunities and expected savings.

  • Pre-deployment Optimisation

    Full gas optimisation pass before mainnet deployment — profile, optimise, benchmark and document.

  • Multi-call Architecture

    Batching patterns for user operations — reducing multiple separate transactions to a single call with multicall or ERC-4337 batching.

The optimisation toolchain.

  • Measurement

    Stack: Foundry gas-report, Hardhat gas-reporter, eth-gas-reporter, Tenderly gas profiler

  • Analysis

    Stack: Slither (storage analysis), Remix (opcode viewer), evm.codes (opcode reference), EVM Playground

  • Optimised Libraries

    Stack: ERC-721A, solmate, OpenZeppelin v5, solady

  • Testing

    Stack: Foundry (fuzz + invariant), Gas snapshots, Differential testing

  • Monitoring

    Stack: Dune Analytics (on-chain gas tracking), Tenderly, Blocknative (gas estimation)

  • Documentation

    Stack: Gas comparison tables, Per-function benchmarks, Optimisation rationale docs

Gas optimisation must not introduce vulnerabilities.

  • unchecked overflow risk

    unchecked blocks remove Solidity 0.8+ overflow protection. Each use must be accompanied by a proof that overflow is impossible — typically a comment with the invariant. Missing or incorrect unchecked blocks are a critical vulnerability class.

  • Assembly correctness

    Inline assembly bypasses Solidity type safety and compiler checks. Every assembly block requires a security review by someone with EVM opcode expertise. Assembly errors are invisible to automated tools.

  • Storage slot collision

    Manual storage slot manipulation in proxy contracts or optimised patterns can create slot collisions — where two variables share the same slot unexpectedly. Verify storage layout with forge inspect before deployment.

  • Readability-driven audit risk

    Aggressively optimised contracts are harder to audit. Measure the audit cost increase against the gas saving per transaction across expected lifetime volume. For low-volume contracts, readability often wins.

  • Regression testing

    Every optimisation must have a comprehensive test suite that passes before and after the optimisation. Gas improvements that break functionality are not improvements.

  • Differential testing

    For complex mathematical optimisations (fixed-point arithmetic, curve calculations), differential testing compares optimised output against a reference implementation across a large random input set.

From profile to optimised contract.

  1. 01. Gas Profiling

    Foundry gas-report for all public functions. Identify top 20% of functions by gas cost.

  2. 02. Opportunity Analysis

    Categorise optimisation opportunities by impact, safety and implementation effort.

  3. 03. Safe Wins First

    Custom errors, calldata parameter types, storage packing — high impact, low risk.

  4. 04. Architecture Patterns

    ERC-721A migration, multicall, bitmap patterns — moderate complexity, high impact.

  5. 05. Advanced Optimisation

    unchecked blocks with proofs, inline assembly for hot paths — high impact, requires audit.

  6. 06. Regression Testing

    Full test suite pass, invariant testing confirms no security regressions.

  7. 07. Benchmark Report

    Per-function before/after comparison, total gas savings estimate and documentation.

Frequently Asked Questions

What is the typical gas reduction achievable?

Depends heavily on the starting point. Contracts written without gas awareness: 30-60% reduction is common. Contracts already following basic best practices: 10-25% improvement. The highest-impact single change is usually storage struct packing (eliminating redundant storage slots) followed by custom errors and calldata parameter types. ERC-721A for batch mint contracts is typically a 40-60% reduction in batch mint gas.

Does gas optimisation affect security?

It can. The optimisation techniques with no security tradeoff: custom errors, calldata vs memory for function parameters, storage struct packing, caching storage values in memory within a function. Techniques that reduce readability and require careful security review: unchecked arithmetic, inline assembly, custom storage slot management. We document which optimisations were applied and why for each PR, so auditors can review the reasoning.

When should we optimise gas vs accept higher costs?

Optimise when: the contract has high daily transaction volume (even small per-transaction savings compound), the gas cost creates a user affordability barrier (NFT mints, DeFi operations), or the contract is already deployed and high gas is driving users to competitors. Accept higher gas costs when: the contract is rarely called, the optimisation significantly reduces readability, or the contract is in a security-critical path where auditability is paramount.

What is solmate vs OpenZeppelin?

solmate is a gas-optimised alternative to OpenZeppelin contracts — ERC-20, ERC-721 and other primitives written for maximum gas efficiency rather than maximum readability and safety features. solady is even more aggressively optimised. OpenZeppelin prioritises safety, documentation and broad compatibility. For production protocols: start with OpenZeppelin (audited, battle-tested), profile, then selectively migrate specific implementations to solmate/solady if gas analysis justifies the readability tradeoff.