Injective | Documentation
InjectiveGithub
Injective | Documentation
Injective | Documentation
  • About Injective
  • DeFi
    • Wallet
      • Create a wallet
      • Accounts
    • Trading
      • Order Types
      • Trading Fees and Rebates
      • Margin Trading
      • Liquidation
      • Funding Rates
      • Performing Liquidations
      • Derivatives
      • Perpetuals
      • Expiry Futures
      • Pre-Launch Futures
      • Index Perpetual Futures
      • iAssets
    • Token Standards
      • INJ coin
      • Token Factory
      • CW20 Standard
    • Bridge
      • From Ethereum
      • From Solana
      • Using Wormhole
      • Using IBC
    • Staking
    • Governance
    • Auction
    • Transactions
    • Transaction Gas and Fees
    • Open Liquidity Program
      • Introduction
      • Rewards
      • Epochs
      • Eligibility
      • Program Details
      • Scoring Formula/Methodology
      • Formula Parameters
      • Reward Allocations
      • Flexible Reward Allocations
      • Eligible Markets
      • Legacy Reward Allocations
      • Reward Disbursements
      • Performance Tracking
      • Volatility Response Modifications
      • Fee Tiers
    • Injective Hub
    • Injective Explorer
  • Infrastructure
    • Command Line Node Interaction
    • gRPC Node Interaction
    • Go Node Interaction
    • REST Node Interaction
    • Run Node
    • Set up Keyring
    • Join Network
    • Cosmovisor
    • Upgrade Node
    • Mainnet Validator
      • Peggo
      • Canonical Chain Upgrades
      • v1.16.2
      • v1.16.1
      • v1.16.0
      • v1.15.0
      • v1.14.1
      • v1.14.0
      • v1.13.3
      • v1.13.2
      • v1.13.0 - Altaris
      • v1.12.1
      • v1.12.0 - Volan
      • v1.11.0
      • v1.10.0
      • 10009
      • 10008 - Camelot
      • 10007-rc1
      • 10006-rc1
      • 10005-rc1
      • 10004-rc1-patch
      • 10004-rc1
      • 10003-rc1
      • 10002-rc2
      • 10002-rc1
    • Testnet Validator
      • Peggo
    • Public Endpoints
    • Premium Endpoints
    • Archival Setup
    • Indexer API Reference
  • Developers
    • Convert addresses
    • Network Information
    • injectived
      • Install injectived
      • Using injectived
      • injectived Commands
      • Testnet Proposals
    • Concepts
      • Sentry Node
      • Indexer API
      • Trading Account
      • gRPC and Protobuf
      • Token Factory
      • Market min price tick size calculation
      • Market min quantity tick size calculation
      • CosmJs Support
      • Networks
    • Assets
      • Denom
      • Token Metadata
      • Injective List
      • Creating Tokens
    • dApps
      • Nuxt configuration
      • React configuration
      • Running examples
      • Smart contract examples
      • DEX examples
      • Webpack examples
    • Testnet Faucet
    • Chain API Reference
    • Injective TypeScript SDK
    • Injective Go SDK
    • Injective Python SDK
    • Injective CosmWasm SDK
    • Injective Rust SDK
    • The Graph
  • EVM Developers
    • EVM Network Information
    • Your First EVM Smart Contract
      • Compile with Hardhat
      • Test with Hardhat
      • Deploy with Hardhat
      • Verify with Hardhat
      • Interact with Hardhat
      • Compile with Foundry
      • Test with Foundry
      • Deploy with Foundry
      • Verify with Foundry
      • Interact with Foundry
    • Your First EVM dApp
      • Connect with MetaMask
      • Connect with WalletConnect
    • EVM Equivalence
    • MultiVM Token Standard
    • Precompiles
    • Bank Precompile
    • Exchange Precompile
    • ERC20 Module
    • Infrastructure & Tooling
    • EVM Testnet Faucet
    • EVM Testnet Explorer
  • Cosmwasm Developers
    • CosmWasm Smart Contracts
      • Your First CosmWasm Smart Contract
      • Injective Name Service
      • NeptuneService
      • CW20 to Bank & Market Order in One Transaction
    • Local Development Guide
    • Mainnet Deployment Guide
    • Whitelisting Deployment Address Guide
    • Create your Swap Contract Guide
    • Creating UIs Guide
    • Using Injective Queries and Messages
    • CW20 Adapter
    • Injective Test Tube
  • DeFi Developers
    • Min Price Tick Size Calculation
    • Min Quantity Tick Size Calculation
    • Testnet Faucet Integration
    • Launch a Token
    • Launch a Market
    • Denom Metadata
    • Provider Oracle
    • Build a DEX
    • Exchange API Reference
  • Native Developers
    • Wallets
      • Accounts
      • Connections
      • Strategy
      • Offchain Data
    • Bridges
      • Ethereum Bridge
    • Transactions
      • Cosmos Transaction
      • Ledger through Keplr Wallet Transaction
      • Ethereum Transaction
      • Ledger through Keplr Wallet Transaction
      • MsgBroadcaster Transaction
      • Private Key Transaction
      • Web3 Gateway Transaction
    • Transaction Examples
      • Auction
      • AuthZ
      • Bank
      • Distribution
      • Exchange
      • Fee Grant
      • Governance
      • IBC
      • Insurance
      • Peggy
      • Permissions
      • Staking
      • Token Factory
      • Wasm
    • Querying the Chain
      • Auction
      • Auth
      • Bank
      • Distribution
      • Exchange
      • Governance
      • IBC
      • Mint
      • Insurance Fund
      • Oracle
      • Peggy
      • Permissions
      • Staking
      • Tendermint
      • Wasm
      • WasmX
      • Token Factory
    • Querying the Indexer
      • Account
      • Auction
      • Derivatives
      • Explorer
      • Insurance Funds
      • Markets
      • Leaderboard
      • Mito
      • Oracle
      • Portfolio
      • Spot
      • Web3 Gateway Transactions
    • Streaming the Indexer
      • Account
      • Auction
      • Derivatives
      • Oracle
      • Portfolio
      • Spot
      • Explorer
    • Querying Ethereum with GraphQL
    • Injective Modules
      • Auction
        • State
        • Messages
        • EndBlock
        • Events
        • Params
        • Errors
      • Exchange
        • Derivative Markets Concepts
        • Spot Markets Concepts
        • Binary Option Markets Concepts
        • Other Concepts
        • State
        • State Transitions
        • Messages
        • Proposals
        • BeginBlock
        • EndBlock
        • Events
        • Params
        • MsgPrivilegedExecuteContract
        • Errors
      • ERC20
        • Concepts
        • State
        • Messages
        • Events
      • EVM
        • Concepts
        • State
        • State Transitions
        • Transactions
        • ABCI
        • Hooks
        • Events
        • Params
        • Client
      • Insurance
        • State
        • State Transitions
        • Messages
        • EndBlock
        • Events
        • Params
        • Improvements
        • Errors
      • OCR
        • Concepts
        • State
        • Messages
        • Proposals
        • BeginBlock
        • Hooks
        • Events
        • Params
        • Errors
      • Oracle
        • State
        • Keeper
        • Messages
        • Proposals
        • Events
        • Improvements
        • Errors
      • Peggy
        • Definitions
        • Workflow
        • State
        • Messages
        • Slashing
        • EndBlock
        • Events
        • Params
        • Relay Semantics
        • Improvements
        • Errors
      • Permissions
        • Concepts
        • State
        • State Transition
        • Errors
      • TokenFactory
        • Concepts
        • State
        • Messages
        • Events
        • Params
        • Errors
      • WasmX
        • Concepts
        • Data
        • Proposals
        • Messages
        • Params
        • Errors
      • Lanes
      • TxFees
    • Core Modules
      • Auth
      • AuthZ
      • Bank
      • Consensus
      • Crisis
      • Distribution
      • Evidence
      • Feegrant
      • Gov
      • Group
      • Mint
      • NFT
      • Params
      • Slashing
      • Staking
      • Upgrade
      • Circuit
      • Genutil
  • FAQ
  • Glossary
  • References
