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 covers ERC6808, a proposal for Fungible Key Bound Tokens (FKBTs) designed to make ERC20 token transfers and management more secure.

This explanation translates, summarizes, and expands on the following specification.

As of September 16, 2023, ERC6808 was at the Last Call stage.

Overview

Fungible Key Bound Tokens (FKBTs) are a category of Key Bound Tokens (KBTs) implemented through smart contracts. FKBT defines common token rules and interfaces, with addBindings providing the foundation for its optional security mechanism. The addBindings function designates separate Key Wallets that can authorize token transfers. Through this mechanism, token spending can be authorized before the holder or a third-party on-chain entity uses the tokens.

The main idea is to embed optional security functionality directly into the fungible asset. This functionality is provided through functions such as allowTransfer and allowApproval. A designated Key Wallet calls these functions to enable the Holding Wallet to invoke ERC20 transfer or approve, respectively. This separates the roles involved in holding and authorizing the use of tokens. The Holding Wallet holds the assets, while the Key Wallets can authorize their use and approvals. A user can retain ordinary fungible ERC20 behavior by not invoking addBindings.

FKBT targets individuals seeking additional protection for fungible assets, as well as third-party wallet providers, brokers, banks, insurers, and other participants. The proposal aims to reduce the risk of unauthorized transfers and theft by implementing asset-level protection within a self-custody model.

Terminology

Key Wallets

Either _keyWallet1 or _keyWallet2. These wallets can call safeFallback, resetBindings, allowTransfer, and allowApproval.

Safe Transfer

A transfer authorized by one of the designated Key Wallets.

Holding Wallet

The wallet holding the FKBTs.

Default behavior

The ordinary behavior of the existing fungible ERC20 standard.

Crypto Scam Reports

Reports of cryptocurrency scams received by the US Federal Trade Commission between January 2021 and March 2022.

Amount Stolen

Reported cryptocurrency scam losses during the same period.

Default values

Default values used for ordinary fungible ERC20 token behavior.

Amount

The amount of FKBTs intended to be used.

Time in allowTransfer

The _time parameter specifies the transfer authorization period. The reference implementation measures the duration in seconds using block.timestamp.

Address (_address)

The address to which the FKBTs are sent.

allFunds (_allFunds)

A Boolean value that can be true or false.

Time in allowApproval

The _time parameter specifies the approval authorization period. The reference implementation uses a duration in seconds.

Number of Transfers (_numberOfTransfers)

The number of transfers a third-party entity may perform on the user's behalf.

_keyWallet1

One of the two Key Wallets configured when calling addBindings.

_keyWallet2

One of the two Key Wallets configured when calling addBindings.

PoS Protocol

A cryptocurrency consensus mechanism used to process transactions and produce new blocks.

Motivation

In a rapidly evolving technological environment, people learn and adapt at different rates. When considering cryptocurrency adoption, it is important to account for users of different ages and backgrounds. Self-custodial wallets give users control over their security, but also place responsibility for protecting their assets on them. Losses caused by mistakes may not be recoverable.

Between January 2021 and March 2022, the US Federal Trade Commission received reports of cryptocurrency scams from more than 46,000 people. The reported consumer losses exceeded one billion US dollars. Fraud and abusive behavior affect the wider financial sector and can lead to stricter regulation. Some participants in the Web3 and blockchain ecosystem, however, prefer approaches that do not depend on government regulation. Both centralized and decentralized security approaches have been explored. The proposal seeks a solution that retains their benefits while reducing their drawbacks.

The authors posed a question that many people had considered before. Rather than asking how to protect the wallet, they asked how to protect the assets themselves. A wallet can be created without charge; the assets stored in it are what carry value. This question motivated the development of Key Bound Tokens (KBTs). The security mechanism is optional and can be configured according to the user's needs. While the security mechanism is active, it can provide additional protection if a Holding Wallet's seed phrase or private key is exposed. Its effectiveness depends on the remaining keys, permissions, and implementation.

The authors identified a need to improve security for the widely used ERC20 token standard. Security of fungible assets concerns participants throughout the cryptocurrency ecosystem. FKBT focuses on asset-level protection in addition to wallet security and aims to provide a scalable, decentralized security mechanism. The mechanism is implemented on-chain, allowing users with blockchain access to use it without relying exclusively on specialized hardware or centralized security services. FKBT was designed as an alternative retaining the familiar ERC20 token functionality. This allows integration with dApps designed for traditional fungible tokens, subject to the optional authorization requirements.

The development of Key Bound Tokens was motivated by the following intended benefits.

Decentralized security

KBT security functionality is implemented on-chain and is intended to avoid requiring a third-party custodian. This supports self-custody, allowing users to retain control through their designated wallets.

Broad accessibility

Centralized services may require account registration and impose geographic restrictions. The KBT mechanism itself does not require a separate service account or geographic registration. Although decentralized solutions may also face scalability constraints, users can access KBT wherever they have access to the relevant blockchain.

Optional security

KBT security functionality is optional, configurable, and removable. Users can choose their preferred security configuration.

Default functionality

Users who want to use KBTs as ordinary ERC20 tokens do not need to activate the additional security functionality. The tokens retain familiar fungible-token functionality, and users who activate the mechanism can customize its settings. Users may set custom or default values directly or through a dApp.

Security

KBT introduces additional security through addBindings, requiring Key Wallet authorization for protected direct transfers and approval operations. This is intended to reduce several risks associated with relying on a Holding Wallet alone.

