Skip to content

Commit

Permalink
Website: Move ERC-7007 to Last Call
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
socathie committed Aug 20, 2024
1 parent 49d81df commit 6e37a79
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 16,661 deletions.
133 changes: 62 additions & 71 deletions ERCS/erc-7007.md

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions assets/erc-7007/contracts/ERC7007Enumerable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ abstract contract ERC7007Enumerable is ERC7007Zkml, IERC7007Enumerable {
interfaceId == type(IERC7007Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}

/**
* @dev See {IERC7007-mint}.
*/

function mint(
address to,
bytes calldata prompt_,
bytes calldata aigcData,
string calldata uri,
bytes calldata proof
) public virtual override(ERC7007Zkml, IERC7007) returns (uint256 tokenId_) {
) public virtual override returns (uint256 tokenId_) {
tokenId_ = ERC7007Zkml.mint(to, prompt_, aigcData, uri, proof);
prompt[tokenId_] = string(prompt_);
tokenId[prompt_] = tokenId_;
Expand Down
45 changes: 21 additions & 24 deletions assets/erc-7007/contracts/ERC7007Opml.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ contract ERC7007Opml is ERC165, IERC7007Updatable, ERC721URIStorage {
) ERC721(name_, symbol_) {
opmlLib = opmlLib_;
}

/**
* @dev See {IERC7007-mint}.
*/

function mint(
address to,
bytes calldata prompt,
bytes calldata aigcData,
string calldata uri,
bytes calldata proof
) public virtual override returns (uint256 tokenId) {
) public returns (uint256 tokenId) {
tokenId = uint256(keccak256(prompt));
_safeMint(to, tokenId);
string memory tokenUri = string(
Expand All @@ -48,11 +45,23 @@ contract ERC7007Opml is ERC165, IERC7007Updatable, ERC721URIStorage {
)
);
_setTokenURI(tokenId, tokenUri);

addAigcData(tokenId, prompt, aigcData, proof);
}

/**
* @dev See {IERC7007-addAigcData}.
*/
function addAigcData(
uint256 tokenId,
bytes calldata prompt,
bytes calldata aigcData,
bytes calldata proof
) public virtual override {
require(ownerOf(tokenId) != address(0), "ERC7007: nonexistent token");
require(tokenIdToRequestId[tokenId] == 0, "ERC7007: requestId already exists");
tokenIdToRequestId[tokenId] = IOpmlLib(opmlLib).initOpmlRequest(prompt);
IOpmlLib(opmlLib).uploadResult(tokenIdToRequestId[tokenId], aigcData);

emit Mint(to, tokenId, prompt, aigcData, uri, proof);
emit AigcData(tokenId, prompt, aigcData, proof);
}

/**
Expand All @@ -74,25 +83,13 @@ contract ERC7007Opml is ERC165, IERC7007Updatable, ERC721URIStorage {
*/
function update(
bytes calldata prompt,
bytes calldata aigcData,
string calldata uri
bytes calldata aigcData
) public virtual override {
require(verify(prompt, aigcData, prompt), "ERC7007: invalid aigcData"); // proof argument is not used in verify() function for opML, so we can pass prompt as proof
uint256 tokenId = uint256(keccak256(prompt));
string memory tokenUri = string(
abi.encodePacked(
"{",
uri,
', "prompt": "',
string(prompt),
'", "aigc_data": "',
string(aigcData),
'"}'
)
);
require(keccak256(bytes(tokenUri)) != keccak256(bytes(tokenURI(tokenId))), "ERC7007: token uri is not changed");

emit Update(tokenId, prompt, aigcData, uri);
require(ownerOf(tokenId) != address(0), "ERC7007: nonexistent token");
// TODO: should update tokenURI with new aigcData
emit Update(tokenId, prompt, aigcData);
}

/**
Expand Down
23 changes: 17 additions & 6 deletions assets/erc-7007/contracts/ERC7007Zkml.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ contract ERC7007Zkml is ERC165, IERC7007, ERC721URIStorage {
verifier = verifier_;
}

/**
* @dev See {IERC7007-mint}.
*/
function mint(
address to,
bytes calldata prompt,
bytes calldata aigcData,
string calldata uri,
bytes calldata proof
) public virtual override returns (uint256 tokenId) {
require(verify(prompt, aigcData, proof), "ERC7007: invalid proof");
) public virtual returns (uint256 tokenId) {
tokenId = uint256(keccak256(prompt));
_safeMint(to, tokenId);
addAigcData(tokenId, prompt, aigcData, proof);

string memory tokenUri = string(
abi.encodePacked(
"{",
Expand All @@ -48,7 +46,20 @@ contract ERC7007Zkml is ERC165, IERC7007, ERC721URIStorage {
)
);
_setTokenURI(tokenId, tokenUri);
emit Mint(to, tokenId, prompt, aigcData, uri, proof);
}

/**
* @dev See {IERC7007-addAigcData}.
*/
function addAigcData(
uint256 tokenId,
bytes calldata prompt,
bytes calldata aigcData,
bytes calldata proof
) public virtual override {
require(ownerOf(tokenId) != address(0), "ERC7007: nonexistent token");
require(verify(prompt, aigcData, proof), "ERC7007: invalid proof");
emit AigcData(tokenId, prompt, aigcData, proof);
}

/**
Expand Down
20 changes: 7 additions & 13 deletions assets/erc-7007/contracts/IERC7007.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,28 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
*/
interface IERC7007 is IERC165, IERC721 {
/**
* @dev Emitted when `tokenId` token is minted.
* @dev Emitted when AI Generated Content (AIGC) data is added to token at `tokenId`.
*/
event Mint(
address indexed to,
event AigcData(
uint256 indexed tokenId,
bytes indexed prompt,
bytes aigcData,
string uri,
bytes proof
);

/**
* @dev Mint token at `tokenId` given `to`, `prompt`, `aigcData`, `uri` and `proof`. `proof` means that we input the ZK proof when using zkML and byte zero when using opML as the verification method.
*
* Requirements:
* - `tokenId` must not exist.'
* - verify(`prompt`, `aigcData`, `proof`) must return true.
* @dev Add AIGC data to token at `tokenId` given `prompt`, `aigcData` and `proof`.
*
* Optional:
* - `proof` should not include `aigcData` to save gas.
* - verify(`prompt`, `aigcData`, `proof`) should return true for zkML scenario.
*/
function mint(
address to,
function addAigcData(
uint256 tokenId,
bytes calldata prompt,
bytes calldata aigcData,
string calldata uri,
bytes calldata proof
) external returns (uint256 tokenId);
) external;

/**
* @dev Verify the `prompt`, `aigcData` and `proof`.
Expand Down
6 changes: 2 additions & 4 deletions assets/erc-7007/contracts/IERC7007Updatable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ interface IERC7007Updatable is IERC7007 {
*/
function update(
bytes calldata prompt,
bytes calldata aigcData,
string calldata uri
bytes calldata aigcData
) external;

/**
Expand All @@ -22,7 +21,6 @@ interface IERC7007Updatable is IERC7007 {
event Update(
uint256 indexed tokenId,
bytes indexed prompt,
bytes indexed aigcData,
string uri
bytes indexed aigcData
);
}
Loading

0 comments on commit 6e37a79

Please sign in to comment.