@@ -164,6 +164,24 @@ object OpCode {
164164 val end = (offset + size).min(bytes.size).toInt
165165 bytes.slice(start, end).padToByteString(size.toInt, 0 .toByte)
166166 }
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+ }
167185}
168186
169187/** Base class for all the opcodes of the EVM
@@ -213,22 +231,10 @@ trait AddrAccessGas { self: OpCode =>
213231 private def coldGasFn : FeeSchedule => BigInt = _.G_cold_account_access
214232 private def warmGasFn : FeeSchedule => BigInt = _.G_warm_storage_read
215233
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)
229236
230237 protected def address [W <: WorldStateProxy [W , S ], S <: Storage [S ]](state : ProgramState [W , S ]): Address
231-
232238}
233239
234240sealed trait ConstGas { self : OpCode =>
@@ -1065,6 +1071,7 @@ abstract class CallOp(code: Int, delta: Int, alpha: Int) extends OpCode(code, de
10651071 .withInternalTxs(internalTx +: result.internalTxs)
10661072 .withLogs(result.logs)
10671073 .withReturnData(result.returnData)
1074+ .addAccessedAddress(toAddr)
10681075 .step()
10691076 }
10701077 }
@@ -1159,7 +1166,9 @@ abstract class CallOp(code: Int, delta: Int, alpha: Int) extends OpCode(code, de
11591166 else 0
11601167
11611168 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
11631172 }
11641173}
11651174
0 commit comments