Skip to content

Commit

Permalink
feat: separate KromaOutputV0 from OutputV0 (#383)
Browse files Browse the repository at this point in the history
* feat: separate `KromaOutputV0` from `OutputV0`

* feat: add `KromaMPTTime` and `L2GenesisKromaMPTTimeOffset`

* feat: add withdrawal proving in MPT
  • Loading branch information
seolaoh committed Nov 8, 2024
1 parent d15b996 commit 3f70540
Show file tree
Hide file tree
Showing 46 changed files with 839 additions and 514 deletions.
4 changes: 2 additions & 2 deletions kroma-bindings/bindings/colosseum.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kroma-bindings/bindings/colosseum_more.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kroma-bindings/bindings/kromaportal.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kroma-bindings/bindings/kromaportal_more.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kroma-bindings/bindings/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions kroma-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ type DeployConfig struct {
// L2GenesisEcotoneTimeOffset is the number of seconds after genesis block that Ecotone hard fork activates.
// Set it to 0 to activate at genesis. Nil to disable Ecotone.
L2GenesisEcotoneTimeOffset *hexutil.Uint64 `json:"l2GenesisEcotoneTimeOffset,omitempty"`
// L2GenesisKromaMPTTimeOffset is the number of seconds after genesis block that Kroma MPT hard fork activates.
// Set it to 0 to activate at genesis. Nil to disable Kroma MPT.
L2GenesisKromaMPTTimeOffset *hexutil.Uint64 `json:"l2GenesisKromaMPTTimeOffset,omitempty"`
// L2GenesisFjordTimeOffset is the number of seconds after genesis block that Fjord hard fork activates.
// Set it to 0 to activate at genesis. Nil to disable Fjord.
L2GenesisFjordTimeOffset *hexutil.Uint64 `json:"l2GenesisFjordTimeOffset,omitempty"`
Expand Down Expand Up @@ -517,11 +520,14 @@ func (d *DeployConfig) Check() error {
if err := checkFork(d.L2GenesisDeltaTimeOffset, d.L2GenesisEcotoneTimeOffset, "delta", "ecotone"); err != nil {
return err
}
if err := checkFork(d.L2GenesisEcotoneTimeOffset, d.L2GenesisFjordTimeOffset, "ecotone", "fjord"); err != nil {
// [Kroma: START]
if err := checkFork(d.L2GenesisEcotoneTimeOffset, d.L2GenesisKromaMPTTimeOffset, "ecotone", "mpt"); err != nil {
return err
}
if err := checkFork(d.L2GenesisKromaMPTTimeOffset, d.L2GenesisFjordTimeOffset, "mpt", "fjord"); err != nil {
return err
}

// [Kroma: START]
if d.ValidatorRewardScalar == 0 {
log.Warn("ValidatorRewardScalar is 0")
}
Expand Down Expand Up @@ -713,6 +719,17 @@ func (d *DeployConfig) EcotoneTime(genesisTime uint64) *uint64 {
return &v
}

func (d *DeployConfig) KromaMPTTime(genesisTime uint64) *uint64 {
if d.L2GenesisKromaMPTTimeOffset == nil {
return nil
}
v := uint64(0)
if offset := *d.L2GenesisKromaMPTTimeOffset; offset > 0 {
v = genesisTime + uint64(offset)
}
return &v
}

func (d *DeployConfig) FjordTime(genesisTime uint64) *uint64 {
if d.L2GenesisFjordTimeOffset == nil {
return nil
Expand Down Expand Up @@ -776,6 +793,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
CanyonTime: d.CanyonTime(l1StartBlock.Time()),
DeltaTime: d.DeltaTime(l1StartBlock.Time()),
EcotoneTime: d.EcotoneTime(l1StartBlock.Time()),
KromaMPTTime: d.KromaMPTTime(l1StartBlock.Time()),
FjordTime: d.FjordTime(l1StartBlock.Time()),
InteropTime: d.InteropTime(l1StartBlock.Time()),
UsePlasma: d.UsePlasma,
Expand Down
9 changes: 8 additions & 1 deletion kroma-chain-ops/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
ShanghaiTime: config.CanyonTime(block.Time()),
CancunTime: config.EcotoneTime(block.Time()),
EcotoneTime: config.EcotoneTime(block.Time()),
InteropTime: config.InteropTime(block.Time()),
// TODO(seolaoh): uncomment this when geth updated
// KromaMPTTime: config.KromaMPTTime(block.Time()),
InteropTime: config.InteropTime(block.Time()),
Kroma: &params.KromaConfig{
EIP1559Denominator: eip1559Denom,
EIP1559Elasticity: eip1559Elasticity,
Expand All @@ -71,6 +73,11 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
Zktrie: true,
}

// TODO(seolaoh): turn off Zktrie when MPT time is past in genesis
//if kromaChainConfig.IsKromaMPT(block.Time()) {
// kromaChainConfig.Zktrie = false
//}

gasLimit := config.L2GenesisBlockGasLimit
if gasLimit == 0 {
gasLimit = defaultGasLimit
Expand Down
35 changes: 14 additions & 21 deletions kroma-chain-ops/genesis/testdata/allocs-l1.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kroma-validator/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func (c *Challenger) OutputAtBlockSafe(ctx context.Context, blockNumber uint64)
return c.cfg.RollupClient.OutputAtBlock(cCtx, blockNumber)
}

func (c *Challenger) OutputWithProofAtBlockSafe(ctx context.Context, blockNumber uint64) (*eth.OutputResponse, error) {
func (c *Challenger) OutputWithProofAtBlockSafe(ctx context.Context, blockNumber uint64) (*eth.OutputWithProofResponse, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
return c.cfg.RollupClient.OutputWithProofAtBlock(cCtx, blockNumber)
Expand Down
13 changes: 12 additions & 1 deletion op-e2e/actions/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type hardforkScheduledTest struct {
canyonTime *hexutil.Uint64
deltaTime *hexutil.Uint64
ecotoneTime *hexutil.Uint64
kromaMPTTime *hexutil.Uint64
fjordTime *hexutil.Uint64
runToFork string
}
Expand All @@ -34,6 +35,8 @@ func (tc *hardforkScheduledTest) fork(fork string) **hexutil.Uint64 {
switch fork {
case "fjord":
return &tc.fjordTime
case "mpt":
return &tc.kromaMPTTime
case "ecotone":
return &tc.ecotoneTime
case "delta":
Expand Down Expand Up @@ -64,7 +67,11 @@ func TestCrossLayerUser(t *testing.T) {
"canyon",
"delta",
"ecotone",
"fjord",
// [Kroma: START]
// TODO(seolaoh): uncomment below forks when geth updated
//"mpt",
// [Kroma: END]
//"fjord",
}
for i, fork := range forks {
i := i
Expand Down Expand Up @@ -112,6 +119,7 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
dp.DeployConfig.L2GenesisCanyonTimeOffset = test.canyonTime
dp.DeployConfig.L2GenesisDeltaTimeOffset = test.deltaTime
dp.DeployConfig.L2GenesisEcotoneTimeOffset = test.ecotoneTime
dp.DeployConfig.L2GenesisKromaMPTTimeOffset = test.kromaMPTTime
dp.DeployConfig.L2GenesisFjordTimeOffset = test.fjordTime

// [Kroma: START]
Expand All @@ -125,6 +133,9 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
if test.ecotoneTime != nil {
require.Zero(t, uint64(*test.ecotoneTime)%uint64(dp.DeployConfig.L2BlockTime), "ecotone fork must be aligned")
}
if test.kromaMPTTime != nil {
require.Zero(t, uint64(*test.kromaMPTTime)%uint64(dp.DeployConfig.L2BlockTime), "kroma mpt fork must be aligned")
}

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand Down
79 changes: 61 additions & 18 deletions op-e2e/e2eutils/mock_l2rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package e2eutils

import (
"context"
"fmt"
"math/rand"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"

"github.com/ethereum-optimism/optimism/op-e2e/testdata"
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)

type MaliciousL2RPC struct {
Expand All @@ -37,24 +37,41 @@ func (m *MaliciousL2RPC) Close() {

func (m *MaliciousL2RPC) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
if method == "optimism_outputAtBlock" || method == "kroma_outputWithProofAtBlock" {
blockNumber := args[0].(hexutil.Uint64)

err := m.rpc.CallContext(ctx, &result, method, blockNumber)
err := m.rpc.CallContext(ctx, result, method, args...)
if err != nil {
return err
}

blockNumber := args[0].(hexutil.Uint64)
if m.targetBlockNumber != nil && *m.targetBlockNumber-1 == blockNumber {
return testdata.SetPrevOutputResponse(result.(**eth.OutputResponse))
if method == "optimism_outputAtBlock" {
if o, ok := result.(**eth.OutputResponse); ok {
return testdata.SetPrevOutputResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
}

if o, ok := result.(**eth.OutputWithProofResponse); ok {
return testdata.SetPrevOutputWithProofResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
} else if m.targetBlockNumber != nil && *m.targetBlockNumber <= blockNumber {
rng := rand.New(rand.NewSource(int64(blockNumber)))

s := result.(**eth.OutputResponse)
(*s).OutputRoot = eth.Bytes32(testutils.RandomHash(rng))
(*s).WithdrawalStorageRoot = testutils.RandomHash(rng)
(*s).StateRoot = testutils.RandomHash(rng)
if o, ok := result.(**eth.OutputResponse); ok {
(**o).OutputRoot = eth.Bytes32(testutils.RandomHash(rng))
(**o).WithdrawalStorageRoot = testutils.RandomHash(rng)
(**o).StateRoot = testutils.RandomHash(rng)

return nil
return nil
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
}

return nil
}

return m.rpc.CallContext(ctx, result, method, args...)
Expand Down Expand Up @@ -91,17 +108,43 @@ func (m *HonestL2RPC) Close() {

func (m *HonestL2RPC) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
if method == "optimism_outputAtBlock" || method == "kroma_outputWithProofAtBlock" {
blockNumber := args[0].(hexutil.Uint64)

err := m.rpc.CallContext(ctx, &result, method, blockNumber)
err := m.rpc.CallContext(ctx, result, method, args...)
if err != nil {
return err
}

blockNumber := args[0].(hexutil.Uint64)
if m.targetBlockNumber != nil && *m.targetBlockNumber-1 == blockNumber {
return testdata.SetPrevOutputResponse(result.(**eth.OutputResponse))
if method == "optimism_outputAtBlock" {
if o, ok := result.(**eth.OutputResponse); ok {
return testdata.SetPrevOutputResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
}

if o, ok := result.(**eth.OutputWithProofResponse); ok {
return testdata.SetPrevOutputWithProofResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
} else if m.targetBlockNumber != nil && *m.targetBlockNumber == blockNumber {
return testdata.SetTargetOutputResponse(result.(**eth.OutputResponse))
if method == "optimism_outputAtBlock" {
if o, ok := result.(**eth.OutputResponse); ok {
return testdata.SetTargetOutputResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
}

if o, ok := result.(**eth.OutputWithProofResponse); ok {
return testdata.SetTargetOutputWithProofResponse(*o)
} else {
return fmt.Errorf("invalid type for result: %T (method %s)", result, method)
}
}

return nil
}

return m.rpc.CallContext(ctx, result, method, args...)
Expand Down
2 changes: 2 additions & 0 deletions op-e2e/e2eutils/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func MakeDeployParams(t require.TestingT, tp *TestParams) *DeployParams {
// genesisTimeOffset := hexutil.Uint64(0)
deployConfig.L2GenesisDeltaTimeOffset = nil
deployConfig.L2GenesisEcotoneTimeOffset = nil
deployConfig.L2GenesisKromaMPTTimeOffset = nil
// [Kroma: END]
ApplyDeployConfigForks(deployConfig)

Expand Down Expand Up @@ -206,6 +207,7 @@ func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *
CanyonTime: deployConf.CanyonTime(uint64(deployConf.L1GenesisBlockTimestamp)),
DeltaTime: deployConf.DeltaTime(uint64(deployConf.L1GenesisBlockTimestamp)),
EcotoneTime: deployConf.EcotoneTime(uint64(deployConf.L1GenesisBlockTimestamp)),
KromaMPTTime: deployConf.KromaMPTTime(uint64(deployConf.L1GenesisBlockTimestamp)),
FjordTime: deployConf.FjordTime(uint64(deployConf.L1GenesisBlockTimestamp)),
InteropTime: deployConf.InteropTime(uint64(deployConf.L1GenesisBlockTimestamp)),
DAChallengeAddress: l1Deployments.DataAvailabilityChallengeProxy,
Expand Down
2 changes: 2 additions & 0 deletions op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func DefaultSystemConfig(t *testing.T) SystemConfig {
// [Kroma: START]
deployConfig.L2GenesisDeltaTimeOffset = nil
deployConfig.L2GenesisEcotoneTimeOffset = nil
deployConfig.L2GenesisKromaMPTTimeOffset = nil
// [Kroma: END]
require.NoError(t, deployConfig.Check(), "Deploy config is invalid, do you need to run make devnet-allocs?")
l1Deployments := config.L1Deployments.Copy()
Expand Down Expand Up @@ -575,6 +576,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
CanyonTime: cfg.DeployConfig.CanyonTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
DeltaTime: cfg.DeployConfig.DeltaTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
EcotoneTime: cfg.DeployConfig.EcotoneTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
KromaMPTTime: cfg.DeployConfig.KromaMPTTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
FjordTime: cfg.DeployConfig.FjordTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
InteropTime: cfg.DeployConfig.InteropTime(uint64(cfg.DeployConfig.L1GenesisBlockTimestamp)),
/* [Kroma: START]
Expand Down
Loading

0 comments on commit 3f70540

Please sign in to comment.