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

fix: return proper synthetic tx in eth_getBlockByNumber RPC #3634

Merged
merged 5 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions precompiles/bank/method_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bank

import (
"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"
"math/big"
"testing"

"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"

sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

Expand Down Expand Up @@ -121,7 +122,7 @@ func Test_Methods(t *testing.T) {
t.Run("should fail when bank has 0 token allowance", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)

methodID := ts.bankABI.Methods[DepositMethodName]

Expand Down Expand Up @@ -151,7 +152,7 @@ func Test_Methods(t *testing.T) {
t.Run("should fail when trying to deposit 0", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)

methodID := ts.bankABI.Methods[DepositMethodName]

Expand All @@ -178,7 +179,7 @@ func Test_Methods(t *testing.T) {
t.Run("should fail when trying to deposit more than allowed to bank", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)

// Allow bank to spend 500 ZRC20 tokens.
allowBank(t, ts, big.NewInt(500))
Expand Down Expand Up @@ -230,7 +231,7 @@ func Test_Methods(t *testing.T) {
t.Run("should fail when trying to deposit more than user balance", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)

// Allow bank to spend 500 ZRC20 tokens.
allowBank(t, ts, big.NewInt(1000))
Expand Down Expand Up @@ -284,7 +285,7 @@ func Test_Methods(t *testing.T) {
t.Run("should deposit tokens and retrieve balance of cosmos coin", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)
methodID := ts.bankABI.Methods[DepositMethodName]

// Allow bank to spend 500 ZRC20 tokens.
Expand Down Expand Up @@ -330,7 +331,7 @@ func Test_Methods(t *testing.T) {
t.Run("should deposit tokens, withdraw and check with balanceOf", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)
methodID := ts.bankABI.Methods[DepositMethodName]

// Allow bank to spend 500 ZRC20 tokens.
Expand Down Expand Up @@ -409,7 +410,7 @@ func Test_Methods(t *testing.T) {
t.Run("should deposit tokens and fail when withdrawing more than depositted", func(t *testing.T) {
ts := setupChain(t)
caller := fungibletypes.ModuleAddressEVM
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000))
ts.fungibleKeeper.DepositZRC20(ts.ctx, ts.zrc20Address, caller, big.NewInt(1000), false)
methodID := ts.bankABI.Methods[DepositMethodName]

// Allow bank to spend 500 ZRC20 tokens.
Expand Down
10 changes: 5 additions & 5 deletions precompiles/staking/method_distribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Test_Distribute(t *testing.T) {
zrc20Denom := precompiletypes.ZRC20ToCosmosDenom(s.zrc20Address)

// Set caller balance.
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000))
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000), false)
require.NoError(t, err)

// Setup method input.
Expand Down Expand Up @@ -136,7 +136,7 @@ func Test_Distribute(t *testing.T) {
zrc20Denom := precompiletypes.ZRC20ToCosmosDenom(s.zrc20Address)

// Set caller balance.
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000))
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000), false)
require.NoError(t, err)

// Allow staking to spend ZRC20 tokens.
Expand Down Expand Up @@ -179,7 +179,7 @@ func Test_Distribute(t *testing.T) {
zrc20Denom := precompiletypes.ZRC20ToCosmosDenom(s.zrc20Address)

// Set caller balance.
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000))
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000), false)
require.NoError(t, err)

// Allow staking to spend ZRC20 tokens.
Expand Down Expand Up @@ -222,7 +222,7 @@ func Test_Distribute(t *testing.T) {
zrc20Denom := precompiletypes.ZRC20ToCosmosDenom(s.zrc20Address)

// Set caller balance.
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000))
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000), false)
require.NoError(t, err)

// Allow staking to spend ZRC20 tokens.
Expand Down Expand Up @@ -263,7 +263,7 @@ func Test_Distribute(t *testing.T) {
distributeMethod := s.stkContractABI.Methods[DistributeMethodName]

// Set caller balance.
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000))
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, big.NewInt(1000), false)
require.NoError(t, err)

// Allow staking to spend ZRC20 tokens.
Expand Down
5 changes: 3 additions & 2 deletions precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package staking

