Skip to content

Commit

Permalink
Merge branch 'master' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrouid committed May 25, 2024
2 parents 4674275 + 1c10367 commit 82e412b
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 97 deletions.
91 changes: 73 additions & 18 deletions ERCS/erc-5521.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ title: Referable NFT
description: An ERC-721 extension to construct reference relationships among NFTs
author: Saber Yu (@OniReimu), Qin Wang <qin.wang@data61.csiro.au>, Shange Fu <shange.fu@monash.edu>, Yilin Sai <yilin.sai@data61.csiro.au>, Shiping Chen <shiping.chen@data61.csiro.au>, Sherry Xu <xiwei.xu@data61.csiro.au>, Jiangshan Yu <jiangshan.yu@monash.edu>
discussions-to: https://ethereum-magicians.org/t/eip-x-erc-721-referable-nft/10310
status: Review
status: Last Call
last-call-deadline: 2024-06-07
type: Standards Track
category: ERC
created: 2022-08-10
Expand All @@ -21,27 +22,40 @@ This standard is an extension of [ERC-721](./eip-721.md). It proposes two refera

## Motivation

Many scenarios require inheritance, reference, and extension of NFTs. For instance, an artist may develop his NFT work based on a previous NFT, or a DJ may remix his record by referring to two pop songs, etc. Proposing a referable solution for existing NFTs and enabling efficient queries on cross-references make much sense.
Many scenarios require the inheritance, reference, and extension of NFTs. For instance, an artist may develop his NFT work based on a previous NFT, or a DJ may remix his record by referring to two pop songs, etc. A gap in existing NFT standards is the absence of established relationships between an NFT and its original creator. This void isolates NFTs, rendering the sale of each one a one-off transaction, thereby obstructing creators from accruing the full value of their intellectual property over time.

In this sense, proposing a referable solution for existing NFTs that enables efficient queries on cross-references is necessary. By introducing a reference relationship between NFTs, a sustainable economic model can be established to incentivize continued engagement in creating, using, and promoting NFTs.

This standard accordingly introduces a new concept, referable NFT (rNFT), which can transform static NFTs into a dynamically extensible network. We embed reference information, including `referring` and `referred` relationships, aiding in the formation of a Direct Acyclic Graph (DAG)-based NFT network. This structure provides a transparent graphical historical record and allows users to query, trace, and analyze relationships. It can enable NFT creators to build upon existing works without the need to start anew.

