Skip to content

Commit

Permalink
fix: changed the data type for FeePayer and FeeGranter (backport #16272
Browse files Browse the repository at this point in the history
…) (#16920)

Co-authored-by: Vishal Potpelliwar <[email protected]>
  • Loading branch information
mergify[bot] and vishal-kanna authored Jul 11, 2023
1 parent 7d07df5 commit 5ca5039
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (types) [#16272](https://github.com/cosmos/cosmos-sdk/pull/16272) From now the `FeeGranter` in the `FeeTx` interface takes the byte type instead of string.
* (testutil) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) The *cli testutil* `QueryBalancesExec` has been removed. Use the gRPC or REST query instead.
* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The *cli testutil* `QueryAccountExec` has been removed. Use the gRPC or REST query instead.
* (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2).
Expand Down
2 changes: 1 addition & 1 deletion types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type (
GetGas() uint64
GetFee() Coins
FeePayer() []byte
FeeGranter() string
FeeGranter() []byte
}

// TxWithMemo must have GetMemo() method to use ValidateMemoDecorator
Expand Down
7 changes: 2 additions & 5 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee

// if feegranter set deduct fee from feegranter account.
// this works with only when feegrant enabled.
if feeGranter != "" {
feeGranterAddr, err := sdk.AccAddressFromBech32(feeGranter)
if err != nil {
return err
}
if feeGranter != nil {
feeGranterAddr := sdk.AccAddress(feeGranter)

if dfd.feegrantKeeper == nil {
return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled")
Expand Down
6 changes: 3 additions & 3 deletions x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ func (w *wrapper) FeePayer() []byte {
return signers[0]
}

func (w *wrapper) FeeGranter() string {
func (w *wrapper) FeeGranter() []byte {
feeGranter := w.tx.AuthInfo.Fee.Granter
if feeGranter != "" {
return feeGranter
return sdk.MustAccAddressFromBech32(feeGranter)
}
return ""
return nil
}

func (w *wrapper) GetTip() *tx.Tip {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,5 @@ func TestBuilderFeeGranter(t *testing.T) {

// set fee granter
txBuilder.SetFeeGranter(addr1)
require.Equal(t, addr1.String(), txBuilder.GetTx().FeeGranter())
require.Equal(t, addr1.String(), sdk.AccAddress(txBuilder.GetTx().FeeGranter()).String())
}
11 changes: 3 additions & 8 deletions x/auth/tx/direct_aux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tx

import (
"bytes"
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -56,13 +56,8 @@ func (signModeDirectAuxHandler) GetSignBytes(

// Fee payer cannot use SIGN_MODE_DIRECT_AUX, because SIGN_MODE_DIRECT_AUX
// does not sign over fees, which would create malleability issues.
addrBz, err := sdk.AccAddressFromBech32(data.Address)
if err != nil {
return nil, err
}

if bytes.Equal(feePayer, addrBz) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", feePayer, signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
if strings.EqualFold(sdk.AccAddress(feePayer).String(), data.Address) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("fee payer %s cannot sign with %s", sdk.AccAddress(feePayer).String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX)
}

signDocDirectAux := types.SignDocDirectAux{
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/direct_aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestDirectAuxHandler(t *testing.T) {

t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX")
_, err = modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, feePayerSigningData, txBuilder.GetTx())
require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", []byte(feePayerAddr), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX))
require.EqualError(t, err, fmt.Sprintf("fee payer %s cannot sign with %s: unauthorized", feePayerAddr.String(), signingtypes.SignMode_SIGN_MODE_DIRECT_AUX))

t.Log("verify GetSignBytes with generating sign bytes by marshaling signDocDirectAux")
signBytes, err := modeHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, signingData, txBuilder.GetTx())
Expand Down

0 comments on commit 5ca5039

Please sign in to comment.