Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply audit #229

Merged
merged 17 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/initia-labs/OPinit/api v0.3.0 // indirect
github.com/initia-labs/OPinit/api v0.3.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,8 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/initia-labs/OPinit v0.3.2 h1:TeELD5GeSJJ9meY5b5YIXDdmCZt9kZOA2Chz+IwxUHc=
github.com/initia-labs/OPinit v0.3.2/go.mod h1:XlYsBFAKOFS6/wRIHB1vVbfonqX8QrC8cWK2GJvmX20=
github.com/initia-labs/OPinit/api v0.3.0 h1:OY8ijwmgZLoYwtw9LI1mSY3VC8PY+gtxJFitB6ZNFl4=
github.com/initia-labs/OPinit/api v0.3.0/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
github.com/initia-labs/OPinit/api v0.3.1 h1:qCCtRZE9yw53FkBxlsOMBozMRGwz2EZVvNoDnZwfz04=
github.com/initia-labs/OPinit/api v0.3.1/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0=
github.com/initia-labs/cometbft v0.0.0-20240704071957-c46468756c01 h1:EGcO68mXypbiO3rmoFsskxLEAeZFcOkJII1PsSK0rRI=
github.com/initia-labs/cometbft v0.0.0-20240704071957-c46468756c01/go.mod h1:xOoGZrtUT+A5izWfHSJgl0gYZUE7lu7Z2XIS1vWG/QQ=
github.com/initia-labs/movevm v0.3.4 h1:kzqs6uzTq0f5peZJNzLq/1qgnmAFfC+I9eCyPBducxM=
Expand Down
20 changes: 19 additions & 1 deletion proto/ibc/applications/nft_transfer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@ message GenesisState {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"class_traces\""
];
Params params = 3 [(gogoproto.nullable) = false];
repeated ClassData class_data = 3 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"class_data\""];
repeated TokenData token_data = 4 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"token_data\""];

Params params = 5 [(gogoproto.nullable) = false];
}

// ClassData contains the class trace hash and the class data
// for genesis.
message ClassData {
bytes trace_hash = 1;
string data = 2;
}

// TokenData contains the trace hash, token id, and the token data
// for genesis.
message TokenData {
bytes trace_hash = 1;
string token_id = 2;
string data = 3;
}
2 changes: 1 addition & 1 deletion proto/initia/distribution/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ message MsgUpdateParamsResponse {}
//
// Since: cosmos-sdk 0.50
message MsgDepositValidatorRewardsPool {
option (amino.name) = "cosmos-sdk/distr/MsgDepositValRewards";
option (amino.name) = "distr/MsgDepositValidatorRewardsPool";
option (cosmos.msg.v1.signer) = "depositor";

option (gogoproto.equal) = false;
Expand Down
10 changes: 1 addition & 9 deletions x/bank/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import (
"context"
"errors"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"cosmossdk.io/collections"
"cosmossdk.io/store/prefix"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -188,13 +186,7 @@

metadata, found := k.GetDenomMetaData(ctx, req.Denom)
if !found {
var err error
metadata, err = k.mk.GetMetadata(ctx, req.Denom)
if errors.Is(err, collections.ErrNotFound) {
return nil, status.Errorf(codes.NotFound, "client metadata for denom %s", req.Denom)
} else if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
return nil, status.Errorf(codes.NotFound, "client metadata for denom %s", req.Denom)

Check warning on line 189 in x/bank/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/bank/keeper/grpc_query.go#L189

Added line #L189 was not covered by tests
}

return &types.QueryDenomMetadataResponse{
Expand Down
12 changes: 12 additions & 0 deletions x/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@
poolDenom := rewardWeight.Denom
poolSize := bondedTokensSum[poolDenom]

// if poolSize is zero, skip allocation and then the poolReward will be allocated to community pool
if poolSize.IsZero() {
continue

Check warning on line 91 in x/distribution/keeper/allocation.go

View check run for this annotation

Codecov / codecov/patch

x/distribution/keeper/allocation.go#L91

Added line #L91 was not covered by tests
}

for _, bondedTokens := range bondedTokens[poolDenom] {
if bondedTokens.Amount.IsZero() {
continue

Check warning on line 96 in x/distribution/keeper/allocation.go

View check run for this annotation

Codecov / codecov/patch

x/distribution/keeper/allocation.go#L96

Added line #L96 was not covered by tests
}

validator := validators[bondedTokens.ValAddr]

amountFraction := math.LegacyNewDecFromInt(bondedTokens.Amount).QuoInt(poolSize)
reward := poolReward.MulDecTruncate(amountFraction)
if reward.IsZero() {
continue

Check warning on line 104 in x/distribution/keeper/allocation.go

View check run for this annotation

Codecov / codecov/patch

x/distribution/keeper/allocation.go#L104

Added line #L104 was not covered by tests
}

err = k.AllocateTokensToValidatorPool(ctx, validator, poolDenom, reward)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
// and concrete types on the provided LegacyAmino codec. These types are used
// for Amino JSON serialization.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// amino is rejecting long type names, so we register under `distr`
legacy.RegisterAminoMsg(cdc, &MsgDepositValidatorRewardsPool{}, "distr/MsgDepositValidatorRewardsPool")

Check warning on line 16 in x/distribution/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/distribution/types/codec.go#L15-L16

Added lines #L15 - L16 were not covered by tests
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "distribution/MsgUpdateParams")
cdc.RegisterConcrete(Params{}, "distribution/Params", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgDepositValidatorRewardsPool{},

Check warning on line 24 in x/distribution/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/distribution/types/codec.go#L24

Added line #L24 was not covered by tests
&MsgUpdateParams{},
)

Expand Down
76 changes: 38 additions & 38 deletions x/distribution/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
return false, err
}

// emergency proposals are handled separately
if proposal.Emergency {
return false, nil
}

Check warning on line 136 in x/gov/abci.go

View check run for this annotation

Codecov / codecov/patch

x/gov/abci.go#L135-L136

Added lines #L135 - L136 were not covered by tests

_, passed, burnDeposits, tallyResults, err := k.Tally(ctx, params, proposal)
if err != nil {
return false, err
Expand Down
1 change: 1 addition & 0 deletions x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ func _createTestInput(
require.NoError(t, govKeeper.ProposalID.Set(ctx, govtypesv1.DefaultStartingProposalID))
govParams := customgovtypes.DefaultParams()
govParams.MinDeposit[0].Denom = bondDenom
govParams.ExpeditedMinDeposit[0].Denom = bondDenom
govParams.EmergencyMinDeposit[0].Denom = bondDenom

require.NoError(t, govKeeper.Params.Set(ctx, govParams))
Expand Down
Loading
Loading