Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trailofbits-4-duplicate-check-ob…
Browse files Browse the repository at this point in the history
…server-set' into trailofbits-4-duplicate-check-observer-set

# Conflicts:
#	changelog.md
  • Loading branch information
kingpinXD committed Aug 9, 2024
2 parents b98e720 + faecf24 commit 275da58
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

### Fixes

* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module
* [2672](https://github.com/zeta-chain/node/pull/2672) - check observer set for duplicates when adding a new observer or updating an existing one

## v19.0.0
Expand Down
1 change: 1 addition & 0 deletions x/authority/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func MigrateStore(
ctx sdk.Context,
keeper authorityKeeper,
) error {
// It is okay to not validate here, as the authorization list is fixed and will not change
keeper.SetAuthorizationList(ctx, types.DefaultAuthorizationsList())
return nil
}
9 changes: 7 additions & 2 deletions x/authority/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (gs GenesisState) Validate() error {
if err := gs.Policies.Validate(); err != nil {
return err
}

return gs.ChainInfo.Validate()
if err := gs.AuthorizationList.Validate(); err != nil {
return err
}
if err := gs.ChainInfo.Validate(); err != nil {
return err
}
return nil
}
36 changes: 32 additions & 4 deletions x/authority/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -26,8 +27,9 @@ func TestGenesisState_Validate(t *testing.T) {
{
name: "valid genesis",
gs: &types.GenesisState{
Policies: sample.Policies(),
ChainInfo: sample.ChainInfo(42),
Policies: sample.Policies(),
ChainInfo: sample.ChainInfo(42),
AuthorizationList: sample.AuthorizationList("testMessage"),
},
errContains: "",
},
Expand All @@ -42,12 +44,13 @@ func TestGenesisState_Validate(t *testing.T) {
},
},
},
ChainInfo: sample.ChainInfo(42),
ChainInfo: sample.ChainInfo(42),
AuthorizationList: sample.AuthorizationList("testMessage"),
},
errContains: "invalid address",
},
{
name: "invalid if policies is invalid",
name: "invalid if chainInfo is invalid",
gs: &types.GenesisState{
Policies: sample.Policies(),
ChainInfo: types.ChainInfo{
Expand All @@ -63,9 +66,34 @@ func TestGenesisState_Validate(t *testing.T) {
},
},
},
AuthorizationList: sample.AuthorizationList("testMessage"),
},
errContains: "chain ID must be positive",
},
{
name: "invalid if authorization list is invalid",
gs: &types.GenesisState{
Policies: sample.Policies(),
ChainInfo: sample.ChainInfo(42),
AuthorizationList: types.AuthorizationList{
Authorizations: []types.Authorization{
{
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
AuthorizedPolicy: types.PolicyType_groupEmergency,
},
{
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
AuthorizedPolicy: types.PolicyType_groupAdmin,
},
{
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
AuthorizedPolicy: types.PolicyType_groupOperational,
},
},
},
},
errContains: "duplicate message url",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 275da58

Please sign in to comment.