Skip to content

Commit

Permalink
Merge branch 'master' into robert/address-derive
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Apr 15, 2021
2 parents 7ee294b + 261c7eb commit ba1b14b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/pre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions x/authz/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions x/authz/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions x/bank/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 18 additions & 13 deletions x/bank/types/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
6 changes: 5 additions & 1 deletion x/feegrant/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
3 changes: 2 additions & 1 deletion x/feegrant/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ba1b14b

Please sign in to comment.