Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change predeploy contract addresses #398

Merged
merged 14 commits into from
Dec 16, 2024
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@ require (

replace github.com/ethereum-optimism/optimism v1.7.2 => ./

replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v1.101308.3-0.20241205054106-fd7e291968d6
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v1.101308.3-0.20241209003634-d80c1f1bfb77
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241205054106-fd7e291968d6 h1:psD31rxeK1/94Uu3G1BpUlOYCOFzCtC4qGxqytfMWWo=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241205054106-fd7e291968d6/go.mod h1:ZG4M8oph2j0C+R6CtUXuHeeUk5TuN5hVyl9gfwZawJg=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241209003634-d80c1f1bfb77 h1:kyVTxKPf35OdA5D4Z0Hskyzv+5JRu1jeRIYYulRqPtM=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241209003634-d80c1f1bfb77/go.mod h1:ZG4M8oph2j0C+R6CtUXuHeeUk5TuN5hVyl9gfwZawJg=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84 h1:VpLCQx+tFV6Nk0hbs3Noyxma/q9wIDdyacKpGQWUMI8=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84/go.mod h1:w54LrYo5rJEV503BgMPRNONsLTOEQv5V87q+uYaw9sM=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
6 changes: 4 additions & 2 deletions kroma-bindings/predeploys/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"

oppredeploys "github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/kroma-network/kroma/kroma-bindings/bindings"
)

func TestGethAddresses(t *testing.T) {
// We test if the addresses in geth match those in op-bindings, to avoid an import-cycle:
// we import geth in the monorepo, and do not want to import kroma-bindings into geth.
require.Equal(t, L1BlockAddr, types.L1BlockAddr)
// we import geth in the monorepo, and do not want to import op-bindings into geth.
require.Equal(t, oppredeploys.L1BlockAddr, types.L1BlockAddr)
require.Equal(t, L1BlockAddr, types.KromaL1BlockAddr)
}

func uintToHash(v uint) common.Hash {
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/channel_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestChannelManager_Close_BeforeMPTBlock(t *testing.T) {
numTx := 1
zktBlock1 := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)
zktBlock2 := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)
mptBlock := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)
mptBlock := derivetest.RandomL2MPTBlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)

h := zktBlock1.Header()
h.Time = kromaMPTTime - rollupConfig.BlockTime*2
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.Payloa
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)
return nil, err
seolaoh marked this conversation as resolved.
Show resolved Hide resolved
}
txBytes[i] = bin
}
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/system_tob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/kroma-chain-ops/crossdomain"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-service/testutils/fuzzerutils"
"github.com/kroma-network/kroma/kroma-bindings/bindings"
"github.com/kroma-network/kroma/kroma-bindings/predeploys"
"github.com/kroma-network/kroma/kroma-chain-ops/crossdomain"
)

// TestGasPriceOracleFeeUpdates checks that the gas price oracle cannot be locked by mis-configuring parameters.
Expand Down
33 changes: 20 additions & 13 deletions op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"

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

// L1ReceiptsFetcher fetches L1 header info and receipts for the payload attributes derivation (the info tx and deposits)
Expand Down Expand Up @@ -108,6 +108,17 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
}
}

// [Kroma: START]
// Include KromaMPT network upgrade transactions in the parent block of the KromaMPT target block.
if ba.rollupCfg.IsKromaMPTParentBlock(nextL2Time) {
mptUpgradeTxs, err := KromaMPTNetworkUpgradeTransactions()
if err != nil {
return nil, NewCriticalError(fmt.Errorf("failed to build kroma mpt network upgrade txs: %w", err))
}
upgradeTxs = append(upgradeTxs, mptUpgradeTxs...)
}
// [Kroma: END]

