Resource processing method in blockchain, and blockchain node
By processing resources through the API provided by the blockchain platform, the security issues caused by programming errors in smart contracts are resolved, and secure management of NFT resources and points resources is achieved, avoiding security risks in resource management and improving the security and reliability of blockchain resource processing.
Patent Information
- Application Number
- PCT/CN2023/135011
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-31
- Filing Date
- 2023-11-29
- Publication Date
- 2024-12-05
AI Technical Summary
Smart contracts in the blockchain have resource security issues due to programming errors, especially security risks caused by improper management of NFT resources and points resources.
Resource creation, transfer, and deletion operations are performed through the interface (API) provided by the blockchain platform. This ensures that security issues caused by programming errors are avoided when storing and updating resources in the contract state. The balance calculation and storage of resource objects are handled using a preset data format and highly secure code.
It improves the security of resource processing in the blockchain, avoids problems such as over-issuance, duplicate issuance, value loss, overflow and data non-conservation, and enhances the reliability of resource management.
Smart Images

Figure CN2023135011_05122024_PF_FP_ABST
Abstract
Description
Resource processing methods and blockchain nodes in blockchain
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on May 31, 2023, with application number 202310638229.7 and application name “Resource Processing Method and Blockchain Node in Blockchain”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The embodiments of this specification belong to the field of blockchain technology, and in particular to a resource processing method in a blockchain and a blockchain node. Background Art
[0003] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain system, data blocks are linked sequentially in chronological order to form a chain-like data structure, cryptographically guaranteeing an unalterable and unforgeable distributed ledger. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application.
[0004] Summary of the Invention
[0005] The purpose of the present invention is to provide a resource processing method in a blockchain to improve the resource security in the blockchain.
[0006] In a first aspect, this specification provides a resource processing method in a blockchain, which is executed by a blockchain node, comprising:
[0007] Receive a first transaction, wherein the first transaction calls a contract, the contract includes a call to a first interface, and the first interface is provided by the blockchain platform;
[0008] By executing the first interface according to the first transaction, it is determined whether the contract state of the contract stores resources corresponding to the first storage key. If the resources corresponding to the first storage key are not stored in the contract state of the contract, the first NFT resource is stored in the contract state in association with the first storage key.
[0009] A second aspect of this specification provides a resource processing method in a blockchain, which is executed by a blockchain node, comprising:
[0010] receiving a second transaction, wherein the second transaction calls a contract, the contract including a call to a second interface provided by the blockchain platform;
[0011] By executing the second interface according to the second transaction, the balance of the first resource corresponding to the third storage key in the contract state of the contract is updated.
[0012] A third aspect of this specification provides a blockchain node, including:
[0013] A receiving unit, configured to receive a first transaction, wherein the first transaction calls a contract, the contract includes a call to a first interface, and the first interface is provided by the blockchain platform;
[0014] The storage unit determines whether the contract state of the contract stores resources corresponding to the first storage key by executing the first interface according to the first transaction. If the contract state of the contract does not store resources corresponding to the first storage key, the storage unit stores the first NFT resource in association with the first storage key in the contract state.
[0015] A fourth aspect of this specification provides a blockchain node, including:
[0016] a receiving unit, configured to receive a second transaction, wherein the second transaction calls a contract, the contract includes a call to a second interface, and the second interface is provided by the blockchain platform;
[0017] An updating unit is configured to update the balance of the first resource corresponding to the third storage key in the contract state of the contract by executing the second interface according to the second transaction.
[0018] A fifth aspect of this specification provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect or the second aspect.
[0019] In a sixth aspect, this specification provides a blockchain node, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect or the second aspect is implemented.
[0020] In the solution provided in the embodiments of this specification, operations such as creation, transfer, and deletion of resources are performed through the interface (API) provided by the blockchain platform, thereby avoiding security issues caused by programming errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] FIG1 is a schematic diagram of deploying a smart contract in one embodiment;
[0023] FIG2 is a schematic diagram of calling a smart contract in one embodiment;
[0024] FIG3 is a schematic diagram of a blockchain data storage structure in one embodiment;
[0025] FIG4 is a schematic diagram of a blockchain data storage structure in one embodiment;
[0026] FIG5 is a schematic diagram of a slot structure in one embodiment;
[0027] FIG6 is a schematic diagram of operating a slot;
[0028] FIG7 is a flow chart of a method for processing NFT resources in an embodiment of this specification;
[0029] FIG8 is a flow chart of a method for processing resources in an embodiment of this specification;
[0030] FIG9 is a schematic diagram of state data of a numerical resource object in an embodiment of this specification;
[0031] FIG10 is an architectural diagram of a blockchain node in an embodiment of this specification;
[0032] FIG11 is an architectural diagram of a blockchain node in an embodiment of this specification. DETAILED DESCRIPTION
[0033] To help those skilled in the art better understand the technical solutions in this specification, the following will provide a clear and complete description of the technical solutions in the embodiments of this specification, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. All other embodiments derived by those skilled in the art based on the embodiments in this specification without creative effort shall fall within the scope of protection of this specification.
[0034] Blockchains are generally categorized into three types: public, private, and consortium. Furthermore, various combinations exist, such as private + consortium, or consortium + public. Public blockchains offer the highest degree of decentralization. Ethereum is a prime example of a public blockchain. Participants can access data on the blockchain, participate in transactions, and compete for the right to record new blocks. Furthermore, participants (represented by nodes on the blockchain) can freely join and exit the network and perform related operations. In contrast, private blockchains have write permissions controlled by a specific organization or institution, while data read permissions are regulated by that organization. Simply put, a private blockchain can be a weakly centralized system with a small number of participating nodes, strictly limited in scope. This type of blockchain is more suitable for internal use within a specific organization. Consortium blockchains fall somewhere between public and private blockchains, achieving "partial decentralization." Each node in a consortium chain typically has a corresponding entity or organization. Participants join the network through authorization and form a stakeholder alliance to jointly maintain the blockchain's operations.
[0035] Whether public, private, or consortium blockchains, most offer smart contract functionality. Smart contracts on the blockchain are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in code.
[0036] Taking Ethereum as an example, users can create and invoke complex logic within the Ethereum network. At the core of Ethereum, a programmable blockchain, is the Ethereum Virtual Machine (EVM), which runs on every Ethereum node. The EVM is a Turing-complete virtual machine, meaning it can implement a wide range of complex logic. When users publish and invoke smart contracts within Ethereum, they are executing on the EVM. In reality, the virtual machine directly runs virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"). Smart contracts deployed on the blockchain can be in bytecode format.
[0037] For example, as shown in Figure 1, after Bob sends a transaction containing information to create a smart contract to the Ethereum network, the EVM on Node 1 executes the transaction and generates a corresponding contract instance. "0x6f8ae93..." in Figure 1 represents the address of the contract. The transaction's data field may contain bytecode, and the transaction's to field is an empty account. Once consensus is reached between the nodes, the contract is successfully deployed and can be subsequently invoked by users.
[0038] After a contract is successfully deployed, a contract account corresponding to the smart contract appears on the blockchain with a specific address. The contract code and account storage are stored in this contract account. The smart contract's behavior is controlled by the contract code, while the smart contract's account storage stores the contract's state. In other words, a smart contract creates a virtual account on the blockchain that contains the contract code and account storage.
[0039] As mentioned above, the data field of a transaction that creates a smart contract may include the bytecode for that smart contract. Bytecode consists of a series of bytes, each of which identifies an operation. For reasons of development efficiency and readability, developers can choose to write smart contract code in a high-level language rather than directly writing bytecode. Smart contract code written in a high-level language is compiled by a compiler to generate bytecode, which can then be deployed on the blockchain. Ethereum supports many high-level languages, such as Solidity, Serpent, and LLL.
[0040] Taking the Solidity language as an example, contracts written in it are very similar to classes in object-oriented programming languages. A contract can declare multiple members (or objects), including state variables, functions, function modifiers, events, etc. State variables are values stored in the smart contract's account storage and are used to save the contract's state.
[0041] The following is a code example of a simple smart contract written in Solidity language 1:
[0042] Code Example 1. SimpleStorage Code
[0043] In the code example 1 above, line 2 declares the state variable storedData of type string, and line 3 declares an event, which stores the address of the initiator of the contract call and the string s. Lines 4-7 define the set function, which takes the string s as its input. The set function sets the input parameter to the state variable storedData and generates an event whose content includes the address of the initiator of the contract call and the string s.
[0044] As mentioned earlier, state variables will ultimately be stored in the database. Lines 8-10 define the get function. This function's operations include returning the value of the queried storedData . returns(string) indicates the type of the return value, and the constant modifier indicates that this function cannot modify the value of the state variable in the contract.
[0045] Furthermore, as shown in Figure 2, still using Ethereum as an example, after Bob sends a transaction containing information to call a smart contract to the Ethereum network, the EVM of Node 1 can execute this transaction and generate the corresponding contract instance. The from field of the transaction in Figure 2 is the address of the account initiating the smart contract call, the "0x6f8ae93..." in the to field represents the address of the smart contract being called, and the data field of the transaction stores the method and parameters used to call the smart contract. After calling the smart contract, the value of storedData may change. Later, a client can view the current value of storedData through a blockchain node (for example, Node 6 in Figure 2).
[0046] Smart contracts can be executed independently on each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain. Therefore, when such a transaction is completed, the blockchain stores transaction credentials that cannot be tampered with or lost.
[0047] As mentioned above, the storedData in the above example is a state variable, which is stored in the smart contract's account storage. In various blockchain networks that introduce smart contracts, such as Ethereum, accounts can generally be of two types:
[0048] Contract account: stores the executed smart contract code and the state value in the smart contract code, and can usually only be activated by external account calls;
[0049] Externally owned account: A user's account.
[0050] The design of external accounts and contract accounts is essentially a mapping of account addresses to account states. Account states typically include fields such as Nonce, Balance, Storage root, and CodeHash. Nonce and Balance exist in both external accounts and contract accounts. CodeHash and Storage root properties are generally only valid for contract accounts.
[0051] Nonce: A counter. For external accounts, this number can represent the number of transactions sent from the account address; for contract accounts, it can be the number of contracts created by the account.
[0052] Balance: Account balance.
[0053] Storage root: The hash of the root node of an MPT tree. This MPT tree organizes the storage of the state variables of the contract account.
[0054] CodeHash: The hash value of the smart contract code. For contract accounts, this is the hash value of the smart contract. For external accounts, since they do not include a smart contract, the CodeHash field can generally be an empty string or a string of all zeros.
[0055] MPT stands for Merkle Patricia Tree, a tree structure that combines the Merkle Tree and the Patricia Tree (a compressed prefix tree, a more space-efficient Trie tree, also known as a dictionary tree). The Merkle Tree algorithm calculates a hash value for each transaction, then hashes each transaction again, until the top-level Merkle root is reached. Ethereum uses a modified MPT tree, such as a hexadecimal tree structure, often referred to as the MPT tree.
[0056] The data structure of the Ethereum MPT tree includes a state trie. The state trie contains key-value pairs (kv or kv) representing the storage content of each account in the Ethereum network. A "key" in the state trie can be a 160-bit identifier (such as an Ethereum account address or a portion of an address's hash value, collectively referred to as an account address). This account address is distributed across the storage from the root node to the leaf nodes of the state trie. The "values" in the state trie are generated by encoding Ethereum account information using Recursive-Length Prefix encoding (RLP). As mentioned previously, for external accounts, the values include nonce and balance; for contract accounts, the values include nonce, balance, codehash, and storageroot.
[0057] A contract account is used to store the state associated with a smart contract. Once a smart contract is deployed on the blockchain, a corresponding contract account is created. This contract account typically has certain states, defined by state variables in the smart contract and generating new values when the smart contract executes. A smart contract is typically a contract defined in code within a blockchain environment that automatically executes its terms. Once an event triggers a term in the contract (meets the execution condition), the code automatically executes. In the blockchain, the state associated with a contract is stored in the storage trie. The hash value of the storage trie's root node is stored in the storageroot, locking all states of the contract to the contract account through the hash. The storage trie is also an MPT tree structure, storing a key-value mapping from state addresses to state values. Part of the information from the storage trie's root node to the leaf nodes is sequentially arranged to store the address of a state, while the leaf nodes store the state value.
[0058] In some blockchain data stores, as shown in Figure 3, each block's header includes several fields, such as the previous block's hash (prev_Hash, in the figure), a random number (in some blockchain systems, this nonce is not a random number, or in some blockchain systems, nonce in the block header is not enabled), a timestamp, a block number (Block Num), a state root hash (State_Root), a transaction root hash (Transaction_Root), and a receipt root hash (Receipt_Root). The Prev_Hash field in the block header of the next block (e.g., block N+1) points to the previous block (e.g., block N), which is the hash value of the previous block. In this way, the block header on the blockchain locks the previous block to the next block. State_Root, Transaction_Root, and Receipt_Root lock the state set, transaction set, and receipt set, respectively. The state set, transaction set, and receipt set organize the state, transactions, and receipts, respectively, in a tree format. Generally, these tree structures can be the same or different. For example, Ethereum uses the same MPT structure. In some tree structures like Ethereum, which include smart contract state collections, there are two levels of MPT structures: the leaf nodes of the upper-level MPT structure include two types: external accounts and contract accounts; each contract account includes the lower-level MPT structure, and the leaf nodes of the lower-level contain the state values of the contract account.
[0059] Figure 4 is a schematic diagram of the blockchain data storage structure. Still using Ethereum as an example, and in conjunction with Figure 3, state_root is the hash value of the root of the MPT tree, which represents the states of all accounts in the current block. This means that the state trie, which points to state_root, is an MPT-style state trie. The root node of this MPT tree is typically an extension node or a branch node, and state_root typically stores the hash value of this root node. The root node can be connected to one or more layers of extension nodes / branch nodes below it. These multiple layers of tree nodes are collectively referred to as internal nodes. A portion of the values in each node from the root to the leaf nodes of the MPT are sequentially concatenated to form an account address, which serves as the key. The account information stored in the leaf nodes is the value corresponding to this account address, thus forming a key-value pair. This key can also be a portion of the hash of the account address (using, for example, the SHA3 algorithm). The stored value can be RLP (Account), the RLP encoding of the account information. Account information is a four-tuple consisting of [nonce, balance, storageRoot, codeHash]. As mentioned earlier, external accounts typically only contain the nonce and balance fields, while the storageRoot and codeHash fields default to empty strings or all zeros. In other words, external accounts do not store contracts or state variables generated after contract execution. Contract accounts typically include Nonce, Balance, Storage Root, and CodeHash. Nonce is the transaction counter for the contract account; Balance is the account balance; Storage Root corresponds to another MPT and can be used to link to contract-related state information; CodeHash is the hash of the contract code. Account information for both external and contract accounts is generally stored in a separate leaf node. From the root node's Extension Node / Branch Node to each account's Leaf Node, there may be several branch nodes and extension nodes in between.
[0060] The state trie can be an MPT-style tree, typically a hexadecimal tree, meaning each layer can have up to 16 child nodes. Extension nodes, used to store common prefixes, typically have one child node, which can be a branch node. Branch nodes can have up to 16 child nodes, which may include extension nodes and / or leaf nodes.
[0061] For a contract account in the state trie, its storage_Root points to another MPT-formatted tree, which stores data related to state variables involved in contract execution. The MPT-formatted tree pointed to by storage_Root is the Storage Trie, which is the hash value of the Storage Trie's root node. Generally, this Storage Trie also stores key-value pairs. The key represents the address of the state variable. Its value can be the result of processing the location of the state variable declaration in the contract (a value starting at 0) using certain rules, such as sha3 (location of the state variable declaration) or sha3 (contract name + location of the state variable declaration). The value stores the value of the state variable (e.g., an RLP-encoded value). The key is formed by concatenating a portion of the data stored along the path from the root node through the intermediate nodes to the leaf nodes. The leaf nodes store the value. As mentioned earlier, the Storage trie can also be an MPT-style tree, typically a hexadecimal tree. This means a Branch Node can have up to 16 child nodes, which may include Extension Nodes and / or Leaf Nodes. An Extension Node can typically have one child node, which can be either a Branch Node or a Leaf Node.
[0062] For example, the Leaf Node Account P of the state trie in Figure 4 is a contract account, and its Storage Root locks all states in the contract storage. These states are organized into an MPT tree, and the tree structure is like the Storage trie linked to the Storage Root. In this linked Storage trie, taking Leaf Node State Variable N as an example, for example, the value of storedData in the aforementioned contract code example, its key can be, for example, but not limited to, sha3 (the declaration location of storedData), and its value is s (for the sake of simplicity, the encoding format of the value is omitted here, for example, RLP, which will be similar in the future and will not be repeated). Among them, the key values are distributed sequentially from the root node to the leaf node (i.e., Leaf Node Variable N) of the storage trie.
[0063] For another example, in the state trie of Figure 4, Leaf Node Account C is an external account, and its key is sha3(Address C), which is the hash value of the address of account C (the hash algorithm uses the sha3 algorithm, for example). The stored value value can be (Account), where the account information Account is a tuple consisting of [nonce, balance]. As mentioned above, since Account C is an external account, its account information includes two items: nonce and balance (excluding codehash and storage root, similar to the following). For example, if an external account has a nonce of 20 and a balance of 4550, then the leaf node Leaf Node State Variable C stores nonce = 20 and balance = 4550. The address of Account C is the key, and its values are distributed sequentially from the root node to the leaf node (i.e., Leaf Node Variable C) of the state trie.
[0064] It can be understood that the data structure of the status data in the embodiments of this specification is not limited to that shown in FIG. 4 , but can be other data structures.
[0065] As described above, after a transaction creating a smart contract is sent to the blockchain and consensus is reached on the transaction, each blockchain node can execute the transaction. A contract account corresponding to the smart contract appears on the blockchain (including, for example, the account's identity, the contract's hash value, and the contract's storage root, StorageRoot) with a specific address. The contract code and account storage are stored in the contract account's storage. The smart contract's behavior is controlled by the contract code, while the smart contract's account storage stores the contract's state. In other words, a smart contract creates a virtual account on the blockchain containing the contract code and storage. Contract deployment or contract update transactions generate or modify the Codehash value. Subsequently, blockchain nodes can receive transaction requests to invoke the deployed smart contract. These transaction requests may include the address of the invoked contract, the function within the invoked contract, and the input parameters. Generally, after consensus is reached on the transaction request, each blockchain node can independently execute the designated smart contract.
[0066] When a blockchain node executes a transaction that calls a contract, the node's virtual machine loads and executes the contract's bytecode, potentially generating and / or reading state, which requires access to the underlying database. The virtual machine requires convenient access to the underlying key-value database. This access typically utilizes pointer-like data access capabilities. For example, in Ethereum, if you need to read the value corresponding to a key from the KV database, you must know the key of the data before accessing it.
[0067] Each contract generally has its own virtual storage space, the capacity of which can be a very large array, for example, 2 256 An array of elements, numbered from 0 to 2 256 -1. Each element can occupy a certain length, for example, 32 bytes. Each element is called a slot. FIG5 is a schematic diagram of a slot structure in one embodiment. It should be noted that a total of 2 256 The storage space of each slot is the total capacity of the virtual space, that is, unused slots do not occupy the actual storage space of the underlying database.
[0068] During the virtual machine's execution of contract bytecode, the slot locations of identical state variables in the virtual storage space must be fixed, ensuring that the keys generated during contract execution are consistent. This fixed location is typically established once the contract code is finalized. Therefore, the task of fixing the location of state variables is typically determined during the compiler compilation phase and is not directly related to the virtual machine.
[0069] The compiler compilation process can generally include the following steps: generating an abstract syntax tree, performing lexical / syntactic analysis based on the abstract syntax tree, filling symbols according to the symbol table, semantic analysis, and code generation. The abstract syntax tree includes a plurality of nodes arranged in sequence, and the plurality of nodes correspond to the plurality of objects declared in the contract. The arrangement order of the plurality of nodes corresponds to the declaration position of the plurality of objects in the contract, and the plurality of objects include the first state variable. In the link of performing lexical / syntactic analysis based on the abstract syntax tree, the slot position information of the state variable of the contract can be generated. Assume that the code of contract C1 is as follows:
[0070] Code Example 2. Solidity code for contract C1
[0071] Based on the contract code, for example, the following abstract syntax tree is generated: In the abstract syntax tree, information related to an object is placed in a node. These objects include, for example, state variables A and B, and mapping relationships "Map1" and "Map3." The multiple nodes corresponding to the multiple objects are arranged in the order in which the objects are declared in the contract. For example, the 0th node in the abstract syntax tree corresponds to state variable A, the 1st node in the abstract syntax tree corresponds to state variable B, the 2nd node in the abstract syntax tree corresponds to mapping relationship Map1, and the 3rd node in the abstract syntax tree corresponds to mapping relationship Map3. Each node contains a number of pieces of information. Overall, the information within a node can be called the node information of the abstract syntax tree.
[0072] For the abstract syntax tree of contract C1, the two state variables A and B in contract C1 have node positions 0 and 1 in the abstract syntax tree respectively, which can correspond to the following two slots in Figure 5: 0x0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0x0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001
[0073] Each of the two slots above is 256 bits, which is 32 bytes when represented by hexadecimal (0x). Four consecutive hexadecimal digits in each segment separated by spaces after 0x represent 2 bytes, so there are 16 such segments in total.
[0074] In this way, in the contract bytecode compiled by the compiler, these two positions in the slot can be used to replace the identifiers of the two state variables, such as the two 256 bits mentioned above replacing A and B respectively. In this way, when the data type is a fixed-size value, the compilation process can pre-allocate storage locations for each data to be stored based on the field sorting order, which is equivalent to specifying a fixed data pointer in advance.
[0075] When the virtual machine loads and executes the contract bytecode, the operation on A is the operation on the slot corresponding to 0x000...00 (i.e., slot position 0 above, with ellipsis replacing the many zeros in the middle). Similarly, the operation on B is the operation on the slot corresponding to 0x000...01.
[0076] Figure 6 illustrates slot operations. For example, a transaction calling contract C1 invokes the setA() function within that contract with the string "0001" as an argument. During the execution of this transaction, the virtual machine stores 0001 in the slot 0x000...01. Specifically, the virtual machine pushes the 32-byte slot 0x000...01 onto the stack, followed by the corresponding value. During interpretation and execution, the virtual machine retrieves the opcode of the called function from memory and begins execution. Based on the stack's first-in, last-out (FIFO) or last-in, first-out (LIFO) nature, the value is popped from the stack, and the slot is then popped from the stack, forming a slot-value pair. The contract virtual machine then executes the opcode, writing the value to the slot. This slot acts as a serial number, uniquely identifying the contract's state variables during contract execution. In the above process, the stack generally uses 32 bytes as a storage unit, which is equal to the length of one slot. The corresponding value may be less than, equal to, or greater than 32 bytes, so the value may occupy one or more units in the stack.
[0077] As shown in Figure 6, for example, a transaction calling contract C1 calls the setB() function in the contract with an input parameter of "36". When the virtual machine executes the transaction, it stores 36 in the slot 0x000...02.
[0078] The results of the execution of the above two contracts can be simply expressed as follows: 0x000...00:0001 (1) 0x000...01:36 (2)
[0079] After the virtual machine is executed, the virtual machine or blockchain platform can convert the slots in the two slot-value pairs (1) and (2) into state keys. Specifically, the state key (i.e., the storage key of the state variable in the storage tree) can be obtained by splicing the contract address + slot position. For example, the address length of contract C1 is 20 bytes, which is 0x3321 dcaf 8911 d384 2e14 a7a4 15be 2fb1 a337 f43e. After splicing the contract address + slot position,
[0080] (1) The corresponding state key of state variable A is: 0x3321dcaf8911d3842e14a7a415be2fb1a337f43e0000000000000000000000000000000 000000000000000000000000000000000000
[0081] (2) The corresponding state key of state variable B is: 0x3321dcaf8911d3842e14a7a415be2fb1a337f43e0000000000000000000000000000000 0000000000000000000000000000000000001
[0082] Afterward, blockchain nodes can store these generated state key-value pairs in the underlying database. Specifically, blockchain nodes may include a tree construction module and a state database module. The tree construction module converts these keys into a storage trie, as shown in Figure 4, and constructs the value in the state key-value pair into a leaf node of this MPT tree. It should be noted that, as previously mentioned, the state key is split into several segments, which are stored sequentially in the tree nodes from the root of the storage trie to the leaf nodes. Which segment of the state key is stored in each tree node depends on whether the state key shares a prefix with other state keys in the tree. From the leaf node, through the intermediate nodes, to the root node, a series of hash value changes occur, and the tree construction module constructs the key-value pairs of these tree nodes. The tree construction module then sends these changed tree node key-value pairs to the state database module, which then stores them in the state database.
[0083] In the above process, the slots for state variables are fixed during compilation. As mentioned above, they are determined by the contract address and the slot location of the state variable. The state key can be obtained by concatenating the contract address and the slot. This way, when running the same contract and reading or writing the same state variable, the same slot is used, corresponding to the fixed state key.
[0084] It should be noted that the state variables A and B in the above example are of type uint256 and bool, respectively. uint256 is 256 bits, or 32 bytes, and bool is 1 byte. The type of these state variables determines that the data length is fixed, or fixed-length. In addition, types such as uint, uint8, and uint128 are also fixed-length. Arrays consisting of a fixed number of fixed-length elements are also fixed-length. For example, uint[2] consists of two elements, each of which is a 32-byte uint type, so uint[2] is 64 bytes in total.
[0085] In addition to fixed-length data storage, there are also variable-length data, or data whose size is unpredictable. In this case, the fixed-length approach cannot directly determine the slot location during compilation, so a different solution is used.
[0086] For example, in contract C1, mapping(uint256=>address)Map1 and mapping(uint256=>Counter)Map3 are defined after state variables A and B. A mapping is a data type of indeterminate length. In the example of mapping(uint256=>address)Map1, Map1 is the name of the mapping.
[0087] The mint1 function in contract C1 is used, for example, to mint NFT resources. Its input parameter, holder, is the recipient account address of the minted NFT resource, and data is the resource data of the minted NFT resource, which may include, for example, the resource identifier of the NFT resource. In the mint1 function, the Pmint1() interface provided by the blockchain platform in the embodiments of this specification is used to set resource information (data) for the NFT resource corresponding to Map1[holder]. Taking Map1[holder] as an example, holder can also be called the key of the mapping relationship Map1.
[0088] The mint2 function in contract C1 is used, for example, to create accumulative resources on the blockchain, such as points, ratings, and scores. Its input parameters, holder, are the recipient account address of the minted resource; data are the resource data for the created resource, including, for example, a resource identifier; and value are the resource shares. The mint2 function uses the Pmint2() interface provided by the blockchain platform in the embodiments of this specification to set resource shares for the resource corresponding to Map3[holder]. The contract can also store other resource information (i.e., data).
[0089] As shown in Figure 6, when the contract code is compiled, the name of the mapping relationship Map1 can be assigned the slot 0x000...02 according to the position of the node corresponding to the mapping relationship Map1 in the abstract syntax tree (i.e., the second position). Since Map1 is not a state variable, there is no value in this slot. Similarly, the mapping relationship Map3 can be assigned a slot with a position value of 0x000...03.
[0090] When the virtual machine executes contract C1, it can uniquely determine the slot of the mapping element corresponding to the key based on the mapping relationship key and the mapping relationship name slot. The slot is, for example: keccak256(key.slot), where "." is a concatenation symbol, and the slot after "." is the location of the slot where the mapping relationship name is located. The number of mapping elements in a mapping relationship is uncertain, and the length of the key and value in the element is also uncertain. For example, after contract C1 is called several times, there may be 2 elements in the mapping relationship Map1, namely: Map1[Account1]=value1 Map1[Account2]=value2
[0091] The corresponding mapping element Map1[Account1]'s slot position can be keccak256(Account1.0x000...02), and the value (for example, the value's data length is greater than 32 bytes) can be stored in one or more consecutive slots starting from this position. Similarly, the second mapping element in the mapping relationship Map1, Map1[Account2]'s slot position can be keccak256(Account2.0x000...02), and the value2 can be stored in one or more consecutive slots starting from this position.
[0092] As shown in Figure 6, the length of the value of Map1[Account1] is less than 32 bytes, and its value (i.e., value1 in Figure 6) can be stored in one slot. The location of this slot is, for example, the value of keccak256(Account1,0x000...02), for example: 0x000...05
[0093] Similarly, value2 of Map1[Account2] can be stored in the slot corresponding to 0x000...07, for example.
[0094] Similarly, when the virtual machine executes contract C1, it can uniquely determine the slot of each element based on the key of the mapping element Map3[holder] and the slot of the mapping relationship Map3, that is, keccak256(holder.0x000...03). For example, as shown in Figure 6, the slot of Map3[Account1] can be determined as: 0x5b4d ed6c c162 9f13 8186 f4b0 7950 04ad bed7 ec13 374d 15ca 04ec 96f1 4913 2460
[0095] The slot of Map3[Account2] can be determined as: 0x9019 1b3f 1d96 c216 c6a6 637b 9c84 98bc 25cc 907a fe24 6d61 1b3a 8bf7 27bc 081d
[0096] That is, for a contract that includes a mapping relationship, once a transaction calls the contract and defines a mapping element, the mapping element's slot can be uniquely determined based on the mapping element's key in the transaction and the slot of the mapping relationship. Once the mapping element's slot is determined, the storage key for the mapping element can be obtained by similarly concatenating the contract address and the slot.
[0097] It can be understood that although the above uses slot as an example to describe how to determine the storage key of the state variable in the contract state (for example, the storage tree shown in Figure 4), this specification is not limited to this. In one embodiment, the storage key of the state variable can be determined based on the contract address and the variable name. For example, for the above-mentioned variable A, its storage key can be determined to be hash (contract address.A), and for the above-mentioned variable Map1[Account1] based on the mapping relationship, its storage key can be determined to be hash (contract address.Map1.Account1). In another embodiment, for resource-type variables, their storage variables can also be determined based on the resource type. For example, the type of NFT resource can be set to 0, and the type of cumulative resource can be set to 1, then the storage key of Map1[Account1] can be determined to be hash (contract address.Map1.Account1.0).
[0098] As described above, blockchains can generate a large number of resources through smart contracts. However, most smart contracts have vulnerabilities, resulting in a high risk of attack and reduced security of blockchain resources. Therefore, the embodiments of this specification provide a resource management solution that uses the API provided by the blockchain platform to perform operations such as creating, transferring, and deleting resources, thereby avoiding security issues caused by programming errors.
[0099] The following describes the resource processing solution provided in the embodiments of this specification using NFT resources and point resources as examples.
[0100] Figure 7 is a flow chart of a method for processing NFT resources in an embodiment of this specification. This method can be executed by a blockchain node.
[0101] In step S710, the blockchain node receives the transaction, and the transaction calls contract C1, which includes a call to the API for processing NFT resources.
[0102] In one embodiment, a user may send a transaction Tx1 for creating an NFT resource to the blockchain. The transaction Tx1, for example, calls the mint1 function in the above-mentioned contract C1 (refer to the code example 2 above). The transaction Tx1 includes input parameters for the mint1 function, such as "Account1, Data1", where Account1 is the holder or owner (holder) of the NFT resource to be created specified by the user, and Data1 is the resource data of the NFT resource to be created, which includes, for example, the name of the NFT resource, media content, etc.
[0103] As shown in Code Example 2, in function mint1, the state variable corresponding to the NFT to be created is set to Map1[holder], and the API provided by the blockchain platform, Pmint1(), is called to store the resource data (data) of the NFT to be created. The data passed to API Pmint1() includes Map1, Account1, Account-C1, and data1, where Account-C1 is the contract address of contract C1. Map1, Account1, and Account-C1 are used to calculate the storage key of the NFT to be created in the contract state of contract C1. Map1 can be the name of a mapping relationship or the identifier of a mapping relationship (e.g., the slot corresponding to the mapping relationship).
[0104] In another embodiment, the user may send a transaction Tx2 for transferring NFT resources to the blockchain. The transaction Tx2, for example, calls the transfer1 function included in the contract C1. The transaction Tx2 includes the input parameters "Account1, Account2" to the transfer1 function, where Account1 is the account that owns the NFT resources, and Account2 is the account to receive the NFT resources.
[0105] For example, the function transfer1 includes "Ptransfer1(Map1, Account1, Map2, Account2, Account-C1)", where Map1, Account1, and Account-C1 are used to calculate the storage key of the state variable of the NFT resource to be transferred, and Map2, Account2, and Account-C1 are used to calculate the storage key of the state variable of the NFT resource to be received. Ptransfer1() is an API provided by the blockchain platform, and is used to transfer NFT resources.
[0106] It can be understood that in the embodiments of this specification, although the storage key corresponding to the NFT resource is determined through a mapping relationship, this specification is not limited to this, and the storage key corresponding to the NFT resource can be determined through other known methods.
[0107] In step S720, the blockchain node executes the API and, if it is determined that the NFT resource corresponding to the target storage key is not stored in the contract state, stores the NFT resource corresponding to the target storage key in the contract state.
[0108] For transaction Tx1, after the blockchain node begins executing it, it executes Pmint1() based on the call to the Pmint1() interface in Tx1. Specifically, the virtual machine in the blockchain node executes Pmint1() with Map1, Account1, Account-C1, and Data1 as parameters. During the execution of Pmint1(), the virtual machine determines the storage key key1 (i.e., the storage key of the variable Map1[Account1]) for the NFT resource to be created based on Map1, Account1, and Account-C1 according to the code in Pmint1(). The determination of this storage key is described above and will not be repeated here. The virtual machine then determines, based on key1, whether the contract state of contract C1 stores the resource corresponding to key1 (this resource may include an NFT resource or points, etc.). If the virtual machine determines that the contract state of contract C1 does not store the resource corresponding to key1, it stores Data1 corresponding to key1 in the contract state of contract C1, thereby completing the creation of the NFT resource. When the virtual machine determines that the contract state of contract C1 stores resources corresponding to key1, it can end the execution of transaction Tx1 and return a transaction execution failure.
[0109] By executing the interface Pmint1(), the blockchain node can store the resource data of the NFT resource in the contract state after determining that the resource corresponding to key1 is not stored in the contract state, thereby avoiding risks such as over-issuance / duplicate issuance.
[0110] For the above-mentioned transaction Tx2, after the blockchain node starts executing transaction Tx2, it executes Ptransfer1() according to the call to the interface Ptransfer1() in transaction Tx2. Specifically, the virtual machine in the blockchain node executes the interface Ptransfer1() with Map1, Account1, Map2, Account2, and Account-C1 as the input parameters of the interface Ptransfer1(). In the process of executing the interface Ptransfer1(), the virtual machine determines the storage key key1 (i.e., the storage key of the variable Map1[Account1]) currently corresponding to the NFT resource and the storage key key2 (i.e., the storage key of the variable Map2[Account2]) corresponding to the NFT resource after the transfer based on the code in the interface Ptransfer1(). Afterwards, the virtual machine determines whether the contract state of contract C1 stores the resources corresponding to key2 (the resources may include NFT resources or points, etc.) based on key2. When the virtual machine determines that the resource corresponding to key2 is not stored in the contract state of contract C1, it can read Data1 stored corresponding to key1 in the contract state of contract C1, delete Data1 stored corresponding to key1, and store Data1 corresponding to key2, thereby completing the transfer of NFT resources.
[0111] In one embodiment, the virtual machine's input parameters to the interface Ptransfer1() also include the resource type (e.g., NFT type) corresponding to the variable Map1[Account1] and the resource type corresponding to the variable Map2[Account2]. The virtual machine performs the above-mentioned NFT resource transfer operation after determining that the resource type corresponding to the variable Map1[Account2] is consistent with the resource type corresponding to the variable Map2[Account1].
[0112] FIG8 is a flow chart of a resource processing method in an embodiment of this specification, which can be executed by a blockchain node.
[0113] As shown in FIG8 , in step S810 , the blockchain node receives a transaction, and the transaction calls contract C1 , which includes a call to an API for processing resources.
[0114] In one embodiment, a user may send a transaction Tx3 to the blockchain for creating a numerical resource (e.g., points). Points are used as an example for description below. This transaction Tx3, for example, calls the mint2 function in the aforementioned contract C1 (see Code Example 2 above). The transaction Tx3 includes parameters passed to the mint2 function, such as "Account1, data2, value1," where Account1 is the user-specified holder of the points to be created, Data2 is information related to the points to be created, including, for example, the name of the points, and value1 is the number of points to be created.
[0115] As shown in Code Example 2, according to the mint2 function, the state variable (also known as the resource object) corresponding to the points to be created in transaction Tx3 is Map3[Account1]. The API provided by the blockchain platform, Pmint2(), is called, and the parameters passed to Pmint2() include Map3, Account1, Account-C1, and value1. Therefore, by executing Pmint2(), the virtual machine can determine the storage key of the resource object Map3[Account1] based on Map3, Account1, and Account-C1, and store the number of points to be created corresponding to this storage key. This number can be stored, for example, in the balance field of the points corresponding to this storage key.
[0116] In one embodiment, the parameters passed to the mint1 function in transaction Tx3 also include "tag1," which indicates the tag (or type) of the points to be created. For example, points with different tags can be created through the mint2 function. For example, tag1 can be set for points on a first platform, tag2 can be set for points on a second platform, and so on. Points for resource objects with different tags cannot be transferred between each other; only points for resource objects with the same tag can be transferred between each other. In this embodiment, the parameters passed to the Mint2 function Pmint2() can also include "tag1," so that the virtual machine can store the tag of the points to be created through Pmint2().
[0117] Specifically, Figure 9 is a schematic diagram of the state data of a numerical resource object in an embodiment of this specification. As shown in Figure 9, the state data of a resource object is divided into API access data and other data. The API access data includes a balance field and a tag field. The blockchain platform configures the API access data to be accessible only to a number of APIs used to change the balance of a resource object, such as the aforementioned Pmint2(), Ptransfer2(), and Pdelete2() interfaces described below. This ensures that calculations and storage of resource object balances can only be performed within the blockchain using the highly secure code provided by the blockchain platform, preventing issues such as value loss, overflow, and data non-conservation, thereby improving the security of resource processing. The other data in Figure 9 can be accessed by the contract using the platform's read / write interfaces. During the execution of transaction Tx3, the virtual machine also stores other information related to the created points (i.e., data2) using the store function within the mint2 function.
[0118] In another embodiment, the user may send a transaction Tx4 for transferring points to the blockchain. For example, the transaction Tx4 calls the transfer2 function included in the contract C1. The transaction Tx4 includes the input parameters "Account1, Account2, value2" to the transfer2 function, where Account1 is the account from which the points are transferred, Account2 is the account to which the points are to be received, and value2 is the number of points to be transferred.
[0119] For example, the function transfer2 includes "Ptransfer2(Map3, Account1, Map4, Account2, Account-C1, value)", where Map3, Account1, and Account-C1 are used to calculate the storage key for the points to be transferred out, and Map4, Account2, and Account-C1 are used to calculate the storage key for the points to be transferred in. Ptransfer2() is an API provided by the blockchain platform, which is used to transfer points between different storage keys.
[0120] In another embodiment, the user may send a transaction Tx5 for deleting points to the blockchain. For example, the transaction Tx5 calls the Delete function included in the contract C1. The transaction Tx5 includes the input parameters "Account1, value3" to the Delete function, where Account1 is the account corresponding to the points to be deleted, and value3 is the number of points to be deleted.
[0121] The Delete function includes, for example, "Pdelete(Map3, Account1, Account-C1, value)", where Map3, Account1, and Account-C1 are used to calculate the storage key corresponding to the points to be deleted. Pdelete() is an API provided by the blockchain platform, and the virtual machine executes Pdelete() to delete the points of the target storage key.
[0122] It is understood that in the embodiments of this specification, although the storage key corresponding to the resource is determined through a mapping relationship, this specification is not limited thereto, and the storage key corresponding to the resource can be determined through other known methods.
[0123] In step S820, the blockchain node updates the quantity of resources corresponding to the target key by executing the API.
[0124] For transaction Tx3, after the blockchain node begins executing it, it executes Pmint2() based on the call to the Pmint2() interface in Tx3. Specifically, the virtual machine in the blockchain node executes Pmint2() with Map3, Account1, value1, and Account-C1 as parameters. During the execution of Pmint2(), the virtual machine determines the storage key key3 (i.e., the storage key of the variable Map3[Account1]) for the points to be created based on Map3, Account1, and Account-C1 according to the code in Pmint2(). The determination of this storage key is described above and will not be repeated here. The virtual machine then determines whether the points corresponding to key3 are stored in the contract state of contract C1 based on key3. If the virtual machine determines that the points corresponding to key3 are not stored in the contract state of contract C1, it stores value1 in the balance field corresponding to key3 in the contract state of contract C1, thereby completing the creation of the points. When the virtual machine determines that the points corresponding to key3 are stored in the contract state of contract C1, it may add value1 to the points balance corresponding to key3. When storing value1 corresponding to key3, the virtual machine stores value1 in a preset data format according to the code in the interface Pmint2(), thereby preventing loss of points. When adding value1 to the points corresponding to key3, the virtual machine also adds the points corresponding to key3 in a preset data format according to the code in the interface Pmint2(), thereby preventing problems such as value loss, overflow, and data conservation violations.
[0125] In one embodiment, the Mint2 function's input parameter to Pmint2() may also include "tag1." When the virtual machine stores value1 corresponding to key3 in the contract state of contract C1, it also stores tag1 in the tag field corresponding to key3. In another embodiment, before adding value1 to the points corresponding to key3, the virtual machine also determines whether the tag field corresponding to key3 contains tag1. If the tag field contains tag1, it adds value1 to the points corresponding to key3.
[0126] By executing the interface Pmint2(), the blockchain node can process the quantity of resources in a preset secure manner according to the code in the interface Pmint2(), thereby improving the security of resource processing.
[0127] For transaction Tx4, after the blockchain node begins executing it, it executes Ptransfer2() based on the call to the Ptransfer2() interface in Tx4. Specifically, the virtual machine in the blockchain node executes Ptransfer2() using Map3, Account1, Map4, Account2, Account-C1, and value2 as parameters. During the execution of Ptransfer2(), the virtual machine determines the storage key key3 (i.e., the storage key of the variable Map3[Account1]) for the points to be transferred out and the storage key key4 (i.e., the storage key of the variable Map4[Account2]) for the points to be received, based on the code in Ptransfer2() and Map3, Account1, and Account-C1. Then, after determining that the number of points corresponding to storage key key3 is greater than value2, the virtual machine decrements the number of points corresponding to key3 by value2 and increments the number of points corresponding to key4 by value2. During the transfer process, the virtual machine represents value2 in a preset format according to the code in the interface Ptransfer2(), and based on the preset format, reduces the number of points corresponding to key3 by value2 and increases the number of points corresponding to key4 by value2, thereby avoiding problems such as numerical loss, overflow, and data non-conservation.
[0128] In one embodiment, before transferring the points corresponding to key3, the virtual machine also reads the tag fields corresponding to key3 and key4 from the contract status according to the code in the interface Ptransfer2(), and determines whether the tag fields corresponding to key3 and key4 are consistent. If the tag fields are consistent, the points of the resource object corresponding to key3 are transferred to the resource object corresponding to key4.
[0129] In one embodiment, the virtual machine's input parameters to the interface Ptransfer2() also include the resource type (such as NFT type or points type) corresponding to the variable Map3[Account1] and the resource type corresponding to the variable Map4[Account2]. The virtual machine performs the above-mentioned points transfer operation after determining that the resource type corresponding to the variable Map4[Account2] is consistent with the resource type corresponding to the variable Map3[Account1].
[0130] For transaction Tx5, after the blockchain node begins executing it, it executes Pdelete() based on the call to the Pdelete() interface in Tx5. Specifically, the virtual machine in the blockchain node executes Pdelete() with Map3, Account1, Account-C1, and value3 as parameters. During the execution of Pdelete(), the virtual machine determines the storage key key3 for the points to be deleted based on Map3, Account1, and Account-C1, according to the code in Pdelete(). Then, if the virtual machine determines that the points balance corresponding to key3 is greater than value3, it decrements the points balance corresponding to key3 by value3. If the virtual machine determines that the points balance corresponding to key3 is equal to value3, it deletes all state data corresponding to key3 from the contract state, thereby deleting the resource object. During this points deletion process, the virtual machine represents value3 in a preset format according to the code in Pdelete() and decrements the points balance corresponding to key3 by value3 based on this preset format. This avoids issues such as value loss, overflow, and data conservation violations.
[0131] FIG10 is an architecture diagram of a blockchain node in an embodiment of this specification, including:
[0132] A receiving unit 101 is configured to receive a first transaction, wherein the first transaction calls a contract, the contract including a call to a first interface provided by the blockchain platform;
[0133] The storage unit 102 is used to determine whether the contract state of the contract stores resources corresponding to the first storage key by executing the first interface according to the first transaction. If the resources corresponding to the first storage key are not stored in the contract state of the contract, the first NFT resource is stored in the contract state in association with the first storage key.
[0134] FIG11 is an architecture diagram of a blockchain node in an embodiment of this specification, including:
[0135] A receiving unit 111 is configured to receive a second transaction, wherein the second transaction calls a contract, the contract including a call to a second interface provided by the blockchain platform;
[0136] The updating unit 112 is configured to update the balance of the first resource corresponding to the third storage key in the contract state of the contract by executing the second interface according to the second transaction.
[0137] The embodiments of this specification also provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the method shown in FIG. 7 or FIG. 8 .
[0138] An embodiment of this specification also provides a blockchain node, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method shown in Figure 7 or Figure 8 is implemented.
[0139] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
[0140] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.
[0141] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude that with the future development of computer technology, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, an in-vehicle human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0142] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any particular order.
[0143] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more of the present specifications, the functions of each module can be implemented in the same or multiple software and / or hardware, or the module that implements the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0144] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more blocks in the block diagram.
[0145] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0146] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0147] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0148] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as a method, system, or computer program product. Thus, one or more embodiments of this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0149] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In distributed computing environments, program modules may be located in local and remote computer storage media, including storage devices.
[0150] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.
[0151] The foregoing is merely an example of one or more embodiments of this specification and is not intended to limit the one or more embodiments of this specification. It will be apparent to those skilled in the art that various modifications and variations may be made to one or more embodiments of this specification. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification shall be included within the scope of the claims.
Claims
1. A resource processing method in a blockchain, executed by a blockchain node, comprising: Receiving a first transaction, in which a contract is called, wherein the contract includes a call to a first interface, and the first interface is provided by the blockchain platform; Based on the call of the first interface by the first transaction, determine whether the contract state of the contract stores resources corresponding to the first storage key. If the resources corresponding to the first storage key are not stored in the contract state of the contract, store the first NFT resource in the contract state in association with the first storage key.
2. According to the method of claim 1, the first interface includes a creation interface for creating NFT resources, the input parameters of the contract to the creation interface include a first identifier of a first mapping relationship, a first account and a contract address of the contract, and the method further includes: The first storage key is determined based on the first identifier, the first account, and a contract address of the contract.
3. According to the method of claim 1, the first interface includes a transfer interface for transferring NFT resources, and the input parameters of the contract to the transfer interface include a first identifier of a first mapping relationship, a first account, a second identifier of a second mapping relationship, a second account, and a contract address of the contract, and the method further includes: Determining the first storage key based on the first identifier, the first account, and the contract address of the contract; Determining a second storage key based on the second identifier, the second account, and the contract address of the contract; Read the first NFT resource from the contract state according to the second storage key.
4. According to the method of claim 3, the input parameters of the contract to the transfer interface also include a first resource type corresponding to the first storage key and a second resource type corresponding to the second storage key, and the determining whether the contract state of the contract stores a resource corresponding to the first storage key comprises: Determining whether the first resource type is consistent with the second resource type; In a case where the first resource type is consistent with the second resource type, it is determined whether a resource corresponding to the first resource object is stored in the contract state of the contract.
5. According to the method of claim 4, the determining whether the contract state of the contract stores a resource corresponding to the first storage key comprises: Determine the first storage key based on the first identifier, the first account, the contract address of the contract, and the first resource type; Determine whether a resource corresponding to the first storage key is stored in the contract state.
6. A resource processing method in a blockchain, executed by a blockchain node, comprising: receiving a second transaction, wherein the second transaction calls a contract, wherein the contract includes a call to a second interface, and the second interface is provided by the blockchain platform; According to the call of the second interface by the second transaction, the balance of the first resource corresponding to the third storage key in the contract state of the contract is updated.
7. According to the method of claim 6, the second interface includes a creation interface for creating resources, the input parameters of the contract to the creation interface include a third identifier of a third mapping relationship, a first account, a first quantity of the first resource, and a contract address of the contract, and the updating the balance of the first resource corresponding to the third storage key by executing the second interface according to the second transaction includes: Determine the third storage key based on the third identifier, the first account, and the contract address of the contract by executing the second interface according to the second transaction; The balance of the first resource corresponding to the third storage key is updated in the contract state of the contract.
8. According to the method of claim 7, the input parameter of the contract to the creation interface also includes a resource tag of the first resource, and the method further includes: By executing the second interface according to the second transaction, the resource tag of the first resource corresponding to the third storage key is stored in the contract state of the contract.
9. The method according to claim 8, wherein the second interface further comprises a transfer interface for transferring resources, and the input parameters of the contract to the transfer interface comprise a third identifier of a third mapping relationship, a first account, a fourth identifier of a fourth mapping relationship, a second account, a second quantity of the first resource to be transferred, and a contract address of the contract, and updating the balance of the first resource corresponding to the third storage key by executing the second interface according to the second transaction comprises: Determine the third storage key based on the third identifier, the first account, and the contract address of the contract, and determine the fourth storage key based on the fourth identifier, the second account, and the contract address of the contract; The balance of the first resource corresponding to the third storage key is reduced by the second amount, and the balance of the first resource corresponding to the fourth storage key is increased by the second amount.
10. According to the method of claim 9, the input parameters of the contract to the transfer interface also include a third asset type corresponding to the third storage key and a fourth asset type corresponding to the fourth storage key, and the determining the third storage key based on the third identifier, the first account and the contract address of the contract, and the determining the fourth storage key based on the fourth identifier, the second account and the contract address of the contract comprises: In the case where it is determined that the third asset type is consistent with the fourth asset type, the third storage key is determined based on the third identifier, the first account, the contract address of the contract and the third asset type, and the fourth storage key is determined based on the fourth identifier, the second account, the contract address of the contract and the fourth asset type.
11. The method according to claim 9 or 10, wherein reducing the balance of the first resource corresponding to the third storage key by the second amount and increasing the balance of the first resource corresponding to the fourth storage key by the second amount comprises: Obtaining a first resource tag corresponding to the third storage key and a second resource tag corresponding to the fourth storage key in the contract state; In the case where the first resource tag is consistent with the second resource tag, the balance of the first resource corresponding to the third storage key is reduced by the second amount, and the balance of the first resource corresponding to the fourth storage key is increased by the second amount.
12. A blockchain node, comprising: A receiving unit, configured to receive a first transaction, wherein a contract is called in the first transaction, wherein the contract includes a call to a first interface, and the first interface is provided by the blockchain platform; A storage unit is used to determine whether resources corresponding to a first storage key are stored in the contract state of the contract based on a call to the first interface by the first transaction, and if resources corresponding to the first storage key are not stored in the contract state of the contract, store a first NFT resource in association with the first storage key in the contract state.
13. A blockchain node, comprising: A receiving unit, configured to receive a second transaction, wherein a contract is called in the second transaction, wherein the contract includes a call to a second interface, and the second interface is provided by the blockchain platform; An updating unit is used to update the balance of the first resource corresponding to the third storage key in the contract state of the contract according to the call of the second interface by the second transaction.
14. A blockchain node, comprising a memory and a processor, wherein the memory stores an executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Intelligent contract calling method and device
CN112015577A
Cross-block-chain data processing method, device and equipment and computer storage medium
CN112837048A
User interaction method and device based on block chain, and node of block chain
CN114862573A
Resource processing method in block chain and block chain node
CN116996200A
Systems and Methods for Maintenance of NFT Assets
US20220391887A1