Security precautions

KBT is designed to provide recovery options if the Holding Wallet or one of the Key Wallets is compromised, although protection is not unconditional. If the Holding Wallet is compromised, a Key Wallet can call safeFallback to move the tokens to the other designated Key Wallet. If a Key Wallet is compromised, an authorized Key Wallet can call resetBindings, after which new Key Wallets can be configured. Because resetting removes protection, the security of the Holding Wallet during recovery remains important.

Security without identity registration

KBT does not inherently require users to submit personal information; its operations can be performed using blockchain addresses. This avoids a separate identity-registration requirement, but public blockchain addresses and transactions remain traceable.

Low-cost security

The cost of KBT security operations depends on on-chain transaction fees, whose gas prices are commonly expressed in gwei.

Environmental considerations

The security functionality is encoded on-chain and does not itself require manufacturing a dedicated physical security device or operating a separate centralized service. The authors view this as a way to limit additional infrastructure requirements; the underlying blockchain still consumes resources.

User experience

Users can activate the optional security functionality by calling addBindings. Two other wallets are required to act as the designated Key Wallets (_keyWallet1 and _keyWallet2; the trailing numbers in the source are footnote-like artifacts). The optional mechanism is intended to improve the user experience for security-conscious participants in the Ethereum ecosystem.

Specification

IKBT20 (token contract)

The following specification uses Solidity 0.8.0 or later syntax.

Callers must handle a false return value where the function can return one. The calling code must check whether a function call succeeds or fails and handle its result appropriately.

A call is not guaranteed to succeed; callers must account for a possible false result.

javascript
interface IKBT20 {
    event AccountSecured(address _account, uint256 _amount);
    event AccountResetBinding(address _account);
    event SafeFallbackActivated(address _account);
    event AccountEnabledTransfer(
        address _account,
        uint256 _amount,
        uint256 _time,
        address _to,
        bool _allFunds
    );
    event AccountEnabledApproval(
        address _account,
        uint256 _time,
        uint256 _numberOfTransfers
    );
    event Ingress(address _account, uint256 _amount);
    event Egress(address _account, uint256 _amount);

    struct AccountHolderBindings {
        address firstWallet;
        address secondWallet;
    }

    struct FirstAccountBindings {
        address accountHolderWallet;
        address secondWallet;
    }

    struct SecondAccountBindings {
        address accountHolderWallet;
        address firstWallet;
    }

    struct TransferConditions {
        uint256 amount;
        uint256 time;
        address to;
        bool allFunds;
    }

    struct ApprovalConditions {
        uint256 time;
        uint256 numberOfTransfers;
    }

    function addBindings(
        address _keyWallet1,
        address _keyWallet2
    ) external returns (bool);

    function getBindings(
        address _account
    ) external view returns (AccountHolderBindings memory);

    function resetBindings() external returns (bool);

    function safeFallback() external returns (bool);

    function allowTransfer(
        uint256 _amount,
        uint256 _time,
        address _to,
        bool _allFunds
    ) external returns (bool);

    function getTransferableFunds(
        address _account
    ) external view returns (TransferConditions memory);

    function allowApproval(
        uint256 _time,
        uint256 _numberOfTransfers
    ) external returns (bool);

    function getApprovalConditions(
        address account
    ) external view returns (ApprovalConditions memory);

    function getNumberOfTransfersAllowed(
        address _account,
        address _spender
    ) external view returns (uint256);

    function isSecureWallet(address _account) external view returns (bool);
}

Events

AccountSecured

javascript
AccountSecured(address _account, uint256 _amount)

Overview

Event emitted when _account is secured by calling addBindings.

Details

  • _account
    • Account address.
  • _amount
    • Current account balance.

AccountResetBinding

javascript
AccountResetBinding(address _account)

Overview

Event emitted when an account holder's Key Wallet bindings are reset through resetBindings.

Details

  • _account
    • Account address.

SafeFallbackActivated

javascript
SafeFallbackActivated(address _account)

Overview

Event emitted when safeFallback moves all of a holder's tokens to a designated Key Wallet.

Details

  • _account
    • Account address.

AccountEnabledTransfer

javascript
AccountEnabledTransfer(address _account, uint256 _amount, uint256 _time, address _to, bool _allFunds)

Overview Event emitted when transfers are enabled for _account through allowTransfer.

Details Records authorization to transfer the specified _amount to _to within the period represented by _time. It is also emitted when _allFunds is set to true to authorize transfers without the individual amount, time, and recipient constraints.

Parameters

  • _account
    • Account address.
  • _amount
    • Authorized token amount.
  • _time
    • Transfer authorization time value, represented as a timestamp in the reference implementation.
  • _to
    • Authorized recipient address.
  • _allFunds
    • true if the unrestricted transfer option is enabled; otherwise, false.

AccountEnabledApproval

javascript
AccountEnabledApproval(address _account, uint256 _time, uint256 _numberOfTransfers)

Overview

Event emitted when allowApproval configures approval authorization for _account, recording _time and _numberOfTransfers.

Details

  • _account
    • Account address.
  • _time
    • Approval authorization time value.
  • _numberOfTransfers
    • Authorized number of transfers.

Ingress

javascript
Ingress(address _account, uint256 _amount)

Overview

Event emitted when _account becomes a token holder. _amount is the account's current balance.

Details

  • _account
    • Account address.
  • _amount
    • Current account balance.

Egress