Powered by GitBook
On this page
Edit on GitHub
Export as PDF
  1. Native Developers
  2. Injective Modules
  3. EVM

State Transitions

PreviousStateNextTransactions

Last updated 1 minute ago

CtrlK
  • Client-Side
  • Server-Side
  • AnteHandler
  • EVM module

The x/evm module allows for users to submit Ethereum transactions (Tx) and execute their containing messages to evoke state transitions on the given state.

Users submit transactions client-side to broadcast it to the network. When the transaction is included in a block during consensus, it is executed server-side. We highly recommend to understand the basics of the Tendermint consensus engine to understand the State Transitions in detail.

Client-Side

::: tip 👉 This is based on the eth_sendTransaction JSON-RPC :::

  1. A user submits a transaction via one of the available JSON-RPC endpoints using an Ethereum-compatible client or wallet (eg Metamask, WalletConnect, Ledger, etc): a. eth (public) namespace:

    • eth_sendTransaction

    • eth_sendRawTransaction b. personal (private) namespace:

    • personal_sendTransaction

  2. An instance of MsgEthereumTx is created after populating the RPC transaction using SetTxDefaults to fill missing tx arguments with default values

  3. The Tx fields are validated (stateless) using ValidateBasic()

  4. The Tx is signed using the key associated with the sender address and the latest ethereum hard fork (London, Berlin, etc) from the ChainConfig

  5. The Tx is built from the msg fields using the Cosmos Config builder

  6. The Tx is broadcasted in sync mode to ensure to wait for a CheckTx execution response. Transactions are validated by the application using CheckTx(), before being added to the mempool of the consensus engine.

  7. JSON-RPC user receives a response with the RLP hash of the transaction fields. This hash is different from the default hash used by SDK Transactions that calculates the sha256 hash of the transaction bytes.

