//1. If current value equals new value (this is a no-op), 200 gas is deducted.
// The legacy gas metering only takes into consideration the current state
//2. If current value does not equal new value
if!evm.chainRules.IsConstantinople{
// 2.1 If original value equals current value (this storage slot has not been changed by the current execution context)
// This checks for 3 scenario's and calculates gas accordingly:
// 2.1.1 If original value is 0, 20000 gas is deducted.
//
// 2.1.2 Otherwise, 5000 gas is deducted. If new value is 0, add 15000 gas to refund counter.
// 1. From a zero-value address to a non-zero value (NEW VALUE)
// 2.2 If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
// 2. From a non-zero value address to a zero-value address (DELETE)
// 2.2.1 If original value is not 0
// 3. From a non-zero to a non-zero (CHANGE)
// 2.2.1.1 If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
switch{
// 2.2.1.2 If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
casecurrent==(common.Hash{})&&y.Sign()!=0:// 0 => non 0
// 2.2.2 If original value equals new value (this storage slot is reset)
returnparams.SstoreSetGas,nil
// 2.2.2.1 If original value is 0, add 19800 gas to refund counter.
casecurrent!=(common.Hash{})&&y.Sign()==0:// non 0 => 0
// 2.2.2.2 Otherwise, add 4800 gas to refund counter.
// The new gas metering is based on net gas costs (EIP-1283):
// 2
//
iforiginal==current{// 2.1
// 1. If current value equals new value (this is a no-op), 200 gas is deducted.
iforiginal==(common.Hash{}){// 2.1.1
// 2. If current value does not equal new value
return20000,nil
// 2.1. If original value equals current value (this storage slot has not been changed by the current execution context)
// 2.1.1. If original value is 0, 20000 gas is deducted.
// 2.1.2. Otherwise, 5000 gas is deducted. If new value is 0, add 15000 gas to refund counter.
// 2.2. If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
// 2.2.1. If original value is not 0
// 2.2.1.1. If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
// 2.2.1.2. If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
// 2.2.2. If original value equals new value (this storage slot is reset)
// 2.2.2.1. If original value is 0, add 19800 gas to refund counter.
// 2.2.2.2. Otherwise, add 4800 gas to refund counter.