-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Submit EIP-4973 - Account-bound tokens #4973
Merged
Merged
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b8e717d
Add EIP-1238.md
TimDaub 391cca9
Rename from 1238 to 4966
TimDaub 9754700
Address feedback from PR
TimDaub 8d7368e
Change name from 4966 to 4973
TimDaub 6c2a00c
Fix header property order
TimDaub 40522db
Remove 79 character manual word wrapping
TimDaub 2e2dd82
Fix syntax error for incomplete link tag
TimDaub 82dc89a
Remove Caveat section (for now)
TimDaub 503d9c5
Clarify standards text
TimDaub c5dfe52
Run through grammarly
TimDaub 48304f8
Update discussion link
TimDaub cd26e76
Update EIPS/eip-4973.md
TimDaub c6b6c2b
Update EIPS/eip-4973.md
TimDaub 594bdaa
Update EIPS/eip-4973.md
TimDaub f2bf116
Update EIPS/eip-4973.md
TimDaub 73525e9
Relicense to CC0-1.0
TimDaub b71be06
More copyediting
TimDaub bc16f29
Rename from "Soulbound" to "Account-bound" tokens
TimDaub 9e26685
Add section on "Exception handling"
TimDaub a68efbe
Add section on revocation
TimDaub 15527ff
Update EIPS/eip-4973.md
TimDaub 22641bd
Rename to 'Account-bound Tokens'
TimDaub 845c337
Correct co-author section
TimDaub 057710f
Correct TLA from non-sensical 'ACT' to 'ABT'
TimDaub 9ef6c49
Remove superfluous, explicit interface definitions
TimDaub 04d7113
Add 'Naming' section
TimDaub c7a6e03
Consistently use EIP-XXXX format
TimDaub 1a0b1ba
Remove reference to badge concept
TimDaub 21ae681
Correctly apply camelCase in tests
TimDaub 835c9f2
Update reference implementation
TimDaub 6754cba
Replace `event Transfer` w/ Attest/Revoke
TimDaub 4be4df0
Fix username prefix in author field
TimDaub 5df30fc
Fix broken link to eip-721.md
TimDaub 1aefe9a
Fix typo
TimDaub acdc991
Fix link to reference implementation
TimDaub 50d2c65
Update EIPS/eip-4973.md
MicahZoltu 194f910
Update EIPS/eip-4973.md
TimDaub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
eip: 4973 | ||
title: Account-bound Tokens | ||
description: A standard interface for non-transferrable non-fungible tokens, also known as "account-bound" or "soulbound tokens" or "badges". | ||
author: Tim Daubenschütz (TimDaub), Raphael Roullet (@ra-phael), Nicola Greco (@nicola) | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
discussions-to: https://ethereum-magicians.org/t/eip-4973-non-transferrable-non-fungible-tokens-soulbound-tokens-or-badges/8825 | ||
status: Draft | ||
type: Standards Track | ||
category: ERC | ||
created: 2022-04-01 | ||
requires: 165, 721 | ||
--- | ||
|
||
## Abstract | ||
|
||
Proposes a standard API for account-bound Tokens (ABT) within smart contracts. An ABT is a non-fungible token bound to a single account, and cannot be transferred between accounts. This EIP defines basic functionality to gift, mint, and track ABTs. | ||
|
||
## Motivation | ||
|
||
The Ethereum community has expressed a need for non-transferrable, non-fungible tokens. Common use cases include tracking an individual's achievements (which can be used as credentials), or items that cannot be transferred (like certain loot in multiplayer online games). | ||
|
||
The purpose of this document is to make ABTs a reality on Ethereum by creating consensus around a **maximally backward-compatible** but otherwise **minimal** interface definition. | ||
|
||
## Specification | ||
|
||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. | ||
|
||
`EIP-4973` tokens _must_ implement the interfaces: | ||
|
||
- [EIP-165](./eip-165.md)'s `ERC165` (`0x01ffc9a7`) | ||
- [EIP-721](./eip-721.md)'s `ERC721Metadata` (`0x5b5e139f`) | ||
|
||
`EIP-4973` tokens _must not_ implement the interfaces: | ||
|
||
- [EIP-721](./eip-721.md)'s `ERC721` (`0x80ac58cd`) | ||
|
||
```solidity | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.6; | ||
|
||
/// @title Account-bound tokens | ||
/// @dev See https://eips.ethereum.org/EIPS/eip-4973 | ||
/// Note: the ERC-165 identifier for this interface is 0x6352211e. | ||
interface IERC4973 /* is ERC165, ERC721Metadata */ { | ||
/// @dev This emits when a new token is created and bound to an account by | ||
/// any mechanism. | ||
/// Note: For a reliable `_from` parameter, retrieve the transaction's | ||
/// authenticated `from` field. | ||
event Attest(address indexed _to, uint256 indexed _tokenId); | ||
/// @dev This emits when an existing ABT is revoked from an account and | ||
/// destroyed by any mechanism. | ||
/// Note: For a reliable `_from` parameter, retrieve the transaction's | ||
/// authenticated `from` field. | ||
event Revoke(address indexed _to, uint256 indexed _tokenId); | ||
/// @notice Find the address bound to an ERC4973 account-bound token | ||
/// @dev ABTs assigned to zero address are considered invalid, and queries | ||
/// about them do throw. | ||
/// @param _tokenId The identifier for an ABT | ||
/// @return The address of the owner bound to the ABT | ||
function ownerOf(uint256 _tokenId) external view returns (address); | ||
} | ||
``` | ||
|
||
See [`EIP-721`](./eip-721.md) for a definition of its metadata JSON Schema. | ||
|
||
## Rationale | ||
|
||
### Interface | ||
|
||
`EIP-4973` shall be maximally backward-compatible but still only expose a minimal and simple to implement interface definition. | ||
|
||
As [`EIP-721`](./eip-721.md) tokens have seen widespread adoption with wallet providers and marketplaces, using its `ERC721Metadata` interface with [`EIP-165`](./eip-165.md) for feature-detection potentially allows implementers to support `EIP-4973` tokens out of the box. | ||
|
||
If an implementer of [`EIP-721`](./eip-721.md) properly built [`EIP-165`](./eip-165.md)'s `function supportsInterface(bytes4 interfaceID)` function, already by recognizing that [`EIP-721`](./eip-721.md)'s track and transfer interface component with the identifier `0x80ac58cd` is not implemented, transferring of a token should not be suggested as a user interface option. | ||
|
||
Still, however, since `EIP-4973` supports [`EIP-721`](./eip-721.md)'s `ERC721Metadata` extension, an account-bound token should be displayed in wallets and marketplaces with no changes needed. | ||
|
||
Although other possible implementations of account-bound tokens are possible, e.g., by having all transfer functions revert, `EIP-4973` is superior as it supports feature detection through [`EIP-165`](./eip-165.md). | ||
|
||
### Exception handling | ||
|
||
Given the non-transferable between accounts property of ABTs, if a user's keys to an account or a contract get compromised or rotated, a user may lose the ability to associate themselves with the token. In some cases, this can be the desired effect. Therefore, it is suggested to implement re-issuance and potential revocation processes on the issuer side to enable recourse when it is not. | ||
|
||
This document is deliberately abstaining from offering a standardized form of exception handling in cases where user keys are compromised or rotated. | ||
|
||
In cases where implementers want to make account-bound tokens sharable among different accounts, e.g., to avoid losing access when keys get compromised, we suggest issuing the account-bound token towards a contract's account that implements a multi-signature functionality. | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Provenance Indexing | ||
|
||
ABTs can be indexed by tracking the emission of `event Attest` and `event Revoke`. To guarantee reliable and implementation-independent indexable information, neither `event Attest` nor `event Revoke` include a `from` argument to depict the transaction sender. Instead, as a `from` property wouldn't be authenticated and hence opens a security vector, we omit it and advise indexers to substitute it with the transaction-level `from` field which gets authenticated through Ethereum's transaction signature validation prior to inclusion in a block. | ||
|
||
## Backwards Compatibility | ||
|
||
We have adopted the [`EIP-165`](./eip-165.md) and `ERC721Metadata` functions purposefully to create a high degree of backward compatibility with [`EIP-721`](./eip-721.md). We have deliberately used [`EIP-721`](./eip-721md`) terminology such as `function ownerOf(...)` to minimize the effort of familiarization for `EIP-4973` implementers already familiar with, e.g., [`EIP-20`](./eip-20.md) or [`EIP-721`](./eip-721.md). | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Reference Implementation | ||
|
||
You can find an implementation of this standard in [../assets/eip-4973](../assets/eip-4973). | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
MicahZoltu marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/IERC165.sol"; | ||
|
||
/** | ||
* @dev Implementation of the {IERC165} interface. | ||
* | ||
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check | ||
* for the additional interface id that will be supported. For example: | ||
* | ||
* ```solidity | ||
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); | ||
* } | ||
* ``` | ||
* | ||
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. | ||
*/ | ||
abstract contract ERC165 is IERC165 { | ||
/** | ||
* @dev See {IERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
return interfaceId == type(IERC165).interfaceId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.6; | ||
|
||
import {ERC165} from "./ERC165.sol"; | ||
|
||
import {IERC721Metadata} from "./interfaces/IERC721Metadata.sol"; | ||
import {IERC4973} from "./interfaces/IERC4973.sol"; | ||
|
||
|
||
abstract contract ERC4973 is ERC165, IERC721Metadata, IERC4973 { | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string private _name; | ||
string private _symbol; | ||
|
||
mapping(uint256 => address) private _owners; | ||
mapping(uint256 => string) private _tokenURIs; | ||
|
||
constructor( | ||
string memory name_, | ||
string memory symbol_ | ||
) { | ||
_name = name_; | ||
_symbol = symbol_; | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) public view override returns (bool) { | ||
return | ||
interfaceId == type(IERC721Metadata).interfaceId || | ||
interfaceId == type(IERC4973).interfaceId || | ||
super.supportsInterface(interfaceId); | ||
} | ||
|
||
function name() public view virtual override returns (string memory) { | ||
return _name; | ||
} | ||
|
||
function symbol() public view virtual override returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { | ||
require(_exists(tokenId), "tokenURI: token doesn't exist"); | ||
return _tokenURIs[tokenId]; | ||
} | ||
|
||
function _exists(uint256 tokenId) internal view virtual returns (bool) { | ||
return _owners[tokenId] != address(0); | ||
} | ||
|
||
function ownerOf(uint256 tokenId) public view virtual returns (address) { | ||
address owner = _owners[tokenId]; | ||
require(owner != address(0), "ownerOf: token doesn't exist"); | ||
return owner; | ||
} | ||
|
||
function _mint( | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
address to, | ||
uint256 tokenId, | ||
string calldata uri | ||
) internal virtual returns (uint256) { | ||
require(!_exists(tokenId), "mint: tokenID exists"); | ||
_owners[tokenId] = to; | ||
_tokenURIs[tokenId] = uri; | ||
emit Attest(to, tokenId); | ||
return tokenId; | ||
} | ||
|
||
function _burn(uint256 tokenId) internal virtual { | ||
address owner = ownerOf(tokenId); | ||
|
||
delete _owners[tokenId]; | ||
delete _tokenURIs[tokenId]; | ||
|
||
emit Revoke(owner, tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.6; | ||
|
||
import {DSTest} from "ds-test/test.sol"; | ||
import {IERC165} from "./interfaces/IERC165.sol"; | ||
|
||
import {IERC721Metadata} from "./interfaces/IERC721Metadata.sol"; | ||
import {IERC4973} from "./interfaces/IERC4973.sol"; | ||
import {ERC4973} from "./ERC4973.sol"; | ||
|
||
contract AccountBoundToken is ERC4973 { | ||
constructor() ERC4973("Name", "Symbol") {} | ||
|
||
function mint( | ||
address to, | ||
uint256 tokenId, | ||
string calldata uri | ||
) external returns (uint256) { | ||
return super._mint(to, tokenId, uri); | ||
} | ||
|
||
function burn(uint256 tokenId) external { | ||
super._burn(tokenId); | ||
} | ||
} | ||
|
||
contract ERC4973Test is DSTest { | ||
AccountBoundToken abt; | ||
|
||
function setUp() public { | ||
abt = new AccountBoundToken(); | ||
} | ||
|
||
function testIERC165() public { | ||
assertTrue(abt.supportsInterface(type(IERC165).interfaceId)); | ||
} | ||
|
||
function testIERC721Metadata() public { | ||
assertTrue(abt.supportsInterface(type(IERC721Metadata).interfaceId)); | ||
} | ||
|
||
function testIERC4973() public { | ||
assertTrue(abt.supportsInterface(type(IERC4973).interfaceId)); | ||
} | ||
|
||
function testCheckMetadata() public { | ||
assertEq(abt.name(), "Name"); | ||
assertEq(abt.symbol(), "Symbol"); | ||
} | ||
|
||
function testMint() public { | ||
string memory tokenURI = "https://example.com/metadata.json"; | ||
uint256 tokenId = 0; | ||
abt.mint(msg.sender, tokenId, tokenURI); | ||
assertEq(abt.tokenURI(tokenId), tokenURI); | ||
assertEq(abt.ownerOf(tokenId), msg.sender); | ||
} | ||
|
||
function testMintToExternalAddress() public { | ||
address thirdparty = address(1337); | ||
string memory tokenURI = "https://example.com/metadata.json"; | ||
uint256 tokenId = 0; | ||
abt.mint(thirdparty, tokenId, tokenURI); | ||
assertEq(abt.tokenURI(tokenId), tokenURI); | ||
assertEq(abt.ownerOf(tokenId), thirdparty); | ||
} | ||
|
||
function testMintAndBurn() public { | ||
string memory tokenURI = "https://example.com/metadata.json"; | ||
uint256 tokenId = 0; | ||
abt.mint(msg.sender, tokenId, tokenURI); | ||
assertEq(abt.tokenURI(tokenId), tokenURI); | ||
assertEq(abt.ownerOf(tokenId), msg.sender); | ||
abt.burn(tokenId); | ||
} | ||
|
||
function testFailToMintTokenToPreexistingTokenId() public { | ||
string memory tokenURI = "https://example.com/metadata.json"; | ||
uint256 tokenId = 0; | ||
abt.mint(msg.sender, tokenId, tokenURI); | ||
assertEq(abt.tokenURI(tokenId), tokenURI); | ||
assertEq(abt.ownerOf(tokenId), msg.sender); | ||
abt.mint(msg.sender, tokenId, tokenURI); | ||
} | ||
|
||
function testFailRequestingNonExistentTokenURI() public view { | ||
abt.tokenURI(1337); | ||
} | ||
|
||
function testFailGetBonderOfNonExistentTokenId() public view { | ||
abt.ownerOf(1337); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev Interface of the ERC165 standard, as defined in the | ||
* https://eips.ethereum.org/EIPS/eip-165[EIP]. | ||
* | ||
* Implementers can declare support of contract interfaces, which can then be | ||
* queried by others ({ERC165Checker}). | ||
* | ||
* For an implementation, see {ERC165}. | ||
*/ | ||
interface IERC165 { | ||
/** | ||
* @dev Returns true if this contract implements the interface defined by | ||
* `interfaceId`. See the corresponding | ||
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] | ||
* to learn more about how these ids are created. | ||
* | ||
* This function call must use less than 30 000 gas. | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) external view returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.6; | ||
|
||
/// @title Account-bound tokens | ||
/// @dev See https://eips.ethereum.org/EIPS/eip-4973 | ||
/// Note: the ERC-165 identifier for this interface is 0x6352211e. | ||
interface IERC4973 /* is ERC165, ERC721Metadata */ { | ||
TimDaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @dev This emits when a new token is created and bound to an account by | ||
/// any mechanism. | ||
/// Note: For a reliable `_from` parameter, retrieve the transaction's | ||
/// authenticated `from` field. | ||
event Attest(address indexed _to, uint256 indexed _tokenId); | ||
/// @dev This emits when an existing ABT is revoked from an account and | ||
/// destroyed by any mechanism. | ||
/// Note: For a reliable `_from` parameter, retrieve the transaction's | ||
/// authenticated `from` field. | ||
event Revoke(address indexed _to, uint256 indexed _tokenId); | ||
/// @notice Find the address bound to an ERC4973 account-bound token | ||
/// @dev ABTs assigned to zero address are considered invalid, and queries | ||
/// about them do throw. | ||
/// @param _tokenId The identifier for an ABT | ||
/// @return The address of the owner bound to the ABT | ||
function ownerOf(uint256 _tokenId) external view returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.6; | ||
|
||
interface IERC721Metadata { | ||
function name() external view returns (string memory); | ||
function symbol() external view returns (string memory); | ||
function tokenURI(uint256 tokenId) external view returns (string memory); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend removing "standard", but I think it's fine to leave in for the draft.