Auth Module (x/auth)
Overview
Thex/auth module is responsible for specifying the base transaction and account types for a Cosmos SDK application. It handles authentication of accounts and transactions, manages account storage, and provides the AnteHandler middleware for transaction validity checks.
Purpose: Provide foundational authentication infrastructure, account management, and transaction validation for blockchain applications.
Key Concepts
Gas & Fees
Fees serve two primary purposes:- State Growth Control: Limit the growth of state stored by every full node
- Spam Prevention: Provide general purpose censorship of low-value transactions
Account Types
Accounts contain authentication information for uniquely identified users:- Public key
- Address
- Account number (for replay protection)
- Sequence number (for replay protection)
State
Accounts
Accounts are stored with the following key structure:Account Interface
BaseAccount
The most common account type storing all requisite fields:AnteHandlers
TheAnteHandler performs basic transaction validity checks before execution. It’s called during both CheckTx and DeliverTx.
Decorator Chain
Decorators are chained together in the following order:- SetUpContextDecorator: Sets the
GasMeterin context - RejectExtensionOptionsDecorator: Rejects extension options
- MempoolFeeDecorator: Checks tx fee against local mempool
minFee - ValidateBasicDecorator: Calls
tx.ValidateBasic() - TxTimeoutHeightDecorator: Checks for tx height timeout
- ValidateMemoDecorator: Validates tx memo
- ConsumeGasTxSizeDecorator: Consumes gas proportional to tx size
- DeductFeeDecorator: Deducts
FeeAmountfrom first signer - SetPubKeyDecorator: Sets pubkey for signers
- ValidateSigCountDecorator: Validates number of signatures
- SigGasConsumeDecorator: Consumes gas for each signature
- SigVerificationDecorator: Verifies all signatures
- IncrementSequenceDecorator: Increments account sequence
Account Keeper
The Account Keeper provides full-permissioned access to account management:Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| MaxMemoCharacters | uint64 | 256 | Maximum memo length |
| TxSigLimit | uint64 | 7 | Maximum signatures per transaction |
| TxSizeCostPerByte | uint64 | 10 | Gas cost per byte of transaction |
| SigVerifyCostED25519 | uint64 | 590 | Gas cost for ED25519 signature verification |
| SigVerifyCostSecp256k1 | uint64 | 1000 | Gas cost for Secp256k1 signature verification |
Queries
Query Account
Retrieve account information by address:Query All Accounts
Query Parameters
Transactions
Sign Transaction
Sign an offline generated transaction:Multi-Sign Transaction
Sign with a multisig account:Broadcast Transaction
Validate Signatures
gRPC Endpoints
Account Query
Accounts Query
Params Query
Code Examples
Creating a New Account
Retrieving an Account
Checking Account Existence
CLI Commands Reference
| Command | Description |
|---|---|
simd query auth account [address] | Query account by address |
simd query auth accounts | Query all accounts |
simd query auth params | Query auth module parameters |
simd tx sign [tx-file] | Sign a transaction |
simd tx multisign [tx-file] [multisig] [sigs...] | Sign with multisig |
simd tx broadcast [tx-file] | Broadcast a signed transaction |
simd tx validate-signatures [tx-file] | Validate transaction signatures |
Integration Guide
To integrate the auth module in your application:- Import the module:
- Initialize the keeper:
- Register the module: