Nimiq GaslessTransfer Audit
OpenZeppelin Security
Findings
Total issues: 5 (5 resolved)
Critical: 0 (0 resolved) · High: 0 (0 resolved) · Medium: 0 (0 resolved) · Low: 0 (0 resolved)
Notes & Additional Information
5 notes raised (5 resolved)
Client Reported Issues
0 reported issues (0 resolved)
Scope
OpenZeppelin performed an audit of the NimiqToolbox/gasless-transfer repository at commit 837fb6b.
In scope were the following files:
contracts
└── src
├── GaslessTransfer.sol
├── base
│ └── GaslessBase.sol
└── libraries
└── TokenAuthLib.solUpdate: The fixes for the findings highlighted in this report have all been merged at commit e932cae.
System Overview
GaslessTransfer lets a user send USDC or USDT0 on Polygon PoS without holding POL for gas. The sender signs an EIP-712 transfer intent off-chain. A relay submits the intent, pays the gas, and receives a fee in the transferred token. The contract takes no custody: it pulls the fee and the amount from the sender and sends them to the relay and the recipient in one atomic call. The contract is not upgradeable and has no pause or rescue mechanism.
Transfer Intent: An intent binds the token, the sender, the recipient, the amount, the fee, the relay, a deadline, the nonce of the sender, and the token authorization. The contract verifies the ECDSA signature of the sender over all of these fields before any other check or external call. Only the relay that the intent names can submit it. Each sender has one sequential nonce, so at most one intent for each nonce executes. A sender can cancel pending intents by raising its own nonce with a direct call.
Token Authorization: The TokenAuthLib library obtains the allowance that a transfer needs. The sender selects one of three modes, and the owner enables the modes for each token. In the permit mode, the contract calls the ERC-2612 permit function of the token with a signature of the sender. In the meta-transaction mode, the contract submits a signed approve call through the meta-transaction entry point of USDT0. In the third mode, the contract spends an allowance that the sender granted beforehand.
In the two signature modes, the contract sets the spender to itself and the value to the amount plus the fee. It also sets the permit deadline to the intent deadline. The contract ignores the outcome of the token call and then requires the allowance to equal the amount plus the fee. Therefore, a third party that submits the token signature first cannot block the transfer. No allowance remains after the call.
Token Configuration: The GaslessBase contract stores the enabled modes of each token. The constructor sets the initial tokens. The owner can later add a token, replace its configuration, or remove it. The deployment on Polygon PoS enables the permit and existing-allowance modes for USDC, and all three modes for USDT0.
Security Model and Trust Assumptions
The central guarantee is that the tokens of an account move only if that account signed the exact request that executes. A standing allowance to the contract cannot be spent without such a signature. The following actors and assumptions determine the security of the system.
Sender: The sender chooses the recipient, the amount, the fee, the relay, the deadline, and the authorization mode. The contract enforces no fee limit, so the signed fee is paid in full. The client software is therefore trusted to build the typed data correctly, to display the recipient, the amount, and the fee, and to enforce a fee limit. A signed intent stays executable until its nonce is used or its deadline passes. This also holds if the relay fails, or if the owner later enables a token or a mode that the contract refused before. An on-chain cancellation is a direct call by the sender and requires POL. The client software is out of scope.
Accounts With Code: The contract accepts only ECDSA signatures and does not support ERC-1271, so smart contract accounts cannot sign intents. An EIP-7702 delegated account can sign an intent with its key. However, USDC validates the permit of any account with code through ERC-1271, and not through ECDSA. The permit mode of USDC then depends on the code that the account delegates to. USDT0 validates permits and meta-transactions through ECDSA only. The Nimiq team stated that the contract intentionally does not validate the token signature and relies only on the resulting allowance.
Relay: The relay is not an on-chain role. Any address can act as the relay of an intent that names it. The relay can submit an intent or withhold it, but it cannot change the amount, the fee, the recipient, or the token authorization. If the relay withholds an intent, the later nonces of the sender wait until the deadline passes or the sender signs a replacement for another relay. The relay pays the gas of a failed submission. A sender can invalidate a request shortly before its inclusion, so the relay is expected to manage this risk off-chain. The relay infrastructure is out of scope.
Owner: The owner is managed through Ownable2Step and controls only the token configuration. The owner cannot move tokens, change nonces, or alter a signed request. By removing a token or a mode, the owner can make pending requests fail. By adding one, the owner can make a previously refused request executable while its nonce and deadline are still valid. If the owner renounces ownership, the configuration becomes permanent. During the audit, the owner of the deployment on Polygon PoS was an externally owned account.
Token Issuers: USDC and USDT0 are trusted to transfer the exact requested amounts and to reduce the allowance by the transferred value. Both tokens are upgradeable by their issuers, who can also pause transfers or block individual accounts. If an issuer blocks the contract, all transfers of that token revert. A change of the token name by the issuer of USDT0 changes its EIP-712 domain, and the client software must then update its signing data. The contract assumes tokens without transfer fees or transfer hooks. The Nimiq team stated that each additional token will be checked for compatibility before the owner enables it.
Token Signatures: A permit expires at the intent deadline. A USDT0 meta-transaction has no expiry and stays valid until the token nonce of the sender changes. Once a relay broadcasts a token signature, anyone can execute it on the token. Such an execution moves no tokens, but it consumes the token nonce and sets an allowance of the signed value for the contract. A different token signature that the sender signed for the same token nonce can therefore make a pending transfer revert. The client software is expected to prefer the permit mode and to avoid signing several token authorizations for one token nonce.
Notes & Additional Information
Inconsistent Signature Verification for Accounts With Code
The _verify function validates the intent signature with ECDSA only. However, in PERMIT mode, the permit call forwards the token signature to USDC. If the sender has code, USDC validates the signature through ERC-1271 and never falls back to ECDSA.
As a result, the two signatures of a single request are validated under different schemes:
- For an EIP-7702 delegated account,
_verifyvalidates the intent against the key of the account, whereas the delegate of the account validates the USDC permit. If the delegate does not implement ERC-1271, the permit fails and the transfer reverts withInsufficientAllowance. This also affects requests signed before the delegation was set. - A smart contract account can produce a permit that USDC accepts, but it can never sign an intent.
USDT0 is not affected because it validates both permits and meta-transactions with ecrecover.
Consider documenting this behavior for integrators and ensuring that clients detect accounts with code before offering the PERMIT mode for USDC. Alternatively, if support for smart contract accounts is desired, consider validating the intent signature with SignatureChecker, which applies the same rule as USDC.
Update: Resolved in pull request #1 at commit 220d56d.
Missing Event Emission in relayTransfer
The relayTransfer function consumes the nonce of the sender and moves tokens without emitting an event. This is a documented design decision.
However, clients are required to reconcile the on-chain outcome before creating a new payment because several requests signed for the same nonce can coexist. Without an event, identifying which request was executed requires scanning the Transfer logs of the token, fetching the transaction calldata, and recomputing the digest. Furthermore, transfers cannot be indexed by filtering logs on the contract address. If the relay is a contract, attributing Transfer logs to a request also requires traces.
Consider emitting an event in relayTransfer that includes the sender, the consumed nonce, and the request digest.
Update: Resolved in pull request #2 at commit 39571a6.
Missing Docstrings
Throughout the codebase, multiple instances of missing docstrings were identified:
- The
TRANSFER_TYPEHASHconstant and the_hashStructfunction inGaslessTransfer.sol - The
TOKEN_AUTH_TYPEHASHconstant and thetokenConfig,DOMAIN_SEPARATOR,_enabled, and_requireRelayfunctions inGaslessBase.sol
Consider documenting all functions and constants that are part of the public API, as well as internal functions implementing sensitive logic, following the Ethereum Natural Specification Format (NatSpec).
Update: Resolved in pull request #3 at commit 2f19063.
Incomplete Docstrings
Throughout the codebase, multiple instances of internal functions that implement sensitive logic and do not document their parameters were identified:
_collectinGaslessTransfer.sol_setTokenConfig,_requireToken,_checkDeadline, and_verifyinGaslessBase.solensureAllowanceinTokenAuthLib.sol
Consider documenting all parameters of the functions listed above, following the Ethereum Natural Specification Format (NatSpec).
Update: Resolved in pull request #3 at commit 07dd746.
Variable Initialized With Its Default Value
In the constructor of the GaslessBase contract, the i loop counter is explicitly initialized to 0, which is already its default value.
Consider not initializing variables with their default values to improve code clarity and avoid redundant operations.
Update: Resolved in pull request #4 at commit 9e6ac94.
Conclusion
GaslessTransfer lets users send USDC and USDT0 on Polygon PoS without holding POL. A sender signs a transfer intent, and a relay submits it in exchange for a fee in the transferred token. OpenZeppelin audited the transfer contract, its base contract, and the token authorization library.
No issues of low or higher severity were identified. The audit identified only notes. They concern docstrings, the absence of an event in the transfer path, a redundant initialization, and the different signature schemes that apply to accounts with code. The codebase is small and limits its attack surface: it has no upgrade path, takes no custody, and gives the owner no access to user funds. The repository contains a detailed protocol reference, as well as unit, invariant, and fork tests against the live tokens. The design restricts flexibility in several places, such as the closed relay, the ECDSA-only intents, and the exact permit value and deadline. The Nimiq team confirmed that these restrictions are deliberate.
The security of the system also depends on components outside the audited contracts. The client software must enforce a fee limit and the documented signing rules, because the contract pays whatever fee the sender signed. The relay must manage failed submissions off-chain. In addition, the contract relies on the behavior of USDC and USDT0, and their issuers can upgrade both tokens. Therefore, any token change or addition requires a compatibility review.
The Nimiq team was responsive throughout the audit and provided thorough documentation of the protocol.
Appendix
Issue Classification
OpenZeppelin classifies smart contract vulnerabilities on a 5-level scale:
- Critical
- High
- Medium
- Low
- Note/Information
Critical Severity
This classification is applied when the issue’s impact is catastrophic, threatening extensive damage to the client's reputation and/or causing severe financial loss to the client or users. The likelihood of exploitation can be high, warranting a swift response. Critical issues typically involve significant risks such as the permanent loss or locking of a large volume of users' sensitive assets or the failure of core system functionalities without viable mitigations. These issues demand immediate attention due to their potential to compromise system integrity or user trust significantly.
High Severity
These issues are characterized by the potential to substantially impact the client’s reputation and/or result in considerable financial losses. The likelihood of exploitation is significant, warranting a swift response. Such issues might include temporary loss or locking of a significant number of users' sensitive assets or disruptions to critical system functionalities, albeit with potential, yet limited, mitigations available. The emphasis is on the significant but not always catastrophic effects on system operation or asset security, necessitating prompt and effective remediation.
Medium Severity
Issues classified as being of medium severity can lead to a noticeable negative impact on the client's reputation and/or moderate financial losses. Such issues, if left unattended, have a moderate likelihood of being exploited or may cause unwanted side effects in the system. These issues are typically confined to a smaller subset of users' sensitive assets or might involve deviations from the specified system design that, while not directly financial in nature, compromise system integrity or user experience. The focus here is on issues that pose a real but contained risk, warranting timely attention to prevent escalation.
Low Severity
Low-severity issues are those that have a low impact on the client's operations and/or reputation. These issues may represent minor risks or inefficiencies to the client's specific business model. They are identified as areas for improvement that, while not urgent, could enhance the security and quality of the codebase if addressed.
Notes & Additional Information Severity
This category is reserved for issues that, despite having a minimal impact, are still important to resolve. Addressing these issues contributes to the overall security posture and code quality improvement but does not require immediate action. It reflects a commitment to maintaining high standards and continuous improvement, even in areas that do not pose immediate risks.