Skip to content

Commit a67863c

Browse files
authored
feat(feynman): upgrade gas oracle predeploy (#1213)
* feat(feynman): upgrade gas oracle predeploy * update execution witness * prettify constants * fix fork application order
1 parent 02b33db commit a67863c

File tree

9 files changed

+115
-26
lines changed

9 files changed

+115
-26
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
152152
if chainConfig.CurieBlock != nil && chainConfig.CurieBlock.Cmp(new(big.Int).SetUint64(pre.Env.Number)) == 0 {
153153
misc.ApplyCurieHardFork(statedb)
154154
}
155+
// Apply Feynman hard fork
156+
if chainConfig.IsFeynmanTransitionBlock(pre.Env.Timestamp, pre.Env.ParentTimestamp) {
157+
misc.ApplyFeynmanHardFork(statedb)
158+
}
155159
// Apply EIP-2935
156160
if pre.Env.BlockHashes != nil && chainConfig.IsFeynman(pre.Env.Timestamp) {
157161
var (

consensus/misc/feynman.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package misc
2+
3+
import (
4+
"github.com/scroll-tech/go-ethereum/common"
5+
"github.com/scroll-tech/go-ethereum/core/state"
6+
"github.com/scroll-tech/go-ethereum/log"
7+
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
8+
)
9+
10+
// ApplyFeynmanHardFork modifies the state database according to the Feynman hard-fork rules,
11+
// updating the bytecode and storage of the L1GasPriceOracle contract.
12+
func ApplyFeynmanHardFork(statedb *state.StateDB) {
13+
log.Info("Applying Feynman hard fork")
14+
15+
// update contract byte code
16+
statedb.SetCode(rcfg.L1GasPriceOracleAddress, rcfg.FeynmanL1GasPriceOracleBytecode)
17+
18+
// initialize new storage slots
19+
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.IsFeynmanSlot, common.BytesToHash([]byte{1}))
20+
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.PenaltyThresholdSlot, common.BigToHash(rcfg.InitialPenaltyThreshold))
21+
statedb.SetState(rcfg.L1GasPriceOracleAddress, rcfg.PenaltyFactorSlot, common.BigToHash(rcfg.InitialPenaltyFactor))
22+
}

core/chain_makers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
249249
if config.CurieBlock != nil && config.CurieBlock.Cmp(b.header.Number) == 0 {
250250
misc.ApplyCurieHardFork(statedb)
251251
}
252+
if config.IsFeynmanTransitionBlock(b.Time(), parent.Time()) {
253+
misc.ApplyFeynmanHardFork(statedb)
254+
}
252255
// Execute any user modifications to the block
253256
if gen != nil {
254257
gen(i, b)

core/state_processor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
9191
if p.config.CurieBlock != nil && p.config.CurieBlock.Cmp(block.Number()) == 0 {
9292
misc.ApplyCurieHardFork(statedb)
9393
}
94+
// Apply Feynman hard fork
95+
parent := p.bc.GetHeaderByHash(block.ParentHash())
96+
if p.config.IsFeynmanTransitionBlock(block.Time(), parent.Time) {
97+
misc.ApplyFeynmanHardFork(statedb)
98+
}
9499
blockContext := NewEVMBlockContext(header, p.bc, p.config, nil)
95100
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
96101
processorBlockTransactionGauge.Update(int64(block.Transactions().Len()))

eth/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ func generateWitness(blockchain *core.BlockChain, block *types.Block) (*stateles
362362
// Collect storage locations that prover needs but sequencer might not touch necessarily
363363
statedb.GetState(rcfg.L2MessageQueueAddress, rcfg.WithdrawTrieRootSlot)
364364

365+
// Note: scroll-revm detects the Feynman transition block using this storage slot,
366+
// since it does not have access to the parent block timestamp. We need to make
367+
// sure that this is always present in the execution witness.
368+
statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.IsFeynmanSlot)
369+
365370
receipts, _, usedGas, err := blockchain.Processor().Process(block, statedb, *blockchain.GetVMConfig())
366371
if err != nil {
367372
return nil, fmt.Errorf("failed to process block %d: %w", block.Number(), err)

miner/scroll_worker.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ func (w *worker) collectPendingL1Messages(startIndex uint64) []types.L1MessageTx
464464
}
465465

466466
// newWork
467-
func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, reorgReason error) error {
468-
parent := w.chain.GetBlockByHash(parentHash)
467+
func (w *worker) newWork(now time.Time, parent *types.Block, reorging bool, reorgReason error) error {
469468
header := &types.Header{
470469
ParentHash: parent.Hash(),
471470
Number: new(big.Int).Add(parent.Number(), common.Big1),
@@ -586,13 +585,14 @@ func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, r
586585
}
587586

588587
// tryCommitNewWork
589-
func (w *worker) tryCommitNewWork(now time.Time, parent common.Hash, reorging bool, reorgReason error) (common.Hash, error) {
588+
func (w *worker) tryCommitNewWork(now time.Time, parentHash common.Hash, reorging bool, reorgReason error) (common.Hash, error) {
589+
parent := w.chain.GetBlockByHash(parentHash)
590590
err := w.newWork(now, parent, reorging, reorgReason)
591591
if err != nil {
592592
return common.Hash{}, fmt.Errorf("failed creating new work: %w", err)
593593
}
594594

595-
shouldCommit, err := w.handleForks()
595+
shouldCommit, err := w.handleForks(parent)
596596
if err != nil {
597597
return common.Hash{}, fmt.Errorf("failed handling forks: %w", err)
598598
}
@@ -626,17 +626,16 @@ func (w *worker) tryCommitNewWork(now time.Time, parent common.Hash, reorging bo
626626
}
627627

628628
// handleForks
629-
func (w *worker) handleForks() (bool, error) {
629+
func (w *worker) handleForks(parent *types.Block) (bool, error) {
630630
// Apply Curie predeployed contract update
631631
if w.chainConfig.CurieBlock != nil && w.chainConfig.CurieBlock.Cmp(w.current.header.Number) == 0 {
632632
misc.ApplyCurieHardFork(w.current.state)
633633
return true, nil
634634
}
635635

636-
// Stop/start miner at Euclid fork boundary on zktrie/mpt nodes
637-
if w.chainConfig.IsEuclid(w.current.header.Time) {
638-
parent := w.chain.GetBlockByHash(w.current.header.ParentHash)
639-
return parent != nil && !w.chainConfig.IsEuclid(parent.Time()), nil
636+
// Apply Feynman hard fork
637+
if w.chainConfig.IsFeynmanTransitionBlock(w.current.header.Time, parent.Time()) {
638+
misc.ApplyFeynmanHardFork(w.current.state)
640639
}
641640

642641
// Apply EIP-2935
@@ -646,6 +645,12 @@ func (w *worker) handleForks() (bool, error) {
646645
core.ProcessParentBlockHash(w.current.header.ParentHash, vmenv, w.current.state)
647646
}
648647

648+
// Stop/start miner at Euclid fork boundary on zktrie/mpt nodes
649+
if w.chainConfig.IsEuclid(w.current.header.Time) {
650+
parent := w.chain.GetBlockByHash(w.current.header.ParentHash)
651+
return parent != nil && !w.chainConfig.IsEuclid(parent.Time()), nil
652+
}
653+
649654
return false, nil
650655
}
651656

params/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,11 @@ func (c *ChainConfig) IsFeynman(now uint64) bool {
10021002
return isForkedTime(now, c.FeynmanTime)
10031003
}
10041004

1005+
// IsFeynmanTransitionBlock returns whether the given block timestamp corresponds to the first Feynman block.
1006+
func (c *ChainConfig) IsFeynmanTransitionBlock(blockTimestamp uint64, parentTimestamp uint64) bool {
1007+
return isForkedTime(blockTimestamp, c.FeynmanTime) && !isForkedTime(parentTimestamp, c.FeynmanTime)
1008+
}
1009+
10051010
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
10061011
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
10071012
if c.TerminalTotalDifficulty == nil {

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 57 // Patch version component of the current release
27+
VersionPatch = 58 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/rcfg/config.go

Lines changed: 56 additions & 16 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)