Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
4a51b33c
Commit
4a51b33c
authored
Nov 27, 2023
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-chain-ops: cleanup abstractions
parent
b604f4f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
29 deletions
+32
-29
registry.go
op-bindings/bindings/registry.go
+13
-0
config.go
op-chain-ops/genesis/config.go
+1
-0
layer_two.go
op-chain-ops/genesis/layer_two.go
+3
-3
layer_two_test.go
op-chain-ops/genesis/layer_two_test.go
+1
-2
immutables.go
op-chain-ops/immutables/immutables.go
+11
-22
immutables_test.go
op-chain-ops/immutables/immutables_test.go
+3
-2
No files found.
op-bindings/bindings/registry.go
View file @
4a51b33c
...
...
@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
"github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/common"
)
...
...
@@ -19,6 +21,17 @@ var deployedBytecodes = make(map[string]string)
// in an init function.
var
immutableReferences
=
make
(
map
[
string
]
string
)
// Create2DeployerCodeHash represents the codehash of the Create2Deployer contract.
var
Create2DeployerCodeHash
=
common
.
HexToHash
(
"0xb0550b5b431e30d38000efb7107aaa0ade03d48a7198a140edda9d27134468b2"
)
func
init
()
{
code
,
err
:=
superchain
.
LoadContractBytecode
(
superchain
.
Hash
(
Create2DeployerCodeHash
))
if
err
!=
nil
{
panic
(
err
)
}
deployedBytecodes
[
"Create2Deployer"
]
=
common
.
Bytes2Hex
(
code
)
}
// GetStorageLayout returns the storage layout of a contract by name.
func
GetStorageLayout
(
name
string
)
(
*
solc
.
StorageLayout
,
error
)
{
layout
:=
layouts
[
name
]
...
...
op-chain-ops/genesis/config.go
View file @
4a51b33c
...
...
@@ -749,6 +749,7 @@ func NewL2ImmutableConfig(config *DeployConfig, block *types.Block) (*immutables
}{
Name
:
"EAS"
,
},
Create2Deployer
:
struct
{}{},
}
if
err
:=
cfg
.
Check
();
err
!=
nil
{
...
...
op-chain-ops/genesis/layer_two.go
View file @
4a51b33c
...
...
@@ -33,7 +33,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
return
nil
,
err
}
immutable
,
err
:=
NewL2ImmutableConfig
(
config
,
l1StartBlock
)
immutable
Config
,
err
:=
NewL2ImmutableConfig
(
config
,
l1StartBlock
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -44,8 +44,8 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
return
nil
,
err
}
// Set up the implementations
deployResults
,
err
:=
immutables
.
BuildOptimism
(
immutable
)
// Set up the implementations
that contain immutables
deployResults
,
err
:=
immutables
.
Deploy
(
immutableConfig
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
op-chain-ops/genesis/layer_two_test.go
View file @
4a51b33c
...
...
@@ -18,7 +18,6 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-chain-ops/immutables"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
...
...
@@ -76,7 +75,7 @@ func testBuildL2Genesis(t *testing.T, config *genesis.DeployConfig) *core.Genesi
create2Deployer
:=
gen
.
Alloc
[
predeploys
.
Create2DeployerAddr
]
codeHash
:=
crypto
.
Keccak256Hash
(
create2Deployer
.
Code
)
require
.
Equal
(
t
,
codeHash
,
immutable
s
.
Create2DeployerCodeHash
)
require
.
Equal
(
t
,
codeHash
,
binding
s
.
Create2DeployerCodeHash
)
if
writeFile
{
file
,
_
:=
json
.
MarshalIndent
(
gen
,
""
,
" "
)
...
...
op-chain-ops/immutables/immutables.go
View file @
4a51b33c
...
...
@@ -5,13 +5,11 @@ import (
"math/big"
"reflect"
"github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
...
...
@@ -69,10 +67,9 @@ type PredeploysImmutableConfig struct {
EAS
struct
{
Name
string
}
Create2Deployer
struct
{}
}
var
Create2DeployerCodeHash
=
common
.
HexToHash
(
"0xb0550b5b431e30d38000efb7107aaa0ade03d48a7198a140edda9d27134468b2"
)
// Check will ensure that the required fields are set on the config.
// An error returned by `GetImmutableReferences` means that the solc compiler
// output for the contract has no immutables in it.
...
...
@@ -122,11 +119,11 @@ func (c *PredeploysImmutableConfig) ForEach(cb func(string, any) error) error {
// contracts so that the immutables can be set properly in the bytecode.
type
DeploymentResults
map
[
string
]
hexutil
.
Bytes
//
BuildOptimism
will deploy L2 predeploys that include immutables. This is to prevent the need
//
Deploy
will deploy L2 predeploys that include immutables. This is to prevent the need
// for parsing the solc output to find the correct immutable offsets and splicing in the values.
// Skip any predeploys that do not have immutables as their bytecode will be directly inserted
// into the state. This does not currently support recursive structs.
func
BuildOptimism
(
config
*
PredeploysImmutableConfig
)
(
DeploymentResults
,
error
)
{
func
Deploy
(
config
*
PredeploysImmutableConfig
)
(
DeploymentResults
,
error
)
{
if
err
:=
config
.
Check
();
err
!=
nil
{
return
DeploymentResults
{},
err
}
...
...
@@ -154,20 +151,18 @@ func BuildOptimism(config *PredeploysImmutableConfig) (DeploymentResults, error)
deployments
=
append
(
deployments
,
deployment
)
}
superchainPredeploys
:=
[]
deployer
.
SuperchainPredeploy
{
{
Name
:
"Create2Deployer"
,
CodeHash
:
Create2DeployerCodeHash
,
},
results
,
err
:=
deployContractsWithImmutables
(
deployments
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot deploy contracts with immutables: %w"
,
err
)
}
return
BuildL2
(
deployments
,
superchainPredeploys
)
return
results
,
nil
}
//
BuildL2
will deploy contracts to a simulated backend so that their immutables
//
deployContractsWithImmutables
will deploy contracts to a simulated backend so that their immutables
// can be properly set. The bytecode returned in the results is suitable to be
// inserted into the state via state surgery.
func
BuildL2
(
constructors
[]
deployer
.
Constructor
,
superchainPredeploys
[]
deployer
.
SuperchainPredeploy
)
(
DeploymentResults
,
error
)
{
log
.
Info
(
"Creating L2 state"
)
func
deployContractsWithImmutables
(
constructors
[]
deployer
.
Constructor
)
(
DeploymentResults
,
error
)
{
deployments
,
err
:=
deployer
.
Deploy
(
deployer
.
NewL2Backend
(),
constructors
,
l2ImmutableDeployer
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -176,13 +171,6 @@ func BuildL2(constructors []deployer.Constructor, superchainPredeploys []deploye
for
_
,
dep
:=
range
deployments
{
results
[
dep
.
Name
]
=
dep
.
Bytecode
}
for
_
,
dep
:=
range
superchainPredeploys
{
code
,
err
:=
superchain
.
LoadContractBytecode
(
superchain
.
Hash
(
dep
.
CodeHash
))
if
err
!=
nil
{
return
nil
,
err
}
results
[
dep
.
Name
]
=
code
}
return
results
,
nil
}
...
...
@@ -270,6 +258,7 @@ func l2ImmutableDeployer(backend *backends.SimulatedBackend, opts *bind.Transact
return
tx
,
err
}
// prepareFeeVaultArguments is a helper function that parses the arguments for the fee vault contracts.
func
prepareFeeVaultArguments
(
deployment
deployer
.
Constructor
)
(
common
.
Address
,
*
big
.
Int
,
uint8
,
error
)
{
recipient
,
ok
:=
deployment
.
Args
[
0
]
.
(
common
.
Address
)
if
!
ok
{
...
...
op-chain-ops/immutables/immutables_test.go
View file @
4a51b33c
...
...
@@ -84,10 +84,11 @@ func TestBuildOptimism(t *testing.T) {
EAS
:
struct
{
Name
string
}{
Name
:
"EAS"
,
},
Create2Deployer
:
struct
{}{},
}
require
.
NoError
(
t
,
cfg
.
Check
())
results
,
err
:=
immutables
.
BuildOptimism
(
&
cfg
)
results
,
err
:=
immutables
.
Deploy
(
&
cfg
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
results
)
...
...
@@ -112,7 +113,7 @@ func TestBuildOptimism(t *testing.T) {
// Ensure that the PredeploysImmutableConfig is kept up to date
for
name
:=
range
predeploys
.
Predeploys
{
require
.
True
(
t
,
all
[
name
]
)
require
.
True
f
(
t
,
all
[
name
],
"predeploy %s not in set of predeploys"
,
name
)
ref
,
err
:=
bindings
.
GetImmutableReferences
(
name
)
// If there is predeploy config, there should be an immutable reference
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment