Docs: Paymaster

Protocol

Paymaster

HipPaymaster pays gas for HIP-ID accounts. A signer service approves each operation, and on-chain daily caps bound what that signer can ever spend.

The policy

HipPaymaster at 0x26aBbBEd6fb0E276d7DF51e7b8f8CEe3BB52c576 pays gas for HIP-ID accounts. These are the values set at deployment and the hard maxima compiled into the contract. The owner can change the values with setLimits, never above the maxima.

LimitCurrentHard maximum
accountDailyWei, per account per UTC day0.003 HYPE0.01 HYPE
globalDailyWei, all accounts together per UTC day0.02 HYPE0.5 HYPE
sessionOpsPerDay, session-key ops per account per UTC day501,000

The account budget and the session-op count are multiplied by 1 + boost, where the boost comes from $ID staking. The global budget is never multiplied.

What validation checks

validatePaymasterUserOp runs, in order:

  1. The caller is the EntryPoint.
  2. paymasterAndData is exactly 129 bytes.
  3. The sender is a HIP-ID account. With initCode, its first 20 bytes must be the HIP-ID factory. Without it, the sender's codehash must equal the hash of the EIP-1167 clone runtime code pointing at the HIP-ID account implementation. This identifies every account the factory made with no registry.
  4. The call is execute or executeBatch, and no inner call targets the paymaster itself. Anything else reverts with CallNotSponsored.
  5. The signer's approval: an EIP-191 signature over getHash(userOp, validUntil, validAfter). A wrong signature is reported to the EntryPoint as a signature failure, not a revert.
  6. The budgets: the full maxCost is reserved against the account and the global budget, or the call reverts.

It returns validUntil and validAfter in validationData, so the EntryPoint enforces the approval window too.

paymasterAndData

paymaster                      20 bytes
paymasterVerificationGasLimit  16 bytes
paymasterPostOpGasLimit        16 bytes
validUntil                      6 bytes   uint48
validAfter                      6 bytes   uint48
signature                      65 bytes   r ++ s ++ v
                              ---------
                              129 bytes

getHash = keccak256(abi.encode(
  sender, nonce, keccak256(initCode), keccak256(callData), accountGasLimits,
  paymasterAndData[20:52], preVerificationGas, gasFees,
  block.chainid, address(paymaster), validUntil, validAfter))

The hash covers the paymaster's own gas limits but neither its own signature nor the account signature, so the account signs after the paymaster has approved.

Budgets and the UTC day

The day is block.timestamp / 86400, which rolls over at 00:00 UTC. On the first sponsored operation of a new day the account's counters and the global counter reset to zero.

  • Account: spentWei + maxCost <= accountDailyWei x (1 + boost), else AccountBudgetExceeded.
  • Session ops: when userOp.signature[0] == 0x01, sessionOps + 1 <= sessionOpsPerDay x (1 + boost), else SessionOpsExceeded.
  • Global: spentWei + maxCost <= globalDailyWei, else GlobalBudgetExceeded.

Anyone can read the state: usageOf(account), budgetOf(account) and globalUsage().

Reserve, then refund

Before the opearlier ops todayvalidatePaymasterUserOpmaxCost reserved in fullpostOpunused part refundedrefundbudget = accountDailyWei x (1 + boost)
One account's daily budget across one sponsored operation. Proportions are illustrative. The same reserve and refund apply to the global budget.

Validation cannot know the final gas, so it reserves the worst case, maxCost, as given by the EntryPoint. After execution postOp computes the charge and returns the rest:

charged = min(actualGasCost + 20,000 * actualUserOpFeePerGas, maxCost)   // POSTOP_OVERHEAD_GAS
refund  = maxCost - charged

The 20,000 gas overhead covers postOp itself, which runs after actualGasCost is measured. If the UTC day rolled over between validation and postOp, the counters were already reset and there is nothing to refund.

The signer service

The bundler holds the paymaster signer key and signs an approval in pm_sponsorUserOperation. Before signing it refuses operations from an unknown factory and operations that would exceed the account's daily budget, which the chain would refuse anyway. Each approval is valid from 30 seconds before signing until 300 seconds after.

The signer can approve, or decline to approve. It cannot raise a cap, cannot sponsor a non-HIP-ID account and cannot redirect a sponsorship to a call on the paymaster. If the key were stolen, the most it could spend is the global daily budget per day, on gas only, until the owner rotates it with setSigner.

EntryPoint stake and deposit

The paymaster is staked in the EntryPoint with an unstake delay of 24 hours (1 day), as ERC-4337 expects from a paymaster that reads its own storage during validation. Gas is paid from the paymaster's EntryPoint deposit, which is the sponsor's own float. Anyone can top it up with deposit(). The owner can withdraw it with sweep; no user money is ever held there.

$ID stake boost

HipStake at 0x6b2C2F34c2fBf65251Da540670f9345655449275 raises an account's budget in exchange for staked $ID. Each full 10,000 $ID staked by the account adds one base budget, up to 9 extra budgets, so the account budget and its session-op count reach at most 10 times the base.

  • stake(amount) moves tokens in. requestUnstake(amount) removes them from the boost at once and starts a 24 hour delay. withdraw() returns them after the delay. A new request adds to the pending amount and restarts the delay.
  • No step needs the owner or a keeper. Stakers can always exit.
  • The token address is set once by the owner and can never change after. It is not set yet, because $ID has not launched. Until then stake reverts and every account's boost is 0.

Planned

Not built yet

Planned: letting the paymaster take its gas fee in tokens, and a buyback or burn funded by those fees. Neither exists in the deployed contract today. The paymaster sponsors in HYPE only and takes no fee.

Tests

TestChecks
invariant_dailyCapsHoldRandom sponsorships, settlements and day changes: no account is ever charged more than its daily budget, and all accounts together never more than the global cap
test_sponsorsAndRefundsmaxCost reserved, then the exact charge kept after postOp
test_accountBudgetSecond op over budget refused; a new UTC day resets
test_globalBudgetThird account refused once the global cap is reached
test_sessionOpsPerDaySession ops beyond the daily count refused
test_stakeRaisesBudget30,000 $ID staked gives 4 times the budget; the boost drops the moment unstake is requested
test_refusesCallToPaymasterDirect and batched calls to the paymaster refused
test_refusesForeignAccountsAn EOA and a foreign factory refused
test_limitsBoundedsetLimits above a maximum, or by anyone but the owner, reverts
test_paymasterRefusesSelfCallElysium mainnet fork: a sponsored call to the paymaster fails in handleOps

The invariant runs 64 sequences of depth 64 (foundry.toml).