Stake-for-Gas and Deterministic Admission Guards: Fee-Free Transactions Without Unchecked Flooding

Architects of modern blockchains and verifiable ledgers face a familiar three-way problem:
- Charge end users a native-token Gas fee for every state write, and mainstream users and newly launched AI agents face a barrier before their first action. Someone posting a comment, acknowledging a credential, or saving a configuration should not have to figure out how to fund an account with a fraction of a native token first.
- Simply set fees to zero, and an attacker can use a short loop to flood the network with tens of thousands of junk writes per second. Unchecked requests can fill node storage and overwhelm the sequencing pipeline.
- Have applications transfer tokens into a third-party relayer or Paymaster contract, and application funds become exposed to an external contract while per-transaction charges steadily consume the balance.
While building @ocap/ledger-core, we chose a different resource model. This first article in the Stake-for-X series examines how ArcBlock combines Stake-for-Gas, which provides renewable compute quotas against a stake, with GasSecurityGuard, which separates admission control from execution, to address usability, operating costs, and abuse prevention together.
1. From Consumable Fuel to Renewable Quotas Without Transferring Ownership
The conventional Gas model resembles a gasoline engine: every kilometer consumes fuel that cannot be recovered. For the frequently invoked ARC (Agentic Realm Computer) and enterprise applications, that model makes operating costs grow directly with transaction volume and complicates budgeting.
In the statedb.stake state machine of @ocap/ledger-core, access to everyday compute resources instead uses an on-chain lock that retains the owner's claim to the funds. Stake-for-Gas supports two distinct modes.
Account Self-Staking: toStakeAddress(owner, owner)
Frequent users, AI agent workers, and merchant accounts can lock official tokens in their own stake slot, toStakeAddress(owner, owner). The default stakeLockPeriod is one year. Once it expires, the owner can initiate revoke_stake and recover the entire stake after the cooldown period.
- No base Gas charge for self-staking: the protocol exempts the self-staking transaction from base Gas so an account can establish its stake.
- The stake remains intact while quotas renew periodically: locked tokens remain in
statedb.stakeas the basis for compute eligibility rather than being deducted as fees. WhilegasStake.valid === true, theensure-costpipeline waives per-transaction charges for qualifying everyday transactions. When the stake is no longer needed and the withdrawal conditions are met, the full amount returns to the account.
Application-Sponsored Gas Through a gasStakeHeaders JWT
An application does not need to send tokens to every newly registered user as a faucet would.
Instead, the developer establishes a Stake-for-Gas pool under the application's own account. When an eligible user submits a transaction, the application backend signs a lightweight extra.gasStakeHeaders JWT with its sponsorship key. The token binds the transaction hash, the sponsorship stake address, and a validity window of gasPassEpochSeconds = 60s. During execution, the ledger verifies the signed token and the pool's quota before allowing the transaction to proceed. The user signs with their own identity while holding no tokens, and qualifying transactions do not consume the application's staked funds.

2. Why Local Rate Counters Must Never Determine State Transitions
Once Stake-for-Gas waives everyday fees, an urgent question follows:
What stops a malicious staked account, or a runaway script holding a sponsorship token, from sending 10,000 transactions in a second? What stops it from exhausting node CPU with malformed transactions that will ultimately fail validation?
The intuitive answer is a sliding-window counter in node memory: count each address's requests and failures over the past 60 seconds, then charge extra or slash its stake when it exceeds a threshold.
Using that local counter to determine an executed transaction's outcome can split consensus.
Local observations are not deterministic:
- Production deployments may run multiple processes, and a rolling upgrade can reset one node's in-memory counters.
- Network delays and clock boundaries can place the same request in different windows. Node A might count transaction 101 inside the current 60-second window and reject or charge it; node B might place it in the next window and grant a fee exemption.
- If two nodes derive different balance changes or receipt statuses for the same sequenced transaction, their incremental Merkle state roots,
stateRootHash, diverge.
The Boundary: Admission-Only Controls and Pure State Transitions
GasSecurityGuard in @ocap/ledger-core therefore follows a strict architectural rule:
Once a transaction enters the ordered sequence, its outcome, including success or failure, actual charges, fee exemptions, and state changes, must be a pure function of
(tx, onChainState). Process-local counters may determine only whether the gateway admits a transaction before sequencing, throughassertTxAdmission. They must never change the pricing, exemption status, or execution result of an admitted transaction.
The two layers have separate responsibilities:
| Protection Layer | Location and Inputs | Responsibility | Enforcement or Guarantee |
|---|---|---|---|
| Layer 1: Pre-sequencing admission control ( assertTxAdmission) | Queue-entry gateway; process-local sliding windows | Track burst quotas and accumulated strikes for each verified signer | Reject enqueueing with TOO_MANY_TXS at the in-memory gateway, with no disk writes or ledger-state changes |
| Layer 2: Pure on-chain execution ( ensure-cost and the state machine) | Single-threaded deterministic sequencer; only tx and persisted on-chain state | Check transaction size, state-operation limits, fee-exempt transaction types, and stake validity | Replay produces a bit-for-bit identical stateRootHash on every verifying node |

