Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC7144, a proposed standard for checking the safety of ERC20 token approvals and transfers.

This article translates, summarizes, and expands on the proposal below.

As of December 15, 2023, ERC7144 was in Review.

I have also covered a range of other ERCs.

Overview

This proposal extends ERC20 to improve token security. ERC20 defines a basic way to exchange tokens on a blockchain. The extension introduces a mechanism that holds transfers and approvals pending validation to check whether an operation is safe.

For example, when you initiate a token transfer to another account, it is not necessarily executed immediately. A validation step first determines whether the transfer is acceptable. This can help prevent unauthorized transactions and theft of funds from wallets.

The additional security mechanism is implemented in smart contracts. Smart contracts are programs that run on a blockchain. With this functionality, token holders can manage their assets with an additional layer of protection.

The proposal defines a framework for validation rather than prescribing a specific verification mechanism.

Motivation

Blockchains give users direct control over their own data, but that advantage also comes with risks. Token theft is a particularly serious problem. Existing theft prevention measures, such as moving tokens to an offline cold wallet, can reduce convenience.

Cold wallets A cold wallet is a way of storing the keys to digital assets such as cryptocurrencies and tokens offline. This contrasts with a hot wallet, which is connected to the internet and makes transactions convenient but exposes users to additional security risks.

The main characteristics of cold wallets are as follows.

  • Offline storage
    • Keeping keys offline reduces their exposure to hacking and online threats.
  • Improved security
    • Offline operation substantially reduces exposure to online attacks and malware.
  • Operational inconvenience
    • Transactions can take longer and require more effort than with a hot wallet.
    • Moving assets requires interacting with an online system, for example by transferring a signed transaction from the offline wallet for broadcasting.
  • Types
    • Cold wallets come in several forms.
    • Examples include hardware wallets (dedicated devices), paper wallets (private keys printed on paper), and computers or smartphones kept entirely offline.
  • Suitable for long-term storage
    • Cold wallets are particularly useful for long-term storage of assets that do not require frequent access.

Overall, cold wallets offer stronger isolation at the cost of additional effort when making transactions. They are often used for holding substantial assets or storing assets for long periods.

The proposal introduces a different solution. It adds a validation step when tokens are transferred (transfer) or approved (approve). This allows smart contract developers to design additional theft prevention measures.

One possible implementation is a system in which a designated validator address validates all relevant transactions involving the token contract. The address is connected to a decentralized application (dApp), through which users review validation requests for their tokens and authorize only legitimate operations.

The validator address is granted authority to validate transactions rather than unrestricted control over the tokens. An attacker attempting to steal tokens through an operation subject to validation would therefore need to control both the user's address and the validator address. Requiring both can improve the security of the system.

Specification

This Ethereum Improvement Proposal (EIP) proposes additional functionality for ERC20-compliant contracts.

When an operation such as transfer or transferFrom requires validation, rather than moving the tokens immediately, the contract must create a pending TransferValidation and emit a ValidateTransfer event. The tokens have not moved at this point.

Likewise, an operation granting permission to spend tokens, such as approve, must create a pending ApprovalValidation and emit a ValidateApproval event. The approval has not yet taken effect.

However, a transfer initiated by an authorized account other than the token owner is executed directly without an additional validation step. This accommodates existing projects that rely on approved accounts being able to move tokens directly.

When validating a TransferValidation or ApprovalValidation, the operation must set its valid field to true and must not permit it to be validated again.

Validating a TransferValidation is responsible for executing the corresponding change in token ownership. Validating an ApprovalValidation is responsible for activating the corresponding approval.

Contract interface

javascript
interface IERC7144 {

    struct TransferValidation {
        // The address of the owner.
        address from;
        // The address of the receiver.
        address to;
        // The token amount.
        uint256 amount;
        // Whether is a valid transfer.
        bool valid;
    }

    struct ApprovalValidation {
        // The address of the owner.
        address owner;
        // The spender address.
        address spender;
        // The token amount approved.
        uint256 amount;
        // Whether is a valid approval.
        bool valid;
    }

    /**
     * @dev Emitted when a new transfer validation has been requested.
     */
    event ValidateTransfer(address indexed from, address indexed to, uint256 amount, uint256 indexed transferValidationId);

