Skip to content

Commit

Permalink
fix: remove unnecessary KromaDepositTx conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangssu committed Dec 6, 2024
1 parent 2a89698 commit ea62d36
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 31 deletions.
14 changes: 14 additions & 0 deletions op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.Payloa
txBytes = append(txBytes, bin)
}

// [Kroma: START] Use KromaDepositTx instead of DepositTx
if d.L2ChainConfig.IsPreKromaMPT(uint64(timestamp)) {
for i := range txBytes {
if txBytes[i][0] == types.DepositTxType {
bin, err := derive.ToKromaDepositBytes(txBytes[i])
if err != nil {
return nil, fmt.Errorf("failed to convert DepositTx to KromaDepositTx: %w", err)
}
txBytes[i] = bin
}
}
}
// [Kroma: END]

var withdrawals *types.Withdrawals
if d.L2ChainConfig.IsCanyon(uint64(timestamp)) {
withdrawals = &types.Withdrawals{}
Expand Down
182 changes: 182 additions & 0 deletions op-e2e/op_geth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func TestInvalidDepositInFCU(t *testing.T) {
Gas: 25000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
badDepositTx, err = badDepositTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// We are inserting a block with an invalid deposit.
// The invalid deposit should still remain in the block.
Expand Down Expand Up @@ -263,6 +267,10 @@ func TestPreregolith(t *testing.T) {
Gas: 25000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
depositTx, err = depositTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

envelope, err := opGeth.AddL2Block(ctx, depositTx)
require.NoError(t, err)
Expand Down Expand Up @@ -308,6 +316,10 @@ func TestPreregolith(t *testing.T) {
Gas: 21_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
incrementNonceTx, err = incrementNonceTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// Contract creation deposit tx
contractCreateTx := types.NewTx(&types.DepositTx{
Expand All @@ -317,6 +329,10 @@ func TestPreregolith(t *testing.T) {
Data: []byte{},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
contractCreateTx, err = contractCreateTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, incrementNonceTx, contractCreateTx)
require.NoError(t, err)
Expand Down Expand Up @@ -367,6 +383,10 @@ func TestPreregolith(t *testing.T) {
Gas: uint64(cfg.DeployConfig.L2GenesisBlockGasLimit) - 1_000_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
depositTx, err = depositTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

signer := types.LatestSigner(opGeth.L2ChainConfig)
// Second tx with a gas limit that will fit in regolith but not bedrock
Expand Down Expand Up @@ -452,6 +472,10 @@ func TestRegolith(t *testing.T) {
Gas: 25000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
depositTx, err = depositTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

envelope, err := opGeth.AddL2Block(ctx, depositTx)
require.NoError(t, err)
Expand Down Expand Up @@ -504,6 +528,10 @@ func TestRegolith(t *testing.T) {
Gas: 21_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
incrementNonceTx, err = incrementNonceTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// Contract creation deposit tx
contractCreateTx := types.NewTx(&types.DepositTx{
Expand All @@ -513,6 +541,10 @@ func TestRegolith(t *testing.T) {
Data: []byte{},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
contractCreateTx, err = contractCreateTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, incrementNonceTx, contractCreateTx)
require.NoError(t, err)
Expand Down Expand Up @@ -570,6 +602,10 @@ func TestRegolith(t *testing.T) {
Gas: uint64(cfg.DeployConfig.L2GenesisBlockGasLimit) - 1_000_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
depositTx, err = depositTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

signer := types.LatestSigner(opGeth.L2ChainConfig)
// Second tx with a gas limit that will fit in regolith but not bedrock
Expand Down Expand Up @@ -674,6 +710,10 @@ func TestRegolith(t *testing.T) {
Gas: 1_000_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
deployTx, err = deployTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// Store a non-zero value
storeTx := types.NewTx(&types.DepositTx{
Expand All @@ -684,6 +724,10 @@ func TestRegolith(t *testing.T) {
Gas: 1_000_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
storeTx, err = storeTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// Store a non-zero value
zeroTx := types.NewTx(&types.DepositTx{
Expand All @@ -694,6 +738,10 @@ func TestRegolith(t *testing.T) {
Gas: 1_000_000,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
zeroTx, err = zeroTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

// Store a non-zero value again
// Has same gas cost as zeroTx, except the first tx gets a gas refund for clearing the storage slot
Expand All @@ -705,6 +753,10 @@ func TestRegolith(t *testing.T) {
Gas: 1_000_001,
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
rezeroTx, err = rezeroTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, deployTx, storeTx, zeroTx, rezeroTx)
require.NoError(t, err)
Expand Down Expand Up @@ -791,6 +843,10 @@ func TestPreCanyon(t *testing.T) {
},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
pushZeroContractCreateTxn, err = pushZeroContractCreateTxn.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, pushZeroContractCreateTxn)
require.NoError(t, err)
Expand Down Expand Up @@ -865,6 +921,10 @@ func TestCanyon(t *testing.T) {
},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
pushZeroContractCreateTxn, err = pushZeroContractCreateTxn.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, pushZeroContractCreateTxn)
require.NoError(t, err)
Expand Down Expand Up @@ -933,6 +993,10 @@ func TestPreEcotone(t *testing.T) {
},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
tstoreTxn, err = tstoreTxn.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, tstoreTxn)
require.NoError(t, err)
Expand Down Expand Up @@ -1014,6 +1078,10 @@ func TestEcotone(t *testing.T) {
},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
tstoreTxn, err = tstoreTxn.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, tstoreTxn)
require.NoError(t, err)
Expand All @@ -1027,3 +1095,117 @@ func TestEcotone(t *testing.T) {
})
}
}

func TestPreKromaMPT(t *testing.T) {
futureTimestamp := hexutil.Uint64(4)

tests := []struct {
name string
kromaMPTTime *hexutil.Uint64
}{
{name: "KromaMPTNotScheduled"},
{name: "KromaMPTNotYetActive", kromaMPTTime: &futureTimestamp},
}
for _, test := range tests {
test := test
t.Run(fmt.Sprintf("KromaDepositTx_%s", test.name), func(t *testing.T) {
InitParallel(t)
cfg := DefaultSystemConfig(t)
s := hexutil.Uint64(0)
cfg.DeployConfig.L2GenesisCanyonTimeOffset = &s
cfg.DeployConfig.L2GenesisDeltaTimeOffset = &s
cfg.DeployConfig.L2GenesisEcotoneTimeOffset = &s
cfg.DeployConfig.L2GenesisKromaMPTTimeOffset = test.kromaMPTTime

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

opGeth, err := NewOpGeth(t, ctx, &cfg)
require.NoError(t, err)
defer opGeth.Close()

fromAddr := cfg.Secrets.Addresses().Alice
// Contract creation deposit tx
contractCreateTx := types.NewTx(&types.DepositTx{
From: fromAddr,
Value: big.NewInt(params.Ether),
Gas: 1000001,
Data: []byte{},
IsSystemTransaction: false,
})
// [Kroma: START] Use KromaDepositTx instead of DepositTx
contractCreateTx, err = contractCreateTx.ToKromaDepositTx()
require.NoError(t, err)
// [Kroma: END]

_, err = opGeth.AddL2Block(ctx, contractCreateTx)
require.NoError(t, err)

// Check L1Info
l2Block, err := opGeth.L2Client.BlockByNumber(ctx, nil)
require.NoError(t, err)
depTxBytes, err := l2Block.Transactions()[0].MarshalBinary()
require.NoError(t, err)
isKromaDepTx, err := types.IsKromaDepositTx(depTxBytes[1:])
require.NoError(t, err)
assert.Equal(t, true, isKromaDepTx)

receipt, err := opGeth.L2Client.TransactionReceipt(ctx, contractCreateTx.Hash())
require.NoError(t, err)
assert.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)
})
}
}

func TestKromaMPT(t *testing.T) {
tests := []struct {
name string
kromaMPTTime hexutil.Uint64
}{
{name: "ActivateAtGenesis", kromaMPTTime: 0},
}
for _, test := range tests {
test := test
t.Run(fmt.Sprintf("ReviveDepositTx_%s", test.name), func(t *testing.T) {
InitParallel(t)
cfg := DefaultSystemConfig(t)
s := hexutil.Uint64(0)
cfg.DeployConfig.L2GenesisCanyonTimeOffset = &s
cfg.DeployConfig.L2GenesisDeltaTimeOffset = &s
cfg.DeployConfig.L2GenesisEcotoneTimeOffset = &s
cfg.DeployConfig.L2GenesisKromaMPTTimeOffset = &test.kromaMPTTime

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

opGeth, err := NewOpGeth(t, ctx, &cfg)
require.NoError(t, err)
defer opGeth.Close()

fromAddr := cfg.Secrets.Addresses().Alice
// Contract creation deposit tx
contractCreateTx := types.NewTx(&types.DepositTx{
From: fromAddr,
Value: big.NewInt(params.Ether),
Gas: 1000001,
Data: []byte{},
IsSystemTransaction: false,
})

_, err = opGeth.AddL2Block(ctx, contractCreateTx)
require.NoError(t, err)

l2Block, err := opGeth.L2Client.BlockByNumber(ctx, nil)
require.NoError(t, err)
depTxBytes, err := l2Block.Transactions()[0].MarshalBinary()
require.NoError(t, err)
isKromaDepTx, err := types.IsKromaDepositTx(depTxBytes[1:])
require.NoError(t, err)
assert.Equal(t, false, isKromaDepTx)

receipt, err := opGeth.L2Client.TransactionReceipt(ctx, contractCreateTx.Hash())
require.NoError(t, err)
assert.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)
})
}
}
16 changes: 0 additions & 16 deletions op-node/p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/kroma-network/kroma/op-node/rollup/derive"
)

// StreamCtxFn provides a new context to use when handling stream requests
Expand Down Expand Up @@ -670,20 +668,6 @@ func (s *SyncClient) readExecutionPayload(data []byte, expectedTime uint64) (*et
return nil, fmt.Errorf("failed to decode response: %w", err)
}

// [Kroma: START] Use KromaDepositTx instead of DepositTx before MPT time
if !s.cfg.IsKromaMPT(expectedTime) {
for i, otx := range res.Transactions {
if otx[0] == types.DepositTxType {
var err error
res.Transactions[i], err = derive.ToKromaDepositBytes(otx)
if err != nil {
return nil, fmt.Errorf("failed to convert deposit tx to KromaDepositTx: %w", err)
}
}
}
}
// [Kroma: END]

return &eth.ExecutionPayloadEnvelope{ExecutionPayload: &res}, nil
}

Expand Down
7 changes: 0 additions & 7 deletions op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ func ToKromaDepositBytes(input hexutil.Bytes) (hexutil.Bytes, error) {
if input[0] != types.DepositTxType {
return nil, fmt.Errorf("unexpected transaction type: %d", input[0])
}
isKromaDepTx, err := types.IsKromaDepositTx(input[1:]);
if err != nil {
return nil, err
}
if isKromaDepTx {
return input, nil
}
var tx types.Transaction
if err := tx.UnmarshalBinary(input); err != nil {
return nil, fmt.Errorf("failed to decode deposit tx: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func TestAttributesQueue(t *testing.T) {
l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
require.NoError(st, err)

l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
kromaDepTx, err := ToKromaDepositBytes(l1InfoTx)
require.NoError(st, err)
testAttributes(l1InfoTx, common.Address{})
testAttributes(kromaDepTx, common.Address{})
})

t.Run("after kroma mpt time", func(st *testing.T) {
Expand Down
Loading

0 comments on commit ea62d36

Please sign in to comment.