From 23fe780b3ef3ff4ead5b39a49cbee6070159c200 Mon Sep 17 00:00:00 2001 From: freeelancer Date: Mon, 26 Feb 2024 14:04:42 +0800 Subject: [PATCH] fix review --- x/smartaccount/ante/auth.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/x/smartaccount/ante/auth.go b/x/smartaccount/ante/auth.go index 5fa42a06..cd1d1ec8 100644 --- a/x/smartaccount/ante/auth.go +++ b/x/smartaccount/ante/auth.go @@ -51,7 +51,11 @@ func NewSmartAccountAuthDecorator( // AnteHandle checks if the tx provides sufficient fee to cover the required fee from the fee market. func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - // check if the tx is from a smart account + // skip the smartaccount auth decorator if the tx is a simulation + if simulate { + return next(ctx, tx, simulate) + } + sigTx, ok := tx.(authsigning.SigVerifiableTx) if !ok { return ctx, sdkerrors.ErrInvalidType.Wrap("expected SigVerifiableTx") @@ -60,12 +64,9 @@ func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu // Signer here is the account that the state transition is affecting // e.g. Account that is transferring some Coins signers := sigTx.GetSigners() - // Current only supports one signer (TODO review in the future) - if len(signers) != 1 { - return ctx, sdkerrors.ErrorInvalidSigner.Wrap("only one account is supported (sigTx.GetSigners()!= 1)") - } account := signers[0].String() + // check if the tx is from a smart account setting, err := sad.sak.GetSetting(ctx, account) if sdkerrors.ErrKeyNotFound.Is(err) { // run through the default handlers for signature verification @@ -79,6 +80,11 @@ func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu return ctx, err } + // Current smartaccount only supports one signer (TODO review in the future) + if len(signers) != 1 { + return ctx, sdkerrors.ErrorInvalidSigner.Wrap("only one account is supported (sigTx.GetSigners()!= 1)") + } + // Sender here is the account that signed the transaction // Could be different from the account above (confusingly named signer) signatures, err := sigTx.GetSignaturesV2() @@ -158,10 +164,18 @@ func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu return ctx, err } } - if !success { + if !success && !setting.Fallback { return ctx, sdkerrors.ErrUnauthorized.Wrap("authorization failed") + } else if !success && setting.Fallback { + // run through the default handlers for signature verification + newCtx, err := sad.defaultVerifySigDecorator(ctx, tx, simulate) + if err != nil { + return newCtx, err + } + // continue to the next handler after default signature verification + return next(newCtx, tx, simulate) } - } else if setting.Fallback { + } else { // run through the default handlers for signature verification newCtx, err := sad.defaultVerifySigDecorator(ctx, tx, simulate) if err != nil {