Skip to content

Commit

Permalink
Merge pull request #212 from scorpioborn/fix/ovm-pubkeys-count
Browse files Browse the repository at this point in the history
Fix / Public Keys count between 3 and 5
  • Loading branch information
3eyedraga authored Jul 19, 2023
2 parents 221db17 + 1fa9fec commit 56c13c3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 30 deletions.
2 changes: 0 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ genesis:
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAw5iPKVbSvyF1A1HDFaWMGlhBp/xTU70i8lMgOml79WM=\n-----END PUBLIC KEY-----",
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAueEgZMdKn6Bp0mcG04HrNAt1a0o7+0eNliQCNmbxkOQ=\n-----END PUBLIC KEY-----",
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAkMnWRwXXVlQqhpHq7LNVGwqA/E2LQY/6remOtilPKpI=\n-----END PUBLIC KEY-----",
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAeEQoiCf6zmsT0ViyY6HFoYhjG+Q4yULkeKCWDQjwpMY=\n-----END PUBLIC KEY-----",
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAef9+By/RbBXdSycfWlfVA1jNnWqcjZ7PI8Tt+pTPe+I=\n-----END PUBLIC KEY-----"
]
gov:
deposit_params:
Expand Down
29 changes: 28 additions & 1 deletion x/ovm/keeper/msg_server_pubkeys_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,34 @@ func TestChangePubkeysListProposal(t *testing.T) {

createNActiveProposal(k, ctx, 1)
creator := simappUtil.TestParamUsers["user1"]
pubs, err := createNTestPubKeys(4)
pubs, err := createNTestPubKeys(types.MinPubKeysCount - 1)
require.NoError(t, err)

proposalTicket := jwt.NewWithClaims(jwt.SigningMethodEdDSA, jwt.MapClaims{
"public_keys": pubs,
"leader_index": 0,
"exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)),
})
singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0])
require.NoError(t, err)

resp, err := msgk.SubmitPubkeysChangeProposal(
wctx,
&types.MsgSubmitPubkeysChangeProposalRequest{
Creator: creator.Address.String(),
Ticket: singedProposalTicket,
},
)
require.ErrorIs(t, sdkerrors.ErrInvalidRequest, err)
require.Nil(t, resp)
})

t.Run("lots of pubkeys", func(t *testing.T) {
k, msgk, ctx, wctx := setupMsgServerAndKeeper(t)

createNActiveProposal(k, ctx, 1)
creator := simappUtil.TestParamUsers["user1"]
pubs, err := createNTestPubKeys(types.MaxPubKeysCount + 1)
require.NoError(t, err)

proposalTicket := jwt.NewWithClaims(jwt.SigningMethodEdDSA, jwt.MapClaims{
Expand Down
2 changes: 1 addition & 1 deletion x/ovm/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestFinishProposals(t *testing.T) {

keyVault, found := k.GetKeyVault(ctx)
require.True(t, found)
require.Equal(t, 7, len(keyVault.PublicKeys))
require.Equal(t, types.MinPubKeysCount, len(keyVault.PublicKeys))
}

func TestFinishProposal(t *testing.T) {
Expand Down
22 changes: 0 additions & 22 deletions x/ovm/types/const.go

This file was deleted.

20 changes: 20 additions & 0 deletions x/ovm/types/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ package types

import sdk "github.com/cosmos/cosmos-sdk/types"

// JWT constants
const (
// JWTHeaderIndex is the index of the header in the JWT ticket
JWTHeaderIndex = 0

// JWTPayloadIndex is the index of the payload in the JWT ticket
JWTPayloadIndex = 1

// JWTSeparator is the separator character between JWT ticket parts
JWTSeparator = "."

// DefaultTimeWeight is the default weight of the time for JWT ticket expiration
DefaultTimeWeight = 1

// MinPubKeysCount is the minimum allowed public keys in the key vault
MinPubKeysCount = 3

// MaxPubKeysCount is the maximum allowed public keys in the key vault
MaxPubKeysCount = 5
)

const (
// MaxValidProposalMinutes is the maximum elapsed time in minutes since
// the start time of a proposal to be acceptable.
MaxValidProposalMinutes = 30
Expand Down
2 changes: 1 addition & 1 deletion x/ovm/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
)

func TestGenesisState_Validate(t *testing.T) {
pubkeys := simappUtil.GenerateOvmPublicKeys(7)
pubkeys := simappUtil.GenerateOvmPublicKeys(types.MaxPubKeysCount)

var votes []*types.Vote
for _, v := range pubkeys {
Expand Down
2 changes: 1 addition & 1 deletion x/ovm/types/key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k *KeyVault) validatePubKeys() error {
return fmt.Errorf(
"total number of pubkeys is %d, this should not be more than %d",
count,
MinPubKeysCount,
MaxPubKeysCount,
)
}

Expand Down
4 changes: 2 additions & 2 deletions x/ovm/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (proposal *PublicKeysChangeProposal) DecideResult(keyvault *KeyVault) Propo
majorityCount := keyvault.MajorityCount()

// check if minimum majority vote count is met or not
if noCount >= majorityCount {
if majorityCount <= noCount {
return ProposalResult_PROPOSAL_RESULT_REJECTED
} else if yesCount > majorityCount {
} else if majorityCount <= yesCount {
return ProposalResult_PROPOSAL_RESULT_APPROVED
}

Expand Down

0 comments on commit 56c13c3

Please sign in to comment.