You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// This checks for 3 scenario's and calculates gas accordingly
124
-
// 1. From a zero-value address to a non-zero value (NEW VALUE)
125
-
// 2. From a non-zero value address to a zero-value address (DELETE)
126
-
// 3. From a non-zero to a non-zero (CHANGE)
127
-
ifval== (common.Hash{}) &&y.Sign() !=0 {
128
-
// 0 => non 0
129
-
returnparams.SstoreSetGas, nil
130
-
} elseifval!= (common.Hash{}) &&y.Sign() ==0 {
131
-
// non 0 => 0
132
-
evm.StateDB.AddRefund(params.SstoreRefundGas)
133
-
returnparams.SstoreClearGas, nil
134
-
} else {
135
-
// non 0 => non 0 (or 0 => 0)
136
-
returnparams.SstoreResetGas, nil
123
+
// The legacy gas metering only takes into consideration the current state
124
+
if!evm.chainRules.IsConstantinople {
125
+
// This checks for 3 scenario's and calculates gas accordingly:
126
+
//
127
+
// 1. From a zero-value address to a non-zero value (NEW VALUE)
128
+
// 2. From a non-zero value address to a zero-value address (DELETE)
129
+
// 3. From a non-zero to a non-zero (CHANGE)
130
+
switch {
131
+
casecurrent== (common.Hash{}) &&y.Sign() !=0: // 0 => non 0
132
+
returnparams.SstoreSetGas, nil
133
+
casecurrent!= (common.Hash{}) &&y.Sign() ==0: // non 0 => 0
134
+
evm.StateDB.AddRefund(params.SstoreRefundGas)
135
+
returnparams.SstoreClearGas, nil
136
+
default: // non 0 => non 0 (or 0 => 0)
137
+
returnparams.SstoreResetGas, nil
138
+
}
139
+
}
140
+
// The new gas metering is based on net gas costs (EIP-1283):
141
+
//
142
+
// 1. If current value equals new value (this is a no-op), 200 gas is deducted.
143
+
// 2. If current value does not equal new value
144
+
// 2.1. If original value equals current value (this storage slot has not been changed by the current execution context)
145
+
// 2.1.1. If original value is 0, 20000 gas is deducted.
146
+
// 2.1.2. Otherwise, 5000 gas is deducted. If new value is 0, add 15000 gas to refund counter.
147
+
// 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.
148
+
// 2.2.1. If original value is not 0
149
+
// 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.
150
+
// 2.2.1.2. If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
151
+
// 2.2.2. If original value equals new value (this storage slot is reset)
152
+
// 2.2.2.1. If original value is 0, add 19800 gas to refund counter.
153
+
// 2.2.2.2. Otherwise, add 4800 gas to refund counter.
0 commit comments