Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3d50dd1
Change l1DataFee to rollupFee for Feynman
ranchalp Jun 7, 2025
98f41d7
Update CommitScalarSlot to ExecScalarSlot
ranchalp Jun 7, 2025
90bd9f4
Rename l1DataFee to rollupFee
ranchalp Jun 9, 2025
49574cb
Scale compression ratio to match scalars precision
ranchalp Jun 9, 2025
685e4ba
Use l1DataFee and commitScalar instead of rollupFee and execScalar
ranchalp Jun 10, 2025
b221a0c
Merge branch 'develop' into l1data-to-rollupfee
ranchalp Jun 10, 2025
a39317a
Merge branch 'develop' into l1data-to-rollupfee
ranchalp Jun 11, 2025
ce2498e
Use blocktime not blocknumber
ranchalp Jun 11, 2025
2b061e4
Add unit test
ranchalp Jun 11, 2025
c3c5595
Clarify test comment
ranchalp Jun 11, 2025
61af023
feat(feynman): upgrade gas oracle predeploy
Thegaram Jun 24, 2025
080cbf3
Merge branch 'develop' into l1data-to-rollupfee
colinlyguo Jun 24, 2025
93f9920
Merge branch 'feat-feynman-gas-oracle' into l1data-to-rollupfee
colinlyguo Jun 24, 2025
393d6c1
address comments
Jun 24, 2025
b93d2c1
revert renaming CalculateL1DataFee to CalculateRollupFee
Jun 24, 2025
9808365
simplify EstimateL1DataFeeForMessage
Jun 24, 2025
3156b02
address comments
Jun 24, 2025
5039d30
add a comment based on pr reviews
Jun 24, 2025
7d7a9b6
update formula
Jun 24, 2025
a36f63c
tweaks
Jun 24, 2025
b621be4
tweak comments
Jun 25, 2025
872ccf5
Estimate compression ratio at rollupFee for Feynman (#1197)
ranchalp Jun 25, 2025
1fbe3ea
refactoring
Jun 25, 2025
8df47a2
Merge branch 'develop' into l1data-to-rollupfee
Thegaram Jun 25, 2025
dd262c1
remove incorrect merge artifact
Thegaram Jun 25, 2025
bd7f658
error handling
Jun 25, 2025
ee255a4
update da-codec commit
Jun 25, 2025
bad7cac
update da-codec commit
Jun 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/misc/curie.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func ApplyCurieHardFork(statedb *state.StateDB) {
// initialize new storage slots
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.IsCurieSlot, common.BytesToHash([]byte{1}))
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.L1BlobBaseFeeSlot, common.BytesToHash([]byte{1}))
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.CommitScalarSlot, common.BigToHash(rcfg.InitialCommitScalar))
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.ExecScalarSlot, common.BigToHash(rcfg.InitialCommitScalar))
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.BlobScalarSlot, common.BigToHash(rcfg.InitialBlobScalar))
}
2 changes: 1 addition & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3757,7 +3757,7 @@ func TestCurieTransition(t *testing.T) {
poseidonCodeHash := statedb.GetPoseidonCodeHash(rcfg.L1GasPriceOracleAddress)

l1BlobBaseFee := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.L1BlobBaseFeeSlot)
commitScalar := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.CommitScalarSlot)
commitScalar := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.ExecScalarSlot)
blobScalar := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.BlobScalarSlot)
isCurie := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.IsCurieSlot)

Expand Down
2 changes: 1 addition & 1 deletion ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var genesis = &core.Genesis{
rcfg.OverheadSlot: common.BigToHash(big.NewInt(10000)),
rcfg.ScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.L1BlobBaseFeeSlot: common.BigToHash(big.NewInt(10000)),
rcfg.CommitScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.ExecScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.BlobScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.IsCurieSlot: common.BytesToHash([]byte{1}),
},
Expand Down
2 changes: 1 addition & 1 deletion ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
rcfg.OverheadSlot: common.BigToHash(big.NewInt(10000)),
rcfg.ScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.L1BlobBaseFeeSlot: common.BigToHash(big.NewInt(10000)),
rcfg.CommitScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.ExecScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.BlobScalarSlot: common.BigToHash(big.NewInt(10000)),
rcfg.IsCurieSlot: common.BytesToHash([]byte{1}),
},
Expand Down
5 changes: 5 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ func (c *ChainConfig) IsEuclidV2(now uint64) bool {
return isForkedTime(now, c.EuclidV2Time)
}

// IsFeynman returns whether num is either equal to the Feynman fork block or greater.
func (c *ChainConfig) IsFeynman(num *big.Int) bool {
return false // placeholder
}

// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
if c.TerminalTotalDifficulty == nil {
Expand Down
62 changes: 49 additions & 13 deletions rollup/fees/rollup_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type gpoState struct {
overhead *big.Int
scalar *big.Int
l1BlobBaseFee *big.Int
commitScalar *big.Int
execScalar *big.Int
blobScalar *big.Int
}

Expand All @@ -74,15 +74,17 @@ func EstimateL1DataFeeForMessage(msg Message, baseFee *big.Int, config *params.C

gpoState := readGPOStorageSlots(rcfg.L1GasPriceOracleAddress, state)

var l1DataFee *big.Int
var rollupFee *big.Int

if !config.IsCurie(blockNumber) {
l1DataFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
rollupFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
} else if !config.IsFeynman(blockNumber) {
rollupFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.execScalar, gpoState.blobScalar)
} else {
l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
rollupFee = calculateEncodedRollupFeeFeeFeynman(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.execScalar, gpoState.blobScalar)
}

return l1DataFee, nil
return rollupFee, nil
}

// asUnsignedTx turns a Message into a types.Transaction
Expand Down Expand Up @@ -164,7 +166,7 @@ func readGPOStorageSlots(addr common.Address, state StateDB) gpoState {
gpoState.overhead = state.GetState(addr, rcfg.OverheadSlot).Big()
gpoState.scalar = state.GetState(addr, rcfg.ScalarSlot).Big()
gpoState.l1BlobBaseFee = state.GetState(addr, rcfg.L1BlobBaseFeeSlot).Big()
gpoState.commitScalar = state.GetState(addr, rcfg.CommitScalarSlot).Big()
gpoState.execScalar = state.GetState(addr, rcfg.ExecScalarSlot).Big()
gpoState.blobScalar = state.GetState(addr, rcfg.BlobScalarSlot).Big()
return gpoState
}
Expand Down Expand Up @@ -193,6 +195,38 @@ func calculateEncodedL1DataFeeCurie(data []byte, l1BaseFee *big.Int, l1BlobBaseF
return l1DataFee
}

// calculateEncodedRollupFeeFeeFeynman computes the L1 fee for an RLP-encoded tx, post Feynman
func calculateEncodedRollupFeeFeeFeynman(
data []byte,
l1BaseFee *big.Int,
l1BlobBaseFee *big.Int,
execScalar *big.Int,
blobScalar *big.Int,
) *big.Int {
// tx size (RLP-encoded)
txSize := big.NewInt(int64(len(data)))

// compression_ratio(tx) = 1 (placeholder, scaled to match scalars precision)
compressionRatio := big.NewInt(rcfg.Precision.Int64())

// compute gas components
execGas := new(big.Int).Mul(execScalar, l1BaseFee)
blobGas := new(big.Int).Mul(blobScalar, l1BlobBaseFee)

// fee per byte = execGas + blobGas
feePerByte := new(big.Int).Add(execGas, blobGas)

// rollupFee = compression_ratio * tx_size * feePerByte
rollupFee := new(big.Int).Mul(compressionRatio, txSize)
rollupFee.Mul(rollupFee, feePerByte)

// Divide by rcfg.Precision (once for ratio, once for scalar)
rollupFee.Div(rollupFee, rcfg.Precision)
rollupFee.Div(rollupFee, rcfg.Precision)

return rollupFee
}

// calculateL1GasUsed computes the L1 gas used based on the calldata and
// constant sized overhead. The overhead can be decreased as the cost of the
// batch submission goes down via contract optimizations. This will not overflow
Expand Down Expand Up @@ -238,21 +272,23 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha

gpoState := readGPOStorageSlots(rcfg.L1GasPriceOracleAddress, state)

var l1DataFee *big.Int
var rollupFee *big.Int

if !config.IsCurie(blockNumber) {
l1DataFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
rollupFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
} else if !config.IsFeynman(blockNumber) {
rollupFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.execScalar, gpoState.blobScalar)
} else {
l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
rollupFee = calculateEncodedRollupFeeFeeFeynman(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.execScalar, gpoState.blobScalar)
}

// ensure l1DataFee fits into uint64 for circuit compatibility
// ensure rollupFee fits into uint64 for circuit compatibility
// (note: in practice this value should never be this big)
if !l1DataFee.IsUint64() {
l1DataFee.SetUint64(math.MaxUint64)
if !rollupFee.IsUint64() {
rollupFee.SetUint64(math.MaxUint64)
}

return l1DataFee, nil
return rollupFee, nil
}

func GetL1BaseFee(state StateDB) *big.Int {
Expand Down
2 changes: 1 addition & 1 deletion rollup/rcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (

// New fields added in the Curie hard fork
L1BlobBaseFeeSlot = common.BigToHash(big.NewInt(5))
CommitScalarSlot = common.BigToHash(big.NewInt(6))
ExecScalarSlot = common.BigToHash(big.NewInt(6))
BlobScalarSlot = common.BigToHash(big.NewInt(7))
IsCurieSlot = common.BigToHash(big.NewInt(8))

Expand Down
2 changes: 1 addition & 1 deletion rollup/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
rcfg.OverheadSlot,
rcfg.ScalarSlot,
rcfg.L1BlobBaseFeeSlot,
rcfg.CommitScalarSlot,
rcfg.ExecScalarSlot,
rcfg.BlobScalarSlot,
rcfg.IsCurieSlot,
},
Expand Down
Loading