Skip to content

Commit

Permalink
plasma mode: Specify valid commitment type (ethereum-optimism#10622)
Browse files Browse the repository at this point in the history
* op-node: Better logging in commitment tracking

* op-node: Properly handle differences in Keccak vs Generic Commitments

* Use daCommitmentType in deploy config

* da-server: Add option to use generic commitments

* CI: Add generic commitment

* op-chain-ops: Set daCommitmentType in testdata

* Fix comm type check

* Fix CI env var

* Set proper default for daCommitmentType

* Use string for daCommitmentType

* Use bytes cast instead of abi.encodePacked
  • Loading branch information
trianglesphere authored and rdovgan committed Jun 24, 2024
1 parent 760873e commit d5afda2
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 47 deletions.
23 changes: 22 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ jobs:
- run:
name: Copy Plasma allocs to .devnet-plasma
command: cp -r .devnet/ .devnet-plasma/
- run:
name: Generate Generic Plasma allocs
command: DEVNET_PLASMA="true" GENERIC_PLASMA="true" make devnet-allocs
- run:
name: Copy Plasma allocs to .devnet-plasma
command: cp -r .devnet/ .devnet-plasma-generic/
- run:
name: Generate non-FPAC allocs
command: make devnet-allocs
Expand Down Expand Up @@ -251,6 +257,11 @@ jobs:
- ".devnet-plasma/allocs-l2.json"
- ".devnet-plasma/allocs-l2-delta.json"
- ".devnet-plasma/allocs-l2-ecotone.json"
- ".devnet-plasma-generic/allocs-l1.json"
- ".devnet-plasma-generic/addresses.json"
- ".devnet-plasma-generic/allocs-l2.json"
- ".devnet-plasma-generic/allocs-l2-delta.json"
- ".devnet-plasma-generic/allocs-l2-ecotone.json"
- "packages/contracts-bedrock/deploy-config/devnetL1.json"
- "packages/contracts-bedrock/deployments/devnetL1"
- notify-failures-on-develop
Expand Down Expand Up @@ -1270,6 +1281,16 @@ jobs:
- run:
name: Set DEVNET_PLASMA = true
command: echo 'export DEVNET_PLASMA=true' >> $BASH_ENV
- when:
condition:
equal: ['plasma-generic', <<parameters.fpac>>]
steps:
- run:
name: Set DEVNET_PLASMA = true
command: echo 'export DEVNET_PLASMA=true' >> $BASH_ENV
- run:
name: Set GENERIC_PLASMA = true
command: echo 'export GENERIC_PLASMA=true' >> $BASH_ENV
- check-changed:
patterns: op-(.+),packages,ops-bedrock,bedrock-devnet
- run:
Expand Down Expand Up @@ -1878,7 +1899,7 @@ workflows:
- devnet:
matrix:
parameters:
fpac: ["legacy", "fault-proofs", "plasma"]
fpac: ["legacy", "fault-proofs", "plasma", "plasma-generic"]
requires:
- pnpm-monorepo
- op-batcher-docker-build
Expand Down
13 changes: 11 additions & 2 deletions bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
DEVNET_NO_BUILD = os.getenv('DEVNET_NO_BUILD') == "true"
DEVNET_FPAC = os.getenv('DEVNET_FPAC') == "true"
DEVNET_PLASMA = os.getenv('DEVNET_PLASMA') == "true"
GENERIC_PLASMA = os.getenv('GENERIC_PLASMA') == "true"

class Bunch:
def __init__(self, **kwds):
Expand Down Expand Up @@ -135,6 +136,8 @@ def init_devnet_l1_deploy_config(paths, update_timestamp=False):
deploy_config['faultGameWithdrawalDelay'] = 0
if DEVNET_PLASMA:
deploy_config['usePlasma'] = True
if GENERIC_PLASMA:
deploy_config['daCommitmentType'] = "GenericCommitment"
write_json(paths.devnet_config_path, deploy_config)

def devnet_l1_allocs(paths):
Expand Down Expand Up @@ -273,11 +276,17 @@ def devnet_deploy(paths):

if DEVNET_PLASMA:
docker_env['PLASMA_ENABLED'] = 'true'
docker_env['PLASMA_DA_SERVICE'] = 'false'
else:
docker_env['PLASMA_ENABLED'] = 'false'

if GENERIC_PLASMA:
docker_env['PLASMA_GENERIC_DA'] = 'true'
docker_env['PLASMA_DA_SERVICE'] = 'true'
else:
docker_env['PLASMA_GENERIC_DA'] = 'false'
docker_env['PLASMA_DA_SERVICE'] = 'false'


# Bring up the rest of the services.
log.info('Bringing up `op-node`, `op-proposer` and `op-batcher`.')
run_command(['docker', 'compose', 'up', '-d', 'op-node', 'op-proposer', 'op-batcher', 'artifact-server'], cwd=paths.ops_bedrock_dir, env=docker_env)
Expand All @@ -287,7 +296,7 @@ def devnet_deploy(paths):
log.info('Bringing up `op-challenger`.')
run_command(['docker', 'compose', 'up', '-d', 'op-challenger'], cwd=paths.ops_bedrock_dir, env=docker_env)

# Optionally bring up OP Plasma.
# Optionally bring up Plasma Mode components.
if DEVNET_PLASMA:
log.info('Bringing up `da-server`, `sentinel`.') # TODO(10141): We don't have public sentinel images yet
run_command(['docker', 'compose', 'up', '-d', 'da-server'], cwd=paths.ops_bedrock_dir, env=docker_env)
Expand Down
12 changes: 10 additions & 2 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"

"github.com/ethereum-optimism/optimism/op-node/rollup"
plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/ethereum-optimism/optimism/op-service/eth"
)

