Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/auth/ante): migrate antehandlers to use execmode #19161

Merged
merged 8 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
// performance benefits, but it'll be more difficult to get right.
anteCtx, msCache = app.cacheTxContext(ctx, txBytes)
anteCtx = anteCtx.WithEventManager(sdk.NewEventManager())
if mode == execModeSimulate {
anteCtx = anteCtx.WithExecMode(sdk.ExecMode(execModeSimulate))
}
newCtx, err := app.anteHandler(anteCtx, tx, mode == execModeSimulate)
Comment on lines 884 to 890
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).runTx (baseapp/baseapp.go:814)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).deliverTx (baseapp/baseapp.go:744)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).internalFinalizeBlock (baseapp/baseapp.go:713)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).FinalizeBlock (baseapp/baseapp.go:874)


if !newCtx.IsZero() {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*storetypes.Gas(len(ctx.TxBytes())), "txSize")

// simulate gas cost for signatures in simulate mode
if simulate {
if ctx.ExecMode() == sdk.ExecModeSimulate {
// in simulate mode, each element should be a nil signature
sigs, err := sigTx.GetSignaturesV2()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/auth/ante/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func TestConsumeGasForTxSize(t *testing.T) {

// Set suite.ctx with smaller simulated TxBytes manually
suite.ctx = suite.ctx.WithTxBytes(simTxBytes)
suite.ctx = suite.ctx.WithExecMode(sdk.ExecModeSimulate)

beforeSimGas := suite.ctx.GasMeter().GasConsumed()

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
// In various cases such as simulation and during the genesis block, we do not
// meter any gas utilization.
if simulate || ctx.BlockHeight() == 0 {
if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.BlockHeight() == 0 {
return ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
}

Expand Down
13 changes: 6 additions & 7 deletions x/auth/ante/sigverify.go
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx sdk.Tx, sim
return err
}

err = svd.consumeSignatureGas(ctx, simulate, acc.GetPubKey(), sig)
err = svd.consumeSignatureGas(ctx, acc.GetPubKey(), sig)
if err != nil {
return err
}

err = svd.verifySig(ctx, simulate, tx, acc, sig)
err = svd.verifySig(ctx, tx, acc, sig)
if err != nil {
return err
}
Expand All @@ -296,11 +296,10 @@ func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx sdk.Tx, sim
// consumeSignatureGas will consume gas according to the pub-key being verified.
func (svd SigVerificationDecorator) consumeSignatureGas(
ctx sdk.Context,
simulate bool,
pubKey cryptotypes.PubKey,
signature signing.SignatureV2,
) error {
if simulate && pubKey == nil {
if ctx.ExecMode() == sdk.ExecModeSimulate && pubKey == nil {
pubKey = simSecp256k1Pubkey
}

Expand All @@ -322,10 +321,10 @@ func (svd SigVerificationDecorator) consumeSignatureGas(
// it will assess:
// - the pub key is on the curve.
// - verify sig
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, simulate bool, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2) error {
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2) error {
// retrieve pubkey
pubKey := acc.GetPubKey()
if !simulate && pubKey == nil {
if ctx.ExecMode() != sdk.ExecModeSimulate && pubKey == nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set")
}

Expand All @@ -343,7 +342,7 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, simulate bool, tx
// we're in simulation mode, or in ReCheckTx, or context is not
// on sig verify tx, then we do not need to verify the signatures
// in the tx.
if simulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() {
if ctx.ExecMode() == sdk.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() {
return nil
}

Expand Down
Loading