javascript
Egress(address _account, uint256 _amount)

Overview

Event emitted when _account transfers all its tokens and ceases to be a holder. _amount is the account's previous balance.

Details

  • _account
    • Account address.
  • _amount
    • Previous account balance.

Functions

addBindings

javascript
function addBindings(address _keyWallet1, address _keyWallet2) external returns (bool)

Overview

Secures the caller's account using two distinct wallets, _keyWallet1 and _keyWallet2, and emits AccountSecured.

Details

The function must revert under the following conditions.

  • The caller is not a token holder.
  • The caller's account is already secured.
  • Both Key Wallets have the same address.
  • A Key Wallet has the same address as the caller.
  • Either Key Wallet is the zero address (0x0).
  • Either Key Wallet is already bound to another holder account.

Parameters

  • _keyWallet1
    • First Key Wallet address.
  • _keyWallet2
    • Second Key Wallet address.

Return value

  • true if the bindings are added successfully; otherwise, false.

getBindings

javascript
function getBindings(address _account) external view returns (AccountHolderBindings memory)

Overview

Returns the Key Wallets associated with _account as a struct.

Parameters

  • _account
    • Account address.

Return value

  • Returns an AccountHolderBindings struct.

resetBindings

javascript
function resetBindings() external returns (bool)

Overview

Allows a Key Wallet to reset a holder account's bindings and emits AccountResetBinding.

Details This is useful when one of the two Key Wallets has been compromised. The function must revert under the following conditions.

  • The caller is not an authorized Key Wallet.

Return value

  • true if the bindings are reset successfully; otherwise, false.

safeFallback

javascript
function safeFallback() external returns (bool);

Overview Allows an authorized Key Wallet to transfer all tokens from the holder account to the other Key Wallet and emits SafeFallbackActivated.

Details This is useful if the holder account is compromised. The function must revert under the following conditions.

  • The caller is not an authorized Key Wallet.

Return value

  • true if the safe fallback succeeds; otherwise, false.

allowTransfer

javascript
function allowTransfer(uint256 _amount, uint256 _time, address _to, bool _allFunds) external returns (bool);

Overview

Authorizes a specified token amount to be transferred to a specified address within a specified period.

Details

  • Called by a Key Wallet before the holder invokes the transfer function.
  • If _amount is 0, there is no individual amount limit.
  • If _time is 0, there is no individual time limit.
  • If _to is the zero address, there is no individual destination restriction.
  • If _allFunds is true, the transfer is unrestricted by the other parameters. In the reference implementation, the authorization is cleared after the next successful direct transfer; without _allFunds, setting all three other values to zero does not authorize a transfer.
  • Emits AccountEnabledTransfer.

The function must revert under the following conditions.

  • The caller is not an authorized Key Wallet.
  • _amount exceeds the holder account's balance.

Parameters

  • _amount
    • Token amount to transfer.
  • _time
    • Transfer authorization duration in seconds in the reference implementation.
  • _to
    • Transfer destination address.
  • _allFunds
    • true to enable the unrestricted transfer option; otherwise, false.

Return value

  • true if authorization succeeds; otherwise, false.

getTransferableFunds

javascript
function getTransferableFunds(address _account) external view returns (TransferConditions memory);

Overview

Retrieves the transfer conditions of _account.

Details

Used to retrieve the transfer conditions associated with the specified account. Returns a TransferConditions struct containing the permitted amount (amount), time value (time), destination (to), and a Boolean flag (allFunds) for the unrestricted transfer option.

Parameters

  • _account
    • Address of the account whose transfer conditions are requested.

Return value

  • TransferConditions
    • Struct representing the transfer conditions.
    • amount
      • Permitted transfer amount.
    • time
      • Transfer authorization time value.
    • to
      • Transfer destination address.
    • allFunds
      • Boolean indicating whether the unrestricted transfer option is enabled.

allowApproval

javascript
function allowApproval(uint256 _time, uint256 _numberOfTransfers) external returns (bool);

Overview

Enables approval within the specified _time period and configures the _numberOfTransfers limit that applies to the resulting spender allowance.

Details

Called by a Key Wallet to configure approval conditions. It is called before approve, increaseAllowance, or decreaseAllowance is invoked by the secured account. During the authorization period, the holder may configure a spender allowance with the specified transfer-count limit. This restricts the number of delegated transfers the spender may perform from the account. It emits AccountEnabledApproval and must revert if the caller is not an authorized Key Wallet.

Parameters

  • _time
    • Time value determining the approval authorization period.
  • _numberOfTransfers
    • Maximum authorized transfer count.
    • A value of 0 means the transfer count is unrestricted.

Return value

  • bool
    • Returns true on success or false otherwise.

getApprovalConditions

javascript
function getApprovalConditions(address _account) external view returns (ApprovalConditions memory);

Overview

Retrieves the approval conditions of _account.

Details

Used to retrieve the specified account's approval conditions. Returns an ApprovalConditions struct containing the timestamp (time) through which approve, increaseAllowance, or decreaseAllowance may be called, and the number of transfers (numberOfTransfers) authorized for the spender.

Parameters

  • _account
    • Address of the account whose approval conditions are requested.

Return value

  • ApprovalConditions
    • time
      • Timestamp through which the approval-management functions may be called.
    • numberOfTransfers
      • Number of transfers authorized for the spender.

transfer

javascript
function transfer(address _to, uint256 _amount) external returns (bool);

Overview

Transfers _amount tokens to _to.

