← All posts

What to inspect in a gasless smart-contract transfer design

OpenZeppelin’s audit of Nimiq GaslessTransfer is a useful prompt to review how gasless smart-contract flows bind signer intent, prevent replay, and constrain relayer power. The core risks sit in message scope, nonce state, token behavior, and adversarial testing.

OpenZeppelin’s audit of Nimiq GaslessTransfer points to a familiar engineering problem in smart-contract systems. You want the user to sign intent, not hold native gas. You also want a relayer to submit the transaction without gaining broad power. Those goals pull in opposite directions.

For you as a builder, gasless flow design is not a product detail. It changes your trust model, replay surface, nonce handling, and failure modes. If you build wallets, account abstraction layers, or meta-transaction relays, small mistakes here turn into stuck funds, duplicate execution, or signatures valid in places you did not expect.

A gasless transfer design lives at the boundary between cryptography, contract state, and off-chain infrastructure. The audit is useful as a prompt to inspect those boundaries with care. One short fact from OpenZeppelin’s report stands out: the work covered a gasless transfer mechanism built around signed messages and relayer submission. From there, the wider lessons apply across many EVM and non-EVM systems.

Define the signed intent with no spare fields

Most gasless designs fail first at message scope. The user signs a payload. If the payload leaves room for interpretation, the relayer or another contract path gains leverage.

Inspect these fields in every signed message:

  • signer address
  • recipient address
  • asset identifier
  • exact amount
  • fee amount and fee recipient, if any
  • nonce or sequence number
  • chain identifier
  • contract address or domain separator
  • expiry or valid-until block or timestamp
  • function selector or action type

If one of these sits outside the signature, treat it as mutable input. Mutable input means execution risk.

A common mistake is to sign an amount and recipient while leaving fee logic to relayer policy. Another is to sign a generic blob with weak domain separation. A valid signature then travels farther than intended, across contracts, chains, or entry points.

For EVM systems, EIP-712 helps, but only if you use it fully. The domain separator needs stable semantics. Contract upgrades, forks, and proxy layouts need thought up front. If you change the verifying contract or version fields without a migration plan, old signatures break or, worse, remain valid in an unexpected context.

Good verification work looks boring:

  • reconstruct the exact digest on-chain
  • bind every execution-relevant field into the digest
  • reject signatures with ambiguous encoding
  • reject malformed s values and invalid recovery forms
  • test with altered field order, empty values, and boundary sizes

Where it goes wrong is often encoding, not cryptography. abi.encodePacked collisions, omitted type hashes, and inconsistent off-chain serialization still show up in production systems.

Treat replay protection as a state machine

Nonce design decides whether gasless transfers are one-time intents or reusable permits. Many teams think of replay protection as a single storage slot. In practice it is a state machine with concurrency edges.

You should inspect:

  • whether nonces are global, per-user, or per-action
  • whether execution consumes a nonce before or after external calls
  • whether cancellation exists n- whether failed execution leaves the nonce reusable
  • whether parallel signing creates ordering deadlocks

A single monotonic nonce is simple. It also creates operational friction. If a relayer withholds nonce 10, the user’s signed nonce 11 cannot execute. This becomes a liveness problem, not a safety problem, but users experience both as breakage.

Bitmap nonces or unordered nonce sets reduce this friction. They also increase implementation complexity. Auditors then look for double-spend edges, bit math errors, and storage aliasing.

Another frequent bug sits in failure semantics. Suppose the contract marks the nonce used only after token transfer logic runs. A reentrant path or a crafted failure branch might permit repeated attempts on the same signature. If the contract marks the nonce too early, a benign downstream failure burns the user’s signed intent and creates griefing potential.

The right choice depends on the action. For pure value transfer, consuming the nonce before interaction is often easier to reason about, paired with tightly controlled external calls. For more complex flows, you need explicit rollback logic in the design and tests proving there is no replay after partial failure.

Write tests around these exact cases:

  • same signature submitted twice in one block
  • same signature submitted through two relayers
  • nonce cancellation racing with execution
  • out-of-order valid nonces
  • relayer withholding low nonces

Relayers are part of the protocol, not a helper service

