From 3d7ab0789da70fcd4ddd9472e7c723cbf5033ee5 Mon Sep 17 00:00:00 2001 From: Paul Lange Date: Mon, 23 Sep 2024 17:58:43 +0200 Subject: [PATCH] migration: Overwrite create2deployer code (#233) --- op-chain-ops/cmd/celo-migrate/state.go | 24 +++++++++++++-------- op-chain-ops/cmd/celo-migrate/state_test.go | 10 +++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/op-chain-ops/cmd/celo-migrate/state.go b/op-chain-ops/cmd/celo-migrate/state.go index 69aefaeeb86a..fe823b74b8c8 100644 --- a/op-chain-ops/cmd/celo-migrate/state.go +++ b/op-chain-ops/cmd/celo-migrate/state.go @@ -47,7 +47,9 @@ var ( // Add any addresses that should be allowed to overwrite existing accounts here. AlfajoresNetworkID: { // Create2Deployer - common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"): false, + // OP uses a version without an owner who can pause the contract, + // so we overwrite the existing contract during migration + common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"): true, // Same code as in allocs file // EntryPoint_v070 @@ -306,8 +308,8 @@ func applyAllocsToState(db vm.StateDB, allocs types.GenesisAlloc, allowlist map[ } if db.Exist(k) { - var allowed bool - overwrite, allowed := allowlist[k] + writeNonceAndStorage := false + writeCode, allowed := allowlist[k] // If the account is not allowed and has a non zero nonce or code size, bail out we will need to manually investigate how to handle this. if !allowed && (db.GetCodeSize(k) > 0 || db.GetNonce(k) > 0) { @@ -316,18 +318,22 @@ func applyAllocsToState(db vm.StateDB, allocs types.GenesisAlloc, allowlist map[ // This means that the account just has balance, in that case we wan to copy over the account if db.GetCodeSize(k) == 0 && db.GetNonce(k) == 0 { - overwrite = true + writeCode = true + writeNonceAndStorage = true } - if overwrite { + if writeCode { overwriteCounter++ db.SetCode(k, v.Code) - db.SetNonce(k, v.Nonce) - for key, value := range v.Storage { - db.SetState(k, key, value) + + if writeNonceAndStorage { + db.SetNonce(k, v.Nonce) + for key, value := range v.Storage { + db.SetState(k, key, value) + } } - log.Info("Overwrote account", "address", k.Hex()) + log.Info("Overwrote account", "address", k.Hex(), "writeNonceAndStorage", writeNonceAndStorage) } continue } diff --git a/op-chain-ops/cmd/celo-migrate/state_test.go b/op-chain-ops/cmd/celo-migrate/state_test.go index 14d18607c1bd..dbe6ce90ef4e 100644 --- a/op-chain-ops/cmd/celo-migrate/state_test.go +++ b/op-chain-ops/cmd/celo-migrate/state_test.go @@ -82,9 +82,10 @@ func TestApplyAllocsToState(t *testing.T) { wantErr: true, }, { - name: "Write account with allowlist overwrites", + name: "Write account with allowlist overwrite, keeps nonce", existingAccount: &types.Account{ Balance: big.NewInt(defaultBalance), + Nonce: 4, Code: bytes.Repeat([]byte{0x01}, 10), }, newAccount: types.Account{ @@ -128,9 +129,14 @@ func TestApplyAllocsToState(t *testing.T) { t.Errorf("account does not exists as expected: %v", address.Hex()) } - assert.Equal(t, tt.newAccount.Nonce, sdb.GetNonce(address)) assert.Equal(t, tt.newAccount.Code, sdb.GetCode(address)) + if tt.existingAccount != nil && tt.existingAccount.Nonce != 0 { + assert.Equal(t, tt.existingAccount.Nonce, sdb.GetNonce(address)) + } else { + assert.Equal(t, tt.newAccount.Nonce, sdb.GetNonce(address)) + } + if tt.existingAccount != nil { assert.True(t, big.NewInt(defaultBalance).Cmp(sdb.GetBalance(address).ToBig()) == 0) } else {