    /**
    * @dev Emitted when a new approval validation has been requested.
    */
    event ValidateApproval(address indexed owner, address indexed spender, uint256 amount, uint256 indexed approvalValidationId);

    /**
     * @dev Returns true if this contract is a validator ERC20.
     */
    function isValidatorContract() external view returns (bool);

    /**
     * @dev Returns the transfer validation struct using the transfer ID.
     *
     */
    function transferValidation(uint256 transferId) external view returns (TransferValidation memory);

    /**
    * @dev Returns the approval validation struct using the approval ID.
    *
    */
    function approvalValidation(uint256 approvalId) external view returns (ApprovalValidation memory);

    /**
     * @dev Return the total amount of transfer validations created.
     *
     */
    function totalTransferValidations() external view returns (uint256);

    /**
     * @dev Return the total amount of transfer validations created.
     *
     */
    function totalApprovalValidations() external view returns (uint256);
}

The isValidatorContract() function

This function identifies whether the contract implements the validation mechanism. It is publicly accessible, allowing anyone to check whether the contract is a validator contract.

The transferValidation(uint256 transferId) function

Retrieves the details of a transfer validation associated with a particular transfer ID. The function may be implemented with public or external visibility. Other contracts and users can therefore retrieve this information.

The approvalValidation(uint256 approveId) function

Retrieves the details of an approval validation associated with a particular approval ID. Like transferValidation, it may be implemented with public or external visibility.

The totalTransferValidations() function

Returns the total number of transfer validations created so far. The interface declares it as view (reads but does not modify contract state); a pure implementation would only be possible if it did not need to read state.

The totalApprovalValidations() function: returns the total number of approval validations created so far. Like totalTransferValidations, the interface declares it as view, and pure would only be appropriate if no state access were needed.

These functions are important for tracking and managing transaction and approval workflows in smart contracts.

Variables

TransferValidation

javascript
struct TransferValidation {
    address from;
    address to;
    uint256 amount;
    bool valid;
}

Overview

A struct representing a token transfer validation.

Details

TransferValidation stores the details of a token transfer. These include the sender address, recipient address, amount to transfer, and whether the transfer has been validated.

Parameters

  • from
    • The address of the user sending the tokens.
  • to
    • The address of the user receiving the tokens.
  • amount
    • The amount of tokens to transfer.
  • valid
    • A boolean indicating whether the transfer has been validated.

ApprovalValidation

javascript
struct ApprovalValidation {
    address owner;
    address spender;
    uint256 amount;
    bool valid;
}

Overview

A struct representing a token approval validation.

Details

ApprovalValidation stores the details of a token approval. These include the token owner's address, the address of the authorized spender, the amount to approve, and whether the approval has been validated.

Parameters

  • owner
    • The address of the token owner.
  • spender
    • The address of the user authorized to spend the tokens.
  • amount
    • The amount of tokens to approve.
  • valid
    • A boolean indicating whether the approval has been validated.

ValidateTransfer

javascript
event ValidateTransfer(address indexed from, address indexed to, uint256 amount, uint256 indexed transferValidationId);

Overview

Emitted when a new transfer validation is requested.

Details

The ValidateTransfer event is emitted when a token transfer validation request is created. The event supplies the transfer validation ID along with the transfer details.

Parameters

  • from
    • The address of the user sending the tokens.
  • to
    • The address of the user receiving the tokens.
  • amount
    • The amount of tokens to transfer.
  • transferValidationId
    • The identifier for the transfer validation.

ValidateApproval

javascript
event ValidateApproval(address indexed owner, address indexed spender, uint256 amount, uint256 indexed approvalValidationId);

Overview

Emitted when a new approval validation is requested.

Details

The ValidateApproval event is emitted when a token approval validation request is created. The event supplies the approval validation ID along with the approval details.

Parameters

  • owner
    • The address of the token owner.
  • spender
    • The address of the user authorized to spend the tokens.
  • amount
    • The amount of tokens to approve.
  • approvalValidationId
    • The identifier for the approval validation.

Functions

isValidatorContract

javascript
function isValidatorContract() external view returns (bool);

Overview

Determines whether this contract implements the ERC20 validation extension.

