From ebfff2cef1bfea00716d90fa23f327f0c3c73dc9 Mon Sep 17 00:00:00 2001 From: nhpd Date: Wed, 27 Nov 2024 16:32:40 +0400 Subject: [PATCH] fix gas consumer --- app/app.go | 2 +- app/sigverify.go | 73 ------------------------------------------------ 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/app/app.go b/app/app.go index 64fb5e8b9..6daf503ec 100644 --- a/app/app.go +++ b/app/app.go @@ -1122,7 +1122,7 @@ func New( HandlerOptions: ante.HandlerOptions{ FeegrantKeeper: app.FeeGrantKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + SigGasConsumer: DefaultSigVerificationGasConsumer, }, BankKeeper: app.BankKeeper, AccountKeeper: app.AccountKeeper, diff --git a/app/sigverify.go b/app/sigverify.go index ff46855a2..94024b9e6 100644 --- a/app/sigverify.go +++ b/app/sigverify.go @@ -143,77 +143,6 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b return next(ctx, tx, simulate) } -// Consume parameter-defined amount of gas for each signature according to the passed-in SignatureVerificationGasConsumer function -// before calling the next AnteHandler -// CONTRACT: Pubkeys are set in context for all signers before this decorator runs -// CONTRACT: Tx must implement SigVerifiableTx interface -type SigGasConsumeDecorator struct { - ak ante.AccountKeeper - sigGasConsumer SignatureVerificationGasConsumer -} - -func NewSigGasConsumeDecorator(ak ante.AccountKeeper, sigGasConsumer SignatureVerificationGasConsumer) SigGasConsumeDecorator { - if sigGasConsumer == nil { - sigGasConsumer = DefaultSigVerificationGasConsumer - } - - return SigGasConsumeDecorator{ - ak: ak, - sigGasConsumer: sigGasConsumer, - } -} - -func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - sigTx, ok := tx.(authsigning.SigVerifiableTx) - if !ok { - return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") - } - - params := sgcd.ak.GetParams(ctx) - sigs, err := sigTx.GetSignaturesV2() - if err != nil { - return ctx, err - } - - // stdSigs contains the sequence number, account number, and signatures. - // When simulating, this would just be a 0-length slice. - signers, err := sigTx.GetSigners() - if err != nil { - return ctx, err - } - - for i, sig := range sigs { - signerAcc, err := GetSignerAcc(ctx, sgcd.ak, signers[i]) - if err != nil { - return ctx, err - } - - pubKey := signerAcc.GetPubKey() - - // In simulate mode the transaction comes with no signatures, thus if the - // account's pubkey is nil, both signature verification and gasKVStore.Set() - // shall consume the largest amount, i.e. it takes more gas to verify - // secp256k1 keys than ed25519 ones. - if simulate && pubKey == nil { - pubKey = simSecp256k1Pubkey - } - - // make a SignatureV2 with PubKey filled in from above - sig = signing.SignatureV2{ - PubKey: pubKey, - Data: sig.Data, - Sequence: sig.Sequence, - } - - err = sgcd.sigGasConsumer(ctx.GasMeter(), sig, params) - if err != nil { - return ctx, err - } - } - - return next(ctx, tx, simulate) -} - // SigVerificationDecorator verifies all signatures for a tx and return an error if any are invalid. Note, // the SigVerificationDecorator will not check signatures on ReCheck. // @@ -333,7 +262,6 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d) and chain-id (%s): (%s)", accNum, chainID, err.Error()) } return ctx, errorsmod.Wrap(sdkerrors.ErrUnauthorized, errMsg) - } } } @@ -435,7 +363,6 @@ func DefaultSigVerificationGasConsumer( return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "ED25519 public keys are unsupported") case *secp256k1.PubKey, *ethsecp256k1.PubKey: - meter.ConsumeGas(params.SigVerifyCostSecp256k1, "ante verify: secp256k1") return nil