Skip to content

πŸ§™β€β™‚οΈ Outlining a path towards gas optimizationΒ #4

Open
@0xClandestine

Description

Hello, I've been looking over the codebase the last few days and I noticed you could use some help optimizing the contract so that it may be better suited for a production environment. To get us started, I thought I'd first start by listing some potential solutions:

  • SSTORE2 could potentially be implemented

  • I'm not entirely sure, but I think most of the arithmetic can be unchecked. (NOTE: where underflow/overflow is impossible or not possible in realistic conditions)

  • Storage can be optimized/packed into less slots since most of mutable state is updated together.

    // single storage slot, rather than 3
    uint32 private latestBlockTime; // equal to lastBlockTime % 2**32
    uint112 private latestBlockHeight;
    uint112 private expectedTarget;

    // can these be simplified or condesed?
    mapping(uint256 => bytes32) private blockHeightToHash;
    mapping(uint256 => uint256) private blockHeightToTotalDifficulty;
  • SLOADs can be avoided, consider caching state variables in memory before using them several times in a function.

  • A rewrite in inline assembly or yul+ could potentially provide some benefit as well.

P.S. Feel free to send questions my way!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions