@@ -164,6 +164,24 @@ object OpCode {
164
164
val end = (offset + size).min(bytes.size).toInt
165
165
bytes.slice(start, end).padToByteString(size.toInt, 0 .toByte)
166
166
}
167
+
168
+ def addressAccessCost [W <: WorldStateProxy [W , S ], S <: Storage [S ]](state : ProgramState [W , S ], address : Address )(
169
+ preGasFn : FeeSchedule => BigInt ,
170
+ postColdGasFn : FeeSchedule => BigInt ,
171
+ postWarmGasFn : FeeSchedule => BigInt
172
+ ): BigInt = {
173
+ val currentBlockNumber = state.env.blockHeader.number
174
+ val etcFork = state.config.blockchainConfig.etcForkForBlockNumber(currentBlockNumber)
175
+ val eip2929Enabled = isEip2929Enabled(etcFork)
176
+ if (eip2929Enabled) {
177
+ val addr = address
178
+ if (state.accessedAddresses.contains(addr))
179
+ postWarmGasFn(state.config.feeSchedule)
180
+ else
181
+ postColdGasFn(state.config.feeSchedule)
182
+ } else
183
+ preGasFn(state.config.feeSchedule)
184
+ }
167
185
}
168
186
169
187
/** Base class for all the opcodes of the EVM
@@ -213,22 +231,10 @@ trait AddrAccessGas { self: OpCode =>
213
231
private def coldGasFn : FeeSchedule => BigInt = _.G_cold_account_access
214
232
private def warmGasFn : FeeSchedule => BigInt = _.G_warm_storage_read
215
233
216
- override protected def baseGas [W <: WorldStateProxy [W , S ], S <: Storage [S ]](state : ProgramState [W , S ]): BigInt = {
217
- val currentBlockNumber = state.env.blockHeader.number
218
- val etcFork = state.config.blockchainConfig.etcForkForBlockNumber(currentBlockNumber)
219
- val eip2929Enabled = isEip2929Enabled(etcFork)
220
- if (eip2929Enabled) {
221
- val addr = address(state)
222
- if (state.accessedAddresses.contains(addr))
223
- warmGasFn(state.config.feeSchedule)
224
- else
225
- coldGasFn(state.config.feeSchedule)
226
- } else
227
- baseGasFn(state.config.feeSchedule)
228
- }
234
+ override protected def baseGas [W <: WorldStateProxy [W , S ], S <: Storage [S ]](state : ProgramState [W , S ]): BigInt =
235
+ OpCode .addressAccessCost(state, address(state))(baseGasFn, coldGasFn, warmGasFn)
229
236
230
237
protected def address [W <: WorldStateProxy [W , S ], S <: Storage [S ]](state : ProgramState [W , S ]): Address
231
-
232
238
}
233
239
234
240
sealed trait ConstGas { self : OpCode =>
@@ -1065,6 +1071,7 @@ abstract class CallOp(code: Int, delta: Int, alpha: Int) extends OpCode(code, de
1065
1071
.withInternalTxs(internalTx +: result.internalTxs)
1066
1072
.withLogs(result.logs)
1067
1073
.withReturnData(result.returnData)
1074
+ .addAccessedAddress(toAddr)
1068
1075
.step()
1069
1076
}
1070
1077
}
@@ -1159,7 +1166,9 @@ abstract class CallOp(code: Int, delta: Int, alpha: Int) extends OpCode(code, de
1159
1166
else 0
1160
1167
1161
1168
val c_xfer : BigInt = if (endowment.isZero) 0 else state.config.feeSchedule.G_callvalue
1162
- state.config.feeSchedule.G_call + c_xfer + c_new
1169
+
1170
+ val callCost : BigInt = OpCode .addressAccessCost(state, to)(_.G_call , _.G_cold_account_access , _.G_warm_storage_read )
1171
+ callCost + c_xfer + c_new
1163
1172
}
1164
1173
}
1165
1174
0 commit comments