
What is Cosmos SDK? Why do we need it? What’s it purpose, and why it is the one of the best alternative for chains like Ethereum? There are many question you may get if you see the posts about Cosmos SDK.
The reason for this hype over the past 2-3 years is because, Cosmos SDK is a toolkit that being used to create our own blockchain, think of it as creating your custom mobile phone with Google Pixel lens, Apple Security system, Xiaomi battery capability (your preference may differ from it)
This blog explores the Cosmos SDK’s core principle, modularity and its application structure, demystifying the modules and concludes with transaction cycle and supporting mechanisms.
The first-generation blockchains (i.e., Bitcoin, Ethereum, Solana) often characterized by monolithic, in simple terms think it as MacBook, where we cannot change any unit as want as they have their own chips like M1, M2 kind of things. To achieve true sovereignty (i.e., full right and power to have itself without external interference) over the applications and deep flexibility of underlying logic, developers search for a framework, this is where Cosmos SDK comes into the act — which is designed to empower developers to build bespoke, sovereign application specific blockchains, popularly known as app-chains.
You may ask there are blockchains like Polygon, Arbitrum, or any layer 2 chains can achieve scalability and flexibility and chains like Polkadot achieves true sovereignty, but the main reason why we are discussing about Cosmos SDK over these is because of so called IBC, where all the chains that are built on Cosmos can interact with each other with true sovereignty and flexibility in underlying logic.
Tendermint Core - Engine that handles the networking (i.e., Peer to Peer) and consensus (i.e., Byzantine Fault Tolerance). It is an Application-Agnostic because it does not care what transaction mean, only application logic validates and update the state accordingly, which will be discussed further. The Tendermint consensus implements sophisticated BFT consensus algorithm (or Tendermint BFT)
Tendermint Core is where developers define the "how". How are transactions ordered? How blocks and transactions propagated across the network?
Application Blockchain Interface (ABCI) - Socket protocol that allows Tendermint core to communicate with application logic, which built using cosmos SDK. Both Tendermint core and application logic are written in Go language.
Let's have an example how they communicate, Tendermint says like "what's the current app hash? (commit)" or "here's a transaction, is it valid? (deliver transaction)", now ABCI accordingly responds using cosmos SDK app, a framework in Go lang to build state machine, i.e., application logic.
Application logic is where developers define the "what". What are valid transaction types? What are the specific rules and business logic of this blockchain? Developers can entirely focus on the domain-specific logic without worrying about consensus and networking.
From here on, hold the string because we are going to discuss lot about technical stuff, you may feel that the content is being repeated, but the reason for that being done is to overlay the path to understand better. So, let’s get started without any delay.
BaseApp: The Central Nervous System of Cosmos SDK ChainBaseApp is the SDKs core implementation of the ABCI interface, acts as central nervous system for of Cosmos SDK based blockchain application. Let's discuss its core responsibilities:
ABCI Implementation: It directly handles ABCI messages from Tendermint
Request Processing & Routing: It receives raw transaction bytes from Tendermint and decodes these bytes into structured sdk.Tx and then sdk.Msg (message) objects that application logic understands. Runs AnteHandlers, which conducts preliminary checks before executing the main message logic Routes sdk.Msg s to appropriate module responsible for handling that specific type of state change.
State Committing: After processing all the transactions in a block, BaseApp commit method finalizes all state changes. It then writes these changes to applications state store (i.e., CommitMultiStore) and returns new state Merkle root hash to Tendermint, sealing the new state.
Unlike Ethereum, which is Monolithic Blockchain, Cosmos SDK is Modular Blockchain, which mean it offers you to pick a different tool for each layer, making it modular that optimizes to your needs.
Monolithic Blockchain — where execution, consensus, settlement, data availability are handled by the single, tightly integrated system. Means if you want to change one layer, let's say consensus mechanism, it's difficult without rebuilding the entire blockchain.
Modular Blockchain — where it split these tasks into separate, customizable layers. Each layer can use different software allowing developers to “plug and play”. Each self-contained packages of functionality called modules.
Before discussing the module in detail, let's see the standard modules provided by Cosmos SDK. Cosmos SDK has a set of pre-built and tested modules that provide common blockchain functionalities.
x/auth — Fundamental for authenticating transactions
x/bank — Handles token transfers, track balances, and manages token supplies
x/staking — Implements Proof-of-Stake logic
x/gov — Provides an on-chain governance mechanism
x/distribution — Manages block reward distribution and transaction fee to validators and delegators respectively.
x/ibc — Enables communication and token transfers between different Cosmos SDK based chains
Module — Each piece of core functionality in blockchain is encapsulated within the module. Each module typically defines the:
Its own types (i.e., purpose)
Own state in KVstore, will be discussed shortly.
Message type that can process
Handlers that process the messages
keeper that manages state and business logic
Queries to expose its state
Keepers are guardian of a module's state, because they are sole entities within a module responsible for reading from and writing to module's dedicated portion of blockchain state.
Each module that needs to persist data has its own keeper, as all the logic that requires modifying or retrieving a module's state must through the methods exposed by its keeper.
StoreKey — unique identifier (which means there is practically no scenario two modules have same StoreKey) that grant access to specific, namespace "slice" of main key-value pair store (KVStore), that allow keeper to manage which part of global state.
When a module is initialized, its Keeper is provided with its dedicated StoreKey. The keeper then uses this key every time it needs to interact with the KVStore (i.e., Key-Value Store).
The design of Keepers and StoreKey strongly align with Object-Capability Model (OCAP), means if a part of code does not have a direct reference to a particular StoreKey, it cannot directly access or modify the associated state, which minimizes the "attack surface" and make state integrity simple.
Inter-Module Communication — happens by one keeper calling the public methods of another keeper. During application setup, if KeeperA needs to use functionality from KeeperB, a reference to KeeperB is passed to KeeperA during it construction, which ensures that KeeperB still controls its own state and KeeperA can only perform action explicitly permitted by KeeperB's public API.
The need of Inter-Module Communication is because direct sharing of StoreKeys between keepers would violate the OCAP principles and break the encapsulation.
KVStore (Key-Value Store) is the database, where Cosmos SDK uses IAVL+ trees for efficient, verifiable state storage. Unlike Ethereum, where global Merkle Patricia trie for world state, Cosmos SDK uses IAVL+ trees, and each module has its own KVStore (i.e., its own Storekey which acts as namespace), and all the partitioned state rolls up into a single app hash in baseApp.
IVAL+ trees — It is a self-balancing, persistent, and versioned Merkle tree structure:
Merkelized: Every update to the tree results in a new root hash, which represents the entire state of application at specific block height.
Root hash of IAVL+ tree = Application state Merkle root, which included in block headers
Versioned: Retains historical versions of the state, means we can query the existed state of any past block.
IVAL+ trees have an ability to generate Merkle Proofs for specific key-value pairs. These proofs can be verified by anyone with corresponding root hash, without needing the entire state which makes the proofs efficient.
CommitMultiStore — It is being used to manage multiple modules of an application, that each needing its own state, and it maps StoreKeys to individual KVStores.
When commit is called from BaseApp, then the CommitMultiStore commits each of its underlying KVStores and calculates a single top-level application Merkle root hash from the root hashes of all the individual module stores.
Once a transaction has passed Tendermint's consensus and is delivered to BaseApp, and after AnteHandler performs their preliminary checks, and then the sdk.Msg contained within are ready for their core processing. This is where Handlers come in. Stateful validation and execution via keepers is the main responsibility of Handlers.
Handler never directly modifies the state, instead it calls the methods on its module's keeper to read data and effect state change. These keepers perform the actual writes to KVStore. Handlers also emit events to signal what occurred during the message processing.
When BaseApp extracts sdk.Msg from transaction, it uses router (MsgSerivceRouter) to determine which module is responsible for processing that specific message type. The router maps the messages type to corresponding modules MsgServer implementation. BaseApp then invokes appropriate method on that MsgServer.
The selected handler (method on MsgServer) is responsible for actual execution of state transition defined by the message.
Let's see the overview of the transaction lifecycle in the below figure before diving into the in-detail discussion.

Transaction Creation
User constructs one or more sdk.Msg objects representing the desired state change(s). Each sdk.Msg is validated locally for stateless checks.
sdk.Msgs are wrapped into an sdk.Tx object, which is signed by the user private key for each sdk.Msg
sdk.Tx is serialized, and the serialized transaction bytes are broadcast to a full node in Cosmos network
Tendermint Core + Application
After full node receives the broadcasted transaction bytes, Tendermint core forwards the transaction bytes to application layer (i.e., BaseApp) via the CheckTx ABCI method.
BaseApp decodes the raw bytes back into an sdk.Tx object, which is being executed by AnteHandlers, which perform stateless and stateful pre-checks like:
Validating fees, gas, memo length Verifying signatures against sdk.Msg signers Deducting fees Checking account sequence number and so on
BaseApp returns a CheckTxResponse to Tendermint. If response succeeds, then Tendermint adds the transaction to its local mempool, then it transmits to other peers in the network, so that they can run CheckTx to their local mempool. Error is thrown to the user if the transaction is rejected.
Key ABCI methods from Tendermint to
BaseAppare:
CheckTx— validate transaction for mempool
BeginBlock— signal the start of new block
DeliverTx— delivers committed transaction for processing
EndBlock— signal the end of block
commit— return an application Merkle root hash
Block Proposal
Tendermint BFT consensus algorithm selects a validator to be the proposer for current block height, who selects a set of transactions from local mempool to include into a new block proposal.
Proposer assembles these transactions into block (e.g., by fee per gas unit) along with block header. Finally, proposer broadcasts this block proposal to all other validator nodes (or peers) in the network.
ABCI DeliverTx Requests
When other validators receive a block proposal, they need to validate and execute it to decide whether to vote for it or not. Tendermint core calls the BeginBlock ABCI method on BaseApp
BaseApp checks all registered modules and execute BeginBlocker logic, and state changes made here are cached in the context. This is used for tasks that need to happen at the start of every block (like distributing rewards from previous block, handling validator evidence)
For each transaction in the proposed block, Tendermint core call DeliverTx ABCI method, which decodes the transaction bytes and run by AnteHandler again, because state might have changed due to previous transactions within the same block
BaseApp returns a DeliverTxResponse to Tendermint. Even if one DeliverTx fails, Tendermint continues to process other transactions in the block.
After all were done, Tendermint core calls the EndBlock ABCI method, which iterates through modules and execute EndBlocker logic, and again state changes are cached in the context.
For each message,
BaseApproutes it to the appropriate module's Handler, which validates the message and call its keeper methods, which update the module's state in KVStore (viasdk.Context), and finally corresponding events are emitted.
Consensus
Validator now vote on its validity in 2 rounds, prevote and precommit rounds. They compare the resulting application state hash and other block details. If more than 2/3rd of the voting power precommit to the same block, Tendermint core considers block committed.
Commit to State
Once block is committed, Tendermint calls the Commit ABCI method, which takes all the cached state changes made during BeginBlock, all successful DeliverTx calls, and EndBlock state changes.
Then it writes these changes to CommitMultiStore(uses IAVL+ trees), which returns a new application Merkle root hash (AppHash) that represents the entire state of application after this block.
BaseApp returns the AppHash to Tendermint core, which includes this AppHash in the header of the finalized block, which being added to the blockchain.
COSMOS SDK is an open-source toolkit for building custom blockchains. The reason why it being so famous is because it achieved the limitation of Ethereum, which are Scalability, Sovereignty, and Flexibility. Scalability is achieved in 2021, by introducing IBC (Inter Blockchain Communication) enables the independent blockchain on cosmos to connect, transact and exchange tokens. Flexibility & Sovereignty is achieved by Application specific blockchains, popularly known as App-chains, where each app-chain has its own validators, tokenomics, governance.
Author - Sai Nikethan
Intern, Security Researcher @TECHFUND