@@ -188,13 +188,13 @@ func (r DiscardReason) String() string {
188188
189189// CalcIntrinsicGas computes the 'intrinsic gas' for a message with the given data.
190190// TODO: move input data to a struct
191- func CalcIntrinsicGas (dataLen , dataNonZeroLen , authorizationsLen uint64 , accessList types.AccessList , isContractCreation , isHomestead , isEIP2028 , isShanghai bool ) (uint64 , DiscardReason ) {
191+ func CalcIntrinsicGas (dataLen , dataNonZeroLen , authorizationsLen uint64 , accessList types.AccessList , isContractCreation , isHomestead , isEIP2028 , isShanghai , isPrague bool ) (gas uint64 , floorGas7623 uint64 , d DiscardReason ) {
192192 // Set the starting gas for the raw transaction
193- var gas uint64
194193 if isContractCreation && isHomestead {
195194 gas = fixedgas .TxGasContractCreation
196195 } else {
197196 gas = fixedgas .TxGas
197+ floorGas7623 = fixedgas .TxGas
198198 }
199199 // Bump the required gas by the amount of transactional data
200200 if dataLen > 0 {
@@ -208,68 +208,81 @@ func CalcIntrinsicGas(dataLen, dataNonZeroLen, authorizationsLen uint64, accessL
208208
209209 product , overflow := emath .SafeMul (nz , nonZeroGas )
210210 if overflow {
211- return 0 , GasUintOverflow
211+ return 0 , 0 , GasUintOverflow
212212 }
213213 gas , overflow = emath .SafeAdd (gas , product )
214214 if overflow {
215- return 0 , GasUintOverflow
215+ return 0 , 0 , GasUintOverflow
216216 }
217217
218218 z := dataLen - nz
219219
220220 product , overflow = emath .SafeMul (z , fixedgas .TxDataZeroGas )
221221 if overflow {
222- return 0 , GasUintOverflow
222+ return 0 , 0 , GasUintOverflow
223223 }
224224 gas , overflow = emath .SafeAdd (gas , product )
225225 if overflow {
226- return 0 , GasUintOverflow
226+ return 0 , 0 , GasUintOverflow
227227 }
228228
229229 if isContractCreation && isShanghai {
230230 numWords := toWordSize (dataLen )
231231 product , overflow = emath .SafeMul (numWords , fixedgas .InitCodeWordGas )
232232 if overflow {
233- return 0 , GasUintOverflow
233+ return 0 , 0 , GasUintOverflow
234234 }
235235 gas , overflow = emath .SafeAdd (gas , product )
236236 if overflow {
237- return 0 , GasUintOverflow
237+ return 0 , 0 , GasUintOverflow
238+ }
239+ }
240+
241+ // EIP-7623
242+ if isPrague {
243+ tokenLen := dataLen + 3 * nz
244+ dataGas , overflow := emath .SafeMul (tokenLen , fixedgas .TxTotalCostFloorPerToken )
245+ if overflow {
246+ return 0 , 0 , GasUintOverflow
247+ }
248+ floorGas7623 , overflow = emath .SafeAdd (floorGas7623 , dataGas )
249+ if overflow {
250+ return 0 , 0 , GasUintOverflow
238251 }
239252 }
240253 }
241254 if accessList != nil {
242255 product , overflow := emath .SafeMul (uint64 (len (accessList )), fixedgas .TxAccessListAddressGas )
243256 if overflow {
244- return 0 , GasUintOverflow
257+ return 0 , 0 , GasUintOverflow
245258 }
246259 gas , overflow = emath .SafeAdd (gas , product )
247260 if overflow {
248- return 0 , GasUintOverflow
261+ return 0 , 0 , GasUintOverflow
249262 }
250263
251264 product , overflow = emath .SafeMul (uint64 (accessList .StorageKeys ()), fixedgas .TxAccessListStorageKeyGas )
252265 if overflow {
253- return 0 , GasUintOverflow
266+ return 0 , 0 , GasUintOverflow
254267 }
255268 gas , overflow = emath .SafeAdd (gas , product )
256269 if overflow {
257- return 0 , GasUintOverflow
270+ return 0 , 0 , GasUintOverflow
258271 }
259272 }
260273
261274 // Add the cost of authorizations
262275 product , overflow := emath .SafeMul (authorizationsLen , fixedgas .PerEmptyAccountCost )
263276 if overflow {
264- return 0 , GasUintOverflow
277+ return 0 , 0 , GasUintOverflow
265278 }
266279
267280 gas , overflow = emath .SafeAdd (gas , product )
268281 if overflow {
269- return 0 , GasUintOverflow
282+ return 0 , 0 , GasUintOverflow
270283 }
271284
272- return gas , Success
285+ return gas , floorGas7623 , Success
273286}
274287
275288// toWordSize returns the ceiled word size required for memory expansion.
0 commit comments