-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy create2deployer in the next hardfork (#126)
* Deploy create2deployer in the next hardfork * Switch to superchain bytecode * Also deploy to Base goerli * Add comment, log, and test * Add additional base testnets / devnets
- Loading branch information
Showing
5 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package misc | ||
|
||
import ( | ||
"github.com/ethereum-optimism/superchain-registry/superchain" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
) | ||
|
||
// The original create2deployer contract could not be deployed to Base mainnet at | ||
// the canonical address of 0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2 due to | ||
// an accidental nonce increment from a deposit transaction. See | ||
// https://github.com/pcaversaccio/create2deployer/issues/128 for context. This | ||
// file applies the contract code to the canonical address manually in the Canyon | ||
// hardfork. | ||
|
||
// create2deployer is already deployed to Base testnets at 0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2, | ||
// so we deploy it to 0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF1 for hardfork testing purposes | ||
var create2DeployerAddresses = map[uint64]common.Address{ | ||
11763071: common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF1"), // Base Goerli devnet | ||
params.BaseGoerliChainID: common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF1"), // Base Goerli testnet | ||
11763072: common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF1"), // Base Sepolia devnet | ||
84532: common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF1"), // Base Sepolia testnet | ||
params.BaseMainnetChainID: common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"), // Base mainnet | ||
} | ||
var create2DeployerCodeHash = common.HexToHash("0xb0550b5b431e30d38000efb7107aaa0ade03d48a7198a140edda9d27134468b2") | ||
var create2DeployerCode []byte | ||
|
||
func init() { | ||
code, err := superchain.LoadContractBytecode(superchain.Hash(create2DeployerCodeHash)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
create2DeployerCode = code | ||
} | ||
|
||
func EnsureCreate2Deployer(c *params.ChainConfig, timestamp uint64, db vm.StateDB) { | ||
if !c.IsOptimism() || c.CanyonTime == nil || *c.CanyonTime != timestamp { | ||
return | ||
} | ||
address, ok := create2DeployerAddresses[c.ChainID.Uint64()] | ||
if !ok || db.GetCodeSize(address) > 0 { | ||
return | ||
} | ||
log.Info("Setting Create2Deployer code", "address", address, "codeHash", create2DeployerCodeHash) | ||
db.SetCode(address, create2DeployerCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package misc | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/params" | ||
) | ||
|
||
func TestEnsureCreate2Deployer(t *testing.T) { | ||
canyonTime := uint64(1000) | ||
var tests = []struct { | ||
name string | ||
override func(cfg *params.ChainConfig) | ||
timestamp uint64 | ||
codeExists bool | ||
applied bool | ||
}{ | ||
{ | ||
name: "at hardfork", | ||
timestamp: canyonTime, | ||
applied: true, | ||
}, | ||
{ | ||
name: "non-optimism chain", | ||
override: func(cfg *params.ChainConfig) { | ||
cfg.Optimism = nil | ||
}, | ||
timestamp: canyonTime, | ||
applied: false, | ||
}, | ||
{ | ||
name: "non-base chain", | ||
override: func(cfg *params.ChainConfig) { | ||
cfg.ChainID = big.NewInt(params.OPMainnetChainID) | ||
}, | ||
timestamp: canyonTime, | ||
applied: false, | ||
}, | ||
{ | ||
name: "pre canyon", | ||
timestamp: canyonTime - 1, | ||
applied: false, | ||
}, | ||
{ | ||
name: "post hardfork", | ||
timestamp: canyonTime + 1, | ||
applied: false, | ||
}, | ||
{ | ||
name: "canyon not configured", | ||
override: func(cfg *params.ChainConfig) { | ||
cfg.CanyonTime = nil | ||
}, | ||
timestamp: canyonTime, | ||
applied: false, | ||
}, | ||
{ | ||
name: "code already exists", | ||
timestamp: canyonTime, | ||
codeExists: true, | ||
applied: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cfg := params.ChainConfig{ | ||
ChainID: big.NewInt(params.BaseMainnetChainID), | ||
Optimism: ¶ms.OptimismConfig{}, | ||
CanyonTime: &canyonTime, | ||
} | ||
if tt.override != nil { | ||
tt.override(&cfg) | ||
} | ||
state := &stateDb{ | ||
codeExists: tt.codeExists, | ||
} | ||
EnsureCreate2Deployer(&cfg, tt.timestamp, state) | ||
assert.Equal(t, tt.applied, state.codeSet) | ||
}) | ||
} | ||
} | ||
|
||
type stateDb struct { | ||
vm.StateDB | ||
codeExists bool | ||
codeSet bool | ||
} | ||
|
||
func (s *stateDb) GetCodeSize(_ common.Address) int { | ||
if s.codeExists { | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
|
||
func (s *stateDb) SetCode(_ common.Address, _ []byte) { | ||
s.codeSet = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters