A blockchain smart contract service framework design method based on hash multi-way tree and an application system

By building a smart contract service framework based on a hash multi-branch tree on the blockchain, the problems of high development difficulty and poor scalability of DApps are solved, the performance and ease of use of DApps are improved, a unified interface for data management and contract management is realized, and data security and integrity are enhanced.

CN116932647BActive Publication Date: 2025-12-09SUN YAT SEN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310845501.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-10
Publication Date
2025-12-09
Estimated Expiration
2043-07-10

AI Technical Summary

Technical Problem

DApps are difficult to develop, have poor scalability, their performance is limited by the speed of blockchain transactions, and the lack of unified design standards leads to poor compatibility and ease of use.

Method used

The blockchain smart contract service framework is constructed based on hash multi-way trees. By using node smart contracts as tree nodes to form hash multi-way trees, it has built-in access mechanisms for roles and permissions, and provides serialization and deserialization engines to realize data management and contract management.

Benefits of technology

It improves the scalability, compatibility, access speed, maintainability, data confidentiality, and data integrity of DApps, and realizes scalability and integrability on the blockchain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116932647B_ABST
    Figure CN116932647B_ABST
Patent Text Reader

Abstract

The application provides a blockchain smart contract service framework design method based on a hash multi-way tree and an application system, relates to the technical field of blockchain smart contracts, and forms a hash multi-way tree on the blockchain by connecting a plurality of node smart contracts to each other with each node smart contract as a tree node, realizes the construction of a blockchain smart contract framework based on the hash multi-way tree, realizes the scalability and the integrated multi-way tree structure on the blockchain, internally builds an access mechanism based on roles and permissions for each tree node of the hash multi-way tree, checks whether a user has specific roles and permissions, sets a user access interface externally, provides a serialization engine and a deserialization engine, realizes two functional domains of data management and contract management, and can effectively improve the scalability, compatibility, access speed, maintainability, data confidentiality and data integrity of a DApp.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of blockchain smart contract, and more particularly to a blockchain smart contract service framework design method based on hash multi-way tree and an application system. BACKGROUND

[0002] Blockchain is a distributed ledger technology, which has the advantages of distribution, security and non-tamperability, and has a high application prospect. Smart contract is an electronic contract, a digital contract and an intelligent contract. A contract is written into a small program using code. Once the code is written, it cannot be modified or tampered with, and is made public and saved in a decentralized blockchain. When external conditions change, such as default or contract expiration, the smart contract will automatically trigger.

[0003] Since the emergence of Ethereum, smart contracts can be run on the blockchain, thereby realizing decentralized, open and transparent, and secure distributed applications DApp (D+App, D is the first letter of the English word decentralization). DApp is considered one of the core technologies of the next generation of Internet Web3.0. The biggest difference between DApp and App is the decentralized feature. It is a product developed from traditional App combined with the characteristics of blockchain.

[0004] The running of DApp relies on the blockchain, and the code is deployed in the block. Each time the user uses DApp, the smart contract code in the historical block needs to be executed simultaneously in all nodes of the blockchain network. After these nodes perform sorting, consensus and verification, etc., the DApp execution result can be returned to the user. Therefore, the performance of DApp is seriously affected by the speed of blockchain transactions. In a typical consortium chain, the speed of blockchain transactions is about 150 times per second, which makes the performance of DApp several orders of magnitude lower than that of traditional App. In addition, due to the strict security requirements of the blockchain, the smart contract must be accurately and consistently run on all network nodes. Therefore, there are many restrictions on the program coding of the smart contract, which also leads to the problems of difficult DApp development and poor scalability. Finally, there is no unified standard for the design of DApp, which makes different DApp systems incompatible and legacy systems unable to be integrated. At the same time, the access and management interface of DApp lacks a unified design paradigm, making it difficult for DApp to achieve the level of traditional App in terms of ease of use, maintainability and manageability. SUMMARY

[0005] In order to solve the problems of current DApp development difficulty, poor scalability, and performance restricted by blockchain transaction speed, the application provides a blockchain smart contract service framework design method and application system based on a hash multi-way tree, constructs a blockchain smart contract framework based on the hash multi-way tree, realizes the scalability and integrability on the blockchain, realizes two major functional domains of data management and contract management, and effectively improves the scalability, compatibility, access speed, maintainability, data confidentiality and data integrity of the DApp.

[0006] In order to achieve the above technical effects, the technical scheme of the application is as follows:

[0007] A blockchain smart contract service framework design method based on a hash multi-way tree comprises the following steps:

[0008] Design a plurality of node smart contracts Node based on a smart contract language;

[0009] Make each node smart contract Node as a tree node, and connect the plurality of node smart contracts Node to each other to form a hash multi-way tree on the blockchain;

[0010] Built-in role and permission access mechanism for each tree node of the hash multi-way tree is provided to check whether a user has a specific role and permission;

[0011] An external user access interface is provided to provide a serialization engine and a deserialization engine; the serialization engine serializes data and topology of the hash multi-way tree into a string and submits the string to the user, and the deserialization engine accepts a string from the user and adds, modifies or deletes data and topology on the hash multi-way tree according to the string.

[0012] Preferably, the blockchain smart contract service framework is divided into a bottom layer, a middle layer and a top layer, wherein the bottom layer is a support layer for providing basic data, security and type conversion functions for the blockchain smart contract service framework; the middle layer is a data layer composed of the hash multi-way tree; and the top layer is an interface layer for providing an external user access interface.

[0013] The smart contract language is a Solidity smart contract language.

[0014] Preferably, each node smart contract Node entity contains an ordered hash mapping table, which is used to record contract addresses of other node smart contract Node entities on the blockchain, and the other node smart contract Node entities recorded in the ordered hash mapping table are used as child nodes of the node smart contract Node entity containing the ordered hash mapping table.

[0015] The one ordered hash mapping table includes a key-address unordered mapping and a key-key linked list, the key-address unordered mapping refers to mapping a 256-bit key to a 160-bit contract address on a blockchain, and the key-key linked list refers to each contract address mapped by the key-address unordered mapping being a linked list node; a key-key linked list node includes a 256-bit front, rear and current linked list node value, the front and rear linked list nodes represent the previous and next linked list nodes corresponding to the key, and the current linked list node value represents the final mapping value of the key.

[0016] Preferably, the ordered mapping contract is implemented by a key-key linked list and a key-address unordered mapping, wherein the key-key linked list records the key values of all child nodes of the entity of a certain node smart contract Node, each node of the linked list corresponds to a child node and a corresponding key value, and records the contract address of the node; the key-address unordered mapping maps the key to the linked list node, and the contract address of the child node is obtained through the linked list node to complete the mapping of the key to the child node, and the linked list node records the key values of adjacent linked list nodes, and the traversal of the linked list can be realized through the key-address unordered mapping.

[0017] The entity of the ordered mapping contract maps a 256-bit key value to a 160-bit address value, wherein the address value is the address of an arbitrary smart contract on a blockchain; each entity of a node smart contract Node includes an entity of an ordered mapping contract, which maps an arbitrary 256-bit key value to the contract address of a child node through key-value mapping, and the ordered mapping contract supports the traversal of the child nodes of the entity of the node smart contract Node through access to the linked list.

[0018] Preferably, each tree node on the hash multi-way tree corresponds to a unique path of the node smart contract Node, the path is composed of the sum of the keys key of all nodes between the tree node Node i and the root node of the hash multi-way tree, and i represents the sequence of the tree node; the hash multi-way tree only supports top-down access to the tree nodes, and each tree node Node i is accessed by giving its path path i , and the access process satisfies:

[0019] Data i =ExtractData(a i ),

[0020] a i ∈{a1,a2,...,a i |a k+1 =ExtractChild(a k ,Key k+1 ),a1=rootNode},

[0021] {Key k}=path i

[0022] wherein a i represents the i-th accessed tree node, Data i represents the data recorded by the accessed tree node, path i represents the path of the accessed tree node in the hash multi-way tree, the set {Key k} represents the key of each tree node along the path path i , the set {a i} represents each tree node along the path path i , ExtractData() represents an operation of extracting data from a tree node, and ExtractChild() represents an operation of extracting a child node from a tree node according to a specified key.

[0023] Preferably, the entity of the node smart contract Node has a 160-bit data slot for storing data within 160 bits or a smart contract address, wherein:

[0024] When storing data within 160 bits, the entity where the data slot is located is used as a structured data field on the blockchain, and the structured data field refers to a specific data on the blockchain that can be accessed by a user through a specific path;

[0025] When storing a smart contract address, the entity where the data slot is located is used as a smart virtual entity or a smart contract version backup on the blockchain, the smart virtual entity refers to a smart contract with intelligent logic and behavior mounted by the blockchain smart contract service framework on a specific path, the smart contract version backup refers to a non-current version of a deployed smart contract mounted by the blockchain smart contract service framework on a hidden path, and the mounting refers to recording the address of a deployed smart contract in the data slot of the entity of the node smart contract Node on a certain determined path.

[0026] The smart contract M is mounted on the tree node I, when the smart contract M needs to be accessed, the data Data I recorded by the accessed tree node I is first extracted, and then the Data IM = ExtractContract(Data

[0027] M = ExtractContract(Data I )

[0028] where ExtractContract represents the operation of extracting a smart contract according to a smart contract address, ExtractContract(Data I ) represents that a user accesses a smart contract M.

[0029] Preferably, an entity of a certain node smart contract Node can be accessed only when and if a user has a certain permission of a certain role, and the role and permission based access mechanism is specifically represented as:

[0030] U = {u i}, R = {r j}, P = {p k}

[0031] UR = U x R, RP = R x P

[0032]

[0033]

[0034] where U represents a set of all users, R represents all defined roles, P represents all defined permissions, Map UR represents a user-to-role mapping table, Map RP represents a role-to-permission mapping table, Map RP and Map UR are both specified by users, and CheckUserHasPermission(u, p) is a proposition that is true when a user u has a permission p.

[0035] Preferably, a role and permission based access mechanism is built in each tree node of a hash multi-tree, and a hash algorithm and an automatic error algorithm are built in the hash multi-tree, the hash multi-tree calculates a hash value from bottom to top, and the hash value of any tree node considers not only the data of the tree node itself, but also the hash values of all child nodes of the tree node, each tree node collects the hash values {h k} of its child nodes, assuming that the data of the tree node is d, the hash values {h k} of the child nodes are XOR added to the data d of the node and packed, and finally the hash value is calculated as:

[0036]

[0037] wherein, keccak represents a keccak256 hash algorithm;

[0038] The current hash value of the tree node is compared with the recorded hash value layer by layer to determine whether the data or topology of the sub-tree corresponding to the tree node is tampered with; if the current hash value is the same as the recorded hash value, the sub-tree is not modified; if the current hash value is different from the recorded hash value, the hash values are compared layer by layer from top to bottom, and the tampered sub-node is found at each layer until the final tampered position is found.

[0039] Preferably, the user access interface provides a unified interface contract, a data management contract, a contract management contract and a permission management contract; the serialized format is a Json format; the expression of the string from the user is:

[0040] string=JSON({Op k})

[0041] Op k ={path k ,operation k ,value k}

[0042] wherein, string represents a string in Json format from the user, JSON() represents a Json encoding algorithm, Op k represents the kth operation, path k represents the path of the tree node operated by Op k , operation k indicates the specific operation of Op k , and value k indicates the value of the operation of Op k ; the deserialization engine extracts {Op k} from the received string, and defines data in the hash multi-way tree according to the description of operation k .

[0043] The application also proposes a hash multi-way tree-based blockchain smart contract service framework application system, comprising:

[0044] A node smart contract module provides a node smart contract, and the node smart contract includes a 160-bit data slot, a 256-bit hash value and an ordered hash mapping table;

[0045] An ordered hash mapping contract module includes a linked list and an unordered hash mapping to realize ordered hash mapping;

[0046] An access control contract module checks whether a user has a specific role and permission when the user performs an access operation;

[0047] A data management contract module provides a consistent, path-based data access interface for a user, integrates a data serialization engine and a deserialization engine;

[0048] A contract management contract module provides a consistent contract management interface for a user, and realizes contract version control function by switching the mounted smart contract on a hash multi-way tree;

[0049] A permission management contract module provides definition and modification operations of roles and permissions for a user.

[0050] Compared with the prior art, the beneficial effects of the technical scheme of the present application are:

[0051] The present application proposes a hash multi-way tree-based blockchain smart contract service framework design method and application system, which makes each node smart contract as a tree node, connects a plurality of node smart contracts to each other, forms a hash multi-way tree on the blockchain, realizes the construction of a blockchain smart contract framework based on a hash multi-way tree, realizes the scalability and integrable multi-way tree structure on the blockchain, internally builds an access mechanism based on roles and permissions for each tree node of the hash multi-way tree, checks whether a user has a specific role and permission, sets a user access interface externally, provides a serialization engine and a deserialization engine, realizes two major functional domains of data management and contract management, and can effectively improve the scalability, compatibility, access speed, maintainability, data confidentiality and data integrity of DApp. BRIEF DESCRIPTION OF DRAWINGS

[0052] Figure 1 A flowchart of the hash multi-way tree-based blockchain smart contract service framework design method proposed in the embodiment of the present application is shown;

[0053] Figure 2 A whole schematic diagram of the node smart contract forming a blockchain smart contract framework based on the Solidity language designed in the embodiment of the present application is shown;

[0054] Figure 3 An implementation reference diagram of the ordered hash mapping table proposed in the embodiment of the present application is shown;

[0055] Figure 4 A schematic diagram of the blockchain smart contract framework proposed in the embodiment of the present application is shown;

[0056] Figure 5 A schematic diagram of the hash operation proposed in the embodiment of the present application is shown;

[0057] Figure 6A schematic diagram showing that the user-to-role mapping table and the role-to-permission mapping table proposed in the embodiment of the application are implemented using unordered mapping.

[0058] Figure 7 A schematic diagram showing the data write rate in different serialization batches proposed in the embodiment of the application.

[0059] Figure 8 A structural schematic diagram of a blockchain smart contract service framework application system based on a hash multi-way tree proposed in the embodiment of the application. DETAILED DESCRIPTION

[0060] The accompanying drawings are only used for illustrative purposes and should not be construed as limiting the patent;

[0061] In order to better illustrate the embodiment, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the actual size;

[0062] For those skilled in the art, it is understandable that some well-known content in the drawings may be omitted.

[0063] The technical solutions of the application will be further described below in combination with the drawings and embodiments.

[0064] The positional relationship described in the drawings is only used for illustrative purposes and should not be construed as limiting the patent;

[0065] Embodiment 1

[0066] The embodiment proposes a hash multi-way tree-based blockchain smart contract service framework design method as shown in the flowchart. Figure 1 The hash multi-way tree-based blockchain smart contract service framework is developed by the Solidity smart contract language and implemented as a distributed application, which can be deployed and run on Ethereum or a consortium chain compatible with the Solidity smart contract language.

[0067] As shown in the flowchart, the blockchain smart contract framework is composed of a plurality of smart contracts and some basic support libraries, and these contracts and support libraries are program files of the Solidity smart contract language. Figure 2 The smart contracts include node contract, ordered mapping contract, access control contract, data management contract, and contract management contract, and there is a mutual import relationship between these smart contracts and support libraries. Compiling them obtains a complete binary file bin, and an application binary interface file abi is obtained for each smart contract. The binary file is deployed on the blockchain through the corresponding blockchain SDK, so that the blockchain smart contract framework can start to provide services; and the application binary file is transmitted to the user program or the blockchain SDK, so that the framework on the blockchain can be accessed.

[0068] Referring to Figure 1 The flowchart of the method shown includes the following steps:

[0069] S1. Designing several node smart contracts Node based on a smart contract language;

[0070] Each entity of the node smart contract Node contains an ordered hash mapping table, which is used to record the contract addresses of other entities of the node smart contract Node on the blockchain, and the other entities of the node smart contract Node recorded in the ordered hash mapping table are regarded as the child nodes of the entity of the node smart contract Node containing the ordered hash mapping table. An ordered hash mapping table contains a key-address unordered mapping and a key-key linked list, the key-address unordered mapping refers to mapping a 256-bit key to a 160-bit contract address on the blockchain, and the key-key linked list refers to that each contract address mapped by the key-address unordered mapping is a linked list node; the mapping principle is as shown in Figure 3 As shown, the blockchain smart contract framework defines an ordered mapping contract and a linked list node contract, and the entity of the ordered mapping contract maps a 256-bit key value to a 160-bit address value, wherein the address value is the address of any smart contract on the blockchain; each entity of the node smart contract Node contains an entity of the ordered mapping contract, and through the key-value mapping of the entity, any 256-bit key value is mapped to the contract address of the child node, at the same time, the ordered mapping contract supports the traversal of the entity of the node smart contract Node to its child nodes through the access to the linked list.

[0071] The ordered mapping contract realizes the ordered mapping contract through a key-key linked list and a key-address unordered mapping, wherein the key-key linked list records the key values of all child nodes of the entity of the node smart contract Node, each node of the linked list corresponds to a child node and a corresponding key value, and records the contract address of the node; the key-address unordered mapping maps the key to the linked list node, and the contract address of the child node is obtained through the linked list node to complete the mapping of the key to the child node, the linked list node records the key values of adjacent linked list nodes, and the traversal of the linked list can be realized through the key-address unordered mapping; a key-key linked list node contains 256-bit values of the previous linked list node, the next linked list node and the current linked list node, the previous linked list node and the next linked list node respectively represent the key corresponding to the previous linked list node and the next linked list node, and the value of the current linked list node represents the final mapping value of the key.

[0072] S2. Let each node smart contract be a tree node, and the several nodes smart contracts are connected to each other to form a hash multi-way tree on the blockchain;

[0073] like Figure 4 As shown, the blockchain smart contract service framework is divided into a bottom layer, a middle layer, and a top layer. The bottom layer is the support layer, which provides basic data, security, type conversion, and other functions for the blockchain smart contract service framework. Ordered mapping contracts are located in this support layer. The middle layer is the data layer, which consists of a hash multi-way tree. Any node in the hash multi-way tree can be addressed through the root node at the top. The top layer is the interface layer, which sets up user access interfaces and provides functions that can be directly used by users, including serialization / deserialization operations, querying / adding / modifying data, obtaining contract addresses, editing user roles and permissions, and performing contract version control.

[0074] The hash multi-way tree is located in the data layer, and each node in the hash multi-way tree... i Each has a unique path, from the root node to the Node. i The sum of the keys of all nodes traversed in between. For example... Figure 5 As shown in the diagram, there are 9 nodes, A through I. The key for each node is its own name; for example, the key for node A's parent node is "A". For instance, if node A is a child of the root node, then the path for node I is: A→C→F→I. These nodes can only be accessed from top to bottom; that is, before accessing a node, its parent node must be visited first.

[0075] Each tree node in a hash multi-way tree corresponds to a smart contract Node, which has a unique path. The path is formed by the tree node Node. i The hash multi-way tree is composed of the sum of the keys of all nodes from the root node to the root node, where i represents the order of the tree nodes; the hash multi-way tree only supports access to tree nodes from top to bottom, by providing each tree node Node i path i The process of accessing the site and satisfying the access method is as follows:

[0076] Data i =ExtractData(a i ),

[0077] a i ∈{a1, a2, ..., a i |a k+1 =ExtractChild(a k Key k+1 ), a1 = rootNode},

[0078] {Key k} = path i

[0079] Among them, a i Data represents the i-th tree node visited. i The path represents the data recorded in the visited tree node. i The set {Key} represents the path of the visited tree node in the hash multi-way tree. k} represents path i The key of each tree node along the way, set {a i} represents path i For each tree node along the way, ExtractData() represents the operation of extracting data from the tree node, and ExtractChild() represents the operation of extracting child nodes from the tree node based on a specified key.