Details

The isValidatorContract function checks whether the contract implements a validation mechanism for ERC20 tokens.

Return value

  • bool
    • Returns true if the contract identifies itself as a validator contract, or false otherwise.

transferValidation

javascript
function transferValidation(uint256 transferId) external view returns (TransferValidation memory);

Overview

Retrieves transfer validation data using a specified transfer ID.

Details

The transferValidation function returns the TransferValidation struct associated with a particular transfer ID. This allows the details of a particular transfer to be retrieved.

Parameters

  • transferId
    • The transfer ID used to retrieve the validation.

Return value

  • TransferValidation
    • The TransferValidation struct associated with the specified transfer ID.

approvalValidation

javascript
function approvalValidation(uint256 approvalId) external view returns (ApprovalValidation memory);

Overview

Retrieves approval validation data using a specified approval ID.

Details

The approvalValidation function returns the ApprovalValidation struct associated with a particular approval ID. This allows the details of a particular approval to be retrieved.

Parameters

  • approvalId
    • The approval ID used to retrieve the validation.

Return value

  • ApprovalValidation
    • The ApprovalValidation struct associated with the specified approval ID.

totalTransferValidations

javascript
function totalTransferValidations() external view returns (uint256);

Overview

Returns the total number of transfer validations created.

Details

The totalTransferValidations function returns the count of all transfer validations created so far.

Return value

  • uint256
    • The total number of transfer validations created.

totalApprovalValidations

javascript
function totalApprovalValidations() external view returns (uint256);

Overview

Returns the total number of approval validations created.

Details

The totalApprovalValidations function returns the count of all approval validations created so far.

Return value

  • uint256
    • The total number of approval validations created.

Additional considerations

This standard establishes the basic framework for token validation while allowing flexibility in how it is used. Two important features are its generality and extensibility.

Generality

  • The standard defines basic validation functionality but leaves its use to developers and users.
    • This is because the validation functionality is designed to operate internally.
  • For example, users could manage validation for their tokens using a designated validator address connected to a decentralized application (dApp).
  • The validator could apply to all tokens in the contract or be scoped to particular users.
  • It is also possible to wrap an existing ERC20 contract, allowing existing tokens to be exchanged for wrapped tokens at a one-to-one ratio.

Extensibility

  • The standard defines validation functionality without specifying the system that performs validation.
  • Third-party protocols can integrate with the functionality, subject to the implementation's authorization rules.

The standard defines rules for token validation but leaves developers and users free to determine how they are applied. This makes it possible to build flexible validation systems for different needs and circumstances.

Backwards compatibility

The proposal extends ERC20 and supports its usual operations while introducing new behavior for transfer, transferFrom, and approve where validation is required.

Conventional ERC20 contracts use these operations to move tokens or activate approvals directly. Under this extension, an operation requiring validation instead generates a validation request. When a user attempts such a transfer or approval, the operation is not executed immediately; a verification process begins to determine whether it should be accepted.

This adds a security layer to transfers and approvals and can reduce the risk of unauthorized transactions or incorrect approvals. It is intended to make token transactions and management safer.

Reference implementation

javascript
// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./IERC7144.sol";

/**
 * @dev Implementation of ERC7144
 */