Details

Reverts if the caller lacks sufficient tokens or, for a secured account, lacks the required authorization from allowTransfer. Emits a Transfer event. A zero-value transfer is treated as a normal token transfer.

Parameters

  • _to
    • Token recipient address.
  • _amount
    • Token amount to transfer.

Return value

  • bool
    • Returns true on success or false otherwise.

approve

javascript
function approve(address _spender, uint256 _amount) external returns (bool);

Overview

Approves _spender to spend up to _amount tokens through one or more transfers.

Details

For a secured caller, the function reverts if approval authorization has not been enabled through allowApproval or its configured time has expired. It emits an Approval event, replaces the existing allowance with the specified value, and records the transfer-count limit established by allowApproval.

Parameters

  • _spender
    • Address authorized to spend tokens.
  • _amount
    • Token amount to approve.
    • An approval amount of 0 grants no positive spending allowance. The transfer-count parameter, rather than the approval amount, controls whether the number of transfers is unrestricted.

Return value

  • bool
    • Returns true on success or false otherwise.

increaseAllowance

javascript
function increaseAllowance(address _spender, uint256 _addedValue) external returns (bool);

Overview

Increases the allowance granted to _spender.

Details

For a secured caller, the required approval authorization must be present and unexpired. The zero spender address is not permitted. Emits Approval and adds the specified _addedValue to the existing allowance.

Parameters

  • _spender
    • Address authorized to spend tokens.
  • _addedValue
    • Token amount by which to increase the allowance.

Return value

  • bool
    • Returns true on success or false otherwise.

decreaseAllowance

javascript
function decreaseAllowance(address _spender, uint256 _subtractedValue) external returns (bool);

Overview

Decreases the allowance granted to _spender.

Details

For a secured caller, the required approval authorization must be present and unexpired. The zero spender address is not permitted. Emits Approval and subtracts the specified _subtractedValue from the existing allowance. The resulting allowance must not be negative.

Parameters

  • _spender
    • Address authorized to spend tokens.
  • _subtractedValue
    • Token amount to subtract from the allowance.

Return value

  • bool
    • Returns true on success or false otherwise.

transferFrom

javascript
function transferFrom(address _from, address _to, uint256 _amount) external returns (bool);

Overview

Transfers _amount tokens from _from to _to.

Details

The call must satisfy the applicable spender allowance; otherwise, it reverts. When a finite authorized transfer count is used, the count decreases on each delegated transfer. When the final authorized transfer is executed, the reference implementation sets the remaining allowance to zero. A zero-value transfer is treated as a normal token transfer and emits Transfer.

Parameters

  • _from
    • Token source address.
  • _to
    • Token destination address.
  • _amount
    • Token amount to transfer.

Return value

  • bool
    • Returns true on success or false otherwise.

Additional considerations

Consistency and backward compatibility

The development of FKBT emphasized consistency with existing ERC20 tokens. This means that FKBT retains familiar ERC20 behavior when the additional security mechanism is not enabled. Existing ERC20-compatible platforms and dApps can integrate FKBT, although secured accounts must satisfy the added authorization conditions.

Self-custodial security

FKBT provides an additional self-custodial security mechanism. Users can manage their own tokens and configure how the assets are protected. This design reflects the importance of security and user control in a decentralized ecosystem.

Inheriting ERC20 functionality

FKBT retains ordinary ERC20 token functionality. It includes fundamental operations such as transfers, approvals, and allowance increases and decreases. This supports integration with ERC20-compatible services and dApps.

Providing user choice

FKBT allows users to choose ordinary token behavior. Users can customize how the token behaves when using the optional security functionality. This enables users to adapt FKBT to their requirements.

Encouraging broad implementation and adoption

The design considers how FKBT can be widely implemented and adopted. It aims to avoid requiring major changes to the existing decentralized ecosystem. The authors expect these compatibility goals to facilitate adoption.

Design of allowTransfer and allowApproval

The allowTransfer and allowApproval functions are designed to return a Boolean on success and revert on failure. This follows a familiar ERC20-style pattern and provides predictable behavior for developers and users.

Backward compatibility

Key Bound Tokens (KBTs) are designed with backward compatibility for existing token standards and wallets in mind. Fungible Key Bound Tokens retain familiar token functionality, so existing wallets can continue to interact with them, subject to the security mechanism's authorization requirements when enabled.

Tests

The test code is available at the following link.

https://eips.ethereum.org/assets/eip-6808/test/kbt20.js

The following table reproduces the reported average gas figures. The original table labels these figures as gwei. Gas consumption is normally measured in gas units, while gwei is a denomination of gas price or Ether; the figures and original label are retained for reference.

Function Reported average gas figure (original label: GWEI)
addBindings 154,991
resetBindings 30,534
safeFallback 51,013
allowTransfer 49,887
allowApproval 44,971

Reference implementation

The following diagram illustrates the design.

https://eips.ethereum.org/assets/eip-6808/Contract%20Interactions%20diagram.svg

The reference implementation is available at the following link.

https://github.com/ethereum/EIPs/blob/master/assets/eip-6808/contracts/KBT20.sol

_holderAccounts

javascript
mapping(address => AccountHolderBindings) private _holderAccounts;

Overview

Mapping associating accounts with their binding information.

Details

Stores FKBT accounts and their associated binding information. Each account is associated with an AccountHolderBindings struct containing its bindings.


_firstAccounts

javascript
mapping(address => FirstAccountBindings) private _firstAccounts;

