Skip to content

Commit a72d34b

Browse files
authored
Merge pull request ethereum#216 from roberto-bayardo/baseFee
baseFee consistency related renaming
2 parents a79bde2 + b52ff66 commit a72d34b

File tree

4 files changed

+88
-88
lines changed

4 files changed

+88
-88
lines changed

core/types/receipt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,15 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu
570570
}
571571
}
572572
if config.Optimism != nil && len(txs) >= 2 { // need at least an info tx and a non-info tx
573-
l1Basefee, costFunc, feeScalar, err := extractL1GasParams(config, time, txs[0].Data())
573+
l1BaseFee, costFunc, feeScalar, err := extractL1GasParams(config, time, txs[0].Data())
574574
if err != nil {
575575
return err
576576
}
577577
for i := 0; i < len(rs); i++ {
578578
if txs[i].IsDepositTx() {
579579
continue
580580
}
581-
rs[i].L1GasPrice = l1Basefee
581+
rs[i].L1GasPrice = l1BaseFee
582582
rs[i].L1Fee, rs[i].L1GasUsed = costFunc(txs[i].RollupCostData())
583583
rs[i].FeeScalar = feeScalar
584584
}

core/types/receipt_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
458458
// Tests that receipt data can be correctly derived from the contextual infos
459459
func TestDeriveFields(t *testing.T) {
460460
// Re-derive receipts.
461-
basefee := big.NewInt(1000)
461+
baseFee := big.NewInt(1000)
462462
blobGasPrice := big.NewInt(920)
463463
derivedReceipts := clearComputedFieldsOnReceipts(receipts)
464-
err := Receipts(derivedReceipts).DeriveFields(params.TestChainConfig, blockHash, blockNumber.Uint64(), blockTime, basefee, blobGasPrice, txs)
464+
err := Receipts(derivedReceipts).DeriveFields(params.TestChainConfig, blockHash, blockNumber.Uint64(), blockTime, baseFee, blobGasPrice, txs)
465465
if err != nil {
466466
t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
467467
}
@@ -765,49 +765,49 @@ func TestDeriveOptimismBedrockTxReceipts(t *testing.T) {
765765
// Bedrock style l1 attributes with L1Scalar=7_000_000 (becomes 7 after division), L1Overhead=50, L1BaseFee=1000*1e6
766766
payload := common.Hex2Bytes("015d8eb900000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000006acfc0015d8eb900000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000006acfc0")
767767
// the parameters we use below are defined in rollup_test.go
768-
l1GasPrice := basefee
768+
l1GasPrice := baseFee
769769
l1GasUsed := bedrockGas
770770
feeScalar := big.NewFloat(float64(scalar.Uint64() / 1e6))
771771
l1Fee := bedrockFee
772772
txs, receipts := getOptimismTxReceipts(t, payload, l1GasPrice, l1GasUsed, feeScalar, l1Fee)
773773

774774
// Re-derive receipts.
775-
basefee := big.NewInt(1000)
775+
baseFee := big.NewInt(1000)
776776
derivedReceipts := clearComputedFieldsOnReceipts(receipts)
777-
err := Receipts(derivedReceipts).DeriveFields(params.OptimismTestConfig, blockHash, blockNumber.Uint64(), 0, basefee, nil, txs)
777+
err := Receipts(derivedReceipts).DeriveFields(params.OptimismTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs)
778778
if err != nil {
779779
t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
780780
}
781781
checkBedrockReceipts(t, receipts, derivedReceipts)
782782

783783
// Should get same result with the Ecotone config because it will assume this is "first ecotone block"
784784
// if it sees the bedrock style L1 attributes.
785-
err = Receipts(derivedReceipts).DeriveFields(ecotoneTestConfig, blockHash, blockNumber.Uint64(), 0, basefee, nil, txs)
785+
err = Receipts(derivedReceipts).DeriveFields(ecotoneTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs)
786786
if err != nil {
787787
t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
788788
}
789789
checkBedrockReceipts(t, receipts, derivedReceipts)
790790
}
791791

792792
func TestDeriveOptimismEcotoneTxReceipts(t *testing.T) {
793-
// Ecotone style l1 attributes with basefeeScalar=2, blobBasfeeScalar=3, baseFee=1000*1e6, blobBasefee=10*1e6
793+
// Ecotone style l1 attributes with baseFeeScalar=2, blobBaseFeeScalar=3, baseFee=1000*1e6, blobBaseFee=10*1e6
794794
payload := common.Hex2Bytes("440a5e20000000020000000300000000000004d200000000000004d200000000000004d2000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2")
795795
// the parameters we use below are defined in rollup_test.go
796-
l1GasPrice := basefee
796+
l1GasPrice := baseFee
797797
l1GasUsed := ecotoneGas
798798
l1Fee := ecotoneFee
799799
txs, receipts := getOptimismTxReceipts(t, payload, l1GasPrice, l1GasUsed, nil /*feeScalar*/, l1Fee)
800800

801801
// Re-derive receipts.
802-
basefee := big.NewInt(1000)
802+
baseFee := big.NewInt(1000)
803803
derivedReceipts := clearComputedFieldsOnReceipts(receipts)
804804
// Should error out if we try to process this with a pre-Ecotone config
805-
err := Receipts(derivedReceipts).DeriveFields(params.OptimismTestConfig, blockHash, blockNumber.Uint64(), 0, basefee, nil, txs)
805+
err := Receipts(derivedReceipts).DeriveFields(params.OptimismTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs)
806806
if err == nil {
807807
t.Fatalf("expected error from deriving ecotone receipts with pre-ecotone config, got none")
808808
}
809809

810-
err = Receipts(derivedReceipts).DeriveFields(ecotoneTestConfig, blockHash, blockNumber.Uint64(), 0, basefee, nil, txs)
810+
err = Receipts(derivedReceipts).DeriveFields(ecotoneTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs)
811811
if err != nil {
812812
t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
813813
}

core/types/rollup_cost.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4444
func 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.
160160
func 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

Comments
 (0)