Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseRegistrarImplementation.renew gas consumption can be improved #398

Open
barakman opened this issue Dec 31, 2024 · 0 comments
Open

BaseRegistrarImplementation.renew gas consumption can be improved #398

barakman opened this issue Dec 31, 2024 · 0 comments

Comments

@barakman
Copy link

The aforementioned function:

    function renew(
        uint256 id,
        uint256 duration
    ) external override live onlyController returns (uint256) {
        require(expiries[id] + GRACE_PERIOD >= block.timestamp); // Name must be registered here or in grace period
        require(
            expiries[id] + duration + GRACE_PERIOD > duration + GRACE_PERIOD
        ); // Prevent future overflow

        expiries[id] += duration;
        emit NameRenewed(id, expiries[id]);
        return expiries[id];
    }

Performs 5 storage-read operations of expiries[id]:

  1. require(expiries[id] ...)
  2. require(expiries[id] ...)
  3. expiries[id] = expiries[id] + duration
  4. emit NameRenewed(id, expiries[id])
  5. return expiries[id]

Each storage-read operation currently costs around 2100 gas units (evm paris, solc 0.8.28).

You can reduce the code in this function to perform a single storage-read operation of expiries[id]:

    function renew(
        uint256 id,
        uint256 duration
    ) external override live onlyController returns (uint256) {
        uint256 expiries_id = expiries[id];
        require(expiries_id + GRACE_PERIOD >= block.timestamp); // Name must be registered here or in grace period
        require(
            expiries_id + duration + GRACE_PERIOD > duration + GRACE_PERIOD
        ); // Prevent future overflow

        expiries_id += duration;
        expiries[id] = expiries_id;
        emit NameRenewed(id, expiries_id);
        return expiries_id;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant