2

I've heard these terms thrown around in discussions surrounding storage pricing in the EVM. But what do they mean, more precisely?

1 Answer 1

2

These terms were first defined in EIP-1283, and they refer to the different states that a storage value can have during the execution of a transaction.

Here's a table that explains the three terms:

Term Description
Original value The value that was in storage at the beginning of the transaction or function call.
Current value The value in storage at the time you are executing the SSTORE operation.
New value The value you are trying to store.

It is worth noting that in most cases, the original value will coincide with the current value.

Here's an example contract to hammer the concept home:

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

// All storage slots are assumed to be cold, so an extra 2100 gas is needed for each operation
// See EIP-2929
contract StorageWriteExamples {
    uint256 public value;

    // original value = 0
    // current value  = 0
    // new value      = 1
    // sstore cost    = 22100 (20000+2100)
    function call_me_first() public {
        value = 1;
    }

    // original value = 1
    // current value  = 1
    // new value      = 42
    // sstore cost    = 5000 (2900+2100)
    function call_me_second() public {
        value = 42;
    }

    // original value = 42
    // current value  = 1
    // new value      = 1337
    // sstore cost    = 100
    function call_me_third() external returns (uint256) {
        call_me_first();
        uint256 startGas = gasleft();
        value = 1337;
        return startGas - gasleft();
    }
}

Notes:

  • In most cases, the original value will coincide with the current value.
  • You might want to take a look at the SSTORE reference on evm.codes (they even have a calculator for estimating the gas cost and refund!)
  • While it is EIP-1283 which defined these terms, the most up-to-date logic can be found in EIP-2200 and EIP-2929

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.