Expand Down Expand Up @@ -271,6 +272,8 @@ type DeployConfig struct {
CustomGasTokenAddress common.Address `json:"customGasTokenAddress"`
// UsePlasma is a flag that indicates if the system is using op-plasma
UsePlasma bool `json:"usePlasma"`
// DACommitmentType specifies the allowed commitment
DACommitmentType string `json:"daCommitmentType"`
// DAChallengeWindow represents the block interval during which the availability of a data commitment can be challenged.
DAChallengeWindow uint64 `json:"daChallengeWindow"`
// DAResolveWindow represents the block interval during which a data availability challenge can be resolved.
Expand Down Expand Up @@ -443,6 +446,9 @@ func (d *DeployConfig) Check() error {
if d.DAResolveWindow == 0 {
return fmt.Errorf("%w: DAResolveWindow cannot be 0 when using plasma mode", ErrInvalidDeployConfig)
}
if !(d.DACommitmentType == plasma.KeccakCommitmentString || d.DACommitmentType == plasma.GenericCommitmentString) {
return fmt.Errorf("%w: DACommitmentType must be either KeccakCommtiment or GenericCommitment", ErrInvalidDeployConfig)
}
}
if d.UseCustomGasToken {
if d.CustomGasTokenAddress == (common.Address{}) {
Expand Down Expand Up @@ -513,9 +519,10 @@ func (d *DeployConfig) CheckAddresses() error {
if d.OptimismPortalProxy == (common.Address{}) {
return fmt.Errorf("%w: OptimismPortalProxy cannot be address(0)", ErrInvalidDeployConfig)
}
if d.UsePlasma && d.DAChallengeProxy == (common.Address{}) {
if d.UsePlasma && d.DACommitmentType == plasma.KeccakCommitmentString && d.DAChallengeProxy == (common.Address{}) {
return fmt.Errorf("%w: DAChallengeContract cannot be address(0) when using plasma mode", ErrInvalidDeployConfig)

} else if d.UsePlasma && d.DACommitmentType == plasma.GenericCommitmentString && d.DAChallengeProxy != (common.Address{}) {
return fmt.Errorf("%w: DAChallengeContract must be address(0) when using generic commitments in plasma mode", ErrInvalidDeployConfig)
}
return nil
}
Expand Down Expand Up @@ -612,6 +619,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
var plasma *rollup.PlasmaConfig
if d.UsePlasma {
plasma = &rollup.PlasmaConfig{
CommitmentType: d.DACommitmentType,
DAChallengeAddress: d.DAChallengeProxy,
DAChallengeWindow: d.DAChallengeWindow,
DAResolveWindow: d.DAResolveWindow,
Expand Down
1 change: 1 addition & 0 deletions op-chain-ops/genesis/testdata/test-deploy-config-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"useFaultProofs": false,
"usePlasma": false,
"daBondSize": 0,
"daCommitmentType": "KeccakCommtiment",
"daChallengeProxy": "0x0000000000000000000000000000000000000000",
"daChallengeWindow": 0,
"daResolveWindow": 0,
Expand Down
8 changes: 5 additions & 3 deletions op-e2e/e2eutils/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-node/rollup"
plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/ethereum-optimism/optimism/op-service/eth"
)

Expand Down Expand Up @@ -143,12 +144,13 @@ func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *
l2Genesis.Alloc[addr] = val
}

var plasma *rollup.PlasmaConfig
var pcfg *rollup.PlasmaConfig
if deployConf.UsePlasma {
plasma = &rollup.PlasmaConfig{
pcfg = &rollup.PlasmaConfig{
DAChallengeAddress: l1Deployments.DataAvailabilityChallengeProxy,
DAChallengeWindow: deployConf.DAChallengeWindow,
DAResolveWindow: deployConf.DAResolveWindow,
CommitmentType: plasma.KeccakCommitmentString,
}
}

Expand Down Expand Up @@ -180,7 +182,7 @@ func Setup(t require.TestingT, deployParams *DeployParams, alloc *AllocParams) *
EcotoneTime: deployConf.EcotoneTime(uint64(deployConf.L1GenesisBlockTimestamp)),
FjordTime: deployConf.FjordTime(uint64(deployConf.L1GenesisBlockTimestamp)),
InteropTime: deployConf.InteropTime(uint64(deployConf.L1GenesisBlockTimestamp)),
PlasmaConfig: plasma,
PlasmaConfig: pcfg,
}

require.NoError(t, rollupCfg.Check())
Expand Down
2 changes: 2 additions & 0 deletions op-node/rollup/derive/engine_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/ethereum-optimism/optimism/op-node/node/safedb"
plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -1256,6 +1257,7 @@ func TestPlasmaFinalityData(t *testing.T) {
plasmaCfg := &rollup.PlasmaConfig{
DAChallengeWindow: 90,
DAResolveWindow: 90,
CommitmentType: plasma.KeccakCommitmentString,
}
// shoud return l1 finality if plasma is not enabled
require.Equal(t, uint64(finalityLookback), calcFinalityLookback(cfg))
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/derive/plasma_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *PlasmaDataSource) Next(ctx context.Context) (eth.Data, error) {
return nil, NewTemporaryError(fmt.Errorf("failed to fetch input data with comm %x from da service: %w", s.comm, err))
}
// inputs are limited to a max size to ensure they can be challenged in the DA contract.
if len(data) > plasma.MaxInputSize {
if s.comm.CommitmentType() == plasma.Keccak256CommitmentType && len(data) > plasma.MaxInputSize {
s.log.Warn("input data exceeds max size", "size", len(data), "max", plasma.MaxInputSize)
s.comm = nil
return s.Next(ctx)
Expand Down
3 changes: 3 additions & 0 deletions op-node/rollup/derive/plasma_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestPlasmaDataSource(t *testing.T) {
PlasmaConfig: &rollup.PlasmaConfig{
DAChallengeWindow: pcfg.ChallengeWindow,
DAResolveWindow: pcfg.ResolveWindow,
CommitmentType: plasma.KeccakCommitmentString,
},
}
// keep track of random input data to validate against
Expand Down Expand Up @@ -333,6 +334,7 @@ func TestPlasmaDataSourceStall(t *testing.T) {
PlasmaConfig: &rollup.PlasmaConfig{
DAChallengeWindow: pcfg.ChallengeWindow,
DAResolveWindow: pcfg.ResolveWindow,
CommitmentType: plasma.KeccakCommitmentString,
},
}

Expand Down Expand Up @@ -451,6 +453,7 @@ func TestPlasmaDataSourceInvalidData(t *testing.T) {
PlasmaConfig: &rollup.PlasmaConfig{
DAChallengeWindow: pcfg.ChallengeWindow,
DAResolveWindow: pcfg.ResolveWindow,
CommitmentType: plasma.KeccakCommitmentString,
},
}

Expand Down
27 changes: 24 additions & 3 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Genesis struct {
type PlasmaConfig struct {
// L1 DataAvailabilityChallenge contract proxy address
DAChallengeAddress common.Address `json:"da_challenge_contract_address,omitempty"`
// CommitmentType specifies which commitment type can be used. Defaults to Keccak (type 0) if not present
CommitmentType string `json:"da_commitment_type"`
// DA challenge window value set on the DAC contract. Used in plasma mode
// to compute when a commitment can no longer be challenged.
DAChallengeWindow uint64 `json:"da_challenge_window"`
Expand Down Expand Up @@ -345,6 +347,18 @@ func validatePlasmaConfig(cfg *Config) error {
if cfg.LegacyDAResolveWindow != cfg.PlasmaConfig.DAResolveWindow {
return fmt.Errorf("LegacyDAResolveWindow (%v) != PlasmaConfig.DAResolveWindow (%v)", cfg.LegacyDAResolveWindow, cfg.PlasmaConfig.DAResolveWindow)
}
if cfg.PlasmaConfig.CommitmentType != plasma.KeccakCommitmentString {
return errors.New("Cannot set CommitmentType with the legacy config")
}
} else if cfg.PlasmaConfig != nil {
if !(cfg.PlasmaConfig.CommitmentType == plasma.KeccakCommitmentString || cfg.PlasmaConfig.CommitmentType == plasma.GenericCommitmentString) {
return fmt.Errorf("invalid commitment type: %v", cfg.PlasmaConfig.CommitmentType)
}
if cfg.PlasmaConfig.CommitmentType == plasma.KeccakCommitmentString && cfg.PlasmaConfig.DAChallengeAddress == (common.Address{}) {
return errors.New("Must set da_challenge_contract_address for keccak commitments")
} else if cfg.PlasmaConfig.CommitmentType == plasma.GenericCommitmentString && cfg.PlasmaConfig.DAChallengeAddress != (common.Address{}) {
return errors.New("Must set empty da_challenge_contract_address for generic commitments")
}
}
return nil
}
Expand Down Expand Up @@ -485,19 +499,21 @@ func (c *Config) GetOPPlasmaConfig() (plasma.Config, error) {
if c.PlasmaConfig == nil {
return plasma.Config{}, errors.New("no plasma config")
}
if c.PlasmaConfig.DAChallengeAddress == (common.Address{}) {
return plasma.Config{}, errors.New("missing DAChallengeAddress")
}
if c.PlasmaConfig.DAChallengeWindow == uint64(0) {
return plasma.Config{}, errors.New("missing DAChallengeWindow")
}
if c.PlasmaConfig.DAResolveWindow == uint64(0) {
return plasma.Config{}, errors.New("missing DAResolveWindow")
}
t, err := plasma.CommitmentTypeFromString(c.PlasmaConfig.CommitmentType)
if err != nil {
return plasma.Config{}, err
}
return plasma.Config{
DAChallengeContractAddress: c.PlasmaConfig.DAChallengeAddress,
ChallengeWindow: c.PlasmaConfig.DAChallengeWindow,
ResolveWindow: c.PlasmaConfig.DAResolveWindow,
CommitmentType: t,
}, nil
}

Expand Down Expand Up @@ -550,6 +566,9 @@ func (c *Config) Description(l2Chains map[string]string) string {
banner += fmt.Sprintf(" - Interop: %s\n", fmtForkTimeOrUnset(c.InteropTime))
// Report the protocol version
banner += fmt.Sprintf("Node supports up to OP-Stack Protocol Version: %s\n", OPStackSupport)
if c.PlasmaConfig != nil {
banner += fmt.Sprintf("Node supports Plasma Mode with CommitmentType %v\n", c.PlasmaConfig.CommitmentType)
}
return banner
}

Expand All @@ -569,6 +588,7 @@ func (c *Config) LogDescription(log log.Logger, l2Chains map[string]string) {
if networkL1 == "" {
networkL1 = "unknown L1"
}

log.Info("Rollup Config", "l2_chain_id", c.L2ChainID, "l2_network", networkL2, "l1_chain_id", c.L1ChainID,
"l1_network", networkL1, "l2_start_time", c.Genesis.L2Time, "l2_block_hash", c.Genesis.L2.Hash.String(),
"l2_block_number", c.Genesis.L2.Number, "l1_block_hash", c.Genesis.L1.Hash.String(),
Expand All @@ -578,6 +598,7 @@ func (c *Config) LogDescription(log log.Logger, l2Chains map[string]string) {
"ecotone_time", fmtForkTimeOrUnset(c.EcotoneTime),
"fjord_time", fmtForkTimeOrUnset(c.FjordTime),
"interop_time", fmtForkTimeOrUnset(c.InteropTime),
"plasma_mode", c.PlasmaConfig != nil,
)
}

Expand Down
2 changes: 1 addition & 1 deletion op-plasma/cmd/daserver/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func StartDAServer(cliCtx *cli.Context) error {
store = s3
}

server := plasma.NewDAServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), store, l)
server := plasma.NewDAServer(cliCtx.String(ListenAddrFlagName), cliCtx.Int(PortFlagName), store, l, cfg.UseGenericComm)

if err := server.Start(); err != nil {
return fmt.Errorf("failed to start the DA server")
Expand Down
10 changes: 10 additions & 0 deletions op-plasma/cmd/daserver/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
S3AccessKeyIDFlagName = "s3.access-key-id"
S3AccessKeySecretFlagName = "s3.access-key-secret"
FileStorePathFlagName = "file.path"
GenericCommFlagName = "generic-commitment"
)

const EnvVarPrefix = "OP_PLASMA_DA_SERVER"
Expand All @@ -44,6 +45,12 @@ var (
Usage: "path to directory for file storage",
EnvVars: prefixEnvVars("FILESTORE_PATH"),
}
GenericCommFlag = &cli.BoolFlag{
Name: GenericCommFlagName,
Usage: "enable generic commitments for testing. Not for production use.",
EnvVars: prefixEnvVars("GENERIC_COMMITMENT"),
Value: false,
}
S3BucketFlag = &cli.StringFlag{
Name: S3BucketFlagName,
Usage: "bucket name for S3 storage",
Expand Down Expand Up @@ -80,6 +87,7 @@ var optionalFlags = []cli.Flag{
S3EndpointFlag,
S3AccessKeyIDFlag,
S3AccessKeySecretFlag,
GenericCommFlag,
}

func init() {
Expand All @@ -96,6 +104,7 @@ type CLIConfig struct {
S3Endpoint string
S3AccessKeyID string
S3AccessKeySecret string
UseGenericComm bool
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
Expand All @@ -105,6 +114,7 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
S3Endpoint: ctx.String(S3EndpointFlagName),
S3AccessKeyID: ctx.String(S3AccessKeyIDFlagName),
S3AccessKeySecret: ctx.String(S3AccessKeySecretFlagName),
UseGenericComm: ctx.Bool(GenericCommFlagName),
}
}

Expand Down
Loading

0 comments on commit d5afda2

Please sign in to comment.