Server-Side

Once a block (containing the Tx) has been committed during consensus, it is applied to the application in a series of ABCI msgs server-side.

Each Tx is handled by the application by calling RunTx. After a stateless validation on each sdk.Msg in the Tx, the AnteHandler confirms whether the Tx is an Ethereum or SDK transaction. As an Ethereum transaction it's containing msgs are then handled by the x/evm module to update the application's state.

AnteHandler

The anteHandler is run for every transaction. It checks if the Tx is an Ethereum transaction and routes it to an internal ante handler. Here, Txs are handled using EthereumTx extension options to process them differently than normal Cosmos SDK transactions. The antehandler runs through a series of options and their AnteHandle functions for each Tx:

  • EthSetUpContextDecorator() is adapted from SetUpContextDecorator from cosmos-sdk, it ignores gas consumption by setting the gas meter to infinite

  • EthValidateBasicDecorator(evmKeeper) validates the fields of a Ethereum type Cosmos Tx msg

  • EthSigVerificationDecorator(evmKeeper) validates that the registered chain id is the same as the one on the message, and that the signer address matches the one defined on the message. It's not skipped for RecheckTx, because it set From address which is critical from other ante handler to work. Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user won't see the error message.

  • EthAccountVerificationDecorator(ak, bankKeeper, evmKeeper) that the sender balance is greater than the total transaction cost. The account will be set to store if it doesn't exist, i.e cannot be found on store. This AnteHandler decorator will fail if:

    • any of the msgs is not a MsgEthereumTx

    • from address is empty

    • account balance is lower than the transaction cost

  • EthNonceVerificationDecorator(ak) validates that the transaction nonces are valid and equivalent to the sender account’s current nonce.

  • EthGasConsumeDecorator(evmKeeper) validates that the Ethereum tx message has enough to cover intrinsic gas (during CheckTx only) and that the sender has enough balance to pay for the gas cost. Intrinsic gas for a transaction is the amount of gas that the transaction uses before the transaction is executed. The gas is a constant value plus any cost incurred by additional bytes of data supplied with the transaction. This AnteHandler decorator will fail if:

    • the transaction contains more than one message

    • the message is not a MsgEthereumTx

    • sender account cannot be found

    • transaction's gas limit is lower than the intrinsic gas

    • user doesn't have enough balance to deduct the transaction fees (gas_limit * gas_price)

    • transaction or block gas meter runs out of gas

  • CanTransferDecorator(evmKeeper, feeMarketKeeper) creates an EVM from the message and calls the BlockContext CanTransfer function to see if the address can execute the transaction.

  • EthIncrementSenderSequenceDecorator(ak) handles incrementing the sequence of the signer (i.e sender). If the transaction is a contract creation, the nonce will be incremented during the transaction execution and not within this AnteHandler decorator.

The options authante.NewMempoolFeeDecorator(), authante.NewTxTimeoutHeightDecorator() and authante.NewValidateMemoDecorator(ak) are the same as for a Cosmos Tx. Click here for more on the anteHandler.

EVM module

After authentication through the antehandler, each sdk.Msg (in this case MsgEthereumTx) in the Tx is delivered to the Msg Handler in the x/evm module and runs through the following the steps:

  1. Convert Msg to an ethereum Tx type

  2. Apply Tx with EVMConfig and attempt to perform a state transition, that will only be persisted (committed) to the underlying KVStore if the transaction does not fail:

    1. Confirm that EVMConfig is created

    2. Create the ethereum signer using chain config value from EVMConfig

    3. Set the ethereum transaction hash to the (impermanent) transient store so that it's also available on the StateDB functions

    4. Generate a new EVM instance

    5. Confirm that EVM params for contract creation (EnableCreate) and contract execution (EnableCall) are enabled

    6. Apply message. If To address is nil, create new contract using code as deployment code. Else call contract at given address with the given input as parameters

    7. Calculate gas used by the evm operation

  3. If Tx applied sucessfully

    1. Execute EVM Tx postprocessing hooks. If hooks return error, revert the whole Tx

    2. Refund gas according to Ethereum gas accounting rules

    3. Update block bloom filter value using the logs generated from the tx

    4. Emit SDK events for the transaction fields and tx logs