@@ -32,17 +32,17 @@ const (
3232 // offsets correspond to the last byte of the value in the slot, counting backwards from the
3333 // end of the slot. For example, The 8-byte sequence number has offset 0, and is therefore
3434 // stored as big-endian format in bytes [24:32] of the slot.
35- BasefeeScalarSlotOffset = 12 // bytes [16:20] of the slot
36- BlobBasefeeScalarSlotOffset = 8 // bytes [20:24] of the slot
35+ BaseFeeScalarSlotOffset = 12 // bytes [16:20] of the slot
36+ BlobBaseFeeScalarSlotOffset = 8 // bytes [20:24] of the slot
3737
3838 // scalarSectionStart is the beginning of the scalar values segment in the slot
39- // array. basefeeScalar is in the first four bytes of the segment, blobBasefeeScalar the next
39+ // array. baseFeeScalar is in the first four bytes of the segment, blobBaseFeeScalar the next
4040 // four.
41- scalarSectionStart = 32 - BasefeeScalarSlotOffset - 4
41+ scalarSectionStart = 32 - BaseFeeScalarSlotOffset - 4
4242)
4343
4444func init () {
45- if BlobBasefeeScalarSlotOffset != BasefeeScalarSlotOffset - 4 {
45+ if BlobBaseFeeScalarSlotOffset != BaseFeeScalarSlotOffset - 4 {
4646 panic ("this code assumes the scalars are at adjacent positions in the scalars slot" )
4747 }
4848}
@@ -57,16 +57,16 @@ var (
5757 // L1BlockAddr is the address of the L1Block contract which stores the L1 gas attributes.
5858 L1BlockAddr = common .HexToAddress ("0x4200000000000000000000000000000000000015" )
5959
60- L1BasefeeSlot = common .BigToHash (big .NewInt (1 ))
60+ L1BaseFeeSlot = common .BigToHash (big .NewInt (1 ))
6161 OverheadSlot = common .BigToHash (big .NewInt (5 ))
6262 ScalarSlot = common .BigToHash (big .NewInt (6 ))
6363
64- // L2BlobBasefeeSlot was added with the Ecotone upgrade and stores the blobBasefee L1 gas
64+ // L2BlobBaseFeeSlot was added with the Ecotone upgrade and stores the blobBaseFee L1 gas
6565 // attribute.
66- L1BlobBasefeeSlot = common .BigToHash (big .NewInt (7 ))
66+ L1BlobBaseFeeSlot = common .BigToHash (big .NewInt (7 ))
6767 // L1FeeScalarsSlot as of the Ecotone upgrade stores the 32-bit basefeeScalar and
68- // blobBasefeeScalar L1 gas attributes at offsets `BasefeeScalarSlotOffset ` and
69- // `BlobBasefeeScalarSlotOffset ` respectively.
68+ // blobBaseFeeScalar L1 gas attributes at offsets `BaseFeeScalarSlotOffset ` and
69+ // `BlobBaseFeeScalarSlotOffset ` respectively.
7070 L1FeeScalarsSlot = common .BigToHash (big .NewInt (3 ))
7171
7272 oneMillion = big .NewInt (1_000_000 )
@@ -130,23 +130,23 @@ func NewL1CostFunc(config *params.ChainConfig, statedb StateGetter) L1CostFunc {
130130 if ! config .IsOptimismEcotone (blockTime ) {
131131 cachedFunc = newL1CostFuncBedrock (config , statedb , blockTime )
132132 } else {
133- l1BlobBasefee := statedb .GetState (L1BlockAddr , L1BlobBasefeeSlot ).Big ()
133+ l1BlobBaseFee := statedb .GetState (L1BlockAddr , L1BlobBaseFeeSlot ).Big ()
134134 l1FeeScalars := statedb .GetState (L1BlockAddr , L1FeeScalarsSlot ).Bytes ()
135135
136136 // Edge case: the very first Ecotone block requires we use the Bedrock cost
137137 // function. We detect this scenario by checking if the Ecotone parameters are
138138 // unset. Not here we rely on assumption that the scalar parameters are adjacent
139139 // in the buffer and basefeeScalar comes first.
140- if l1BlobBasefee .BitLen () == 0 &&
140+ if l1BlobBaseFee .BitLen () == 0 &&
141141 bytes .Equal (emptyScalars , l1FeeScalars [scalarSectionStart :scalarSectionStart + 8 ]) {
142142 log .Info ("using bedrock l1 cost func for first Ecotone block" , "time" , blockTime )
143143 cachedFunc = newL1CostFuncBedrock (config , statedb , blockTime )
144144 } else {
145- l1Basefee := statedb .GetState (L1BlockAddr , L1BasefeeSlot ).Big ()
145+ l1BaseFee := statedb .GetState (L1BlockAddr , L1BaseFeeSlot ).Big ()
146146 offset := scalarSectionStart
147- l1BasefeeScalar := new (big.Int ).SetBytes (l1FeeScalars [offset : offset + 4 ])
148- l1BlobBasefeeScalar := new (big.Int ).SetBytes (l1FeeScalars [offset + 4 : offset + 8 ])
149- cachedFunc = newL1CostFuncEcotone (l1Basefee , l1BlobBasefee , l1BasefeeScalar , l1BlobBasefeeScalar )
147+ l1BaseFeeScalar := new (big.Int ).SetBytes (l1FeeScalars [offset : offset + 4 ])
148+ l1BlobBaseFeeScalar := new (big.Int ).SetBytes (l1FeeScalars [offset + 4 : offset + 8 ])
149+ cachedFunc = newL1CostFuncEcotone (l1BaseFee , l1BlobBaseFee , l1BaseFeeScalar , l1BlobBaseFeeScalar )
150150 }
151151 }
152152 }
@@ -158,16 +158,16 @@ func NewL1CostFunc(config *params.ChainConfig, statedb StateGetter) L1CostFunc {
158158// newL1CostFuncBedrock returns an L1 cost function suitable for Bedrock, Regolith, and the first
159159// block only of the Ecotone upgrade.
160160func newL1CostFuncBedrock (config * params.ChainConfig , statedb StateGetter , blockTime uint64 ) l1CostFunc {
161- l1Basefee := statedb .GetState (L1BlockAddr , L1BasefeeSlot ).Big ()
161+ l1BaseFee := statedb .GetState (L1BlockAddr , L1BaseFeeSlot ).Big ()
162162 overhead := statedb .GetState (L1BlockAddr , OverheadSlot ).Big ()
163163 scalar := statedb .GetState (L1BlockAddr , ScalarSlot ).Big ()
164164 isRegolith := config .IsRegolith (blockTime )
165- return newL1CostFuncBedrockHelper (l1Basefee , overhead , scalar , isRegolith )
165+ return newL1CostFuncBedrockHelper (l1BaseFee , overhead , scalar , isRegolith )
166166}
167167
168168// newL1CostFuncBedrockHelper is lower level version of newL1CostFuncBedrock that expects already
169169// extracted parameters
170- func newL1CostFuncBedrockHelper (l1Basefee , overhead , scalar * big.Int , isRegolith bool ) l1CostFunc {
170+ func newL1CostFuncBedrockHelper (l1BaseFee , overhead , scalar * big.Int , isRegolith bool ) l1CostFunc {
171171 return func (rollupCostData RollupCostData ) (fee , gasUsed * big.Int ) {
172172 if rollupCostData == (RollupCostData {}) {
173173 return nil , nil // Do not charge if there is no rollup cost-data (e.g. RPC call or deposit)
@@ -180,35 +180,35 @@ func newL1CostFuncBedrockHelper(l1Basefee, overhead, scalar *big.Int, isRegolith
180180 }
181181 gasWithOverhead := new (big.Int ).SetUint64 (gas )
182182 gasWithOverhead .Add (gasWithOverhead , overhead )
183- l1Cost := l1CostHelper (gasWithOverhead , l1Basefee , scalar )
183+ l1Cost := l1CostHelper (gasWithOverhead , l1BaseFee , scalar )
184184 return l1Cost , gasWithOverhead
185185 }
186186}
187187
188188// newL1CostFuncEcotone returns an l1 cost function suitable for the Ecotone upgrade except for the
189189// very first block of the upgrade.
190- func newL1CostFuncEcotone (l1Basefee , l1BlobBasefee , l1BasefeeScalar , l1BlobBasefeeScalar * big.Int ) l1CostFunc {
190+ func newL1CostFuncEcotone (l1BaseFee , l1BlobBaseFee , l1BaseFeeScalar , l1BlobBaseFeeScalar * big.Int ) l1CostFunc {
191191 return func (costData RollupCostData ) (fee , calldataGasUsed * big.Int ) {
192192 calldataGas := (costData .zeroes * params .TxDataZeroGas ) + (costData .ones * params .TxDataNonZeroGasEIP2028 )
193193 calldataGasUsed = new (big.Int ).SetUint64 (calldataGas )
194194
195195 // Ecotone L1 cost function:
196196 //
197- // (calldataGas/16)*(l1Basefee *16*l1BasefeeScalar + l1BlobBasefee*l1BlobBasefeeScalar )/1e6
197+ // (calldataGas/16)*(l1BaseFee *16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar )/1e6
198198 //
199199 // We divide "calldataGas" by 16 to change from units of calldata gas to "estimated # of bytes when
200200 // compressed". Known as "compressedTxSize" in the spec.
201201 //
202202 // Function is actually computed as follows for better precision under integer arithmetic:
203203 //
204- // calldataGas*(l1Basefee *16*l1BasefeeScalar + l1BlobBasefee*l1BlobBasefeeScalar )/16e6
204+ // calldataGas*(l1BaseFee *16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar )/16e6
205205
206- calldataCostPerByte := new (big.Int ).Set (l1Basefee )
206+ calldataCostPerByte := new (big.Int ).Set (l1BaseFee )
207207 calldataCostPerByte = calldataCostPerByte .Mul (calldataCostPerByte , sixteen )
208- calldataCostPerByte = calldataCostPerByte .Mul (calldataCostPerByte , l1BasefeeScalar )
208+ calldataCostPerByte = calldataCostPerByte .Mul (calldataCostPerByte , l1BaseFeeScalar )
209209
210- blobCostPerByte := new (big.Int ).Set (l1BlobBasefee )
211- blobCostPerByte = blobCostPerByte .Mul (blobCostPerByte , l1BlobBasefeeScalar )
210+ blobCostPerByte := new (big.Int ).Set (l1BlobBaseFee )
211+ blobCostPerByte = blobCostPerByte .Mul (blobCostPerByte , l1BlobBaseFeeScalar )
212212
213213 fee = new (big.Int ).Add (calldataCostPerByte , blobCostPerByte )
214214 fee = fee .Mul (fee , calldataGasUsed )
@@ -219,12 +219,12 @@ func newL1CostFuncEcotone(l1Basefee, l1BlobBasefee, l1BasefeeScalar, l1BlobBasef
219219}
220220
221221// extractL1GasParams extracts the gas parameters necessary to compute gas costs from L1 block info
222- func extractL1GasParams (config * params.ChainConfig , time uint64 , data []byte ) (l1Basefee * big.Int , costFunc l1CostFunc , feeScalar * big.Float , err error ) {
222+ func extractL1GasParams (config * params.ChainConfig , time uint64 , data []byte ) (l1BaseFee * big.Int , costFunc l1CostFunc , feeScalar * big.Float , err error ) {
223223 if config .IsEcotone (time ) {
224224 // edge case: for the very first Ecotone block we still need to use the Bedrock
225225 // function. We detect this edge case by seeing if the function selector is the old one
226226 if len (data ) >= 4 && ! bytes .Equal (data [0 :4 ], BedrockL1AttributesSelector ) {
227- l1Basefee , costFunc , err = extractL1GasParamsEcotone (data )
227+ l1BaseFee , costFunc , err = extractL1GasParamsEcotone (data )
228228 return
229229 }
230230 }
@@ -234,52 +234,52 @@ func extractL1GasParams(config *params.ChainConfig, time uint64, data []byte) (l
234234 return nil , nil , nil , fmt .Errorf ("expected at least %d L1 info bytes, got %d" , 4 + 32 * 8 , len (data ))
235235 }
236236 data = data [4 :] // trim function selector
237- l1Basefee = new (big.Int ).SetBytes (data [32 * 2 : 32 * 3 ]) // arg index 2
237+ l1BaseFee = new (big.Int ).SetBytes (data [32 * 2 : 32 * 3 ]) // arg index 2
238238 overhead := new (big.Int ).SetBytes (data [32 * 6 : 32 * 7 ]) // arg index 6
239239 scalar := new (big.Int ).SetBytes (data [32 * 7 : 32 * 8 ]) // arg index 7
240240 fscalar := new (big.Float ).SetInt (scalar ) // legacy: format fee scalar as big Float
241241 fdivisor := new (big.Float ).SetUint64 (1_000_000 ) // 10**6, i.e. 6 decimals
242242 feeScalar = new (big.Float ).Quo (fscalar , fdivisor )
243- costFunc = newL1CostFuncBedrockHelper (l1Basefee , overhead , scalar , config .IsRegolith (time ))
243+ costFunc = newL1CostFuncBedrockHelper (l1BaseFee , overhead , scalar , config .IsRegolith (time ))
244244 return
245245}
246246
247247// extractEcotoneL1GasParams extracts the gas parameters necessary to compute gas from L1 attribute
248248// info calldata after the Ecotone upgrade, but not for the very first Ecotone block.
249- func extractL1GasParamsEcotone (data []byte ) (l1Basefee * big.Int , costFunc l1CostFunc , err error ) {
249+ func extractL1GasParamsEcotone (data []byte ) (l1BaseFee * big.Int , costFunc l1CostFunc , err error ) {
250250 if len (data ) != 164 {
251251 return nil , nil , fmt .Errorf ("expected 164 L1 info bytes, got %d" , len (data ))
252252 }
253253 // data layout assumed for Ecotone:
254254 // offset type varname
255255 // 0 <selector>
256256 // 4 uint32 _basefeeScalar
257- // 8 uint32 _blobBasefeeScalar
257+ // 8 uint32 _blobBaseFeeScalar
258258 // 12 uint64 _sequenceNumber,
259259 // 20 uint64 _timestamp,
260260 // 28 uint64 _l1BlockNumber
261261 // 36 uint256 _basefee,
262- // 68 uint256 _blobBasefee ,
262+ // 68 uint256 _blobBaseFee ,
263263 // 100 bytes32 _hash,
264264 // 132 bytes32 _batcherHash,
265- l1Basefee = new (big.Int ).SetBytes (data [36 :68 ])
266- l1BlobBasefee := new (big.Int ).SetBytes (data [68 :100 ])
267- l1BasefeeScalar := new (big.Int ).SetBytes (data [4 :8 ])
268- l1BlobBasefeeScalar := new (big.Int ).SetBytes (data [8 :12 ])
269- costFunc = newL1CostFuncEcotone (l1Basefee , l1BlobBasefee , l1BasefeeScalar , l1BlobBasefeeScalar )
265+ l1BaseFee = new (big.Int ).SetBytes (data [36 :68 ])
266+ l1BlobBaseFee := new (big.Int ).SetBytes (data [68 :100 ])
267+ l1BaseFeeScalar := new (big.Int ).SetBytes (data [4 :8 ])
268+ l1BlobBaseFeeScalar := new (big.Int ).SetBytes (data [8 :12 ])
269+ costFunc = newL1CostFuncEcotone (l1BaseFee , l1BlobBaseFee , l1BaseFeeScalar , l1BlobBaseFeeScalar )
270270 return
271271}
272272
273273// L1Cost computes the the data availability fee for transactions in blocks prior to the Ecotone
274274// upgrade. It is used by e2e tests so must remain exported.
275- func L1Cost (rollupDataGas uint64 , l1Basefee , overhead , scalar * big.Int ) * big.Int {
275+ func L1Cost (rollupDataGas uint64 , l1BaseFee , overhead , scalar * big.Int ) * big.Int {
276276 l1GasUsed := new (big.Int ).SetUint64 (rollupDataGas )
277277 l1GasUsed .Add (l1GasUsed , overhead )
278- return l1CostHelper (l1GasUsed , l1Basefee , scalar )
278+ return l1CostHelper (l1GasUsed , l1BaseFee , scalar )
279279}
280280
281- func l1CostHelper (gasWithOverhead , l1Basefee , scalar * big.Int ) * big.Int {
281+ func l1CostHelper (gasWithOverhead , l1BaseFee , scalar * big.Int ) * big.Int {
282282 fee := new (big.Int ).Set (gasWithOverhead )
283- fee .Mul (fee , l1Basefee ).Mul (fee , scalar ).Div (fee , oneMillion )
283+ fee .Mul (fee , l1BaseFee ).Mul (fee , scalar ).Div (fee , oneMillion )
284284 return fee
285285}
0 commit comments