l1InfoTx, err := L1InfoDepositBytes(ba.rollupCfg, sysConfig, seqNumber, l1Info, nextL2Time)
if err != nil {
return nil, NewCriticalError(fmt.Errorf("failed to create l1InfoTx: %w", err))
Expand All @@ -119,17 +130,20 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
txs = append(txs, upgradeTxs...)

// [Kroma: START]
// In Kroma, the IsSystemTransaction field was deleted from DepositTx.
// After transitioning to MPT, we bring back the IsSystemTransaction field for compatibility with OP.
// Therefore, before MPT time, use KromaDepositTx struct to create deposit transactions without that field.
if !ba.rollupCfg.IsKromaMPT(nextL2Time) {
suggestedFeeRecipient := common.Address{}
if ba.rollupCfg.IsKromaMPT(nextL2Time) {
suggestedFeeRecipient = oppredeploys.SequencerFeeVaultAddr
} else {
// In Kroma, the IsSystemTransaction field was deleted from DepositTx.
// After transitioning to MPT, we bring back the IsSystemTransaction field for compatibility with OP.
// Therefore, before MPT time, use KromaDepositTx struct to create deposit transactions without that field.
for i, otx := range txs {
if otx[0] != types.DepositTxType {
continue
}
tx, err := ToKromaDepositBytes(otx)
if err != nil {
return nil, NewCriticalError(fmt.Errorf("failed to convert deposit tx to KromaDepositTx: %w", err))
return nil, NewCriticalError(err)
}
txs[i] = tx
}
Expand All @@ -149,13 +163,6 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
}
}

// [Kroma: START]
suggestedFeeRecipient := common.Address{}
if ba.rollupCfg.IsKromaMPT(nextL2Time) {
suggestedFeeRecipient = predeploys.ProtocolVaultAddr
}
// [Kroma: END]

return &eth.PayloadAttributes{
Timestamp: hexutil.Uint64(nextL2Time),
PrevRandao: eth.Bytes32(l1Info.MixDigest()),
Expand Down
31 changes: 26 additions & 5 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/kroma-network/kroma/kroma-bindings/predeploys"
)

// TestAttributesQueue checks that it properly uses the PreparePayloadAttributes function
Expand Down Expand Up @@ -59,6 +59,12 @@ func TestAttributesQueue(t *testing.T) {
GasLimit: 1234,
ValidatorRewardScalar: [32]byte{},
}
expectedMPTL1Cfg := eth.SystemConfig{
BatcherAddr: common.Address{42},
Overhead: [32]byte{},
Scalar: [32]byte{},
GasLimit: 1234,
}

testAttributes := func(l1InfoTx []byte, suggestedFeeRecipient common.Address) {
l1Fetcher := &testutils.MockL1Source{}
Expand All @@ -67,10 +73,15 @@ func TestAttributesQueue(t *testing.T) {
l2Fetcher := &testutils.MockL2Client{}
l2Fetcher.ExpectSystemConfigByL2Hash(safeHead.Hash, parentL1Cfg, nil)

parentBeaconRoot := l1Info.ParentBeaconRoot()
if cfg.IsEcotone(safeHead.Time+cfg.BlockTime) && parentBeaconRoot == nil { // default to zero hash if there is no beacon-block-root available
parentBeaconRoot = new(common.Hash)
}
attrs := eth.PayloadAttributes{
Timestamp: eth.Uint64Quantity(safeHead.Time + cfg.BlockTime),
PrevRandao: eth.Bytes32(l1Info.InfoMixDigest),
SuggestedFeeRecipient: suggestedFeeRecipient,
ParentBeaconBlockRoot: parentBeaconRoot,
Transactions: []eth.Data{l1InfoTx, eth.Data("foobar"), eth.Data("example")},
NoTxPool: true,
GasLimit: (*eth.Uint64Quantity)(&expectedL1Cfg.GasLimit),
Expand All @@ -82,11 +93,17 @@ func TestAttributesQueue(t *testing.T) {
actual, err := aq.createNextAttributes(context.Background(), &batch, safeHead)

require.NoError(t, err)
require.Equal(t, attrs, *actual)
require.Equal(t, attrs, *actual, "Expected %v but got %v", attrs, actual)
}

t.Run("before kroma mpt time", func(st *testing.T) {
rollupCfg := rollup.Config{}
zero := uint64(0)
cfg.RegolithTime = &zero
cfg.EcotoneTime = &zero
rollupCfg := rollup.Config{
RegolithTime: &zero,
EcotoneTime: &zero,
}
l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
require.NoError(st, err)

Expand All @@ -98,11 +115,15 @@ func TestAttributesQueue(t *testing.T) {
t.Run("after kroma mpt time", func(st *testing.T) {
zero := uint64(0)
cfg.KromaMPTTime = &zero
cfg.RegolithTime = &zero
cfg.EcotoneTime = &zero
rollupCfg := rollup.Config{
RegolithTime: &zero,
EcotoneTime: &zero,
KromaMPTTime: &zero,
}
l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedMPTL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
require.NoError(st, err)
testAttributes(l1InfoTx, predeploys.ProtocolVaultAddr)
testAttributes(l1InfoTx, predeploys.SequencerFeeVaultAddr)
})
}
2 changes: 0 additions & 2 deletions op-node/rollup/derive/ecotone_upgrade_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func toDepositTxn(t *testing.T, data hexutil.Bytes) (common.Address, *types.Tran
err := txn.UnmarshalBinary(data)
require.NoError(t, err)
require.Truef(t, txn.IsDepositTx(), "expected deposit txn, got %v", txn.Type())
/* [Kroma: START]
require.False(t, txn.IsSystemTx())
[Kroma: END] */

signer := types.NewLondonSigner(big.NewInt(420))
from, err := signer.Sender(txn)
Expand Down
28 changes: 28 additions & 0 deletions op-node/rollup/derive/fuzz_parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ func FuzzL1InfoEcotoneRoundTrip(f *testing.F) {
})
}

// FuzzL1InfoKromaMPTRoundTrip checks that our Kroma MPT encoder round trips properly
func FuzzL1InfoKromaMPTRoundTrip(f *testing.F) {
f.Fuzz(func(t *testing.T, number, time uint64, baseFee, blobBaseFee, hash []byte, seqNumber uint64, baseFeeScalar, blobBaseFeeScalar uint32) {
in := L1BlockInfo{
Number: number,
Time: time,
BaseFee: BytesToBigInt(baseFee),
BlockHash: common.BytesToHash(hash),
SequenceNumber: seqNumber,
BlobBaseFee: BytesToBigInt(blobBaseFee),
BaseFeeScalar: baseFeeScalar,
BlobBaseFeeScalar: blobBaseFeeScalar,
}
enc, err := in.marshalBinaryKromaMPT()
if err != nil {
t.Fatalf("Failed to marshal binary: %v", err)
}
var out L1BlockInfo
err = out.unmarshalBinaryKromaMPT(enc)
if err != nil {
t.Fatalf("Failed to unmarshal binary: %v", err)
}
if !cmp.Equal(in, out, cmp.Comparer(testutils.BigEqual)) {
t.Fatalf("The data did not round trip correctly. in: %v. out: %v", in, out)
}
})
}

// FuzzL1InfoAgainstContract checks the custom Bedrock L1 Info marshalling functions against the
// setL1BlockValues contract bindings to ensure that our functions are up to date and match the
// bindings. Note that we don't test setL1BlockValuesEcotone since it accepts only custom packed
Expand Down
Loading