Skip to content

Commit

Permalink
Fix/multi challenger audit (#87)
Browse files Browse the repository at this point in the history
* feat: support multi challenger

* fix: remove multi submitter

- for preventing duplicated submit

* fix: launch cmd bug

* fix: lauch cmd bug

* fix: unused code & name

* fix: refactoring

* fix/multi-challenger-audit

* fix to check already taken channel

---------

Co-authored-by: suha jin <[email protected]>
  • Loading branch information
beer-1 and djm07073 authored Jun 27, 2024
1 parent 5cc0de9 commit a4b8921
Show file tree
Hide file tree
Showing 33 changed files with 1,102 additions and 767 deletions.
524 changes: 293 additions & 231 deletions api/opinit/ophost/v1/tx.pulsar.go

Large diffs are not rendered by default.

282 changes: 171 additions & 111 deletions api/opinit/ophost/v1/types.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contrib/launchtools/steps/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func InitializeGenesisWithPostSetup(

// store genesis
if err := genutil.ExportGenesisFile(appGenesis, ctx.ServerContext().Config.GenesisFile()); err != nil {
return errors.Wrap(err, "failed to export genesis file")
return errors.New("failed to export genesis file")
}

return nil
Expand Down Expand Up @@ -114,7 +114,7 @@ func initializeGenesis(
// prepare genesis
genFilePath := cometConfig.GenesisFile()
if cometos.FileExists(genFilePath) {
return nil, errors.Wrap(err, "genesis file already exists")
return nil, errors.New("genesis file already exists")
}

// prepare default genesis
Expand Down
4 changes: 2 additions & 2 deletions contrib/launchtools/steps/opbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func createOpBridge(
return ophosttypes.NewMsgCreateBridge(
executorAddress,
ophosttypes.BridgeConfig{
Challenger: challengerAddress,
Proposer: outputAddress,
Challengers: []string{challengerAddress},
Proposer: outputAddress,
BatchInfo: ophosttypes.BatchInfo{
Submitter: submitterAddress,
Chain: submitTarget,
Expand Down
1 change: 1 addition & 0 deletions contrib/launchtools/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func NewLauncher(
defaultGenesis map[string]json.RawMessage,
artifactsDir string,
) *LauncherContext {

kr, err := keyring.New("minitia", keyring.BackendTest, clientCtx.HomeDir, nil, clientCtx.Codec)
if err != nil {
panic("failed to create keyring")
Expand Down
2 changes: 1 addition & 1 deletion proto/opinit/opchild/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ message MsgSpendFeePool {
// MsgSpendFeePoolResponse returns deposit result data
message MsgSpendFeePoolResponse {}

// MsgUpdateOracle is a message to update oracle prices which contains L1 extended commits for oracle.
// MsgUpdateOracle is a message to update oracle prices which contains L1 extended commits for oracle.
message MsgUpdateOracle {
option (cosmos.msg.v1.signer) = "sender";
option (amino.name) = "opchild/MsgUpdateOracle";
Expand Down
21 changes: 13 additions & 8 deletions proto/opinit/ophost/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ service Msg {
// UpdateProposer defines a rpc handler method for MsgUpdateProposer.
rpc UpdateProposer(MsgUpdateProposer) returns (MsgUpdateProposerResponse);

// UpdateChallenger defines a rpc handler method for MsgUpdateChallenger.
rpc UpdateChallenger(MsgUpdateChallenger) returns (MsgUpdateChallengerResponse);
// UpdateChallengers defines a rpc handler method for MsgUpdateChallengers.
rpc UpdateChallengers(MsgUpdateChallengers) returns (MsgUpdateChallengersResponse);

// UpdateBatchInfo defines a rpc handler method for MsgUpdateBatchInfo.
rpc UpdateBatchInfo(MsgUpdateBatchInfo) returns (MsgUpdateBatchInfoResponse);
Expand Down Expand Up @@ -220,20 +220,22 @@ message MsgUpdateProposerResponse {
}

// MsgUpdateChallenger is a message to change a challenger
message MsgUpdateChallenger {
message MsgUpdateChallengers {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "ophost/MsgUpdateChallenger";
option (amino.name) = "ophost/MsgUpdateChallengers";

// authority is the address that controls the module (defaults to x/gov unless overwritten)
// or the current challenger address.
//
// If the given authority is a challenger address, it has the ability to replace itself with another address.
string authority = 1 [(gogoproto.moretags) = "yaml:\"authority\"", (cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 bridge_id = 2 [(gogoproto.moretags) = "yaml:\"bridge_id\""];
string new_challenger = 3
[(gogoproto.moretags) = "yaml:\"new_challenger\"", (cosmos_proto.scalar) = "cosmos.AddressString"];
repeated string new_challengers = 3
[(gogoproto.moretags) = "yaml:\"new_challengers\"", (cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgUpdateChallengerResponse returns a message handle result.
message MsgUpdateChallengerResponse {
// MsgUpdateChallengersResponse returns a message handle result.
message MsgUpdateChallengersResponse {
// last finalized output index
uint64 output_index = 1;
// last finalized l2 block number
Expand Down Expand Up @@ -268,6 +270,9 @@ message MsgUpdateMetadata {

// authority is the address that controls the module (defaults to x/gov unless overwritten)
// or the current challenger address.
//
// If the given authority is a challenger address, it has the ability to replace oneself to another address or remove
// oneself.
string authority = 1 [(gogoproto.moretags) = "yaml:\"authority\"", (cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 bridge_id = 2 [(gogoproto.moretags) = "yaml:\"bridge_id\""];
bytes metadata = 3 [(gogoproto.moretags) = "yaml:\"metadata\""];
Expand Down
6 changes: 3 additions & 3 deletions proto/opinit/ophost/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message Params {
// BridgeConfig defines the set of bridge config.
message BridgeConfig {
// The address of the challenger.
string challenger = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
repeated string challengers = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// The address of the proposer.
string proposer = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// The information about batch submission.
Expand Down Expand Up @@ -84,6 +84,6 @@ message Output {

// BatchInfoWithOutput defines the batch information with output.
message BatchInfoWithOutput {
BatchInfo batchInfo = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Output output = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
BatchInfo batch_info = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Output output = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
4 changes: 2 additions & 2 deletions x/opchild/client/cli/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ $ %s add-genesis-validator my-key-name --home=/path/to/home/dir --keyring-backen

genDoc.AppState = appStateJSON
if err = genutil.ExportGenesisFile(genDoc, config.GenesisFile()); err != nil {
return errors.Wrap(err, "Failed to export genesis file")
return errors.New("Failed to export genesis file")
}

return nil
Expand Down Expand Up @@ -203,7 +203,7 @@ the address will be looked up in the local Keybase.

genDoc.AppState = appStateJSON
if err = genutil.ExportGenesisFile(genDoc, config.GenesisFile()); err != nil {
return errors.Wrap(err, "Failed to export genesis file")
return errors.New("Failed to export genesis file")
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions x/opchild/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func NewSetBridgeInfoCmd(ac address.Codec) *cobra.Command {
fmt.Sprintf(
`send a tx to set a bridge info with a config file as a json.
Example:
$ %s tx ophost set-bridge-info 1 init10d07y265gmmuvt4z0w9aw880jnsr700j55nka3 mahalo-2 07-tendermint-0 path/to/bridge-config.json
$ %s tx opchild set-bridge-info 1 init10d07y265gmmuvt4z0w9aw880jnsr700j55nka3 mahalo-2 07-tendermint-0 path/to/bridge-config.json
Where bridge-config.json contains:
{
Expand Down Expand Up @@ -296,7 +296,7 @@ func NewSetBridgeInfoCmd(ac address.Codec) *cobra.Command {
return err
}

origConfig := ophostcli.BridgeConfig{}
origConfig := ophostcli.BridgeCliConfig{}
err = json.Unmarshal(configBytes, &origConfig)
if err != nil {
return err
Expand All @@ -318,14 +318,15 @@ func NewSetBridgeInfoCmd(ac address.Codec) *cobra.Command {
}

bridgeConfig := ophosttypes.BridgeConfig{
Challenger: origConfig.Challenger,
Challengers: origConfig.Challengers,
Proposer: origConfig.Proposer,
SubmissionInterval: submissionInterval,
FinalizationPeriod: finalizationPeriod,
SubmissionStartTime: submissionStartTime,
BatchInfo: origConfig.BatchInfo,
BatchInfo: ophosttypes.BatchInfo(origConfig.BatchInfo),
Metadata: []byte(origConfig.Metadata),
}

if err = bridgeConfig.ValidateWithNoAddrValidation(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/opchild/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (s *CLITestSuite) TestNewSetBridgeInfo() {

invalidConfig.WriteString(`{}`)
validConfig.WriteString(`{
"challenger": "init1q6jhwnarkw2j5qqgx3qlu20k8nrdglft5ksr0g",
"challengers": ["init1q6jhwnarkw2j5qqgx3qlu20k8nrdglft5ksr0g"],
"proposer": "init1k2svyvm60r8rhnzr9vemk5f6fksvm6tyeujp3c",
"submission_interval": "100s",
"finalization_period": "1000s",
Expand Down
4 changes: 2 additions & 2 deletions x/opchild/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Test_GenesisImportExport(t *testing.T) {
BridgeId: 1,
BridgeAddr: addrsStr[1],
BridgeConfig: ophosttypes.BridgeConfig{
Challenger: addrsStr[2],
Proposer: addrsStr[3],
Challengers: []string{addrsStr[2]},
Proposer: addrsStr[3],
BatchInfo: ophosttypes.BatchInfo{
Submitter: addrsStr[4],
Chain: "l1",
Expand Down
8 changes: 4 additions & 4 deletions x/opchild/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func Test_MsgServer_Withdraw(t *testing.T) {
L1ChainId: "test-chain-id",
L1ClientId: "test-client-id",
BridgeConfig: ophosttypes.BridgeConfig{
Challenger: addrsStr[2],
Proposer: addrsStr[3],
Challengers: []string{addrsStr[2]},
Proposer: addrsStr[3],
BatchInfo: ophosttypes.BatchInfo{
Submitter: addrsStr[4],
Chain: "l1",
Expand Down Expand Up @@ -332,8 +332,8 @@ func Test_MsgServer_SetBridgeInfo(t *testing.T) {
L1ChainId: "test-chain-id",
L1ClientId: "test-client-id",
BridgeConfig: ophosttypes.BridgeConfig{
Challenger: addrsStr[2],
Proposer: addrsStr[3],
Challengers: []string{addrsStr[2]},
Proposer: addrsStr[3],
BatchInfo: ophosttypes.BatchInfo{
Submitter: addrsStr[4],
Chain: "l1",
Expand Down
4 changes: 2 additions & 2 deletions x/opchild/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func Test_QuerySetBridgeInfo(t *testing.T) {
BridgeId: 1,
BridgeAddr: addrsStr[1],
BridgeConfig: ophosttypes.BridgeConfig{
Challenger: addrsStr[2],
Proposer: addrsStr[3],
Challengers: []string{addrsStr[2]},
Proposer: addrsStr[3],
BatchInfo: ophosttypes.BatchInfo{
Submitter: addrsStr[4],
Chain: "l1",
Expand Down
13 changes: 9 additions & 4 deletions x/ophost/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewCreateBridge(ac address.Codec) *cobra.Command {
Where bridge-config.json contains:
{
"challenger": "bech32-address",
"challengers": ["bech32-address"],
"proposer": "bech32-addresss",
"submission_interval": "duration",
"finalization_period": "duration",
Expand All @@ -119,9 +119,10 @@ func NewCreateBridge(ac address.Codec) *cobra.Command {
return err
}

origConfig := BridgeConfig{}
origConfig := BridgeCliConfig{}
err = json.Unmarshal(configBytes, &origConfig)
if err != nil {

return err
}

Expand All @@ -141,25 +142,29 @@ func NewCreateBridge(ac address.Codec) *cobra.Command {
}

config := types.BridgeConfig{
Challenger: origConfig.Challenger,
Challengers: origConfig.Challengers, // Ensure Challenger is properly assigned
Proposer: origConfig.Proposer,
SubmissionInterval: submissionInterval,
FinalizationPeriod: finalizationPeriod,
SubmissionStartTime: submissionStartTime,
Metadata: []byte(origConfig.Metadata),
BatchInfo: origConfig.BatchInfo,
BatchInfo: types.BatchInfo(origConfig.BatchInfo),
}

if err = config.Validate(ac); err != nil {

return err
}

fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress())
if err != nil {

return err
}

msg := types.NewMsgCreateBridge(fromAddr, config)
if err = msg.Validate(ac); err != nil {

return err
}

Expand Down
2 changes: 1 addition & 1 deletion x/ophost/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *CLITestSuite) TestNewCreateBridge() {

invalidConfig.WriteString(`{}`)
validConfig.WriteString(`{
"challenger": "init1q6jhwnarkw2j5qqgx3qlu20k8nrdglft5ksr0g",
"challengers": ["init1q6jhwnarkw2j5qqgx3qlu20k8nrdglft5ksr0g"],
"proposer": "init1k2svyvm60r8rhnzr9vemk5f6fksvm6tyeujp3c",
"submission_interval": "100s",
"finalization_period": "1000s",
Expand Down
35 changes: 14 additions & 21 deletions x/ophost/client/cli/types.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package cli

import "github.com/initia-labs/OPinit/x/ophost/types"

// BridgeConfig defines the set of bridge config.
//
// NOTE: it is a modified BridgeConfig from x/ophost/types/types.pb.go to make unmarshal easier
type BridgeConfig struct {
// The address of the challenger.
Challenger string `protobuf:"bytes,1,opt,name=challenger,proto3" json:"challenger,omitempty"`
// The address of the proposer.
Proposer string `protobuf:"bytes,2,opt,name=proposer,proto3" json:"proposer,omitempty"`
// The time interval at which checkpoints must be submitted.
// NOTE: this param is currently not used, but will be used for challenge in future.
SubmissionInterval string `protobuf:"bytes,3,opt,name=submission_interval,json=submissionInterval,proto3,stdduration" json:"submission_interval,omitempty"`
// The minium time duration that must elapse before a withdrawal can be finalized.
FinalizationPeriod string `protobuf:"bytes,4,opt,name=finalization_period,json=finalizationPeriod,proto3,stdduration" json:"finalization_period,omitempty"`
// The time of the first l2 block recorded.
// NOTE: this param is currently not used, but will be used for challenge in future.
SubmissionStartTime string `protobuf:"bytes,5,opt,name=submission_start_time,json=submissionStartTime,proto3,stdtime" json:"submission_start_time"`
// Normally it is IBC channelID for permissioned IBC relayer.
Metadata string `protobuf:"bytes,6,opt,name=metadata,proto3" json:"metadata,omitempty"`
// BatchInfo is the batch information for the bridge.
BatchInfo types.BatchInfo `json:"batch_info"`
// NOTE: it is a modified BridgeConfig from x/ophost/types/types.go to make unmarshal easier
type BridgeCliConfig struct {
Challengers []string `json:"challengers"`
Proposer string `json:"proposer"`
SubmissionInterval string `json:"submission_interval"`
FinalizationPeriod string `json:"finalization_period"`
SubmissionStartTime string `json:"submission_start_time"`
Metadata string `json:"metadata"`
BatchInfo BatchCliInfo `json:"batch_info"`
}

type BatchCliInfo struct {
Submitter string `json:"submitter"`
Chain string `json:"chain"`
}

// MsgFinalizeTokenWithdrawal is a message to remove a validator from designated list
Expand Down
6 changes: 3 additions & 3 deletions x/ophost/keeper/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Test_BridgeConfig(t *testing.T) {
ctx, input := createDefaultTestInput(t)
config := types.BridgeConfig{
Challenger: addrs[0].String(),
Challengers: []string{addrs[0].String()},
Proposer: addrs[1].String(),
SubmissionInterval: time.Second * 100,
FinalizationPeriod: time.Second * 10,
Expand All @@ -28,7 +28,7 @@ func Test_BridgeConfig(t *testing.T) {
func Test_IterateBridgeConfig(t *testing.T) {
ctx, input := createDefaultTestInput(t)
config1 := types.BridgeConfig{
Challenger: addrs[0].String(),
Challengers: []string{addrs[0].String()},
Proposer: addrs[1].String(),
SubmissionInterval: time.Second * 100,
FinalizationPeriod: time.Second * 10,
Expand All @@ -37,7 +37,7 @@ func Test_IterateBridgeConfig(t *testing.T) {
BatchInfo: types.BatchInfo{Submitter: addrsStr[0], Chain: "l1"},
}
config2 := types.BridgeConfig{
Challenger: addrs[2].String(),
Challengers: []string{addrs[2].String()},
Proposer: addrs[3].String(),
SubmissionInterval: time.Second * 100,
FinalizationPeriod: time.Second * 10,
Expand Down
16 changes: 8 additions & 8 deletions x/ophost/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ func _createTestInput(
}

type bridgeHook struct {
proposer string
challenger string
batchInfo ophosttypes.BatchInfo
metadata []byte
err error
proposer string
challengers []string
batchInfo ophosttypes.BatchInfo
metadata []byte
err error
}

func (h *bridgeHook) BridgeCreated(
Expand All @@ -336,11 +336,11 @@ func (h *bridgeHook) BridgeCreated(

h.metadata = bridgeConfig.Metadata
h.proposer = bridgeConfig.Proposer
h.challenger = bridgeConfig.Challenger
h.challengers = bridgeConfig.Challengers
return nil
}

func (h *bridgeHook) BridgeChallengerUpdated(
func (h *bridgeHook) BridgeChallengersUpdated(
ctx context.Context,
bridgeId uint64,
bridgeConfig ophosttypes.BridgeConfig,
Expand All @@ -349,7 +349,7 @@ func (h *bridgeHook) BridgeChallengerUpdated(
return h.err
}

h.challenger = bridgeConfig.Challenger
h.challengers = bridgeConfig.Challengers

return nil
}
Expand Down
Loading

0 comments on commit a4b8921

Please sign in to comment.