contract ERC7144 is IERC7144, ERC20 {

    // Mapping from transfer ID to transfer validation
    mapping(uint256 => TransferValidation) private _transferValidations;

    // Mapping from approval ID to approval validation
    mapping(uint256 => ApprovalValidation) private _approvalValidations;

    // Total number of transfer validations
    uint256 private _totalTransferValidations;

    // Total number of approval validations
    uint256 private _totalApprovalValidations;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_){
    }

    /**
    * @dev Returns true if this contract is a validator ERC721.
    */
    function isValidatorContract() public pure returns (bool) {
        return true;
    }

    /**
     * @dev Returns the transfer validation struct using the transfer ID.
     *
     */
    function transferValidation(uint256 transferId) public view override returns (TransferValidation memory) {
        require(transferId < _totalTransferValidations, "ERC7144: invalid transfer ID");
        TransferValidation memory v = _transferValidation(transferId);

        return v;
    }

    /**
     * @dev Returns the approval validation struct using the approval ID.
     *
     */
    function approvalValidation(uint256 approvalId) public view override returns (ApprovalValidation memory) {
        require(approvalId < _totalApprovalValidations, "ERC7144: invalid approval ID");
        ApprovalValidation memory v = _approvalValidation(approvalId);

        return v;
    }

    /**
     * @dev Return the total amount of transfer validations created.
     *
     */
    function totalTransferValidations() public view override returns (uint256) {
        return _totalTransferValidations;
    }

    /**
     * @dev Return the total amount of approval validations created.
     *
     */
    function totalApprovalValidations() public view override returns (uint256) {
        return _totalApprovalValidations;
    }

    /**
     * @dev Returns the transfer validation of the `transferId`. Does NOT revert if transfer doesn't exist
     */
    function _transferValidation(uint256 transferId) internal view virtual returns (TransferValidation memory) {
        return _transferValidations[transferId];
    }

    /**
     * @dev Returns the approval validation of the `approvalId`. Does NOT revert if transfer doesn't exist
     */
    function _approvalValidation(uint256 approvalId) internal view virtual returns (ApprovalValidation memory) {
        return _approvalValidations[approvalId];
    }

    /**
     * @dev Validate the transfer using the transfer ID.
     *
     */
    function _validateTransfer(uint256 transferId) internal virtual {
        TransferValidation memory v = transferValidation(transferId);
        require(!v.valid, "ERC721V: the transfer is already validated");

        super._transfer(v.from, v.to, v.amount);

        _transferValidations[transferId].valid = true;
    }

    /**
     * @dev Validate the approval using the approval ID.
     *
     */
    function _validateApproval(uint256 approvalId) internal virtual {
        ApprovalValidation memory v = approvalValidation(approvalId);
        require(!v.valid, "ERC7144: the approval is already validated");

        super._approve(v.owner, v.spender, v.amount);

        _approvalValidations[approvalId].valid = true;
    }

    /**
     * @dev Create a transfer petition of `tokenId` from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * Emits a {ValidateTransfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        require(from != address(0), "ERC7144: transfer from the zero address");
        require(to != address(0), "ERC7144: transfer to the zero address");

        if(_msgSender() == from) {
            TransferValidation memory v;

            v.from = from;
            v.to = to;
            v.amount = amount;

            _transferValidations[_totalTransferValidations] = v;

            emit ValidateTransfer(from, to, amount, _totalTransferValidations);

            _totalTransferValidations++;
        } else {
            super._transfer(from, to, amount);
        }
    }

    /**
     * @dev Create an approval petition from `owner` to operate the `amount`
     *
     * Emits an {ValidateApproval} event.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual override {
        require(owner != address(0), "ERC7144: approve from the zero address");
        require(spender != address(0), "ERC7144: approve to the zero address");

        ApprovalValidation memory v;

        v.owner = owner;
        v.spender = spender;
        v.amount = amount;

        _approvalValidations[_totalApprovalValidations] = v;

        emit ValidateApproval(v.owner, spender, amount, _totalApprovalValidations);

        _totalApprovalValidations++;
    }
}

Security considerations

This proposal defines new behavior for operations that change token ownership or grant authority to manage tokens. Under the standard, transfers (transfer) and approvals (approve) that require validation enter a pending TransferValidation or ApprovalValidation state rather than executing immediately. These operations require appropriate validation before the tokens move or the approval takes effect.

Operations that validate transfers and approvals require strong security controls. One possible approach is to designate an address responsible for validating transactions. Users could also choose their own validator address, which would be the only address authorized to validate their requests.

The key requirement is that no address can validate transfers or approvals without authorization from the chosen validation system. This can make token transactions and management safer and reduce the risk of unauthorized transactions or erroneous approvals.

Citation

Eduard López i Fina (@eduardfina), "ERC-7144: ERC-20 with transaction validation step. [DRAFT]," Ethereum Improvement Proposals, no. 7144, May 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7144.

Conclusion

This article covered ERC7144, a proposed standard for checking the safety of ERC20 token approvals and transfers. I hope you found it useful.

If you have any questions, feel free to contact me via Twitter DM.

Twitter @cardene777

I also publish on other platforms, which you can find below.

https://chaldene.net/