[0080] by Figure 5 Taking the hash operation result shown as an example, when it is necessary to access the data of the I-node, the path is path. i ={Key k = "root.ACFI" To access data in inodes, it's necessary to start from the root node and extract the child nodes of each node sequentially according to their keywords, following the path of the inodes.

[0081] A=ExtractChild(root,"A")

[0082] C=ExtractChild(root,"C")

[0083] F=ExtractChild(root,"F")

[0084] I=ExtractChild(root,"I")

[0085] Finally, extract data from the I node, Data I =ExtractData(I).

[0086] Data i With 160 bits of storage space, it can meet almost all data storage needs, including but not limited to: Boolean values, long integers, double-precision floating-point numbers, strings, byte strings, digital signatures, and encrypted data. The Node smart contract entity has 160 data slots for storing any data up to 160 bits or a smart contract address, where:

[0087] When storing data within 160 bits, the entity where the data slot is located is used as a structured data field on the blockchain, which means that a user can access a specific data on the blockchain through a specific path;

[0088] When storing smart contract addresses, the entity where the data slot is located is used as a smart virtual entity or smart contract version backup on the blockchain, which means that the blockchain smart contract service framework mounts a smart contract with intelligent logic and behavior on a specific path, and the smart contract version backup means that the blockchain smart contract service framework mounts a non-current version of a deployed smart contract under a hidden path, and the mounting means recording the address of a deployed smart contract in the data slot of the entity of the node smart contract Node on a certain determined path.

[0089] On the other hand, Data i can be used to store smart contract addresses, which means that the target smart contract is mounted in the node where the Data i is located. Similarly, taking Figure 5 as an example, assuming that the user mounts the smart contract M on the I node, when the user needs to access M, first extract the Data i according to the foregoing steps, and then extract the contract M from the Data i :

[0090] M = ExtractContract(Data I )

[0091] In the above formula, ExtractContract means an algorithm for extracting a contract according to a smart contract address. Then, the user can access the smart contract M. This smart contract mounting method actually provides a flexible, scalable, indexable, and easy-to-manage on-chain smart contract management mode, which has high practical application value.

[0092] The hash multiway tree has scalability. Specifically, the node contract Node has the following methods: AddNode(key): adding a child node for the Node entity according to the key; DeleteNode(key): deleting a child node for the Node entity according to the key. Therefore, the hash multiway tree can flexibly expand, change or trim its topology, which embodies the compatibility of the hash multiway tree. It is worth noting that the hash multiway tree supports ring, cross and other topologies.

[0093] S3. For each tree node of the hash multiway tree, an access mechanism based on roles and permissions is built in to check whether the user has a specific role and permission;

[0094] An entity of a certain node smart contract Node can be accessed only when and if a user has a certain permission of a certain role, which is specifically represented as a role and permission based access mechanism:

[0095] U = {u i}, R = {r j}, P = {p k}

[0096] UR = U x R. RP = R x P

[0097]

[0098]

[0099] where U represents a set of all users, R represents all defined roles, P represents all defined permissions, Map UR represents a user-to-role mapping table, Map RP represents a role-to-permission mapping table, Map RP and Map UR are specified by users, and CheckUserHasPermission(u, p) is a proposition that is true when a user u has a permission p. Wherein, the mapping tables Map RP and Map UR are specified by users, and generally need to have administrator permissions or proxy permissions to access them. In the framework, the two mapping tables are each implemented using two unordered mappings, refer to Figure 6 .

[0100] S4. An external user access interface is provided, which provides a serialization engine and a deserialization engine; the serialization engine serializes the data and topology of the hash multi-way tree into a string and submits it to the user, and the deserialization engine accepts a string from the user and adds, modifies or deletes data and topology on the hash multi-way tree according to the string.

[0101] The hash multi-way tree provides an external user access interface, which are smart contracts open to users, and these smart contracts have strict permission control mechanisms and event mechanisms to ensure that user access is legal and recorded. At the same time, these smart contracts provide user-friendly interface functions, and users can quickly and conveniently use the framework to implement data management, contract management, permission management and other functions by calling these functions.

[0102] In this embodiment, the user access interface provides a unified interface contract, a data management contract, a contract management contract and a permission management contract; as Figure 4As shown, the user access interface provides a unified interface contract, which provides the address of other interface contracts for the user; the user access interface provides a data management contract, which uses a hash multi-tree to implement structured query, indexing, modification, read-write, and other operations on chain data; the user access interface provides a contract management contract, which uses a hash multi-tree structure to implement version update, backup, recovery, and other operations on chain contracts; the user access interface provides a permission management contract, which, under strict access permission verification, defines, modifies, and deletes user-identity relationships and identity-permission relationships, and defines and modifies access permissions for data and contracts managed by the hash multi-tree.

[0103] The hash multi-tree provides a serialization engine and a deserialization engine. The serialization engine is a series of functions of the interface smart contract, which can serialize the data and topology of the complete tree or a subtree of the hash multi-tree into a string in Json format and submit it to the user. The serialization engine traverses the nodes of the subtree and recursively packs the data and topology of these nodes into Json format during the process.

[0104] The deserialization engine is a series of functions of the interface smart contract, which can accept a Json format string from the user and add, modify, or delete data and topology on the hash multi-tree accordingly. The expression of the string from the user is:

[0105] string=JSON({Op k})

[0106] Op k ={path k ,operation k ,value k}

[0107] wherein string represents a Json format string from the user, JSON() represents a Json encoding algorithm, Op k represents the kth operation, path k represents the path of the tree node operated by Op k , operation k indicates the specific operation of Op k , and value k indicates the value of the operation of Op k ; the deserialization engine extracts {Op k} from the received string and defines data in the hash multi-tree according to the description of operation k .

[0108] In the case of using serialization engine and deserialization engine, data write test is carried out on the blockchain smart contract framework, and the time required to complete the data write for a given amount of data is counted. Figure 7 , Figure 7 The abscissa of the graph represents the amount of data written, and the ordinate represents the data write rate, and the curve of the data write rate under the usual method is obtained. Among them, the usual curve represents the data write rate curve of the usual method, batch5, batch100, batch2000 are the data write rate curves of the application when the serialization batch is 5, 100, 2000 respectively, and the serialization batch refers to the number of elements of {Op k}.

[0109] Figure 7 It can be seen that the application can obtain an effective improvement of the data write rate compared with the usual method, and the specific improvement effect is related to the serialization batch. When the serialization batch is higher, the application can obtain a performance improvement of at most 874% compared with the traditional method.

[0110] An access mechanism based on roles and permissions is built in each tree node of the hash multi-way tree, and a hash algorithm and an automatic error algorithm are built in the hash multi-way tree, such as Figure 5 The hash multi-way tree calculates the hash value from bottom to top, and the hash value of any node not only considers the data of the node itself, but also considers the hash of all child nodes of the node, so the hash value contains the entire data and the entire topology of the subtree with the node as the root. For example, in Figure 6 The hash value of F node is composed of the data of F, the hash of H and the hash of I.

[0111] The hash algorithm is implemented in a recursive manner, and each tree node collects the hash values {h k} of its child nodes, and sets the data of the node as d. The hash values {h k} of the child nodes are XOR added to the data d of the node and packaged, and finally the hash value is calculated as:

[0112]

[0113] Wherein, keccak represents the keccak256 hash algorithm;

[0114] The current hash value of the tree node is compared with the recorded hash value layer by layer to determine whether the data or topology of the subtree corresponding to the tree node is tampered with. If the current hash value is the same as the recorded hash value, the subtree is not modified. If the current hash value is different from the recorded hash value, the hash values are compared layer by layer from top to bottom, and the tampered child node is found at each layer until the final tampered position is found. This function embodies data confidentiality, data integrity and maintainability.

[0115] Embodiment 3

[0116] As Figure 8 shown, the embodiment proposes a blockchain smart contract service framework application system based on hash multi-way tree, comprising:

[0117] A node smart contract module provides a node smart contract, the node smart contract contains a 160-bit data slot, a 256-bit hash value and an ordered hash mapping table;

[0118] An ordered hash mapping contract module contains a linked list and an unordered hash mapping to realize ordered hash mapping;

[0119] An access control contract module checks whether a user has a specific role and permission when the user performs an access operation;

[0120] A data management contract module provides a consistent, path-based data access interface for users, integrates data serialization and deserialization engines;

[0121] A contract management contract module provides a consistent contract management interface for users, and realizes contract version control function by switching the mounted smart contract on the hash multi-way tree;

[0122] A permission management contract module provides definition and modification operations of roles and permissions for users.

[0123] Obviously, the above embodiments of the present application are only examples for clearly illustrating the present application, and are not intended to limit the embodiments of the present application. For those skilled in the art, on the basis of the above description, other different forms of changes or variations can also be made. Here, it is not necessary and also impossible to exhaust all the embodiments. Any modification, equivalent replacement and improvement made within the spirit and principle of the present application shall be included in the protection scope of the claims of the present application.

Claims

1. A method for designing a hash multi-tree based blockchain smart contract service framework, characterized in that, Comprising the following steps: Designing several node smart contracts based on smart contract language Node ; Let each node smart contract Node As a tree node, the several node smart contracts Node Connected with each other, forming a hash multi-tree on the blockchain; Each node smart contract Node contains an ordered hash map that records the contract addresses of other node smart contracts Node of entities on the blockchain, and the entity of the node smart contract Node containing the ordered hash map records the entity of other node smart contracts Node as child nodes of the entity of the node smart contract The one ordered hash mapping table includes one key-address unordered mapping and one key-key linked list, the key-address unordered mapping refers to mapping 256-bit key on the blockchain to a 160-bit contract address, the key-key linked list refers to each contract address mapped by the key-address unordered mapping being a linked list node; one key- key linked list node includes 256-bit values of a previous linked list node, a next linked list node and a current linked list node, the previous linked list node and the next linked list node respectively represent keys corresponding to a previous linked list node and a next linked list node, and the value of the current linked list node represents a value finally mapped by the key; For each tree node of the hash multi-tree, a role and permission based access mechanism is built in to check whether a user has a specific role and permission; An external user access interface is provided to provide serialization and deserialization engines; The serialization engine serializes the data and topology of the hash multi-tree into a string and submits it to the user, and the deserialization engine accepts a string from the user and adds, modifies or deletes data and topology on the hash multi-tree according to the string.

2. The hash multi-tree based blockchain smart contract service framework design method of claim 1, wherein, The blockchain smart contract service framework is divided into a bottom layer, a middle layer and a top layer, wherein the bottom layer is a support layer for providing basic data, security and type conversion functions for the blockchain smart contract service framework; the middle layer is a data layer composed of a hash multi-tree; and the top layer is an interface layer for providing an external user access interface; The smart contract language is Solidity a smart contract language. 3.The hash multi-tree based blockchain smart contract service framework design method of claim 1, wherein, Through a key-key Linked list and a key-address Unordered mappings implement ordered mapping contracts, where, key- key The linked list records the smart contracts of a certain node. Node All child nodes of the entity key In a linked list, each node corresponds to a child node and a corresponding value. key The value was recorded, along with the contract address of that node; key-address Unordered mappings will key Mapping to a linked list node, obtaining the contract address of the child node through the linked list node, and completing the process. key The mapping to child nodes is such that each linked list node records the information of its adjacent linked list nodes. key Value, can be obtained through key-address Unordered mappings are used to traverse linked lists. An entity of the ordered mapping contract maps a 256-bit key value to a 160-bit address value, where, address the value is an address of an arbitrary smart contract on the blockchain; each entity of a node smart contract Node contains an entity of the ordered mapping contract, through which the key-value mapping of a key value within any 256-bit key is mapped to the contract address of a child node, and the ordered mapping contract supports the traversal of the child nodes by the entity of the node smart contract Node through access to the linked list.

4. The hash multi-tree based blockchain smart contract framework design method of claim 3, wherein, Each tree node on the hash multi-tree corresponds to a node smart contract Node Each tree node on the hash multi-tree corresponds to a node smart contract Each tree node on the hash multi-tree corresponds to a node smart contract key Each tree node on the hash multi-tree corresponds to a node smart contract i Each tree node on the hash multi-tree corresponds to a node smart contract Each tree node on the hash multi-tree corresponds to a node smart contract Each tree node on the hash multi-tree corresponds to a node smart contract wherein, represents the accessed th i tree node, represents the data of the accessed tree node record, represents the path of the accessed tree node in the hash trie, the set represents the keys of each tree node along the path , represents each tree node along the path , represents the operation of extracting data from a tree node, () represents the operation of extracting a child node from a tree node according to a specified key.

5. The hash multi-tree based blockchain smart contract framework design method of claim 4, wherein, The node smart contract Node The entity has a data slot of 160 bits for storing any data within 160 bits or a smart contract address, wherein: When storing any data within 160 bits, the entity where the data slot is located is used as a structured data field on the blockchain, which means that a user can access a specific data on the blockchain through a specific path; In the storage of the smart contract address, the entity where the data slot is located is used as a smart virtual entity or a smart contract version backup on the blockchain, the smart virtual entity refers to a smart contract with smart logic and behavior mounted by the blockchain smart contract service framework on a specific path, the smart contract version backup refers to a non-current version of a certain deployed smart contract mounted by the blockchain smart contract service framework under a certain hidden path, and the mounting refers to recording the address of a certain deployed smart contract in the data slot of the entity of the node smart contract on a certain determined path. Node ​ smart contracts M Mount to tree node I When access to smart contracts is required M First, extract the visited tree nodes. I Recorded data , and then from Extract smart contracts M The process satisfies: wherein, represents an operation of extracting a smart contract according to a smart contract address, represents a user accessing a smart contract M .

6. The hash multi-tree based blockchain smart contract framework design method of claim 1, wherein, A user can access a specific node's smart contract only if the user has specific permissions for a specific role. Node The access mechanism based on roles and permissions is specifically expressed as follows: wherein, denotes the set of all users, denotes the set of all defined roles, denotes the set of all defined permissions, denotes the mapping table of users to roles, denotes the mapping table of roles to permissions, and are specified by the user, is a proposition that is true when the user has the permission .

7. The hash multi-tree based blockchain smart contract framework design method of claim 6, wherein, When the role-based and permission-based access mechanism is built in each tree node of the hash multi-way tree, the hash algorithm and the automatic error algorithm are built in the hash multi-way tree, the hash value is calculated from bottom to top in the hash multi-way tree, and the hash value of any tree node considers not only the data of the tree node itself, but also the hash values of all child nodes of the tree node, and each tree node collects the hash values of the child nodes thereof Supposing that the data of the tree node is d, the hash values of the child nodes are , the data d of the node is , and the hash values of the child nodes are XORed with the data d of the node and packed, the final hash value is calculated as follows: wherein represents keccak256 hashing algorithm; The current hash value of the tree node is compared with the recorded hash value layer by layer to determine whether the data or topology of the subtree corresponding to the tree node has been tampered with; if the current hash value is the same as the recorded hash value, the subtree has not been modified; if the current hash value is different from the recorded hash value, the hash values are compared layer by layer from top to bottom, and the tampered child node is found at each layer until the final tampered position is found. 8.The hash multi-tree based blockchain smart contract framework design method of claim 1, wherein, The user access interface provides a unified interface contract, a data management contract, a contract management contract and a permission management contract; the serialization format is Json format; the expression of the string from the user is: wherein, represents a string in Json format from a user, ( ) represents a Json encoding algorithm, represents the th operation, the path of the tree node operated, the specific operation, the value of the operation; the deserialization engine extracts from the received string, and defines data in the hash multi-tree according to the description of .​​ 9.A hash multi-tree based blockchain smart contract service framework application system, characterized in that, Comprising: A node smart contract module provides a node smart contract, which includes a 160-bit data slot, a 256-bit hash value and an ordered hash mapping table; Let each node smart contract Node As a tree node, several node smart contracts Node Connected with each other, forming a hash multi-tree on the blockchain; Each node smart contract Node contains an ordered hash map that records the contract addresses of other node smart contracts Node of entities on the blockchain, and the entity of each node smart contract Node that records other node smart contracts Node of entities in the ordered hash map as a child node of the node smart contract The one ordered hash mapping table includes one key-address unordered mapping and one key-key linked list, the key-address unordered mapping refers to mapping 256-bit key contract addresses on the blockchain to 160-bit contract addresses, the key-key linked list refers to each contract address mapped by the key-address unordered mapping being a linked list node; one key- key linked list node includes 256-bit values of a previous linked list node, a next linked list node and a current linked list node, the previous linked list node and the next linked list node respectively represent keys corresponding to a previous linked list node and a next linked list node, and the value of the current linked list node represents a value finally mapped by the key; An ordered hash mapping contract module includes a linked list and an unordered hash mapping to implement ordered hash mapping; An access control contract module checks whether a user has a specific role and permission when the user performs an access operation; The data management contract module provides a consistent and path-based data access interface for users, integrates a data serialization engine and a deserialization engine; The contract management contract module provides a consistent contract management interface for users, and realizes contract version control function by switching the mounted smart contract on the hash multi-way tree; The permission management contract module provides definition and modification operations of roles and permissions for users.

Citation Information

Patent Citations

  • Block chain-based data storage method, electronic integral processing method and system

    CN112035491A

  • Blockchain-based smart contract invocation method, apparatus and device

    WO2023103341A1