Skip to main content

2. How GA Works: Technical Deep Dive

This section provides a detailed technical overview of how Gas Abstraction operates within the Kaia network, including transaction bundling, atomicity, and the roles of key components.

2.1 Architecture Overview

GA is built on a decentralized architecture that leverages smart contracts and transaction bundling to ensure a seamless user experience.

Key Components

  • KIP-247 (Gasless Transaction): Defines the specific transaction formats (GaslessApproveTx, GaslessSwapTx) that the network recognizes as eligible for gas abstraction.
  • KIP-245 (Transaction Bundle): Guarantees that the necessary sequence of transactions (lending, approving, swapping) is executed atomically—they either all succeed or all fail together.
  • GaslessSwapRouter (GSR): A core smart contract that performs the token-to-KAIA swap and repays the block proposer for the initial gas loan, all within the same block.

Key Actors

The following diagram illustrates the key actors and their interactions in the GA process:

  • Wallet: The user's wallet or dApp interface that initiates the gasless transaction.
  • User Account: The wallet or dApp user initiating the gasless transaction.
  • Block Proposer: The node proposing the block, which temporarily lends KAIA for gas fees.
  • GaslessSwapRouter (GSR): The smart contract that handles the swap and repayment logic.
  • DEX Router: The underlying decentralized exchange that performs the actual token swap.

2.2 Transaction Bundle Components

GA operates through transaction bundling, where the blockchain client groups only LendTx + (optional) ApproveTx + SwapTx into an atomic bundle. These three either all succeed or all fail. Any AppTx sent right after the bundle is outside the bundle and can revert independently.

LendTx (Lend Transaction)

  • Signer: Block proposer
  • Purpose: Temporarily lends KAIA to user for gas fees
  • Creation: Dynamically generated during block construction
  • Amount: Calculated to cover gas for ApproveTx + SwapTx

ApproveTx (Approval Transaction) - Optional

  • Signer: User
  • Purpose: Approves ERC-20 token spending for GaslessSwapRouter
  • When needed: If user hasn't previously approved the token
  • Format: Must follow KIP-247 specifications

SwapTx (Swap Transaction)

  • Signer: User
  • Purpose: Swaps user tokens for KAIA and repays the proposer
  • Contract: Calls GaslessSwapRouter.sol
  • Validation: Ensures amountReceived >= minAmountOut >= amountRepay

2.3 Atomicity and Failure Handling

KIP-245 Bundle Properties:

  • All-or-nothing execution: If any transaction fails, entire bundle reverts
  • Timeout exemption: Bundles are exempt from 250ms per-block execution limits
  • State rollback: Failed bundles trigger complete state reversion

Common Failure Scenarios:

  • Insufficient token balance → Bundle reverts, no gas lost
  • Price slippage exceeded → SwapTx fails, bundle reverts
  • Missing token approval → Validation fails, transactions remain in pool

2.4 Network-Level Processing

Transaction Pool Validation

Gasless transactions bypass normal balance checks in the transaction pool. The validation logic detects gasless transactions and skips the account balance check for gas fees.

Promotion and Bundling Logic

  • GaslessApproveTx cannot be promoted without a corresponding GaslessSwapTx
  • GaslessSwapTx can be promoted independently if the token is already approved
  • Both transactions are promoted simultaneously when both are present

Block Proposer Injection and Execution

Block proposers automatically inject LendTx when they detect gasless transactions. The LendTx is created on-the-fly during block generation and placed before the user's gasless transactions.

2.5 Example Workflow with Balance Changes

Let's walk through a scenario where a user has 1.00 BORA and 0 KAIA.

StepActionProposer BalanceUser BalanceNotes
1. Initial-10.00 KAIA0.00 KAIA, 1.00 BORAUser wants to pay for a tx.
2. LendTxProposer lends 0.02 KAIA.9.97 KAIA0.02 KAIA, 1.00 BORAProposer pays its own gas.
3. ApproveTxUser approves BORA for GSR.9.97 KAIA0.01 KAIA, 1.00 BORAGas (0.01 KAIA) paid from loan.
4. SwapTxUser swaps 0.06 BORA for 0.04 KAIA.10.00 KAIA0.01 KAIA, 0.94 BORAProposer is repaid 0.03 KAIA.
5. AppTxUser executes their main tx.10.00 KAIA0.00 KAIA, 0.94 BORAGas paid with KAIA from swap.
Make this page better