From 07a628cfc5ec4a756b2c9ed5b7985395dddf57d6 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 25 Aug 2025 09:54:14 +0800 Subject: [PATCH 1/3] chore: align balance change reason for tracing for more info, https://github.com/ethereum/go-ethereum/blob/v1.16.2/core/evm.go#L143 --- precompiles/common/balance_handler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/precompiles/common/balance_handler.go b/precompiles/common/balance_handler.go index 29292430a..ad015da1c 100644 --- a/precompiles/common/balance_handler.go +++ b/precompiles/common/balance_handler.go @@ -74,7 +74,7 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S return fmt.Errorf("failed to parse amount from event %q: %w", banktypes.EventTypeCoinSpent, err) } - stateDB.SubBalance(common.BytesToAddress(spenderAddr.Bytes()), amount, tracing.BalanceChangeUnspecified) + stateDB.SubBalance(common.BytesToAddress(spenderAddr.Bytes()), amount, tracing.BalanceChangeTransfer) case banktypes.EventTypeCoinReceived: receiverAddr, err := ParseAddress(event, banktypes.AttributeKeyReceiver) @@ -91,7 +91,7 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S return fmt.Errorf("failed to parse amount from event %q: %w", banktypes.EventTypeCoinReceived, err) } - stateDB.AddBalance(common.BytesToAddress(receiverAddr.Bytes()), amount, tracing.BalanceChangeUnspecified) + stateDB.AddBalance(common.BytesToAddress(receiverAddr.Bytes()), amount, tracing.BalanceChangeTransfer) case precisebanktypes.EventTypeFractionalBalanceChange: addr, err := ParseAddress(event, precisebanktypes.AttributeKeyAddress) @@ -114,9 +114,9 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S } if delta.Sign() == 1 { - stateDB.AddBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeUnspecified) + stateDB.AddBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeTransfer) } else if delta.Sign() == -1 { - stateDB.SubBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeUnspecified) + stateDB.SubBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeTransfer) } default: From dd447f577c5e905ff51ce518bfcdb9519d0e88d4 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 25 Aug 2025 09:55:20 +0800 Subject: [PATCH 2/3] cleanup deprecated BalanceChangeEntry for more info, https://github.com/cosmos/evm/pull/201/files --- precompiles/common/precompile.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/precompiles/common/precompile.go b/precompiles/common/precompile.go index a1fb80668..d64453da3 100644 --- a/precompiles/common/precompile.go +++ b/precompiles/common/precompile.go @@ -7,7 +7,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/vm" - "github.com/holiman/uint256" "github.com/cosmos/evm/x/vm/statedb" @@ -35,16 +34,6 @@ const ( Add ) -type BalanceChangeEntry struct { - Account common.Address - Amount *uint256.Int - Op Operation -} - -func NewBalanceChangeEntry(acc common.Address, amt *uint256.Int, op Operation) BalanceChangeEntry { - return BalanceChangeEntry{acc, amt, op} -} - // RequiredGas calculates the base minimum required gas for a transaction or a query. // It uses the method ID to determine if the input is a transaction or a query and // uses the Cosmos SDK gas config flat cost and the flat per byte cost * len(argBz) to calculate the gas. From 713c7901be6496f4d72eb1ab9b4be920c3046888 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 25 Aug 2025 12:14:57 +0800 Subject: [PATCH 3/3] Revert "chore: align balance change reason for tracing" This reverts commit 07a628cfc5ec4a756b2c9ed5b7985395dddf57d6. --- precompiles/common/balance_handler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/precompiles/common/balance_handler.go b/precompiles/common/balance_handler.go index ad015da1c..29292430a 100644 --- a/precompiles/common/balance_handler.go +++ b/precompiles/common/balance_handler.go @@ -74,7 +74,7 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S return fmt.Errorf("failed to parse amount from event %q: %w", banktypes.EventTypeCoinSpent, err) } - stateDB.SubBalance(common.BytesToAddress(spenderAddr.Bytes()), amount, tracing.BalanceChangeTransfer) + stateDB.SubBalance(common.BytesToAddress(spenderAddr.Bytes()), amount, tracing.BalanceChangeUnspecified) case banktypes.EventTypeCoinReceived: receiverAddr, err := ParseAddress(event, banktypes.AttributeKeyReceiver) @@ -91,7 +91,7 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S return fmt.Errorf("failed to parse amount from event %q: %w", banktypes.EventTypeCoinReceived, err) } - stateDB.AddBalance(common.BytesToAddress(receiverAddr.Bytes()), amount, tracing.BalanceChangeTransfer) + stateDB.AddBalance(common.BytesToAddress(receiverAddr.Bytes()), amount, tracing.BalanceChangeUnspecified) case precisebanktypes.EventTypeFractionalBalanceChange: addr, err := ParseAddress(event, precisebanktypes.AttributeKeyAddress) @@ -114,9 +114,9 @@ func (bh *BalanceHandler) AfterBalanceChange(ctx sdk.Context, stateDB *statedb.S } if delta.Sign() == 1 { - stateDB.AddBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeTransfer) + stateDB.AddBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeUnspecified) } else if delta.Sign() == -1 { - stateDB.SubBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeTransfer) + stateDB.SubBalance(common.BytesToAddress(addr.Bytes()), deltaAbs, tracing.BalanceChangeUnspecified) } default: