From f345db14586b209895ac93c0dae03c26a86289be Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 21 Jun 2022 19:21:52 +0800 Subject: [PATCH] fix(evm): clear logs if tx failed in post processing hooks (#1128) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Problem: clear logs if tx failed in post processing hooks * Update x/evm/keeper/state_transition.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- CHANGELOG.md | 3 ++- x/evm/handler_test.go | 1 + x/evm/keeper/state_transition.go | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac6ada4059..6968f01133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking -* (evm) [tharsis#1124](https://github.com/evmos/ethermint/pull/1124) Reject non-replay-protected tx in ante handler to prevent replay attack +* (evm) [\#1128](https://github.com/tharsis/ethermint/pull/1128) Clear tx logs if tx failed in post processing hooks +* (evm) [tharsis#1124](https://github.com/tharsis/ethermint/pull/1124) Reject non-replay-protected tx in `AnteHandler` to prevent replay attack ### API Breaking diff --git a/x/evm/handler_test.go b/x/evm/handler_test.go index 38c212cb74..733b1708c4 100644 --- a/x/evm/handler_test.go +++ b/x/evm/handler_test.go @@ -599,6 +599,7 @@ func (suite *EvmTestSuite) TestERC20TransferReverted() { suite.Require().True(res.Failed()) suite.Require().Equal(tc.expErr, res.VmError) + suite.Require().Empty(res.Logs) after := k.GetBalance(suite.ctx, suite.from) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 1c4b4b29e9..fdc04943c6 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -268,6 +268,9 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t // If hooks return error, revert the whole tx. res.VmError = types.ErrPostTxProcessing.Error() k.Logger(ctx).Error("tx post processing failed", "error", err) + + // If the tx failed in post processing hooks, we should clear the logs + res.Logs = nil } else if commit != nil { // PostTxProcessing is successful, commit the tmpCtx commit()