A dynamic NFT identification method and device based on a solidity smart contract
By performing feature processing and machine learning classification on Solidity smart contract code, the problem of identifying dynamic NFT contracts has been solved, the risk of fraud has been reduced, and accurate identification and regulatory support for dynamic NFTs have been achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2023-08-18
- Publication Date
- 2026-07-03
AI Technical Summary
Current technologies cannot effectively identify dynamic NFT contracts, leading to fraud risks and regulatory challenges. In particular, during the buying and selling of NFTs, buyers may not be aware that the dynamic nature of NFTs causes metadata changes that do not match expectations, and traditional regulatory methods are unable to detect potential social harms in a timely manner.
By parsing the Solidity smart contract code, converting it into feature vectors, and using machine learning classification techniques to identify and classify the smart contract feature vectors, the process includes obtaining the contract source code, converting it into an abstract syntax tree, extracting metadata function syntax tree subtrees, preorder traversal, and feature processing, and finally inputting it into a machine learning model for classification.
It enables accurate identification of dynamic NFT contracts, reduces buying and selling risks, increases user investment confidence, and supports the healthy development and regulation of the NFT market.
Smart Images

Figure CN117009891B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of blockchain technology, and in particular relates to a dynamic NFT identification method and device based on Solidity smart contracts. Background Technology
[0002] NFTs (Non-Fungible Tokens) are an application of blockchain technology derived from Ethereum's smart contracts. NFTs were initially proposed in Ethereum Improvement Proposal (EIP-721) and further developed in EIP-1155. The unique aspect of NFTs is that they are non-fungible, and each NFT has a unique digital identifier. Any piece of artwork can be created as an NFT, and its creation and transaction history can be easily traced based on its digital identifier. Another unique feature of NFTs is that they can be traded on the blockchain, meaning that NFT transactions are decentralized, and all transactions are transparent and traceable.
[0003] In the early stages of NFT application exploration across various fields, the presentation format was mainly static media such as images and text. However, with the rapid development of the industry and the deepening of applications, higher demands have been placed on the multimodal, interactive, and dynamic nature of NFT content, especially in fields such as gaming and sports. This has led to the development of dynamic NFTs. Dynamic NFTs (dNFTs), also known as NFT 2.0, have metadata that can change based on instructions written in smart contracts and external conditions or actions. Dynamic NFTs have a unique and static tokenID (ownership) and dynamic metadata (or other dynamic elements, such as certain external conditions triggering minting / burning). The unique tokenID serves as the identifier for the dNFT, while its dynamic metadata can change according to external conditions, including on-chain or off-chain events, actions, results, or data updates.
[0004] Currently, real-world applications of dynamic NFTs are becoming increasingly common in Web3.0 and the Metaverse. The NFT community generally believes that dynamic NFTs represent the future direction of NFT development. One of the most popular examples of dynamic NFTs is the NFTs issued by Regenerative Resources Co (RRC). RRC provides ecosystem services and promotes regenerative economic development, and has released five NFT short films designed by renowned artists. These NFTs initially consist of only one frame, with more frames added after each transaction until the NFT holder can view the complete short film. RRC has already raised enough funds through these NFTs to plant 100 million mangroves. In the financial sector, Solv Protocol uses dynamic NFTs based on the ERC-3525 standard, allowing anyone with specific issuance needs—whether seeking to raise funds or institutions wanting to sell products—to flexibly buy and sell financial derivatives. In sports, an NBA player released a set of dynamic NFTs that upgraded based on his performance in games and provided benefits to holders. When he won the 2020-2021 NBA Rookie of the Year award, the NFT turned gold, and the Saturn he held transformed into the Sun. Another use case for dynamic NFTs is the tokenization of real-world assets, which usually requires a lot of information changes. For example, an NFT representing property can reflect its maintenance history, age, market value, etc. Tokenizing these constantly changing assets requires NFTs to be able to update as metadata changes.
[0005] While the development of dynamic NFTs has injected vitality into the blockchain ecosystem and is considered the future direction of NFT development, it has also raised some issues. Firstly, it introduces new fraud risks. During the buying and selling of NFTs, buyers may be unaware of the dynamic nature of NFTs, and therefore may find that the NFT's metadata has changed after purchase, contradicting their initial expectations and posing a risk of fraud. Secondly, it presents new challenges for regulation. For example, some malicious NFTs may initially display normal images and become popular after promotion, but may subsequently transform into inappropriate images, such as child pornography, violence, gore, racial discrimination, or Nazi extremist propaganda. Due to the rapid dissemination capabilities of the internet, this could cause serious social harm, but traditional regulatory methods are unlikely to detect it effectively and promptly.
[0006] However, there is currently no dynamic NFT identification method. Therefore, a dynamic NFT identification method is needed to better support the development and effective regulation of the NFT market. Summary of the Invention
[0007] To address the shortcomings of existing technologies, the purpose of this application is to provide a method, apparatus, and electronic device to solve the technical problem of the inability to identify dynamic NFT contracts in related technologies. The implementation process of this invention mainly consists of two stages: first, parsing the Solidity smart contract code and converting it into feature vectors; then, using machine learning classification technology to identify and classify the smart contract feature vectors.
[0008] According to a first aspect of the embodiments of this application, a dynamic NFT identification method based on Solidity smart contracts is provided, the method comprising the following steps:
[0009] S1: Obtain the Solidity source code of the NFT contract and convert the Solidity smart contract source code into an abstract syntax tree;
[0010] S2: Extract the function syntax tree subtree from the syntax tree that queries NFT metadata;
[0011] S3: Perform a preorder traversal on the extracted abstract syntax tree subtree and add the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function will be appended to the current traversed node.
[0012] S4: Use the word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of the NFT contract code;
[0013] S5: Input the feature vector into the machine learning model for training and classification, and determine whether the NFT contract is a dynamic NFT.
[0014] Further, step S1 includes the following sub-steps:
[0015] S11: Obtain the Solidity source code of the NFT contract through the blockchain explorer EtherScan;
[0016] S12: Use the solc compiler to convert the obtained Solidity source code into an abstract syntax tree.
[0017] Furthermore, step S2 is as follows:
[0018] S21: Traverse the nodes of the abstract syntax tree to determine whether the interface implemented by the NFT contract is ERC721 or ERC1155;
[0019] S22: If the implemented interface is ERC721, extract the abstract syntax tree subtree of the tokenURI function; if the implemented interface is ERC1155, extract the abstract syntax tree subtree of the uri function.
[0020] Further, step S3 includes the following sub-steps:
[0021] S31: Preorder traversal of the extracted abstract syntax tree subtree. When traversing each node, determine the type of the node. If it is a node of function call type, find the abstract syntax tree subtree of the called function and attach it as a subtree to the current node.
[0022] S32: During traversal, determine whether the current node is a leaf node; if it is a leaf node, record it.
[0023] S33: If the traversal is complete, output the sequence of leaf nodes of the records.
[0024] Further, step S4 includes the following sub-steps:
[0025] S41: Obtain the Solidity smart contract for the NFT contract;
[0026] S42: Transform Solidity smart contracts into abstract syntax trees using the solc compiler;
[0027] S43: Extract the abstract syntax tree subtree of the NFT contract read metadata function;
[0028] S44: Perform a preorder traversal on the extracted abstract syntax tree subtree and add the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function will be appended to the current traversal node.
[0029] S45: Use the word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of the NFT contract code.
[0030] Further, step S5 includes the following sub-steps:
[0031] S51: Input the feature vectors of NFT contract codes in the training set into three machine learning models: support vector machine, random forest, and multilayer perceptron for training.
[0032] S52: Input the feature vectors of the NFT contract codes to be identified into the three trained models in sequence;
[0033] S53: Obtain the model output results. If two or more models output that the NFT contract is a dynamic NFT, then the NFT is determined to be a dynamic NFT; otherwise, it is a static NFT.
[0034] The dynamic NFT refers to an NFT with a unique and immutable Token ID and dynamic metadata, whose metadata is dynamically updated based on on-chain or off-chain data; the Token ID is the unique identifier of the NFT, and the metadata is the basic information of the NFT, including media file or link information, name information and description information.
[0035] According to a second aspect of the embodiments of this application, a dynamic NFT recognition device based on Solidity smart contracts is provided, the device comprising the following modules:
[0036] The conversion module retrieves the Solidity source code of the NFT contract and converts the Solidity smart contract source code into an abstract syntax tree.
[0037] Extraction module: Extracts the function syntax tree subtree from the syntax tree that queries NFT metadata;
[0038] Traversal and splicing module: Performs a preorder traversal on the extracted abstract syntax tree subtree and adds the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function is spliced to the current traversed node.
[0039] Feature processing module: Uses word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of NFT contract code;
[0040] Judgment module: Inputs the feature vector into the machine learning model for training and classification, and determines whether the NFT contract is a dynamic NFT.
[0041] According to a third aspect of the embodiments of this application, an electronic device is provided, comprising:
[0042] One or more processors;
[0043] Memory, used to store one or more programs;
[0044] When the one or more programs are executed by the one or more processors, the one or more processors implement the methods described above.
[0045] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, on which computer instructions are stored, which, when executed by a processor, implement the steps of the above-described method.
[0046] The beneficial effects of this invention are as follows:
[0047] As can be seen from the above embodiments, this application provides a method for non-computer professionals to identify dynamic NFTs, enabling them to identify whether an NFT contract is a dynamic NFT or a static NFT, thereby reducing the risk of buying and selling NFTs and increasing the confidence of participants in investing.
[0048] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0049] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0050] Figure 1 This is a flowchart of the algorithm for NFT contract code characterization in this invention;
[0051] Figure 2 The following are examples of the preorder traversal syntax tree subtree and the called function syntax tree subtree in the NFT contract code characterization stage of the present invention; wherein (a) is the left subtree before splicing and (b) is the right subtree before splicing.
[0052] Figure 3 This is an example diagram showing the concatenation of the preorder traversal syntax tree subtree and the called function syntax tree subtree in the NFT contract code characterization stage of this invention;
[0053] Figure 4 This is a schematic diagram of the equipment process of the present invention. Detailed Implementation
[0054] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.
[0055] The following is in conjunction with the appendix Figure 1 The invention is further described through embodiments, but the scope of the invention is not limited in any way.
[0056] The first aspect of this invention provides a process for a dynamic NFT identification method based on Solidity smart contracts, such as... Figure 1 As shown, the specific implementation includes five stages:
[0057] Phase 1: Source code conversion phase;
[0058] Phase Two: Abstract Syntax Tree Subtree Extraction Phase;
[0059] Phase 3: Traversing the syntax tree;
[0060] Phase Four: Vectorization of the Traversal Sequence;
[0061] Phase 5: Machine Learning Classification Phase;
[0062] Phase one includes the following steps:
[0063] Step 1, Extract NFT Contract Source Code: Obtain the NFT contract source code through the blockchain explorer Etherscan and save it as a .sol file;
[0064] Step 2: Convert the NFT contract source code into an abstract syntax tree: Use the Solidity compiler (solc) to parse the obtained NFT contract source code into an abstract syntax tree, a data structure widely used to represent the structure of program code.
[0065] Phase Two includes the following steps:
[0066] Step 3: Determine whether the NFT contract is an ERC721 contract or an ERC1155 contract; parse the obtained abstract syntax tree to determine which interfaces the NFT contract implements. If it implements the functions corresponding to ERC721, it is an ERC721 contract; if it implements the functions corresponding to ERC1155, it is an ERC1155 contract.
[0067] Step 4: For the ERC721 contract, extract the subtree of the abstract syntax tree of the tokenURI function: Traverse the abstract syntax tree and extract the subtree of the tokenURI function call node in the syntax tree. The tokenURI function is the function in the ERC721 contract that obtains NFT metadata.
[0068] For the ERC1155 contract, extract the subtree of the abstract syntax tree of the URI function; traverse the abstract syntax tree and extract the subtree of the URI function call node in the syntax tree. The URI function is the function in the ERC1155 contract that retrieves NFT metadata.
[0069] Phase three includes the following steps:
[0070] Step 5: Perform a preorder traversal of the extracted syntax tree subtree. If a leaf node is encountered, add it to the traversal sequence. If the current traversed node is a function call node, append the abstract syntax tree subtree of the called function to the current traversed node. For example... Figure 2 As shown, where Figure 2As shown in (a), where expression represents an expression node, type represents the node type, identifier represents that the element is an identifier, and name represents that the identifier's name is buildMetadata. When traversing the left subtree, the node buildMetadata is encountered, and it is found that buildMetadata is a function call method. The syntax tree subtree of the buildMetadata function is as follows: Figure 2 As shown in (b), where subNodes represents the root node of the function's syntax tree subtree, type represents the node type, Function Definition indicates that the node type is a function definition, name indicates that the function name is buildMetadata, statements represent the function's declaration statements, and body represents the root node of the function's method body, then the subtree of the body node of the function call method is appended to the current node. The appended left subtree is as follows: Figure 3 As shown;
[0071] Step 6: Collect all the leaf nodes traversed and organize them into a node sequence: Save the leaf nodes in the preorder traversal of the syntax tree into a sequence according to the order of traversal.
[0072] Phase four includes the following steps:
[0073] Step 7: Vectorize the node sequence using the word2vec model; input the node sequence into the Word2Vec model for training;
[0074] Step 8: Obtain the feature vector of the NFT contract code; input each node in the node sequence into the trained word2vec model to obtain the feature vector, and save it as a feature vector sequence.
[0075] Phase five includes the following steps:
[0076] Step 9: Input the feature vector of the obtained NFT contract code into three machine learning models, namely support vector machine, random forest and multilayer perceptron, for training;
[0077] Step 10: Input the feature vector of the NFT contract code to be identified into the three trained models;
[0078] Step 11: Obtain the model output results. If two or more models output that the NFT contract is a dynamic NFT, then the NFT is determined to be a dynamic NFT; otherwise, it is a static NFT.
[0079] According to a second aspect of the embodiments of this application, a dynamic NFT recognition device based on Solidity smart contracts is provided, the device comprising the following modules:
[0080] The conversion module retrieves the Solidity source code of the NFT contract and converts the Solidity smart contract source code into an abstract syntax tree.
[0081] Extraction module: Extracts the function syntax tree subtree from the syntax tree that queries NFT metadata;
[0082] Traversal and splicing module: Performs a preorder traversal on the extracted abstract syntax tree subtree and adds the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function is spliced to the current traversed node.
[0083] Feature processing module: Uses word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of NFT contract code;
[0084] Judgment module: Inputs the feature vector into the machine learning model for training and classification, and determines whether the NFT contract is a dynamic NFT.
[0085] like Figure 4 As shown, according to a third aspect of the embodiments of this application, an electronic device is provided, comprising:
[0086] One or more processors;
[0087] Memory, used to store one or more programs;
[0088] When the one or more programs are executed by the one or more processors, the one or more processors implement the methods described above.
[0089] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, on which computer instructions are stored, which, when executed by a processor, implement the steps of the above-described method.
[0090] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0091] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.
Claims
1. A dynamic NFT identification method based on solidity smart contract, characterized in that, The method includes the following steps: S1: Obtain the Solidity source code of the NFT contract and convert the Solidity smart contract source code into an abstract syntax tree; specifically including the following sub-steps: S11: Obtain the Solidity source code of the NFT contract through the blockchain explorer EtherScan; S12: Use the solc compiler to convert the obtained Solidity source code into an abstract syntax tree; S2: Extract the function syntax tree subtree from the syntax tree that queries NFT metadata; S3: Perform a preorder traversal on the extracted abstract syntax tree subtree and add the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function will be appended to the current traversed node. S4: Use the word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of the NFT contract code; S5: Input the feature vector into the machine learning model for training and classification to determine whether the NFT contract is a dynamic NFT; this includes the following sub-steps: S51: Input the feature vectors of NFT contract codes in the training set into three machine learning models: support vector machine, random forest, and multilayer perceptron for training. S52: Input the feature vectors of the NFT contract codes to be identified into the three trained models in sequence; S53: Obtain the model output results. If two or more models output that the NFT contract is a dynamic NFT, then the NFT is determined to be a dynamic NFT; otherwise, it is a static NFT. The dynamic NFT refers to an NFT with a unique and immutable Token ID and dynamic metadata, whose metadata is dynamically updated based on on-chain or off-chain data; the Token ID is the unique identifier of the NFT, and the metadata is the basic information of the NFT, including media file or link information, name information and description information.
2. The dynamic NFT identification method based on solidity smart contract according to claim 1, characterized in that, The process of step S2 is as follows: S21: Traverse the nodes of the abstract syntax tree to determine whether the interface implemented by the NFT contract is ERC721 or ERC1155; S22: If the implemented interface is ERC721, extract the abstract syntax tree subtree of the tokenURI function; if the implemented interface is ERC1155, extract the abstract syntax tree subtree of the uri function.
3. The dynamic NFT identification method based on Solidity smart contracts according to claim 1, characterized in that, Step S3 includes the following sub-steps: S31: Preorder traversal of the extracted abstract syntax tree subtree. When traversing each node, determine the type of the node. If it is a node of function call type, find the abstract syntax tree subtree of the called function and attach it as a subtree to the current node. S32: During traversal, determine whether the current node is a leaf node; if it is a leaf node, record it. S33: If the traversal is complete, output the sequence of leaf nodes of the records.
4. The dynamic NFT identification method based on Solidity smart contracts according to claim 1, characterized in that, Step S4 includes the following sub-steps: S41: Obtain the Solidity smart contract for the NFT contract; S42: Transform Solidity smart contracts into abstract syntax trees using the solc compiler; S43: Extract the abstract syntax tree subtree of the NFT contract read metadata function; S44: Perform a preorder traversal on the extracted abstract syntax tree subtree and add the leaf nodes to the traversal sequence; During the preorder traversal, if the current node being traversed is a function call node, the abstract syntax tree subtree of the called function will be appended to the current traversed node. S45: Use the word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of the NFT contract code.
5. A dynamic NFT recognition device based on Solidity smart contracts, characterized in that, The device includes the following modules: The conversion module retrieves the Solidity source code of the NFT contract and converts it into an abstract syntax tree; specifically, it includes: Obtain the Solidity source code of the NFT contract using the blockchain explorer EtherScan; The obtained Solidity source code is converted into an abstract syntax tree using the solc compiler; Extraction module: Extracts the function syntax tree subtree from the syntax tree that queries NFT metadata; Traversal and splicing module: Performs a preorder traversal on the extracted abstract syntax tree subtree and adds the leaf nodes to the traversal sequence; during the preorder traversal, if the current node being traversed is a function call node, then the abstract syntax tree subtree of the called function is spliced to the current traversed node. Feature processing module: Uses the word2vec model to perform feature processing on the traversal sequence to obtain the feature vector of the NFT contract code; The judgment module: inputs the feature vector into the machine learning model for training and classification, and determines whether the NFT contract is a dynamic NFT; specifically including: The feature vectors of NFT contract codes in the training set are input into three machine learning models: support vector machine, random forest, and multilayer perceptron for training. The feature vectors of the NFT contract codes to be identified are sequentially input into the three trained models; If two or more models output that the NFT contract is a dynamic NFT, then the NFT is determined to be a dynamic NFT; otherwise, it is a static NFT. The dynamic NFT refers to an NFT with a unique and immutable Token ID and dynamic metadata, whose metadata is dynamically updated based on on-chain or off-chain data; the Token ID is the unique identifier of the NFT, and the metadata is the basic information of the NFT, including media file or link information, name information and description information.
6. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-4.
7. A computer-readable storage medium storing computer instructions thereon, characterized in that, When executed by the processor, this instruction implements the steps of the method as described in any one of claims 1-4.