Overview

Mapping associating accounts with their first-wallet binding information.

Details

Each account is associated with a FirstAccountBindings struct containing its first-wallet binding information.


_secondAccounts

javascript
mapping(address => SecondAccountBindings) private _secondAccounts;

Overview

Mapping associating accounts with their second-wallet binding information.

Details

Each account is associated with a SecondAccountBindings struct containing its second-wallet binding information.


_transferConditions

javascript
mapping(address => TransferConditions) private _transferConditions;

Overview

Mapping associating accounts with their transfer conditions.

Details

Each account is associated with a TransferConditions struct containing its transfer conditions.


_approvalConditions

javascript
mapping(address => ApprovalConditions) private _approvalConditions;

Overview

Mapping associating accounts with their approval conditions.

Details

Each account is associated with an ApprovalConditions struct containing its approval conditions.


_numberOfTransfersAllowed

javascript
mapping(address => mapping(address => uint256)) private _numberOfTransfersAllowed;

Overview

Mapping associating accounts and their spenders with authorized transfer counts.

Details

For each account and spender pair, stores the corresponding authorized transfer count.

Parameters

  • _account
    • Address of the account granting transfer authorization.
  • _spender
    • Address of the authorized spender.

addBindings

javascript
function addBindings(
    address _keyWallet1,
    address _keyWallet2
) external returns (bool) {
    address sender = _msgSender();
    require(balanceOf(sender) > 0, "[200] KBT20: Wallet is not a holder");
    require(
        _holderAccounts[sender].firstWallet == address(0) &&
            _holderAccounts[sender].secondWallet == address(0),
        "[201] KBT20: Key wallets are already filled"
    );
    require(
        _keyWallet1 != address(0) && _keyWallet2 != address(0),
        "[202] KBT20: Does not follow 0x standard"
    );
    require(
        _keyWallet1 != _keyWallet2,
        "[205] KBT20: Key wallet 1 must be different than key wallet 2"
    );
    require(
        _keyWallet1 != sender,
        "[206] KBT20: Key wallet 1 must be different than the sender"
    );
    require(
        sender != _keyWallet2,
        "[207] KBT20: Key wallet 2 must be different than the sender"
    );
    require(
        _firstAccounts[_keyWallet1].accountHolderWallet == address(0),
        "[203] KBT20: Key wallet 1 is already registered"
    );
    require(
        _secondAccounts[_keyWallet2].accountHolderWallet == address(0),
        "[204] KBT20: Key wallet 2 is already registered"
    );

    _holderAccounts[sender] = AccountHolderBindings({
        firstWallet: _keyWallet1,
        secondWallet: _keyWallet2
    });

    _firstAccounts[_keyWallet1] = FirstAccountBindings({
        accountHolderWallet: sender,
        secondWallet: _keyWallet2
    });

    _secondAccounts[_keyWallet2] = SecondAccountBindings({
        accountHolderWallet: sender,
        firstWallet: _keyWallet1
    });

    emit AccountSecured(sender, balanceOf(sender));

    return true;
}

Overview

Binds Key Wallets to an FKBT holder account.

Details

Allows an FKBT holder to bind two Key Wallets to their account. The designated wallets are used by the optional security functionality. The holder must specify distinct Key Wallets and have a nonzero token balance. The Key Wallet addresses must not be identical to each other or to the caller.

Parameters

  • _keyWallet1
    • Address of the first Key Wallet to bind.
  • _keyWallet2
    • Address of the second Key Wallet to bind.

Return value

  • bool
    • true if the bindings are added successfully; otherwise, false.

getBindings

javascript
function getBindings(
    address _account
) external view returns (AccountHolderBindings memory) {
    return _holderAccounts[_account];
}

Overview

Retrieves the binding information associated with a specified account.

Details

Returns the binding information for the specified account. The information includes the first and second Key Wallet addresses.

Parameters

  • ``_account`
    • Address of the account whose bindings are requested.

Return value

  • AccountHolderBindings memory
    • AccountHolderBindings struct containing the binding information.

resetBindings

javascript
function resetBindings() external returns (bool) {
    address accountHolder = _getAccountHolder();
    require(
        accountHolder != address(0),
        "[300] KBT20: Key authorization failure"
    );

    delete _firstAccounts[_holderAccounts[accountHolder].firstWallet];
    delete _secondAccounts[_holderAccounts[accountHolder].secondWallet];
    delete _holderAccounts[accountHolder];

    emit AccountResetBinding(accountHolder);

    return true;
}

Overview

Resets the bindings and disables the associated security mechanism.

Details

Deletes the binding information, disabling the additional security mechanism. Removes the wallet bindings associated with the holder account.

Return value

  • bool
    • true if the reset succeeds; otherwise, false.

safeFallback

javascript
function safeFallback() external returns (bool) {
    address accountHolder = _getAccountHolder();
    address otherSecureWallet = _getOtherSecureWallet();
    require(
        accountHolder != address(0),
        "[400] KBT20: Key authorization failure"
    );

    _transfer(accountHolder, otherSecureWallet, balanceOf(accountHolder));

    emit SafeFallbackActivated(accountHolder);

    return true;
}

Overview

Activates the safe fallback and moves FKBTs to the other Key Wallet.

Details

Transfers the holder account's entire FKBT balance to the other designated Key Wallet. This provides an alternative recovery path when the Holding Wallet is unavailable or compromised.

Return value

  • bool
    • true if activation succeeds; otherwise, false.

allowTransfer

javascript
function allowTransfer(
    uint256 _amount,
    uint256 _time,
    address _to,
    bool _allFunds
) external virtual returns (bool) {
    address accountHolder = _getAccountHolder();

    require(
        accountHolder != address(0),
        "[500] KBT20: Key authorization failure"
    );
    require(
        balanceOf(accountHolder) >= _amount,
        "[501] KBT20: Not enough tokens"
    );

    _time = _time > 0 ? (block.timestamp + _time) : 0;

    _transferConditions[accountHolder] = TransferConditions({
        amount: _amount,
        time: _time,
        to: _to,
        allFunds: _allFunds
    });

    emit AccountEnabledTransfer(
        accountHolder,
        _amount,
        _time,
        _to,
        _allFunds
    );

    return true;
}

Overview

Configures transfer conditions and authorizes a protected token transfer.

Details

Sets the holder account's transfer conditions and enables a transfer subject to those conditions. The conditions include the amount, permitted time, destination address, and unrestricted transfer flag.

Parameters

  • _amount
    • Transfer amount.
  • _time
    • Duration in seconds, converted into an expiration timestamp by the reference implementation.
  • _to
    • Destination address receiving the tokens.
  • _allFunds
    • Boolean indicating whether the unrestricted transfer option is enabled.

Return value

  • bool
    • true if the conditions are configured successfully; otherwise, false.

getTransferableFunds

javascript
function getTransferableFunds(
    address _account
) external view returns (TransferConditions memory) {
    return _transferConditions[_account];
}

Overview

Retrieves the transfer conditions configured for a specified account.

Details

Returns the transfer conditions associated with the specified account. These conditions include the permitted amount, validity time, recipient address, and unrestricted transfer flag.

Parameters

  • _account
    • Address of the account whose transfer conditions are requested.

Return value

  • TransferConditions memory
    • TransferConditions struct containing the transfer conditions.

allowApproval

javascript
function allowApproval(
    uint256 _time,
    uint256 _numberOfTransfers
) external virtual override returns (bool) {
    address accountHolder = _getAccountHolder();
    require(
        accountHolder != address(0),
        "[600] KBT20: Key authorization failure"
    );

    _time = block.timestamp + _time;

    _approvalConditions[accountHolder].time = _time;
    _approvalConditions[accountHolder]
        .numberOfTransfers = _numberOfTransfers;

    emit AccountEnabledApproval(accountHolder, _time, _numberOfTransfers);

    return true;
}

Overview

Configures approval conditions and enables an approval operation under those conditions.

Details

Sets approval conditions for the holder account. These conditions include the expiration timestamp for approval authorization and the permitted number of delegated transfers.

Parameters

  • _time
    • Authorization duration in seconds, added to block.timestamp.
  • _numberOfTransfers
    • Number of authorized transfers.

Return value

  • bool
    • true if the approval conditions are configured successfully; otherwise, false.

getApprovalConditions

javascript
function getApprovalConditions(
    address _account
) external view returns (ApprovalConditions memory) {
    return _approvalConditions[_account];
}

Overview

Retrieves the approval conditions configured for a specified account.

Details

Returns the approval conditions associated with the specified account. The conditions include the approval authorization expiration timestamp and the authorized transfer count.

Parameters

  • _account
    • Address of the account whose approval conditions are requested.

Return value

  • ApprovalConditions memory
    • ApprovalConditions struct containing the approval conditions.

getNumberOfTransfersAllowed

javascript
function getNumberOfTransfersAllowed(
    address _account,
    address _spender
) external view returns (uint256) {
    return _numberOfTransfersAllowed[_account][_spender];
}

Overview

Retrieves the number of transfers authorized for a specified spender by a specified account.

Details

Returns the transfer-count limit recorded for the specified account and spender.

Parameters

  • _account
    • Address of the account whose authorization is queried.
  • _spender
    • Spender address whose transfer count is requested.

Return value

  • uint256
    • Authorized transfer count.

isSecureWallet

javascript
function isSecureWallet(address _account) public view returns (bool) {
    return
        _holderAccounts[_account].firstWallet != address(0) &&
        _holderAccounts[_account].secondWallet != address(0);
}

Overview

Checks whether a specified account is secured.

Details

Determines whether the specified account has activated the security mechanism. A secured account has designated first and second Key Wallets bound to it.

Parameters

  • _account
    • Address of the account to check.

Return value

  • bool
    • true if the account is secured; otherwise, false.

transfer

javascript
function transfer(
    address _to,
    uint256 _amount
) public virtual override returns (bool) {
    address _owner = _msgSender();

    if (isSecureWallet(_owner)) {
        require(
            _hasAllowedTransfer(_owner, _amount, _to),
            "[100] KBT20: Sender is a secure wallet and doesn't have approval for the amount"
        );
    }

    _transfer(_owner, _to, _amount);

    delete _transferConditions[_owner];

    return true;
}

Overview

Transfers tokens to a specified address.

Details

Transfers the specified token amount from the caller to the designated recipient. If the caller is a secured account, checks that the transfer satisfies the configured authorization conditions.

Parameters

  • _to
    • Token recipient address.
  • _amount
    • Token amount to transfer.

Return value

  • bool
    • true if the transfer succeeds; otherwise, false.

approve

javascript
function approve(
    address _spender,
    uint256 _amount
) public virtual override returns (bool) {
    address _owner = _msgSender();
    if (isSecureWallet(_owner)) {
        require(
            _approvalConditions[_owner].time > 0,
            "[101] KBT20: Spending of funds is not authorized."
        );
        require(
            _isApprovalAllowed(_owner),
            "[102] KBT20: Time has expired for the spending of funds"
        );
    }

    _approve(_owner, _spender, _amount);

    _numberOfTransfersAllowed[_owner][_spender] = _approvalConditions[
        _owner
    ].numberOfTransfers;

    delete _approvalConditions[_owner];

    return true;
}

Overview

Authorizes a specified address to spend up to a specified quantity of the caller's tokens.

Details

The caller grants the specified address (the spender) a token allowance. If the caller is secured, checks that the approval authorization conditions are satisfied.

Parameters

  • _spender
    • Address authorized to spend tokens.
  • _amount
    • Token amount approved for the spender.

Return value

  • bool
    • true if the approval succeeds; otherwise, false.

transferFrom

javascript
function transferFrom(
    address _from,
    address _to,
    uint256 _amount
) public virtual override returns (bool) {
    address spender = _msgSender();
    _spendAllowance(_from, spender, _amount);
    _transfer(_from, _to, _amount);

    if (_numberOfTransfersAllowed[_from][spender] != 0) {
        if (_numberOfTransfersAllowed[_from][spender] == 1) {
            _approve(_from, spender, 0);
        }
        _numberOfTransfersAllowed[_from][spender] -= 1;
    }
    return true;
}

Overview

Transfers tokens from one specified address to another.

Details

Transfers the specified token amount from the source address to the destination address. The reference implementation spends the delegated allowance, performs the transfer, and updates a finite transfer-count limit if one is configured.

Parameters

  • _from
    • Address from which tokens are transferred.
  • _to
    • Token recipient address.
  • _amount
    • Token amount to transfer.

Return value

  • bool
    • true if the transfer succeeds; otherwise, false.

increaseAllowance

javascript
function increaseAllowance(
    address _spender,
    uint256 _addedValue
) public virtual override returns (bool) {
    address _owner = _msgSender();
    require(
        _approvalConditions[_owner].time > 0,
        "[101] KBT20: Spending of funds is not authorized."
    );
    require(
        _isApprovalAllowed(_owner),
        "[102] KBT20: Time has expired for the spending of funds"
    );

    _approve(_owner, _spender, allowance(_owner, _spender) + _addedValue);

    delete _approvalConditions[_owner];

    return true;
}

Overview

Increases the token amount a spender may spend.

Details

Increases the allowance granted to the specified spender. Checks the required approval authorization when the caller is a secured account.

Parameters

  • _spender
    • Address authorized to spend tokens (spender).
  • _addedValue
    • Additional token amount to approve for the spender.

Return value

  • bool
    • true if the allowance update succeeds; otherwise, false.

decreaseAllowance

javascript
function decreaseAllowance(
    address _spender,
    uint256 _subtractedValue
) public virtual override returns (bool) {
    address _owner = _msgSender();
    require(
        _approvalConditions[_owner].time > 0,
        "[101] KBT20: Spending of funds is not authorized."
    );
    require(
        _isApprovalAllowed(_owner),
        "[102] KBT20: Time has expired for the spending of funds"
    );

    uint256 currentAllowance = allowance(_owner, _spender);
    require(
        currentAllowance >= _subtractedValue,
        "ERC20: decreased allowance below zero"
    );
    unchecked {
        _approve(_owner, _spender, currentAllowance - _subtractedValue);
    }

    delete _approvalConditions[_owner];

    return true;
}

Overview

Decreases the token amount a spender may spend.

Details

Decreases the allowance granted to the specified spender. Checks the required approval authorization when the caller is a secured account.

Parameters

  • _spender
    • Address authorized to spend tokens (spender).
  • _subtractedValue
    • Token amount to subtract from the spender's allowance.

Return value

  • bool
    • true if the allowance update succeeds; otherwise, false.

_afterTokenTransfer

javascript
function _afterTokenTransfer(
    address from,
    address to,
    uint256 amount
) internal virtual override {
    // region update secureAccounts
    if (isSecureWallet(from) && balanceOf(from) == 0) {
        delete _firstAccounts[_holderAccounts[from].firstWallet];
        delete _secondAccounts[_holderAccounts[from].secondWallet];
        delete _holderAccounts[from];
    }
    // endregion

    if (balanceOf(from) == 0) {
        emit Egress(from, amount);
    }

    if (balanceOf(to) == amount) {
        emit Ingress(to, amount);
    }
}

Overview

Manages operations performed after a token transfer.

Details

Performs additional actions after the token transfer completes. If the source is a secured account and its token balance becomes zero, removes its associated wallet bindings. It also emits Egress when the source balance becomes zero and Ingress when the recipient's balance equals the transferred amount.

Parameters

  • from
    • Token source address.
  • to
    • Token destination address.
  • amount
    • Amount of tokens transferred.

_hasAllowedTransfer

javascript
function _hasAllowedTransfer(
    address _account,
    uint256 _amount,
    address _to
) internal view returns (bool) {
    TransferConditions memory conditions = _transferConditions[_account];

    if (conditions.allFunds) {
        return true;
    }

    if (
        (conditions.amount == 0 &&
            conditions.time == 0 &&
            conditions.to == address(0)) ||
        (conditions.amount > 0 && conditions.amount < _amount) ||
        (conditions.time > 0 && conditions.time < block.timestamp) ||
        (conditions.to != address(0) && conditions.to != _to)
    ) {
        return false;
    }

    return true;
}

Overview

Determines whether a token transfer is authorized.

Details

Checks whether the specified account has authorized the transfer under the given conditions. Checks any configured constraints on the amount, validity time, and destination. In the reference implementation, _allFunds bypasses these checks, whereas all-zero amount, time, and destination values without that flag do not authorize a transfer.

Parameters

  • _account
    • Account address from which tokens would be transferred.
  • _amount
    • Token amount to transfer.
  • _to
    • Token destination address.

Return value

  • bool
    • true if the transfer is authorized; otherwise, false.

_isApprovalAllowed

javascript
function _isApprovalAllowed(address account) internal view returns (bool) {
    return _approvalConditions[account].time >= block.timestamp;
}

Overview

Determines whether approval management is currently authorized.

Details

Checks whether the specified account has valid approval authorization. The reference implementation compares the stored authorization timestamp with block.timestamp.

Parameters

  • account
    • Account whose approval authorization is checked.

Return value

  • bool
    • true if approval management is authorized; otherwise, false.

_getAccountHolder

javascript
function _getAccountHolder() internal view returns (address) {
    address sender = _msgSender();
    return
        _firstAccounts[sender].accountHolderWallet != address(0)
            ? _firstAccounts[sender].accountHolderWallet
            : (
                _secondAccounts[sender].accountHolderWallet != address(0)
                    ? _secondAccounts[sender].accountHolderWallet
                    : address(0)
            );
}

Overview

Retrieves the holder account associated with a Key Wallet.

Details

Retrieves the holder account bound to the caller's address. This association is used by Key Wallet operations that manage the holder account's tokens. The reference implementation first checks the first-wallet mapping, then the second-wallet mapping, and returns the corresponding holder if found.

Return value

  • address
    • Holder account address, or address(0) if no binding exists.

_getOtherSecureWallet

javascript
function _getOtherSecureWallet() internal view returns (address) {
    address sender = _msgSender();
    address accountHolder = _getAccountHolder();

    return
        _holderAccounts[accountHolder].firstWallet == sender
            ? _holderAccounts[accountHolder].secondWallet
            : _holderAccounts[accountHolder].firstWallet;
}

Overview

Retrieves the other Key Wallet associated with a secured account.

Details

Returns the other Key Wallet bound to the same holder account as the caller. This address is used as the destination for the safe fallback operation.

Return value

  • address
    • Address of the other designated Key Wallet.
    • address(0) if no such binding exists.

Security considerations

Key Wallets

  • When calling addBindings, the user must designate two wallets.
  • These wallets act as _keyWallet1 and _keyWallet2 and are added together.
  • Configuring both wallets in one operation is intended to reduce fees, manual errors, and incomplete setup.
  • Two Key Wallets are required to provide the alternative destination used by safeFallback.
  • When security is enabled, FKBT operates with three wallet addresses: the Holding Wallet and two Key Wallets.

safeFallback

  • Intended for situations where the owner believes the Holding Wallet has been compromised or can no longer access it.
  • A user can call safeFallback from _keyWallet1, moving the FKBTs from the Holding Wallet to the other Key Wallet.
  • This can reduce exposure to a compromised Holding Wallet, provided the recovery path remains secure.

resetBindings

  • Intended for situations where the owner believes _keyWallet1 or _keyWallet2 has been compromised or can no longer access it.
  • An authorized Key Wallet can call resetBindings to remove both bindings and reset the security mechanism.
  • FKBT returns to ordinary ERC20 behavior until new Key Wallets are configured.

allowTransfer

  • Provides configurable transfer authorization and permits dApps to use ordinary ERC20-style transfer behavior when the required authorization is present.

  • The user can configure the transfer details or enable the unrestricted transfer option. In the reference implementation, this authorization is consumed by a successful direct transfer.

  • The security properties depend on the user's configuration and protection of the designated keys.

  • Four parameters allow different transfer authorization configurations.

    • _amount8
      • Amount of FKBTs authorized for the transfer.
    • _time9
      • Transfer authorization duration, measured in seconds by the reference implementation.
    • _address10
      • Transfer destination address.
    • _allFunds11
      • Boolean flag that, when true, removes the individual amount, time, and destination restrictions for the authorized transfer.

allowApproval

  • Provides additional controls when third parties spend a user's FKBTs.
  • Intended to reduce the risk of unauthorized approval operations and constrain delegated transfers.
  • Two parameters allow different approval authorization configurations.
    • _time12
      • Duration during which a spender approval may be configured, measured in seconds by the reference implementation.
    • _numberOfTransfers13
      • Number of transfers a third party may execute on the user's behalf.

These design choices allow FKBT users to configure additional security controls. The reference implementation's approval deadline applies when configuring an allowance, not as a separate expiry check on each transferFrom; already granted allowances and compromise of an authorized Key Wallet must therefore also be considered.

References

Mihai Onila (@MihaiORO), Nick Zeman (@NickZCZ), Narcis Cotaie (@NarcisCRO), "ERC-6808: Fungible Key Bound Token [DRAFT]," Ethereum Improvement Proposals, no. 6808, March 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6808.

Conclusion

This article covered ERC6808, a proposal for Fungible Key Bound Tokens (FKBTs) designed to improve security when transferring ERC20-style assets. I hope it helped clarify the mechanism.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/