Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 2 additions & 39 deletions app/ante/evm_checktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,8 @@ func EvmCheckTxAnte(
}

func EvmStatelessChecks(ctx sdk.Context, tx sdk.Tx, chainID *big.Int) error {
txBody, ok := tx.(TxBody)
if ok {
body := txBody.GetBody()
if body.Memo != "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "memo must be empty for EVM txs")
}
if body.TimeoutHeight != 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "timeout_height must be zero for EVM txs")
}
if len(body.ExtensionOptions) > 0 || len(body.NonCriticalExtensionOptions) > 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "extension options must be empty for EVM txs")
}
}

txAuth, ok := tx.(TxAuthInfo)
if ok {
authInfo := txAuth.GetAuthInfo()
if len(authInfo.SignerInfos) > 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "signer_infos must be empty for EVM txs")
}
if authInfo.Fee != nil {
if len(authInfo.Fee.Amount) > 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee amount must be empty for EVM txs")
}
if authInfo.Fee.Payer != "" || authInfo.Fee.Granter != "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee payer and granter must be empty for EVM txs")
}
}
}

txSig, ok := tx.(TxSignaturesV2)
if ok {
sigs, err := txSig.GetSignaturesV2()
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "could not get signatures")
}
if len(sigs) > 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "signatures must be empty for EVM txs")
}
if err := evmante.ValidateNoCosmosTxFields(tx); err != nil {
return err
}

if len(tx.GetMsgs()) != 1 {
Expand Down
13 changes: 13 additions & 0 deletions giga/deps/xevm/types/ethtx/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ func (tx AccessListTx) Validate() error {
}
}

if err := validateAccessList(tx.Accesses); err != nil {
return err
}
if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}

chainID := tx.GetChainID()

if chainID == nil {
Expand Down
13 changes: 12 additions & 1 deletion giga/deps/xevm/types/ethtx/associate_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ func (tx *AssociateTx) GetRawSignatureValues() (v, r, s *big.Int) {
func (tx *AssociateTx) SetSignatureValues(_, _, _, _ *big.Int) { panic("not implemented") }

func (tx *AssociateTx) AsEthereumData() ethtypes.TxData { panic("not implemented") }
func (tx *AssociateTx) Validate() error { panic("not implemented") }
func (tx *AssociateTx) Validate() error {
if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}
return nil
}

func (tx *AssociateTx) Fee() *big.Int { panic("not implemented") }
func (tx *AssociateTx) Cost() *big.Int { panic("not implemented") }
Expand Down
13 changes: 13 additions & 0 deletions giga/deps/xevm/types/ethtx/blob_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ func (tx BlobTx) Validate() error {
}
}

if err := validateAccessList(tx.Accesses); err != nil {
return err
}
if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}

chainID := tx.GetChainID()

if chainID == nil {
Expand Down
13 changes: 13 additions & 0 deletions giga/deps/xevm/types/ethtx/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ func (tx DynamicFeeTx) Validate() error {
}
}

if err := validateAccessList(tx.Accesses); err != nil {
return err
}
if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}

chainID := tx.GetChainID()

if chainID == nil {
Expand Down
10 changes: 10 additions & 0 deletions giga/deps/xevm/types/ethtx/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ func (tx *LegacyTx) Validate() error {
}
}

if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}

chainID := tx.GetChainID()

if chainID == nil {
Expand Down
79 changes: 79 additions & 0 deletions giga/deps/xevm/types/ethtx/semantic_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ethtx

import (
"encoding/hex"
"fmt"

"github.com/ethereum/go-ethereum/common"
)

func validateHexAddress(fieldName, value string) error {
if len(value) >= 2 && value[0] == '0' && (value[1] == 'x' || value[1] == 'X') {
value = value[2:]
}
if len(value) != common.AddressLength*2 {
return fmt.Errorf("invalid %s: wrong length", fieldName)
}
if _, err := hex.DecodeString(value); err != nil {
return fmt.Errorf("invalid %s", fieldName)
}
return nil
}

func validateHexHash(fieldName, value string) error {
if len(value) >= 2 && value[0] == '0' && (value[1] == 'x' || value[1] == 'X') {
value = value[2:]
}
if len(value) != common.HashLength*2 {
return fmt.Errorf("invalid %s: wrong length", fieldName)
}
if _, err := hex.DecodeString(value); err != nil {
return fmt.Errorf("invalid %s", fieldName)
}
return nil
}

func validateAccessList(accessList AccessList) error {
for _, tuple := range accessList {
if err := validateHexAddress("access list address", tuple.Address); err != nil {
return err
}
for _, storageKey := range tuple.StorageKeys {
if err := validateHexHash("access list storage key", storageKey); err != nil {
return err
}
}
}
return nil
}

func validateAuthList(authList AuthList) error {
for _, auth := range authList {
if auth.ChainID == nil {
return fmt.Errorf("auth list chain id cannot be nil")
}
if err := validateHexAddress("auth list address", auth.Address); err != nil {
return err
}
if err := validateSignatureValue("auth list v", auth.V, 1); err != nil {
return err
}
if err := validateSignatureValue("auth list r", auth.R, 32); err != nil {
return err
}
if err := validateSignatureValue("auth list s", auth.S, 32); err != nil {
return err
}
}
return nil
}

func validateSignatureValue(fieldName string, value []byte, maxLen int) error {
if len(value) > maxLen {
return fmt.Errorf("invalid %s: too long", fieldName)
}
if len(value) > 1 && value[0] == 0 {
return fmt.Errorf("invalid %s: leading zero", fieldName)
}
return nil
}
16 changes: 16 additions & 0 deletions giga/deps/xevm/types/ethtx/set_code_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ func (tx SetCodeTx) Validate() error {
}
}

