forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-deployer: Add support for alt-DA deployments (ethereum-optimism#12798
) * op-deployer: Add support for alt-DA deployments Gives users the ability to deploy an alt-DA chain by specifying an alt-DA config in their chain's intent. The chain will be deployed using OPCM, then an additional pipeline step will deploy the alt-DA challenge contracts. The owner of the challenge contract is set to the L1 proxy admin owner. To reflect the experimental nature of this feature, the field in the intent is prefixed with `Dangerous`. Users should not use this for production chains until we have performed further testing. This may not appear like an important feature on its surface. However, without it we cannot delete the legacy allocs files. Since it was low lift I figured I'd just knock it out, and get us one step closer to being able to rip out the legacy deployment scripts and tooling once and for all. * semgrep * forge fmt * label * flip args
- Loading branch information
Showing
13 changed files
with
718 additions
and
6 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package opcm | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum-optimism/optimism/op-chain-ops/script" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type DeployAltDAInput struct { | ||
Salt common.Hash | ||
ProxyAdmin common.Address | ||
ChallengeContractOwner common.Address | ||
ChallengeWindow *big.Int | ||
ResolveWindow *big.Int | ||
BondSize *big.Int | ||
ResolverRefundPercentage *big.Int | ||
} | ||
|
||
type DeployAltDAOutput struct { | ||
DataAvailabilityChallengeProxy common.Address | ||
DataAvailabilityChallengeImpl common.Address | ||
} | ||
|
||
type DeployAltDAScript struct { | ||
Run func(input, output common.Address) error | ||
} | ||
|
||
func DeployAltDA( | ||
host *script.Host, | ||
input DeployAltDAInput, | ||
) (DeployAltDAOutput, error) { | ||
var output DeployAltDAOutput | ||
inputAddr := host.NewScriptAddress() | ||
outputAddr := host.NewScriptAddress() | ||
|
||
cleanupInput, err := script.WithPrecompileAtAddress[*DeployAltDAInput](host, inputAddr, &input) | ||
if err != nil { | ||
return output, fmt.Errorf("failed to insert DeployAltDAInput precompile: %w", err) | ||
} | ||
defer cleanupInput() | ||
|
||
cleanupOutput, err := script.WithPrecompileAtAddress[*DeployAltDAOutput](host, outputAddr, &output, | ||
script.WithFieldSetter[*DeployAltDAOutput]) | ||
if err != nil { | ||
return output, fmt.Errorf("failed to insert DeployAltDAOutput precompile: %w", err) | ||
} | ||
defer cleanupOutput() | ||
|
||
implContract := "DeployAltDA" | ||
deployScript, cleanupDeploy, err := script.WithScript[DeployAltDAScript](host, "DeployAltDA.s.sol", implContract) | ||
if err != nil { | ||
return output, fmt.Errorf("failed to laod %s script: %w", implContract, err) | ||
} | ||
defer cleanupDeploy() | ||
|
||
if err := deployScript.Run(inputAddr, outputAddr); err != nil { | ||
return output, fmt.Errorf("failed to run %s script: %w", implContract, err) | ||
} | ||
|
||
return output, nil | ||
} |
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,43 @@ | ||
package opcm | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster" | ||
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/testutil" | ||
"github.com/ethereum-optimism/optimism/op-deployer/pkg/env" | ||
"github.com/ethereum-optimism/optimism/op-service/testlog" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeployAltDA(t *testing.T) { | ||
_, artifacts := testutil.LocalArtifacts(t) | ||
|
||
host, err := env.DefaultScriptHost( | ||
broadcaster.NoopBroadcaster(), | ||
testlog.Logger(t, log.LevelInfo), | ||
common.Address{'D'}, | ||
artifacts, | ||
0, | ||
) | ||
require.NoError(t, err) | ||
|
||
input := DeployAltDAInput{ | ||
Salt: common.HexToHash("0x1234"), | ||
ProxyAdmin: common.Address{'P'}, | ||
ChallengeContractOwner: common.Address{'O'}, | ||
ChallengeWindow: big.NewInt(100), | ||
ResolveWindow: big.NewInt(200), | ||
BondSize: big.NewInt(300), | ||
ResolverRefundPercentage: big.NewInt(50), // must be < 100 | ||
} | ||
|
||
output, err := DeployAltDA(host, input) | ||
require.NoError(t, err) | ||
|
||
require.NotEmpty(t, output.DataAvailabilityChallengeProxy) | ||
require.NotEmpty(t, output.DataAvailabilityChallengeImpl) | ||
} |
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,56 @@ | ||
package pipeline | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm" | ||
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func DeployAltDA(env *Env, intent *state.Intent, st *state.State, chainID common.Hash) error { | ||
lgr := env.Logger.New("stage", "deploy-alt-da") | ||
|
||
chainIntent, err := intent.Chain(chainID) | ||
if err != nil { | ||
return fmt.Errorf("failed to get chain intent: %w", err) | ||
} | ||
|
||
chainState, err := st.Chain(chainID) | ||
if err != nil { | ||
return fmt.Errorf("failed to get chain state: %w", err) | ||
} | ||
|
||
if !shouldDeployAltDA(chainIntent, chainState) { | ||
lgr.Info("alt-da deployment not needed") | ||
return nil | ||
} | ||
|
||
var dao opcm.DeployAltDAOutput | ||
lgr.Info("deploying alt-da contracts") | ||
dao, err = opcm.DeployAltDA(env.L1ScriptHost, opcm.DeployAltDAInput{ | ||
Salt: st.Create2Salt, | ||
ProxyAdmin: st.ImplementationsDeployment.OpcmProxyAddress, | ||
ChallengeContractOwner: chainIntent.Roles.L1ProxyAdminOwner, | ||
ChallengeWindow: new(big.Int).SetUint64(chainIntent.DangerousAltDAConfig.DAChallengeWindow), | ||
ResolveWindow: new(big.Int).SetUint64(chainIntent.DangerousAltDAConfig.DAResolveWindow), | ||
BondSize: new(big.Int).SetUint64(chainIntent.DangerousAltDAConfig.DABondSize), | ||
ResolverRefundPercentage: new(big.Int).SetUint64(chainIntent.DangerousAltDAConfig.DAResolverRefundPercentage), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("failed to deploy alt-da contracts: %w", err) | ||
} | ||
|
||
chainState.DataAvailabilityChallengeProxyAddress = dao.DataAvailabilityChallengeProxy | ||
chainState.DataAvailabilityChallengeImplAddress = dao.DataAvailabilityChallengeImpl | ||
return nil | ||
} | ||
|
||
func shouldDeployAltDA(chainIntent *state.ChainIntent, chainState *state.ChainState) bool { | ||
if !chainIntent.DangerousAltDAConfig.UseAltDA { | ||
return false | ||
} | ||
|
||
return chainState.DataAvailabilityChallengeImplAddress == common.Address{} | ||
} |
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
Oops, something went wrong.