An intuitive example: users can create new NFTs (C, D, E) by referencing existing ones (A, B), while the `referred` function informs the original NFTs (A, B) about their citations (e.g., A &#8592; D; C &#8592; E; B &#8592; E, and A &#8592; E). Here, the `createdTimestamp` (block-level) serves as an indicator for the creation time of NFTs (A, B, C, D, E).

### Key Takeaways

This standard provides several advantages:

*Clear ownership inheritance*: This standard extends the static NFT into a virtually extensible NFT network. Artists do not have to create work isolated from others. The ownership inheritance avoids reinventing the same wheel.

*Incentive Compatibility*: This standard clarifies the referable relationship across different NFTs, helping to integrate multiple up-layer incentive models for both original NFT owners and new creators.

*Easy Integration*: This standard makes it easier for the existing token standards or third-party protocols. For instance, the rNFT can be applied to rentable scenarios (cf. [ERC-5006](./eip-5006.md) to build a hierarchical rental market, where multiple users can rent the same NFT during the same time or one user can rent multiple NFTs during the same duration).

*Scalable Interoperability*: This standard enables cross-contract references, giving a scalable adoption for the broader public with stronger interoperability.

By adding the `referring` indicator, users can mint new NFTs (e.g., C, D, E) by referring to existing NFTs (e.g., A, B), while `referred` enables the referred NFTs (A, B) to be aware that who has quoted it (e.g., A &#8592; D; C &#8592; E; B &#8592; E, and A &#8592; E). The `createdTimestamp` is an indicator used to show the creation time of NFTs (A, B, C, D, E).

## 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.

- `Relationship`: a structure that contains `referring`, `referred`, `referringKeys`, `referredKeys`, `createdTimestamp`, and other customized and **OPTIONAL** attributes (i.e., not necessarily included in the standard) such as `privityOfAgreement` recording the ownerships of referred NFTs at the time the rNFTs were being created or `profitSharing` recording the profit sharing of `referring`.
- `referring`: an out-degree indicator, used to show the users this NFT refers to;
- `referred`: an in-degree indicator, used to show the users who have refereed this NFT;
- `referringKeys`: a helper for mapping conversion of out-degree indicators, used for events;
- `referredKeys`: a helper for mapping conversion of in-degree indicators, used for events;
- `createdTimestamp`: a time-based indicator, used to compare the timestamp of mint, which **MUST NOT** be editable anyhow by callers;
- `UpdateNode`: event emitted when `setNode` is invoked;
- `safeMint`: mint a new rNFT;
- `setNode`: set the referring list of an rNFT and update the referred list of each one in the referring list;
- `setNodeReferring`: set the referring list of an rNFT;
- `setNodeReferred`: set the referred list of the given rNFTs sourced from different contracts;
- `setNodeReferredExternal`: set the referred list of the given rNFTs sourced from external contracts;
- `referringOf`: get the referring list of an rNFT;
- `referredOf`: get the referred list of an rNFT.
- `referredOf`: get the referred list of an rNFT;
- `createdTimestampOf`: get the timestamp of an rNFT when it is being created.

Implementers of this standard **MUST** have all of the following functions:

Expand Down Expand Up @@ -81,6 +95,11 @@ interface IERC_5521 is IERC165 {
/// @param `tokenId` of the rNFT being focused, `_address` of contract address associated with the focused rNFT.
/// @return the referred mapping of the rNFT.
function referredOf(address _address, uint256 tokenId) external view returns(address[] memory, uint256[][] memory);
/// @notice get the timestamp of an rNFT when is being created.
/// @param `tokenId` of the rNFT being focused, `_address` of contract address associated with the focused rNFT.
/// @return the timestamp of the rNFT when is being created with uint256 format.
function createdTimestampOf(address _address, uint256 tokenId) external view returns(uint256);
/// @notice check supported interfaces, adhereing to ERC165.
function supportsInterface(bytes4 interfaceId) external view returns (bool);
Expand All @@ -96,6 +115,8 @@ interface TargetContract is IERC165 {
function referringOf(address _address, uint256 tokenId) external view returns(address[] memory, uint256[][] memory);
function referredOf(address _address, uint256 tokenId) external view returns(address[] memory, uint256[][] memory);
function createdTimestampOf(address _address, uint256 tokenId) external view returns(uint256);
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Expand All @@ -104,15 +125,19 @@ interface TargetContract is IERC165 {

## Rationale

This standard is intended to establish the referable DAG for queries on cross-relationship and accordingly provide the simplest functions. It provides advantages as follows.
### Is this event informative enough?
`UpdateNode`: This event disseminates crucial information, including the rNFT ID, its owner, and lists of contract addresses/IDs with rNFTs referring to or referred by the subject rNFT. This data set enables stakeholders to efficiently manage and navigate the complex web of relationships inherent in the rNFT ecosystem.

*Clear ownership inheritance*: This standard extends the static NFT into a virtually extensible NFT network. Artists do not have to create work isolated from others. The ownership inheritance avoids reinventing the same wheel.
Implementers are free to choose to use a struct (a **RECOMMENDED** struct is given in the Reference Implementation), or several separate mappings, or whatever other storage mechanism. Whichever mechanism chosen has no observable effect on the behaviour of the contract, as long as its output can fulfill the `UpdateNode` event.

*Incentive Compatibility*: This standard clarifies the referable relationship across different NFTs, helping to integrate multiple up-layer incentive models for both original NFT owners and new creators.
### Why `createdTimestampOf`?
`createdTimestamp`: A key principle of this standard is that an rNFT should reference content already accepted by the community (a time-based sequence known by participants). Global timestamps for rNFTs are thus essential, serving to prevent conflicting states (akin to concurrency issues in transaction processing and block organization). We define a block-level timestamp where `createdTimestamp = block.timestamp` Note that, given that the granularity of references is tied to the block timestamp, it is impractical to discern the order of two rNFTs within the same block.


### How is cross-contract reference performed?
`setNodeReferredExternal`: This function operates conditionally, dependent on successful interface verification in external contracts. Such selective invocation ensures backward compatibility and integration with existing contracts, provided they adhere to specified interfaces.

*Easy Integration*: This standard makes it easier for the existing token standards or third-party protocols. For instance, the rNFT can be applied to rentable scenarios (cf. [ERC-5006](./eip-5006.md) to build a hierarchical rental market, where multiple users can rent the same NFT during the same time or one user can rent multiple NFTs during the same duration).

*Scalable Interoperability* From March 26th 2023, this standard has been stepping forward by enabling cross-contract references, giving a scalable adoption for the broader public with stronger interoperability.

## Backwards Compatibility

Expand All @@ -124,6 +149,17 @@ Test cases are included in [ERC_5521.test.js](../assets/eip-5521/ERC_5521.test.j

## Reference Implementation

The **RECOMMENDED** implementation is demonstrated as follows:

- `Relationship`: a structure that contains `referring`, `referred`, `referringKeys`, `referredKeys`, `createdTimestamp`, and other customized and **OPTIONAL** attributes (i.e., not necessarily included in the standard) such as `privityOfAgreement` recording the ownerships of referred NFTs at the time the Referable NFTs (rNFTs) were being created or `profitSharing` recording the profit sharing of `referring`.
- `referring`: an out-degree indicator, used to show the users this NFT refers to;
- `referred`: an in-degree indicator, used to show the users who have refereed this NFT;
- `referringKeys`: a helper for mapping conversion of out-degree indicators, used for events;
- `referredKeys`: a helper for mapping conversion of in-degree indicators, used for events;
- `createdTimestamp`: a time-based indicator, used to compare the timestamp of mint, which **MUST NOT** be editable anyhow by callers.
- `referringOf` and `referredOf`: First, the current `referringOf` and `referredOf` allow cross-contract looking up, while this cannot be done by directly accessing `_relationship`. Secondly, only if privacy is not a concern, making `_relationship` public simplifies the contract by relying on Solidity’s automatically generated getters. However, if you need to control the visibility of the data, keeping the state variable private and providing specific getter functions would be the best approach. For example, if `_relationship` includes details about specific users’ interactions or transactions or some private extensible parameters (in the updated version, we specifically highlight the `Relationship` can be extended to meet different requirements), always making this data public could reveal users’ behavior patterns or preferences, leading to potential privacy breaches.
- `convertMap`: This function is essential for retrieving the full mapping contents within a struct. Even if `_relationship` is public, The getters only allow retrieval of individual values for specific keys. Since we need comprehensive access to all stored addresses, `convertMap` is necessary to fulfill our event emission requirements.

```solidity
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -264,6 +300,24 @@ contract ERC_5521 is ERC721, IERC_5521, TargetContract {
return (_referredKeys, _referredValues);
}
/// @notice Get the timestamp of an rNFT when is being created.
/// @param `tokenId` of the rNFT being focused, `_address` of contract address associated with the focused rNFT.
/// @return The timestamp of the rNFT when is being created with uint256 format.
function createdTimestampOf(address _address, uint256 tokenId) external view returns(uint256) {
uint256 memory createdTimestamp;
if (_address == address(this)) {
require(_exists(tokenId), "ERC_5521: token ID not existed");
Relationship storage relationship = _relationship[tokenId];
createdTimestamp = relationship.createdTimestamp;
} else {
TargetContract targetContractInstance = TargetContract(_address);
require(targetContractInstance.supportsInterface(type(TargetContract).interfaceId), "ERC_5521: target contract not supported");
createdTimestamp = targetContractInstance.createdTimestampOf(_address, tokenId);
}
return createdTimestamp;
}
/// @dev See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view virtual override (ERC721, IERC_5521, TargetContract) returns (bool) {
return interfaceId == type(IERC_5521).interfaceId
Expand Down Expand Up @@ -305,6 +359,7 @@ contract ERC_5521 is ERC721, IERC_5521, TargetContract {
```


## Security Considerations

### Timestamp
Expand All @@ -313,13 +368,13 @@ The `createdTimestamp` only covers the block-level timestamp (based on block hea

### Ownership and Reference

The change of ownership has nothing to do with the reference relationship. Normally, the distribution of profits complies to the aggreement when the NFT was being created regardless of the change of ownership unless specified in the agreement.
The change of ownership has nothing to do with the reference relationship. Normally, the distribution of profits complies with the agreement when the NFT was being created regardless of the change of ownership unless specified in the agreement.

Referring a token will not refer its descendants by default. In the case that only a specific child token gets referred, it means the privity of contract will involve nobody other than the owner of this specific child token. Alternatively, a chain-of-reference all the way from the root token to a specific very bottom child token (from root to leaf) can be constructured and recorded in the `referring` to explicitly define the distribution of profits.
Referring a token will not refer to its descendants by default. In the case that only a specific child token gets referred, it means the privity of the contract will involve nobody other than the owner of this specific child token. Alternatively, a chain-of-reference all the way from the root token to a specific very bottom child token (from root to leaf) can be constructed and recorded in the `referring` to explicitly define the distribution of profits.

### Open Minting and Relationship Risks

The `safeMint` function has been deliberately designed to allow unrestricted minting and relationship setting, akin to the open referencing system seen in platforms such as Google Scholar. This decision facilitates strong flexibility, enabling any user to create and define relationships between NFTs without centralized control. While this design aligns with the intended openness of the system, it inherently carries certain risks. Unauthorized or incorrect references can be created, mirroring the challenges faced in traditional scholarly referencing where erroneous citations may occur. Additionally, the open nature may expose the system to potential abuse by malicious actors, who might manipulate relationships or inflate token supply. It is important to recognize that these risks are not considered design flaws but intentional trade-offs, which balances the system's flexibility against potential reliability concerns.
The `safeMint` function has been deliberately designed to allow unrestricted minting and relationship setting, akin to the open referencing system seen in platforms such as Google Scholar. This decision facilitates strong flexibility, enabling any user to create and define relationships between NFTs without centralized control. While this design aligns with the intended openness of the system, it inherently carries certain risks. Unauthorized or incorrect references can be created, mirroring the challenges faced in traditional scholarly referencing, where erroneous citations may occur. Additionally, the open nature may expose the system to potential abuse by malicious actors, who might manipulate relationships or inflate the token supply. It is important to recognize that these risks are not considered design flaws but intentional trade-offs, which balance the system's flexibility against potential reliability concerns.

Stakeholders should be aware that the on-chain data integrity guarantees extend only to what has been recorded on the blockchain and do not preclude the possibility of off-chain errors or manipulations. Thus, users and integrators should exercise caution and judgment in interpreting and using the relationships and other data provided by this system.

Expand Down
6 changes: 4 additions & 2 deletions ERCS/erc-6551.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
eip: 6551
title: Non-fungible Token Bound Accounts
description: An interface and registry for smart contract accounts owned by non-fungible tokens
author: Jayden Windle (@jaydenwindle), Benny Giang <bg@futureprimitive.xyz>, Steve Jang, Druzy Downs (@druzydowns), Raymond Huynh (@huynhr), Alanah Lam <alanah@futureprimitive.xyz>, Wilkins Chung (@wwhchung) <wilkins@manifold.xyz>, Paul Sullivan (@sullivph) <paul.sullivan@manifold.xyz>, Auryn Macmillan (@auryn-macmillan), Jan-Felix Schwarz (@jfschwarz), Anton Bukov (@k06a), Mikhail Melnik (@ZumZoom), Josh Weintraub (@jhweintraub) <josh@revest.finance>, Rob Montgomery (@RobAnon) <rob@revest.finance>, vectorized (@vectorized)
author: Jayden Windle (@jaydenwindle), Benny Giang <bg@futureprimitive.xyz>, Steve Jang, Druzy Downs (@druzydowns), Raymond Huynh (@huynhr), Alanah Lam <alanah@futureprimitive.xyz>, Wilkins Chung (@wwhchung) <wilkins@manifold.xyz>, Paul Sullivan (@sullivph) <paul.sullivan@manifold.xyz>, Auryn Macmillan (@auryn-macmillan), Jan-Felix Schwarz (@jfschwarz), Anton Bukov (@k06a), Mikhail Melnik (@ZumZoom), Josh Weintraub (@jhweintraub) <josh@revest.finance>, Rob Montgomery (@RobAnon) <rob@revest.finance>, vectorized (@vectorized), Víctor Martínez (@vnmrtz), Adrián Pajares (@0xadrii)
discussions-to: https://ethereum-magicians.org/t/non-fungible-token-bound-accounts/13030
status: Review
type: Standards Track
Expand Down Expand Up @@ -348,6 +348,8 @@ interface IERC6551Executable {
}
contract ERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Executable {
uint256 immutable deploymentChainId = block.chainid;
uint256 public state;
receive() external payable {}
Expand Down Expand Up @@ -414,7 +416,7 @@ contract ERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Executabl
function owner() public view virtual returns (address) {
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return address(0);
if (chainId != deploymentChainId) return address(0);
return IERC721(tokenContract).ownerOf(tokenId);
}
Expand Down
Loading

0 comments on commit 82e412b

Please sign in to comment.