Teams often model the relayer as an off-chain convenience layer. In a gasless system, the relayer shapes execution guarantees, fee extraction, and censorship risk. Treat it as part of the protocol boundary.

A relayer has three forms of power:

  • ordering power
  • withholding power
  • selective submission power

If your design assumes the relayer behaves neutrally, state where that assumption holds and where it fails. Many designs need cryptographic limits on relayer discretion.

Examples:

  • The user signs a maximum fee, not an open fee.
  • The user signs an expiry, so withheld messages die quickly.
  • The relayer address is either fixed in the signed payload or explicitly left open.
  • Replacement rules are defined, so a user or backup relayer can supersede a pending intent.

One subtle issue is who receives fees and in what asset. If the relayer is paid from transferred funds, inspect rounding, dust, and fee-on-transfer token behavior. If the relayer is paid separately, inspect whether the signed amount and fee remain economically coupled. Systems break when one leg succeeds and the other does not.

You should also test for relayer-induced denial of service. For example:

  • relayer submits with too little gas, causing repeated failure
  • relayer front-runs a cancellation with an older signed message
  • relayer batches many signatures and one bad item reverts the whole bundle

On chains with mempool privacy differences or proposer-builder separation, relayer assumptions shift again. A private relay path changes frontrunning risk but adds trust in delivery. A public mempool exposes signed intent timing and ordering to more actors.

External calls and token behavior still dominate risk

Even when the signature path is correct, transfer execution often fails at the token boundary. Gasless transfer systems tend to inherit every odd behavior in token contracts.

Inspect for:

  • ERC-20 tokens which return no boolean
  • fee-on-transfer tokens
  • rebasing balances
  • callback hooks such as ERC-777 style receive logic
  • blacklists or pause switches
  • non-standard revert behavior

If the gasless mechanism supports arbitrary assets, your code path must survive all of these. Safe wrappers help, but they do not remove semantic differences.

This is where checks-effects-interactions still matters. Verify signatures. Mark replay state. Bound fees. Then interact externally. If you must call multiple contracts, define the invariant after each step.

For example, if the design transfers tokens to a recipient and then pays a relayer fee, what happens when the first call succeeds and the second fails. If both sit in one transaction, atomicity helps, unless one token uses unexpected callback behavior. If the fee comes from a different asset, your atomicity assumptions weaken.

Audits often find issues where the gasless wrapper assumes token transfer means value delivered. With rebasing or taxed assets, the recipient might receive less than the signed amount. The protocol then needs one of two clear semantics:

  • sign the gross amount sent from the signer
  • sign the net amount the recipient must receive

Mixing them leads to disputes, bad accounting, and replay edge cases around minimum received logic.

Verification needs adversarial tests, not only unit coverage

Gasless systems often ship with high unit-test coverage and still miss the interesting bugs. The issue is path shape, not raw coverage count.

You want tests which vary signer intent, relayer behavior, and token behavior together.

A solid test plan includes:

  • property tests for nonce uniqueness and one-time execution
  • fuzzing for message encoding and signature recovery
  • invariant tests across partial failures
  • tests against mock tokens with hostile behavior
  • cross-chain or forked-chain domain separation checks
  • upgrade tests if proxies or versioned domains are involved

Formal methods fit well on narrow components. Signature verification, nonce consumption, and domain separation logic are good targets because they have crisp invariants. Full economic behavior is harder to prove and still needs scenario testing.

If your stack uses account abstraction, include bundler and paymaster behavior in the test harness. Many bugs sit one layer above the contract under review. A valid user operation rejected by one bundler and accepted by another points to spec interpretation risk, which becomes an operational problem in production.

The simplest review question is often the best one: what exact user intent does one signature authorize, once, on one chain, through which executor set, until when. If your team answers this differently across wallet code, relay code, and contract code, there is work left.

What to watch next

Gasless transfer designs are moving toward richer account abstraction patterns, session keys, and delegated execution. This reduces user friction. It also widens the space for replay, fee, and domain-separation mistakes.

Watch how teams specify signer intent at the protocol level, not only in code comments. Watch nonce models, relayer replacement rules, and token-behavior assumptions. Those are still the parts most likely to fail under real traffic.