3. The Safeguards Inside GasSecurityGuard
With admission and execution separated, GasSecurityGuard can constrain abusive traffic without treating a large sponsored application as a single user.
Count Bursts by Verified Signer, Not Gas Payer
Rate-limiting by Gas payer can penalize an entire application when hundreds of legitimate users act at once. A shared sponsorship account reaches its aggregate limit, and everyone stalls.
Our burst-quota algorithm instead keys its sliding window, burstWindowMs = 60,000ms, by the verified transaction signer:
- Ordinary transactions use
tx.from. - Delegated transactions use the
(delegatee, principal)pair, with an additional per-principal aggregate cap ofdelegatedBurstMultiple = 20. - Burst allowance scales with the stake multiple through
baseBurstAllowance * stakeMultiple. Idempotent network retries of the sametxHashdo not consume quota twice.
An abusive user therefore triggers TOO_MANY_TXS for their own signing key rather than exhausting the quota of thousands of other users sharing a sponsorship pool.
Distinguish Ordinary State Conflicts from Weighted Strikes
Concurrent state conflicts are routine in distributed systems. An honest AI agent may encounter insufficient funds (INSUFFICIENT_*), an already-used sequence number (INVALID_NONCE), or a retransmitted transaction (DUPLICATE_TX). Penalizing those events would punish normal application behavior.
The strike tracker assigns responsibility more narrowly:
- Ordinary state conflicts never add strikes:
INSUFFICIENT_*,INVALID_NONCE, andDUPLICATE_TXdo not increase the score. - Sponsorship-header errors do not penalize the user:
extra.gasStakeHeadersis outside the user's original transaction signature. If a sponsorship gateway supplies an invalid header, the innocent signer does not receive a strike. - Security violations trigger an admission cooldown: requests that violate WAF rules or post-execution invariants accumulate weighted strikes. Reaching
throttleThreshold = 5withinstrikeWindowMs = 600,000msplaces the signer in athrottleCooldownMs = 15,000msadmission cooldown.
Four Deterministic Execution Rules and DIRECT_GAS_REQUIRED_TX_TYPES
After admission, four rules govern execution:
- A hard size limit for fee-exempt transactions:
maxFreeGasTxSize = 4096 Bytes. Large payloads do not qualify for the free quota. - A hard state-operation limit:
maxFreeGasStateOps = 6. Limiting the number of state-tree leaves touched by one fee-exempt transaction bounds its state-processing work. - Failed execution requires actual Gas payment. A transaction that fails during on-chain execution incurs a real charge, preventing free rollbacks from becoming an unrestricted drain on sequencer resources.
- High-impact primitives cannot claim stake-based exemptions:
DIRECT_GAS_REQUIRED_TX_TYPES. Operations such as creating a token factory or registering a bridge change global topology. They require direct payment regardless of the initiator's stake or the sponsor's pools. A sponsor may pay through Direct-Charge mode. These charges flow entirely into the circular protocol revenue treasury,config.vaults.txGas, without burning tokens.

Everyday Transactions Without Sacrificing Determinism
A mature protocol should not make ordinary users manage abuse prevention every time they click a button.
Combining renewable quotas through Stake-for-Gas with admission rate limits and pure on-chain execution through GasSecurityGuard removes per-action fee friction for qualifying transactions. Just as critically, local traffic observations never become inputs to consensus state changes. Nodes can enforce their admission policies while replaying the same ordered transactions to the same state root.
The next article examines Stake-for-Bid and Stake-for-Offer: how NFT auctions and structured buy offers become native asset-state operations instead of relying on external auction escrow contracts.