From a4a6e05babbcb4066d231c5ad3f3d565a37c16be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Apr 2021 02:07:35 -0400 Subject: [PATCH 1/4] build(deps): bump github.com/tendermint/tendermint (#9119) Bumps [github.com/tendermint/tendermint](https://github.com/tendermint/tendermint) from 0.34.9 to 0.34.10. - [Release notes](https://github.com/tendermint/tendermint/releases) - [Changelog](https://github.com/tendermint/tendermint/blob/v0.34.10/CHANGELOG.md) - [Commits](https://github.com/tendermint/tendermint/compare/v0.34.9...v0.34.10) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 302b631a929e..48bbe3f789e1 100644 --- a/go.mod +++ b/go.mod @@ -49,11 +49,11 @@ require ( github.com/tendermint/cosmos-rosetta-gateway v0.3.0-rc2.0.20210304154332-87d6ca4410df github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 github.com/tendermint/go-amino v0.16.0 - github.com/tendermint/tendermint v0.34.9 + github.com/tendermint/tendermint v0.34.10 github.com/tendermint/tm-db v0.6.4 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f - google.golang.org/grpc v1.36.1 + google.golang.org/grpc v1.37.0 google.golang.org/protobuf v1.26.0 gopkg.in/ini.v1 v1.61.0 // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 8cc2fdc74898..bf91ecf0f8e8 100644 --- a/go.sum +++ b/go.sum @@ -680,8 +680,8 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= -github.com/tendermint/tendermint v0.34.9 h1:9P2MXDEPOcPW0NBcHQ/HDSfvczZm+q5nUUw7AZ6f1Vc= -github.com/tendermint/tendermint v0.34.9/go.mod h1:kl4Z1JwGx1I+u1SXIzMDy7Z3T8LiMeCAOnzNn6AIMT4= +github.com/tendermint/tendermint v0.34.10 h1:wBOc/It8sh/pVH9np2V5fBvRmIyFN/bUrGPx+eAHexs= +github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ= From ef69863f46225d01208893cea643c93ad7a3c916 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 15 Apr 2021 14:13:55 +0700 Subject: [PATCH 2/4] x/bank/types: fix AddressFromBalancesStore address length overflow (#9112) addrLen is encoded in a byte, so it's an uint8. The code in AddressFromBalancesStore cast it to int for bound checking, but wrongly uses "addrLen+1", which can be overflow. To fix this, just cast addrLen once and use it in all places. Found by fuzzing added in #9060. Fixes #9111 --- x/bank/types/key.go | 7 +++---- x/bank/types/key_test.go | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/x/bank/types/key.go b/x/bank/types/key.go index 0d8ec96a0de3..a50d04a0a78f 100644 --- a/x/bank/types/key.go +++ b/x/bank/types/key.go @@ -44,12 +44,11 @@ func AddressFromBalancesStore(key []byte) (sdk.AccAddress, error) { return nil, ErrInvalidKey } addrLen := key[0] - if len(key[1:]) < int(addrLen) { + bound := int(addrLen) + if len(key)-1 < bound { return nil, ErrInvalidKey } - addr := key[1 : addrLen+1] - - return sdk.AccAddress(addr), nil + return key[1 : bound+1], nil } // CreateAccountBalancesPrefix creates the prefix for an account's balances. diff --git a/x/bank/types/key_test.go b/x/bank/types/key_test.go index c54037a2279e..9a7f457e45bd 100644 --- a/x/bank/types/key_test.go +++ b/x/bank/types/key_test.go @@ -24,29 +24,34 @@ func TestAddressFromBalancesStore(t *testing.T) { require.NoError(t, err) addrLen := len(addr) require.Equal(t, 20, addrLen) - key := cloneAppend(address.MustLengthPrefix(addr), []byte("stake")) - res, err := types.AddressFromBalancesStore(key) - require.NoError(t, err) - require.Equal(t, res, addr) -} -func TestInvalidAddressFromBalancesStore(t *testing.T) { tests := []struct { - name string - key []byte + name string + key []byte + wantErr bool + expectedKey sdk.AccAddress }{ - {"empty", []byte("")}, - {"invalid", []byte("3AA")}, + {"valid", key, false, addr}, + {"#9111", []byte("\xff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), false, nil}, + {"empty", []byte(""), true, nil}, + {"invalid", []byte("3AA"), true, nil}, } for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() - _, err := types.AddressFromBalancesStore(tc.key) - assert.Error(t, err) - assert.True(t, errors.Is(types.ErrInvalidKey, err)) + addr, err := types.AddressFromBalancesStore(tc.key) + if tc.wantErr { + assert.Error(t, err) + assert.True(t, errors.Is(types.ErrInvalidKey, err)) + } else { + assert.NoError(t, err) + } + if len(tc.expectedKey) > 0 { + assert.Equal(t, tc.expectedKey, addr) + } }) } } From bc4c3be15c33f2565f08e8f31e0a6caa6a129cbc Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+technicallyty@users.noreply.github.com> Date: Thu, 15 Apr 2021 02:09:01 -0700 Subject: [PATCH 3/4] add docs for gas consumption (#9118) Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- x/authz/spec/01_concepts.md | 3 +++ x/authz/spec/README.md | 1 + x/feegrant/spec/01_concepts.md | 6 +++++- x/feegrant/spec/README.md | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/x/authz/spec/01_concepts.md b/x/authz/spec/01_concepts.md index 0f5e482f1619..8be3333e62ff 100644 --- a/x/authz/spec/01_concepts.md +++ b/x/authz/spec/01_concepts.md @@ -35,3 +35,6 @@ Cosmos-SDK `x/authz` module comes with following authorization types +++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/generic_authorization.go#L20-L28 - `method_name` holds ServiceMsg type. + +## Gas +In order to prevent DoS attacks, granting `StakeAuthorizaiton`s with `x/authz` incur gas. `StakeAuthorizaiton` allows you to authorize another account to delegate, undelegate, or redelegate to validators. The authorizer can define a list of validators they will allow and/or deny delegations to. The SDK will iterate over these lists and charge 10 gas for each validator in both of the lists. \ No newline at end of file diff --git a/x/authz/spec/README.md b/x/authz/spec/README.md index 07ec1ba0c1e6..c5f982440702 100644 --- a/x/authz/spec/README.md +++ b/x/authz/spec/README.md @@ -16,6 +16,7 @@ granting arbitrary privileges from one account (the granter) to another account 1. **[Concept](01_concepts.md)** - [Authorization](01_concepts.md#Authorization) - [Built-in Authorizations](01_concepts.md#Built-in-Authorization) + - [Gas](01_concepts.md#gas) 2. **[State](02_state.md)** 3. **[Messages](03_messages.md)** - [Msg/GrantAuthorization](03_messages.md#MsgGrantAuthorization) diff --git a/x/feegrant/spec/01_concepts.md b/x/feegrant/spec/01_concepts.md index 92200f2d4797..afdd96d254b8 100644 --- a/x/feegrant/spec/01_concepts.md +++ b/x/feegrant/spec/01_concepts.md @@ -3,7 +3,6 @@ order: 1 --> # Concepts - ## FeeAllowanceGrant `FeeAllowanceGrant` is stored in the KVStore to record a grant with full context. Every grant will contain `granter`, `grantee` and what kind of `allowance` is granted. `granter` is an account address who is giving permission to `grantee` (the beneficiary account address) to pay for some or all of `grantee`'s transaction fees. `allowance` defines what kind of fee allowance (`BasicFeeAllowance` or `PeriodicFeeAllowance`, see below) is granted to `grantee`. `allowance` accepts an interface which implements `FeeAllowanceI`, encoded as `Any` type. There can be only one existing fee grant allowed for a `grantee` and `granter`, self grants are not allowed. @@ -68,3 +67,8 @@ Example cmd: ## DeductGrantedFeeDecorator `feegrant` module also adds a `DeductGrantedFeeDecorator` ante handler. Whenever a transaction is being executed with `granter` field set, then this ante handler will check whether `payer` and `granter` have proper fee allowance grant in state. If it exists the fees will be deducted from the `granter`'s account address. If the `granter` field isn't set then this ante handler works as normal fee deductor. + +## Gas +In order to prevent DoS attacks, using a filtered `x/feegrant` incurs gas. The SDK must assure that the `grantee`'s transactions all conform to the filter set by the `granter`. The SDK does this by iterating over the allowed messages in the filter and charging 10 gas per filtered message. The SDK will then iterate over the messages being sent by the `grantee` to ensure the messages adhere to the filter, also charging 10 gas per message. The SDK will stop iterating and fail the transaction if it finds a message that does not conform to the filter. + +**WARNING**: The gas is charged against the granted allowance. Ensure your messages conform to the filter, if any, before sending transactions using your allowance. \ No newline at end of file diff --git a/x/feegrant/spec/README.md b/x/feegrant/spec/README.md index 1abdcf464b14..26be4c49f516 100644 --- a/x/feegrant/spec/README.md +++ b/x/feegrant/spec/README.md @@ -20,12 +20,13 @@ This module allows accounts to grant fee allowances and to use fees from their a - [PeriodicFeeAllowance](01_concepts.md#periodicfeeallowance) - [FeeAccount flag](01_concepts.md#feeaccount-flag) - [DeductGrantedFeeDecorator](01_concepts.md#deductgrantedfeedecorator) + - [Gas](01_concepts.md#gas) 2. **[State](02_state.md)** - [FeeAllowance](02_state.md#feeallowance) 3. **[Messages](03_messages.md)** - [Msg/GrantFeeAllowance](03_messages.md#msggrantfeeallowance) - [Msg/RevokeFeeAllowance](03_messages.md#msgrevokefeeallowance) -3. **[Events](04_events.md)** +4. **[Events](04_events.md)** - [MsgGrantFeeAllowance](04_events.md#msggrantfeeallowance) - [MsgrevokeFeeAllowance](04_events.md#msgrevokefeeallowance) - [Exec fee allowance](04_events.md#exec-fee-allowance) From 261c7ebd8910eb68d2ffacbeae1b4390db7d8718 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 15 Apr 2021 14:17:36 +0000 Subject: [PATCH 4/4] dont generate uml docs (#9121) --- docs/pre.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pre.sh b/docs/pre.sh index e5a0f9fe131b..c52b14847398 100755 --- a/docs/pre.sh +++ b/docs/pre.sh @@ -11,4 +11,4 @@ done cat ../x/README.md | sed 's/\.\/x/\/modules/g' | sed 's/spec\/README.md//g' | sed 's/\.\.\/docs\/building-modules\/README\.md/\/building-modules\/intro\.html/g' > ./modules/README.md -plantuml -tsvg uml/*.puml +# plantuml -tsvg uml/*.puml