Skip to content

Commit

Permalink
fix some error
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Nov 8, 2024
1 parent a4fd1ab commit 4a1db24
Show file tree
Hide file tree
Showing 95 changed files with 1,519 additions and 1,351 deletions.
13 changes: 5 additions & 8 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"fmt"
"runtime/debug"

tmlog "github.com/cometbft/cometbft/libs/log"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -60,9 +60,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = newEthAnteHandler(options)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// Deprecated: Handle as normal Cosmos SDK tx, except signature is checked for Legacy EIP712 representation
anteHandler = NewLegacyCosmosAnteHandlerEip712(options)
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = newCosmosAnteHandler(options)
Expand All @@ -89,7 +86,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}, nil
}

func Recover(logger tmlog.Logger, err *error) {
func Recover(logger log.Logger, err *error) {
if r := recover(); r != nil {
*err = errorsmod.Wrapf(errortypes.ErrPanic, "%v", r)

Expand All @@ -114,7 +111,7 @@ var _ authante.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsu
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
// by the concrete type.
func DefaultSigVerificationGasConsumer(
meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params,
meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
) error {
pubkey := sig.PubKey
switch pubkey := pubkey.(type) {
Expand All @@ -137,7 +134,7 @@ func DefaultSigVerificationGasConsumer(

// ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature
func ConsumeMultisignatureVerificationGas(
meter sdk.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
meter storetypes.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
params authtypes.Params, accSeq uint64,
) error {
size := sig.BitArray.Count()
Expand Down
72 changes: 35 additions & 37 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ import (
"testing"
"time"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/stretchr/testify/suite"

storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/suite"

"github.com/ethereum/go-ethereum/core/types"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

func TestAnteTestSuite(t *testing.T) {
Expand Down Expand Up @@ -363,7 +361,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 create validator",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -374,7 +372,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 create validator (with blank fields)",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgCreateValidator2(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -385,7 +383,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 MsgSubmitProposal",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
// reusing the gasAmount for deposit
Expand All @@ -399,7 +397,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
func() sdk.Tx {
from := acc.GetAddress()
grantee := sdk.AccAddress("_______grantee______")
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC)
Expand All @@ -416,7 +414,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 MsgGrantAllowance",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
gasAmount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712GrantAllowance(from, privKey, "ethermint_9000-1", gas, gasAmount)
Expand All @@ -427,7 +425,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
// "success- DeliverTx EIP712 edit validator",
// func() sdk.Tx {
// from := acc.GetAddress()
// coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
// coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
// amount := sdk.NewCoins(coinAmount)
// gas := uint64(200000)
// txBuilder := suite.CreateTestEIP712MsgEditValidator(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -438,7 +436,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 submit evidence",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgSubmitEvidence(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -449,7 +447,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 submit proposal v1",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712SubmitProposalV1(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -460,7 +458,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 MsgExec",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgExec(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -471,7 +469,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 MsgVoteV1",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MsgVoteV1(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -482,7 +480,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"success- DeliverTx EIP712 Multiple MsgSend",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MultipleMsgSend(from, privKey, "ethermint_9000-1", gas, amount)
Expand All @@ -493,7 +491,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"fails - DeliverTx EIP712 Multiple Signers",
func() sdk.Tx {
from := acc.GetAddress()
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
amount := sdk.NewCoins(coinAmount)
gas := uint64(200000)
txBuilder := suite.CreateTestEIP712MultipleSignerMsgs(from, privKey, "ethermint_9000-1", gas, amount)
Expand Down Expand Up @@ -604,7 +602,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -634,7 +632,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -664,7 +662,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -719,7 +717,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -749,7 +747,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -779,7 +777,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -809,7 +807,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand All @@ -823,7 +821,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
"EIP-712",
)

msg.Amount[0].Amount = sdk.NewInt(5)
msg.Amount[0].Amount = math.NewInt(5)
txBuilder.SetMsgs(msg)

return txBuilder.GetTx()
Expand All @@ -842,7 +840,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -871,7 +869,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
math.NewInt(1),
),
),
)
Expand Down Expand Up @@ -1368,7 +1366,7 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
}

type args struct {
meter sdk.GasMeter
meter storetypes.GasMeter
sig signing.SignatureData
pubkey cryptotypes.PubKey
params authtypes.Params
Expand All @@ -1379,11 +1377,11 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
gasConsumed uint64
shouldErr bool
}{
{"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true},
{"PubKeyEthSecp256k1", args{sdk.NewInfiniteGasMeter(), nil, pkSet1[0], params}, 21_000, false},
{"PubKeySecp256r1", args{sdk.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), false},
{"Multisig", args{sdk.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false},
{"unknown key", args{sdk.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
{"PubKeyEd25519", args{storetypes.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true},
{"PubKeyEthSecp256k1", args{storetypes.NewInfiniteGasMeter(), nil, pkSet1[0], params}, 21_000, false},
{"PubKeySecp256r1", args{storetypes.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), false},
{"Multisig", args{storetypes.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false},
{"unknown key", args{storetypes.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
}
for _, tt := range tests {
sigV2 := signing.SignatureV2{
Expand Down
25 changes: 18 additions & 7 deletions app/ante/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"
"time"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -341,20 +342,30 @@ func (suite *AnteTestSuite) TestRejectDeliverMsgsInAuthz() {
bz, err := txEncoder(tx)
suite.Require().NoError(err)

resCheckTx := suite.app.CheckTx(
abci.RequestCheckTx{
resCheckTx,err := suite.app.CheckTx(
&abci.RequestCheckTx{
Tx: bz,
Type: abci.CheckTxType_New,
},
)
suite.Require().NoError(err)
suite.Require().Equal(resCheckTx.Code, tc.expectedCode, resCheckTx.Log)

resDeliverTx := suite.app.DeliverTx(
abci.RequestDeliverTx{
Tx: bz,
header := suite.ctx.BlockHeader()
blockRes, err := suite.app.FinalizeBlock(
&abci.RequestFinalizeBlock{
Height: suite.ctx.BlockHeight() + 1,
Txs: [][]byte{bz},
Hash: header.AppHash,
NextValidatorsHash: header.NextValidatorsHash,
ProposerAddress: header.ProposerAddress,
Time: header.Time.Add(time.Second),
},
)
suite.Require().Equal(resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log)
suite.Require().NoError(err)
suite.Require().Len(blockRes.TxResults, 1)
txRes := blockRes.TxResults[0]
suite.Require().Equal(txRes.Code, tc.expectedCode, txRes.Log)
})
}
}
Expand Down Expand Up @@ -439,7 +450,7 @@ func (suite *AnteTestSuite) createTx(priv cryptotypes.PrivKey, msgs ...sdk.Msg)
}

func (suite *AnteTestSuite) createEIP712Tx(priv cryptotypes.PrivKey, msgs ...sdk.Msg) (sdk.Tx, error) {
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, math.NewInt(20))
fees := sdk.NewCoins(coinAmount)
cosmosTxArgs := utiltx.CosmosTxArgs{
TxCfg: suite.clientCtx.TxConfig,
Expand Down
Loading

0 comments on commit 4a1db24

Please sign in to comment.