if err := validateAccessList(tx.Accesses); err != nil {
return err
}
if err := validateAuthList(tx.AuthList); err != nil {
return err
}
if err := validateSignatureValue("v", tx.V, 32); err != nil {
return err
}
if err := validateSignatureValue("r", tx.R, 32); err != nil {
return err
}
if err := validateSignatureValue("s", tx.S, 32); err != nil {
return err
}

chainID := tx.GetChainID()

if chainID == nil {
Expand Down
19 changes: 17 additions & 2 deletions giga/deps/xevm/types/message_evm_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,24 @@ func (msg *MsgEVMTransaction) GetSignBytes() []byte {
}

func (msg *MsgEVMTransaction) ValidateBasic() error {
if msg.Derived != nil && msg.Derived.PubKey == nil {
return sdkerrors.ErrInvalidPubKey
}
txData, err := UnpackTxData(msg.Data)
if err != nil {
return err
}
if _, ok := txData.(*ethtx.AssociateTx); !ok {
if err := txData.Validate(); err != nil {
return err
}
}
amsg, isAssociate := msg.GetAssociateTx()
if isAssociate && len(amsg.CustomMessage) > MaxAssociateCustomMessageLength {
return sdkerrors.Wrapf(sdkerrors.ErrTxTooLarge, "custom message can have at most 64 characters")
if isAssociate {
if len(amsg.CustomMessage) > MaxAssociateCustomMessageLength {
return sdkerrors.Wrapf(sdkerrors.ErrTxTooLarge, "custom message can have at most 64 characters")
}
return amsg.Validate()
}
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions giga/tests/giga_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func CreateEVMTransferTxs(t testing.TB, tCtx *GigaTestContext, transfers []EVMTr
err = txBuilder.SetMsgs(msg)
require.NoError(t, err)
txBuilder.SetGasLimit(10000000000)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000000))))

txBytes, err := tc.TxEncoder()(txBuilder.GetTx())
require.NoError(t, err)
Expand Down Expand Up @@ -666,7 +665,6 @@ func CreateContractDeployTxs(t testing.TB, tCtx *GigaTestContext, deploys []EVMC
err = txBuilder.SetMsgs(msg)
require.NoError(t, err)
txBuilder.SetGasLimit(10000000000)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000000))))

txBytes, err := tc.TxEncoder()(txBuilder.GetTx())
require.NoError(t, err)
Expand Down Expand Up @@ -727,7 +725,6 @@ func CreateContractCallTxs(t testing.TB, tCtx *GigaTestContext, calls []EVMContr
err = txBuilder.SetMsgs(msg)
require.NoError(t, err)
txBuilder.SetGasLimit(10000000000)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000000))))

txBytes, err := tc.TxEncoder()(txBuilder.GetTx())
require.NoError(t, err)
Expand Down Expand Up @@ -1733,7 +1730,6 @@ func createCustomEVMTx(
err = txBuilder.SetMsgs(msg)
require.NoError(t, err)
txBuilder.SetGasLimit(10000000000)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000000))))

txBytes, err := tc.TxEncoder()(txBuilder.GetTx())
require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions giga/tests/harness/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/sei-protocol/sei-chain/app"
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
"github.com/sei-protocol/sei-chain/x/evm/config"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
Expand Down Expand Up @@ -153,7 +152,6 @@ func EncodeTxForApp(signedTx *ethtypes.Transaction) ([]byte, error) {
return nil, err
}
txBuilder.SetGasLimit(10000000000)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000000))))

txBytes, err := tc.TxEncoder()(txBuilder.GetTx())
if err != nil {
Expand Down
39 changes: 27 additions & 12 deletions occ_tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/sei-protocol/sei-chain/sei-cosmos/baseapp"
"github.com/sei-protocol/sei-chain/sei-cosmos/client"
clienttx "github.com/sei-protocol/sei-chain/sei-cosmos/client/tx"
codectypes "github.com/sei-protocol/sei-chain/sei-cosmos/codec/types"
cryptotypes "github.com/sei-protocol/sei-chain/sei-cosmos/crypto/types"
Expand Down Expand Up @@ -228,19 +229,33 @@ func toTxBytes(testCtx *TestContext, msgs []*TestMessage) [][]byte {
panic(err)
}

tBuilder := tx.WrapTx(&txtype.Tx{
Body: &txtype.TxBody{
Messages: []*codectypes.Any{a},
},
AuthInfo: &txtype.AuthInfo{
Fee: &txtype.Fee{
Amount: Funds(10000000000),
GasLimit: 10000000000,
Payer: testCtx.TestAccounts[0].AccountAddress.String(),
Granter: testCtx.TestAccounts[0].AccountAddress.String(),
var tBuilder client.TxBuilder
if tm.IsEVM {
tBuilder = tx.WrapTx(&txtype.Tx{
Body: &txtype.TxBody{
Messages: []*codectypes.Any{a},
},
},
})
AuthInfo: &txtype.AuthInfo{
Fee: &txtype.Fee{
GasLimit: 10000000000,
},
},
})
} else {
tBuilder = tx.WrapTx(&txtype.Tx{
Body: &txtype.TxBody{
Messages: []*codectypes.Any{a},
},
AuthInfo: &txtype.AuthInfo{
Fee: &txtype.Fee{
Amount: Funds(10000000000),
GasLimit: 10000000000,
Payer: testCtx.TestAccounts[0].AccountAddress.String(),
Granter: testCtx.TestAccounts[0].AccountAddress.String(),
},
},
})
}

if tm.IsEVM {
amounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(1000000000000000000)), sdk.NewCoin("uusdc", sdk.NewInt(1000000000000000)))
Expand Down
Loading
Loading