EIPs Explained

ERC-6997 · Review · ERC · 2023-05-07

ERC-6997: ERC-721 with transaction validation step.

An ERC-721 extension where owner-initiated transfers and approvals only create pending requests that a separate validator must confirm, so a stolen key alone cannot drain a wallet's NFTs.

What problem does it solve?

NFT theft usually comes down to one compromised key or one malicious signature: the attacker calls transferFrom or setApprovalForAll and everything is gone. Keeping NFTs in a cold wallet helps, but makes them awkward to use.

ERC-6997 adds a second factor at the token level. Moving or approving an NFT from the owner's account no longer takes effect immediately; it creates a request that some separate validation system must approve. A thief would need both the owner's key and the validator's.

How it works

  • When the owner calls transferFrom / safeTransferFrom, the contract records a TransferValidation {from, to, tokenId, valid} and emits ValidateTransfer. Ownership does not change yet.
  • approve / setApprovalForAll likewise record an ApprovalValidation {owner, approve, tokenId, approveAll, valid} and emit ValidateApproval, without granting anything.
  • Validating a request performs the transfer or grants the approval, and sets valid = true. A request can never be validated twice.
  • Transfers made by an already-approved account (not the owner) execute immediately, so existing marketplaces that pull NFTs via approvals still work.
  • Views: isValidatorContract() (returns true), transferValidation(id), approvalValidation(id), totalTransferValidations(), totalApprovalValidations().

The standard deliberately does not say who validates or how. Examples given: a single validator address connected to a dApp where users review and accept requests, or a per-user chosen validator. It could also be deployed as a wrapper around an existing ERC-721.

Sample code

Adding a validator role on top of the spec's reference implementation (which exposes internal _validateTransfer / _validateApproval):

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;

import "./ERC6997.sol"; // reference implementation from the EIP

contract GuardedNFT is ERC6997 {
    address public immutable validator;

    constructor(address validator_) ERC6997("Guarded", "GRD") {
        validator = validator_;
    }

    function confirmTransfer(uint256 id) external {
        require(msg.sender == validator, "not validator");
        _validateTransfer(id);   // moves the token, marks valid
    }

    function confirmApproval(uint256 id) external {
        require(msg.sender == validator, "not validator");
        _validateApproval(id);   // grants approve / approveAll
    }
}

A dApp for the validator would watch ValidateTransfer and ValidateApproval events and let the user confirm the legitimate ones.

Things to know

  • Status is Review; it may still change.
  • Approvals are the escape hatch: once an operator has been validated, its transfers are not checked again. The security of the scheme rests on approvals being validated carefully.
  • The validator's own permissions become the critical secret. If it is compromised along with the owner key, the protection is gone.
  • Wallets and tools that assume transferFrom from the owner moves the token immediately will show confusing results; the transaction succeeds but ownership doesn't change until validation.

#nft #erc721 #security #anti-theft

Details

Authors
Eduard López i Fina (@eduardfina)
Status
Review
Type
Standards Track / ERC
Created
2023-05-07
Requires

Machine-readable: Markdown · JSON