import (
"encoding/json"
"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"
"testing"

"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"

"math/big"

"cosmossdk.io/log"
Expand Down Expand Up @@ -442,7 +443,7 @@ func distributeZRC20(
) {
distributeMethod := s.stkContractABI.Methods[DistributeMethodName]

_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, amount)
_, err := s.fungibleKeeper.DepositZRC20(s.ctx, s.zrc20Address, s.defaultCaller, amount, false)
require.NoError(t, err)
allowStaking(t, s, amount)

Expand Down
2 changes: 1 addition & 1 deletion rpc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func ParseTxBlockResult(
if len(txs.Txs) == 0 {
return nil, nil, nil
}
parsedTx := txs.Txs[0]
parsedTx := txs.Txs[len(txs.Txs)-1]
if parsedTx.Type == CosmosEVMTxType {
return &ethermint.TxResult{
Height: height,
Expand Down
18 changes: 9 additions & 9 deletions testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/crosschain/keeper/abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (k Keeper) LegacyRefundAbortedAmountOnZetaChainGas(
return errorsmod.Wrapf(types.ErrForeignCoinNotFound, "zrc20 contract address not found for chain %d", chainID)
}
// deposit the amount to the tx origin instead of receiver as this is a refund
if _, err := k.fungibleKeeper.DepositZRC20(ctx, zrc20, refundAddress, refundAmount.BigInt()); err != nil {
if _, err := k.fungibleKeeper.DepositZRC20(ctx, zrc20, refundAddress, refundAmount.BigInt(), false); err != nil {
return errors.New("failed to refund zeta on ZetaChain" + err.Error())
}
return nil
Expand Down Expand Up @@ -221,7 +221,7 @@ func (k Keeper) LegacyRefundAbortedAmountOnZetaChainERC20(
}

// deposit the amount to the sender
if _, err := k.fungibleKeeper.DepositZRC20(ctx, zrc20, refundAddress, refundAmount.BigInt()); err != nil {
if _, err := k.fungibleKeeper.DepositZRC20(ctx, zrc20, refundAddress, refundAmount.BigInt(), false); err != nil {
return errors.New("failed to deposit zrc20 on ZetaChain" + err.Error())
}

Expand Down
11 changes: 1 addition & 10 deletions x/crosschain/keeper/cctx_gateway_observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/zeta-chain/node/pkg/chains"
cctxerror "github.com/zeta-chain/node/pkg/errors"
"github.com/zeta-chain/node/x/crosschain/types"
)
Expand Down Expand Up @@ -40,14 +39,6 @@ func (c CCTXGatewayObservers) InitiateOutbound(
) (newCCTXStatus types.CctxStatus, err error) {
tmpCtx, commit := ctx.CacheContext()
outboundReceiverChainID := config.CCTX.GetCurrentOutboundParam().ReceiverChainId
// TODO (https://github.com/zeta-chain/node/issues/1010): workaround for this bug
noEthereumTxEvent := false
if chains.IsZetaChain(
config.CCTX.InboundParams.SenderChainId,
c.crosschainKeeper.GetAuthorityKeeper().GetAdditionalChainList(ctx),
) {
noEthereumTxEvent = true
}

err = func() error {
// If ShouldPayGas flag is set during ValidateInbound PayGasAndUpdateCctx should be called
Expand All @@ -58,7 +49,7 @@ func (c CCTXGatewayObservers) InitiateOutbound(
outboundReceiverChainID,
config.CCTX,
config.CCTX.InboundParams.Amount,
noEthereumTxEvent,
true,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_orchestrator_validate_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (k Keeper) processFailedOutboundOnExternalChain(
cctx.InboundParams.SenderChainId,
cctx,
inputAmount,
false,
true,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/gas_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k Keeper) PayGasInERC20AndUpdateCctx(
newAmount := inputAmount.Sub(sdkmath.NewUintFromBigInt(feeInZRC20))

// mint the amount of ERC20 to be burnt as gas fee
_, err = k.fungibleKeeper.DepositZRC20(ctx, zrc20, types.ModuleAddressEVM, feeInZRC20)
_, err = k.fungibleKeeper.DepositZRC20(ctx, zrc20, types.ModuleAddressEVM, feeInZRC20, noEthereumTxEvent)
if err != nil {
return cosmoserrors.Wrap(fungibletypes.ErrContractCall, err.Error())
}
Expand Down
5 changes: 3 additions & 2 deletions x/crosschain/keeper/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
package keeper_test

import (
"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"
"math/big"
"testing"

"github.com/zeta-chain/node/e2e/contracts/erc1967proxy"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -220,7 +221,7 @@ func setupZRC20Pool(
liquidityAmount := big.NewInt(1e17)

// mint some zrc20 and zeta
_, err = k.DepositZRC20(ctx, zrc20Addr, types.ModuleAddressEVM, liquidityAmount)
_, err = k.DepositZRC20(ctx, zrc20Addr, types.ModuleAddressEVM, liquidityAmount, false)
require.NoError(t, err)
err = bankKeeper.MintCoins(
ctx,
Expand Down
1 change: 1 addition & 0 deletions x/crosschain/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type FungibleKeeper interface {
contract ethcommon.Address,
to ethcommon.Address,
amount *big.Int,
noEthereumTxEvent bool,
) (*evmtypes.MsgEthereumTxResponse, error)
ZRC20DepositAndCallContract(
ctx sdk.Context,
Expand Down
8 changes: 4 additions & 4 deletions x/fungible/keeper/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (k Keeper) ZRC20DepositAndCallContract(
return nil, false, types.ErrCallNonContract
}

res, err := k.DepositZRC20(ctx, zrc20Contract, to, amount)
res, err := k.DepositZRC20(ctx, zrc20Contract, to, amount, false)
return res, false, err
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func (k Keeper) ProcessDeposit(
}

// simple deposit
res, err := k.DepositZRC20(ctx, zrc20Addr, to, amount)
res, err := k.DepositZRC20(ctx, zrc20Addr, to, amount, false)
return res, false, err
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func (k Keeper) ProcessRevert(
return res, err
} else {
// simply deposit back to the revert address
res, err := k.DepositZRC20(ctx, zrc20Addr, revertAddress, amount)
res, err := k.DepositZRC20(ctx, zrc20Addr, revertAddress, amount, false)
return res, err
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func (k Keeper) ProcessAbort(
// simply deposit back to the revert address
// if the deposit fails, processing the abort entirely fails
// MsgRefundAbort can still be used to retry the operation later on
if _, err := k.DepositZRC20(ctx, zrc20Addr, abortAddress, amount); err != nil {
if _, err := k.DepositZRC20(ctx, zrc20Addr, abortAddress, amount, false); err != nil {
return nil, err
}
}
Expand Down
9 changes: 5 additions & 4 deletions x/fungible/keeper/deposits_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper_test

import (
"math/big"
"testing"

"cosmossdk.io/math"
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
Expand All @@ -9,8 +12,6 @@ import (
"github.com/zeta-chain/node/e2e/contracts/reverter"
"github.com/zeta-chain/node/e2e/contracts/testdappv2"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
"math/big"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) {
k.SetForeignCoins(ctx, foreignCoin)

// increase total supply
_, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500))
_, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500), false)
require.NoError(t, err)

// deposit
Expand Down Expand Up @@ -327,7 +328,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) {
k.SetForeignCoins(ctx, foreignCoin)

// increase total supply
_, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500))
_, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500), false)
require.NoError(t, err)

// deposit (500 + 501 > 1000)
Expand Down
3 changes: 2 additions & 1 deletion x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (k Keeper) DepositZRC20(
contract common.Address,
to common.Address,
amount *big.Int,
noEthereumTxEvent bool,
) (*evmtypes.MsgEthereumTxResponse, error) {
zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
Expand All @@ -261,7 +262,7 @@ func (k Keeper) DepositZRC20(
BigIntZero,
DefaultGasLimit,
true,
false,
noEthereumTxEvent,
"deposit",
to,
amount,
Expand Down
4 changes: 2 additions & 2 deletions x/fungible/keeper/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestKeeper_DeployZRC20Contract(t *testing.T) {
require.Equal(t, int64(0), oldBalance.Int64())

amount := big.NewInt(100)
_, err = k.DepositZRC20(ctx, addr, to, amount)
_, err = k.DepositZRC20(ctx, addr, to, amount, false)
require.NoError(t, err)

newBalance, err := k.BalanceOfZRC4(ctx, addr, to)
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestKeeper_DeployZRC20Contract(t *testing.T) {
require.Equal(t, int64(0), oldBalance.Int64())

amount := big.NewInt(100)
_, err = k.DepositZRC20(ctx, addr, to, amount)
_, err = k.DepositZRC20(ctx, addr, to, amount, false)
require.NoError(t, err)

newBalance, err := k.BalanceOfZRC4(ctx, addr, to)
Expand Down
Loading
Loading