Skip to content

Commit ba1b14b

Browse files
Merge branch 'master' into robert/address-derive
2 parents 7ee294b + 261c7eb commit ba1b14b

File tree

9 files changed

+37
-24
lines changed

9 files changed

+37
-24
lines changed

docs/pre.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ done
1111

1212
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
1313

14-
plantuml -tsvg uml/*.puml
14+
# plantuml -tsvg uml/*.puml

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ require (
4949
github.com/tendermint/cosmos-rosetta-gateway v0.3.0-rc2.0.20210304154332-87d6ca4410df
5050
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
5151
github.com/tendermint/go-amino v0.16.0
52-
github.com/tendermint/tendermint v0.34.9
52+
github.com/tendermint/tendermint v0.34.10
5353
github.com/tendermint/tm-db v0.6.4
5454
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
5555
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
56-
google.golang.org/grpc v1.36.1
56+
google.golang.org/grpc v1.37.0
5757
google.golang.org/protobuf v1.26.0
5858
gopkg.in/ini.v1 v1.61.0 // indirect
5959
gopkg.in/yaml.v2 v2.4.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM
680680
github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
681681
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
682682
github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ=
683-
github.com/tendermint/tendermint v0.34.9 h1:9P2MXDEPOcPW0NBcHQ/HDSfvczZm+q5nUUw7AZ6f1Vc=
684-
github.com/tendermint/tendermint v0.34.9/go.mod h1:kl4Z1JwGx1I+u1SXIzMDy7Z3T8LiMeCAOnzNn6AIMT4=
683+
github.com/tendermint/tendermint v0.34.10 h1:wBOc/It8sh/pVH9np2V5fBvRmIyFN/bUrGPx+eAHexs=
684+
github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
685685
github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI=
686686
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
687687
github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ=

x/authz/spec/01_concepts.md

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ Cosmos-SDK `x/authz` module comes with following authorization types
3535
+++ https://github.com/cosmos/cosmos-sdk/blob/c95de9c4177442dee4c69d96917efc955b5d19d9/x/authz/types/generic_authorization.go#L20-L28
3636

3737
- `method_name` holds ServiceMsg type.
38+
39+
## Gas
40+
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.

x/authz/spec/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ granting arbitrary privileges from one account (the granter) to another account
1616
1. **[Concept](01_concepts.md)**
1717
- [Authorization](01_concepts.md#Authorization)
1818
- [Built-in Authorizations](01_concepts.md#Built-in-Authorization)
19+
- [Gas](01_concepts.md#gas)
1920
2. **[State](02_state.md)**
2021
3. **[Messages](03_messages.md)**
2122
- [Msg/GrantAuthorization](03_messages.md#MsgGrantAuthorization)

x/bank/types/key.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ func AddressFromBalancesStore(key []byte) (sdk.AccAddress, error) {
4444
return nil, ErrInvalidKey
4545
}
4646
addrLen := key[0]
47-
if len(key[1:]) < int(addrLen) {
47+
bound := int(addrLen)
48+
if len(key)-1 < bound {
4849
return nil, ErrInvalidKey
4950
}
50-
addr := key[1 : addrLen+1]
51-
52-
return sdk.AccAddress(addr), nil
51+
return key[1 : bound+1], nil
5352
}
5453

5554
// CreateAccountBalancesPrefix creates the prefix for an account's balances.

x/bank/types/key_test.go

+18-13
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,34 @@ func TestAddressFromBalancesStore(t *testing.T) {
2424
require.NoError(t, err)
2525
addrLen := len(addr)
2626
require.Equal(t, 20, addrLen)
27-
2827
key := cloneAppend(address.MustLengthPrefix(addr), []byte("stake"))
29-
res, err := types.AddressFromBalancesStore(key)
30-
require.NoError(t, err)
31-
require.Equal(t, res, addr)
32-
}
3328

34-
func TestInvalidAddressFromBalancesStore(t *testing.T) {
3529
tests := []struct {
36-
name string
37-
key []byte
30+
name string
31+
key []byte
32+
wantErr bool
33+
expectedKey sdk.AccAddress
3834
}{
39-
{"empty", []byte("")},
40-
{"invalid", []byte("3AA")},
35+
{"valid", key, false, addr},
36+
{"#9111", []byte("\xff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), false, nil},
37+
{"empty", []byte(""), true, nil},
38+
{"invalid", []byte("3AA"), true, nil},
4139
}
4240

4341
for _, tc := range tests {
4442
tc := tc
4543
t.Run(tc.name, func(t *testing.T) {
4644
t.Parallel()
47-
_, err := types.AddressFromBalancesStore(tc.key)
48-
assert.Error(t, err)
49-
assert.True(t, errors.Is(types.ErrInvalidKey, err))
45+
addr, err := types.AddressFromBalancesStore(tc.key)
46+
if tc.wantErr {
47+
assert.Error(t, err)
48+
assert.True(t, errors.Is(types.ErrInvalidKey, err))
49+
} else {
50+
assert.NoError(t, err)
51+
}
52+
if len(tc.expectedKey) > 0 {
53+
assert.Equal(t, tc.expectedKey, addr)
54+
}
5055
})
5156
}
5257
}

x/feegrant/spec/01_concepts.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ order: 1
33
-->
44

55
# Concepts
6-
76
## FeeAllowanceGrant
87

98
`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:
6867
## DeductGrantedFeeDecorator
6968

7069
`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.
70+
71+
## Gas
72+
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.
73+
74+
**WARNING**: The gas is charged against the granted allowance. Ensure your messages conform to the filter, if any, before sending transactions using your allowance.

x/feegrant/spec/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ This module allows accounts to grant fee allowances and to use fees from their a
2020
- [PeriodicFeeAllowance](01_concepts.md#periodicfeeallowance)
2121
- [FeeAccount flag](01_concepts.md#feeaccount-flag)
2222
- [DeductGrantedFeeDecorator](01_concepts.md#deductgrantedfeedecorator)
23+
- [Gas](01_concepts.md#gas)
2324
2. **[State](02_state.md)**
2425
- [FeeAllowance](02_state.md#feeallowance)
2526
3. **[Messages](03_messages.md)**
2627
- [Msg/GrantFeeAllowance](03_messages.md#msggrantfeeallowance)
2728
- [Msg/RevokeFeeAllowance](03_messages.md#msgrevokefeeallowance)
28-
3. **[Events](04_events.md)**
29+
4. **[Events](04_events.md)**
2930
- [MsgGrantFeeAllowance](04_events.md#msggrantfeeallowance)
3031
- [MsgrevokeFeeAllowance](04_events.md#msgrevokefeeallowance)
3132
- [Exec fee allowance](04_events.md#exec-fee-allowance)

0 commit comments

Comments
 (0)