diff --git a/README.md b/README.md index 915e57d..673c178 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # OPinit CosmosSDK Modules + The OPinit Stack is a versatile framework designed for CosmosSDK, facilitating the development of vm-agnostic Optimistic Rollups. This framework aligns closely with the interface of Optimism's Bedrock, promoting a straightforward user experience. Leveraging the Initia L1 Governance model, it addresses fraud-proof disputes efficiently. ## Optimistic Rollup Architecture ![image](https://github.com/initia-labs/OPinit/assets/160459432/77103140-73ef-41f2-95ba-682bee616f4e) - ### L1 Components #### [Bridge Module](./specs/l1_bridge.md) diff --git a/contrib/launchtools/README.md b/contrib/launchtools/README.md index 68211c5..2aed6ba 100644 --- a/contrib/launchtools/README.md +++ b/contrib/launchtools/README.md @@ -58,7 +58,7 @@ minitiad launch $TARGET_NETWORK --with-config [path-to-config] "l1_address": "init1f4lu0ze9c7zegrrjfpymjvztucqz48z3cy8p5f" }, "batch_submitter": { - "l1_address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72" + "da_address": "init1hqv5xqt7lckdj9p5kfp2q5auc5z37p2vyt4d72" }, "challenger": { "l1_address": "init1gn0yjtcma92y27c0z84ratxf6juy69lpln6u88", diff --git a/contrib/launchtools/config.go b/contrib/launchtools/config.go index 9987449..e9d699b 100644 --- a/contrib/launchtools/config.go +++ b/contrib/launchtools/config.go @@ -11,15 +11,10 @@ import ( "github.com/pkg/errors" - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client/input" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" - cmtcrypto "github.com/cometbft/cometbft/crypto" - "github.com/initia-labs/OPinit/contrib/launchtools/utils" ophosttypes "github.com/initia-labs/OPinit/x/ophost/types" ) @@ -289,6 +284,7 @@ func (l1config *L1Config) Finalize(buf *bufio.Reader) error { type SystemAccount struct { L1Address string `json:"l1_address,omitempty"` L2Address string `json:"l2_address,omitempty"` + DAAddress string `json:"da_address,omitempty"` Mnemonic string `json:"mnemonic,omitempty"` } @@ -367,51 +363,6 @@ func generateMnemonic() (string, error) { return mnemonic, nil } -func deriveAddress(mnemonic string, codec address.Codec) (string, error) { - addrBz, err := deriveAddressBz(mnemonic) - if err != nil { - return "", errors.Wrap(err, "failed to convert address to bech32") - } - return codec.BytesToString(addrBz) -} - -func deriveL1L2Addresses(mnemonic string) (string, string, error) { - l1Addr, err := deriveAddress(mnemonic, utils.L1AddressCodec()) - if err != nil { - return "", "", err - } - l2Addr, err := deriveAddress(mnemonic, utils.L2AddressCodec()) - return l1Addr, l2Addr, err -} - -func deriveAddressWithChainType(mnemonic string, chainType ophosttypes.BatchInfo_ChainType) (string, error) { - var codec address.Codec - switch chainType { - case ophosttypes.BatchInfo_CHAIN_TYPE_INITIA: - codec = utils.L1AddressCodec() - case ophosttypes.BatchInfo_CHAIN_TYPE_CELESTIA: - codec = utils.CelestiaAddressCodec() - default: - return "", errors.New("unsupported chain type") - } - return deriveAddress(mnemonic, codec) -} - -func deriveAddressBz(mnemonic string) (cmtcrypto.Address, error) { - algo := hd.Secp256k1 - derivedPriv, err := algo.Derive()( - mnemonic, - keyring.DefaultBIP39Passphrase, - sdk.GetConfig().GetFullBIP44Path(), - ) - if err != nil { - return nil, errors.Wrap(err, "failed to derive private key") - } - - privKey := algo.Generate()(derivedPriv) - return privKey.PubKey().Address(), nil -} - func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget ophosttypes.BatchInfo_ChainType) error { if systemKeys.Validator == nil { mnemonic, err := generateMnemonic() @@ -420,7 +371,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget } // derive address - _, l2Addr, err := deriveL1L2Addresses(mnemonic) + l2Addr, err := utils.DeriveL2Address(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -437,13 +388,13 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget } // derive address - daAddr, err := deriveAddressWithChainType(mnemonic, batchSubmissionTarget) + daAddr, err := utils.DeriveDAAddress(mnemonic, batchSubmissionTarget) if err != nil { return errors.Wrap(err, "failed to derive address") } systemKeys.BatchSubmitter = &SystemAccount{ - L1Address: daAddr, + DAAddress: daAddr, Mnemonic: mnemonic, } } @@ -458,7 +409,11 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget } // derive address - l1Addr, l2Addr, err := deriveL1L2Addresses(mnemonic) + l1Addr, err := utils.DeriveL1Address(mnemonic) + if err != nil { + return errors.Wrap(err, "failed to derive address") + } + l2Addr, err := utils.DeriveL2Address(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -476,7 +431,11 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget } // derive address - l1Addr, l2Addr, err := deriveL1L2Addresses(mnemonic) + l1Addr, err := utils.DeriveL1Address(mnemonic) + if err != nil { + return errors.Wrap(err, "failed to derive address") + } + l2Addr, err := utils.DeriveL2Address(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -494,7 +453,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget } // derive address - l1Addr, _, err := deriveL1L2Addresses(mnemonic) + l1Addr, err := utils.DeriveL1Address(mnemonic) if err != nil { return errors.Wrap(err, "failed to derive address") } @@ -512,7 +471,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader, batchSubmissionTarget if systemKeys.BridgeExecutor.L1Address == "" || systemKeys.BridgeExecutor.L2Address == "" || systemKeys.BridgeExecutor.Mnemonic == "" { return errors.New("bridge_executor account not initialized") } - if systemKeys.BatchSubmitter.L1Address == "" { + if systemKeys.BatchSubmitter.DAAddress == "" { return errors.New("batch_submitter account not initialized") } if systemKeys.OutputSubmitter.L1Address == "" { diff --git a/contrib/launchtools/steps/opbridge.go b/contrib/launchtools/steps/opbridge.go index 99dd0c9..63a63d3 100644 --- a/contrib/launchtools/steps/opbridge.go +++ b/contrib/launchtools/steps/opbridge.go @@ -44,7 +44,7 @@ func InitializeOpBridge( config.SystemKeys.BridgeExecutor.L1Address, config.SystemKeys.Challenger.L1Address, config.SystemKeys.OutputSubmitter.L1Address, - config.SystemKeys.BatchSubmitter.L1Address, + config.SystemKeys.BatchSubmitter.DAAddress, config.OpBridge.BatchSubmissionTarget, *config.OpBridge.OutputSubmissionInterval, *config.OpBridge.OutputFinalizationPeriod, diff --git a/contrib/launchtools/utils/address.go b/contrib/launchtools/utils/address.go index 2892dbc..b4b5629 100644 --- a/contrib/launchtools/utils/address.go +++ b/contrib/launchtools/utils/address.go @@ -1,9 +1,17 @@ package utils import ( + "github.com/pkg/errors" + + cmtcrypto "github.com/cometbft/cometbft/crypto" + "cosmossdk.io/core/address" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + + ophosttypes "github.com/initia-labs/OPinit/x/ophost/types" ) func L1AddressCodec() address.Codec { @@ -27,3 +35,47 @@ func HackBech32Prefix(prefix string) func() { sdk.GetConfig().SetBech32PrefixForAccount(originPrefix, originPubPrefix) } } + +func DeriveL1Address(mnemonic string) (string, error) { + return deriveAddress(mnemonic, L1AddressCodec()) +} + +func DeriveL2Address(mnemonic string) (string, error) { + return deriveAddress(mnemonic, L2AddressCodec()) +} + +func DeriveDAAddress(mnemonic string, chainType ophosttypes.BatchInfo_ChainType) (string, error) { + var codec address.Codec + switch chainType { + case ophosttypes.BatchInfo_CHAIN_TYPE_INITIA: + codec = L1AddressCodec() + case ophosttypes.BatchInfo_CHAIN_TYPE_CELESTIA: + codec = CelestiaAddressCodec() + default: + return "", errors.New("unsupported chain type") + } + return deriveAddress(mnemonic, codec) +} + +func deriveAddress(mnemonic string, codec address.Codec) (string, error) { + addrBz, err := deriveAddressBz(mnemonic) + if err != nil { + return "", errors.Wrap(err, "failed to convert address to bech32") + } + return codec.BytesToString(addrBz) +} + +func deriveAddressBz(mnemonic string) (cmtcrypto.Address, error) { + algo := hd.Secp256k1 + derivedPriv, err := algo.Derive()( + mnemonic, + keyring.DefaultBIP39Passphrase, + sdk.GetConfig().GetFullBIP44Path(), + ) + if err != nil { + return nil, errors.Wrap(err, "failed to derive private key") + } + + privKey := algo.Generate()(derivedPriv) + return privKey.PubKey().Address(), nil +}