CN114444097A - Blockchain-based user access method, device, electronic device and storage medium - Google Patents
Blockchain-based user access method, device, electronic device and storage medium Download PDFInfo
- Publication number
- CN114444097A CN114444097A CN202210028059.6A CN202210028059A CN114444097A CN 114444097 A CN114444097 A CN 114444097A CN 202210028059 A CN202210028059 A CN 202210028059A CN 114444097 A CN114444097 A CN 114444097A
- Authority
- CN
- China
- Prior art keywords
- user
- value
- blockchain
- smart contract
- target user
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 65
- 238000011156 evaluation Methods 0.000 claims abstract description 138
- 238000010801 machine learning Methods 0.000 claims description 23
- 230000004044 response Effects 0.000 claims description 10
- 239000003999 initiator Substances 0.000 claims description 4
- 238000012549 training Methods 0.000 description 23
- 238000012360 testing method Methods 0.000 description 19
- 230000006870 function Effects 0.000 description 18
- 230000008569 process Effects 0.000 description 17
- 230000008859 change Effects 0.000 description 12
- 238000010586 diagram Methods 0.000 description 11
- 238000005516 engineering process Methods 0.000 description 7
- 238000012546 transfer Methods 0.000 description 6
- 230000006399 behavior Effects 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 3
- 238000007726 management method Methods 0.000 description 3
- 230000002085 persistent effect Effects 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 238000013500 data storage Methods 0.000 description 2
- 238000003066 decision tree Methods 0.000 description 2
- 238000007477 logistic regression Methods 0.000 description 2
- 230000007257 malfunction Effects 0.000 description 2
- 238000004519 manufacturing process Methods 0.000 description 2
- 239000003607 modifier Substances 0.000 description 2
- 230000008520 organization Effects 0.000 description 2
- 238000007619 statistical method Methods 0.000 description 2
- OKTJSMMVPCPJKN-UHFFFAOYSA-N Carbon Chemical compound [C] OKTJSMMVPCPJKN-UHFFFAOYSA-N 0.000 description 1
- 241000270295 Serpentes Species 0.000 description 1
- 241000207961 Sesamum Species 0.000 description 1
- 235000003434 Sesamum indicum Nutrition 0.000 description 1
- 230000009471 action Effects 0.000 description 1
- 238000004873 anchoring Methods 0.000 description 1
- 238000013475 authorization Methods 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 239000006227 byproduct Substances 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000011478 gradient descent method Methods 0.000 description 1
- 229910021389 graphene Inorganic materials 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 229920001690 polydopamine Polymers 0.000 description 1
- 238000007781 pre-processing Methods 0.000 description 1
- 239000000047 product Substances 0.000 description 1
- 238000012216 screening Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/604—Tools and structures for managing or administering access control systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/21—Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
- G06F18/214—Generating training patterns; Bootstrap methods, e.g. bagging or boosting
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q20/00—Payment architectures, schemes or protocols
- G06Q20/38—Payment protocols; Details thereof
- G06Q20/40—Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
- G06Q20/401—Transaction verification
- G06Q20/4016—Transaction verification involving fraud or risk level assessment in transaction processing
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- General Physics & Mathematics (AREA)
- Business, Economics & Management (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Accounting & Taxation (AREA)
- Data Mining & Analysis (AREA)
- Computer Hardware Design (AREA)
- General Health & Medical Sciences (AREA)
- Bioethics (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Life Sciences & Earth Sciences (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Finance (AREA)
- Strategic Management (AREA)
- General Business, Economics & Management (AREA)
- Automation & Control Theory (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
Description
技术领域technical field
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种基于区块链的用户准入方法、装置、电子设备及存储介质。One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a blockchain-based user access method, apparatus, electronic device, and storage medium.
背景技术Background technique
机构需要给用户提供信用服务,因此会检查用户的特征的数值,当用户特征的数值满足预设条件时,则允许用户准入,被准入的用户可以获得机构提供的服务。现有的相关技术中,检查用户的特征的数值采用的策略是一种“断路”的策略,即如果用户某一特征的数值被不满足预设条件,则不允许用户准入;由于一部分特征对用户信用的评判不重要,如果用户仅因为不重要的特征而不予准入,则用户会投诉;同时现有的相关技术检查时运行在特定的服务器上,一旦服务器被恶意控制或发生故障,对用户准入的判断会不准确。The institution needs to provide users with credit services, so it will check the value of the user's characteristics. When the value of the user's characteristics meets the preset conditions, the user is allowed to enter, and the admitted user can obtain the services provided by the institution. In the existing related art, the strategy used to check the value of the user's feature is a "circuit breaker" strategy, that is, if the value of a certain feature of the user does not meet the preset conditions, the user is not allowed to enter; Judgment of user credit is not important. If the user is denied access only because of unimportant features, the user will complain; at the same time, the existing related technology is run on a specific server. Once the server is maliciously controlled or malfunctions , the judgment of user access will be inaccurate.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本申请提供一种基于区块链的用户准入方法及装置、电子设备。In view of this, the present application provides a blockchain-based user access method, device, and electronic device.
根据本申请的第一方面,一种基于区块链的用户准入方法,应用于所述区块链中的节点设备;所述区块链中部署有用于对用户进行准入评估的智能合约,所述区块链的区块中预先存储有用户特征的数值;所述方法包括步骤:According to a first aspect of the present application, a blockchain-based user access method is applied to node devices in the blockchain; a smart contract for evaluating user access is deployed in the blockchain , the values of user characteristics are pre-stored in the blocks of the blockchain; the method includes the steps:
接收对目标用户的准入评估交易;其中,所述准入评估交易用于调用所述智能合约获取与所述目标用户关联的所述用户特征的数值;Receive an access evaluation transaction for the target user; wherein, the access evaluation transaction is used to call the smart contract to obtain the value of the user characteristic associated with the target user;
响应于所述准入评估交易,调用所述智能合约查询所述目标用户对应的历史信用评估值是否已被存储在区块链的区块中;In response to the admission evaluation transaction, invoking the smart contract to query whether the historical credit evaluation value corresponding to the target user has been stored in the block of the blockchain;
基于查询结果或调用智能合约确定所述目标用户是否允许准入。Whether the target user is allowed to enter is determined based on the query result or invoking the smart contract.
根据本申请的第二方面,提供了一种基于区块链的用户准入装置,所述装置应用于所述区块链中的节点设备;所述区块链中部署有用于对用户进行准入评估的智能合约,所述区块链的区块中预先存储有用户特征的数值;所述装置包括:According to a second aspect of the present application, a blockchain-based user admission device is provided, the device is applied to node devices in the blockchain; The smart contract entered into the evaluation, the value of the user characteristic is pre-stored in the block of the blockchain; the device includes:
接收模块,用于接收对目标用户的准入评估交易;其中,所述准入评估交易用于调用所述智能合约获取与所述目标用户关联的所述用户特征的数值;a receiving module, configured to receive an access evaluation transaction for a target user; wherein, the access evaluation transaction is used to call the smart contract to obtain the value of the user characteristic associated with the target user;
查询模块,用于响应于所述准入评估交易,调用所述智能合约查询所述目标用户对应的历史信用评估值是否已被存储在区块链的区块中;基于查询结果或调用智能合约确定所述目标用户是否允许准入。The query module is used for invoking the smart contract to query whether the historical credit evaluation value corresponding to the target user has been stored in the block of the blockchain in response to the admission evaluation transaction; based on the query result or calling the smart contract It is determined whether the target user is allowed to admit.
根据本申请的第三方面,提供了一种电子设备,所述电子设备包括处理器;According to a third aspect of the present application, there is provided an electronic device, the electronic device comprising a processor;
用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
其中,所述处理器通过运行所述可执行指令以实现本申请第一方面所述的方法。Wherein, the processor implements the method described in the first aspect of the present application by running the executable instructions.
根据本申请的第四方面,提供了一种计算机可读存储介质,所述可读存储介质上有计算机指令,该指令被处理器执行时实现本申请第一方面所述的方法的步骤。According to a fourth aspect of the present application, a computer-readable storage medium is provided, and the readable storage medium has computer instructions, and when the instructions are executed by a processor, implement the steps of the method described in the first aspect of the present application.
在上述技术方案中,由于调用所述智能合约中的智能合约代码对应的查询逻辑,基于查询结果或调用智能合约确定所述目标用户是否允许准入,实现对用户准入的判断更准确,减少用户投诉率,提升用户的准入概率。并且将所确定出的信用评估值存入所述区块链的区块中,保证准入信用评估值可追溯及不可篡改,实现用户准入的安全和可靠。In the above technical solution, since the query logic corresponding to the smart contract code in the smart contract is invoked, it is determined whether the target user is allowed access based on the query result or the smart contract is invoked, so as to realize a more accurate judgment on user access and reduce The user complaint rate increases the user's access probability. And the determined credit evaluation value is stored in the block of the blockchain to ensure that the access credit evaluation value can be traced back and cannot be tampered with, so as to realize the safety and reliability of user access.
附图说明Description of drawings
图1是一示例性实施例提供的一种将区块链的账户状态数据组织成MPT状态树的示意图;FIG. 1 is a schematic diagram of organizing account state data of a blockchain into an MPT state tree provided by an exemplary embodiment;
图2是一示例性实施例提供的一种将合约账户对应的存储空间中存储的合约数据组织成MPT storage树的示意图;2 is a schematic diagram of organizing contract data stored in a storage space corresponding to a contract account into an MPT storage tree provided by an exemplary embodiment;
图3是一示例性实施例提供的创建智能合约和调用智能合约的示意图;3 is a schematic diagram of creating a smart contract and invoking a smart contract provided by an exemplary embodiment;
图4是一示例性实施例提供的一种基于区块链的智能合约管理方法的流程图;4 is a flowchart of a blockchain-based smart contract management method provided by an exemplary embodiment;
图5是一示例性实施例提供的另一种基于区块链的智能合约管理方法的流程图;5 is a flowchart of another blockchain-based smart contract management method provided by an exemplary embodiment;
图6是一示例性实施例提供的一种基于区块链的用户准入系统使用的示意图;6 is a schematic diagram of the use of a blockchain-based user access system provided by an exemplary embodiment;
图7是一示例性实施例提供的一种基于区块链的用户准入方法的流程图;7 is a flowchart of a blockchain-based user access method provided by an exemplary embodiment;
图8是一示例性实施例提供的一种基于区块链的用户准入方法的装置的框图;8 is a block diagram of an apparatus for a blockchain-based user access method provided by an exemplary embodiment;
图9是一示例性实施例提供的一种电子设备的硬件结构图。FIG. 9 is a hardware structure diagram of an electronic device provided by an exemplary embodiment.
具体实施方式Detailed ways
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书一个或多个实施例相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. Where the following description refers to the drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatus and methods consistent with some aspects of one or more embodiments of this specification, as recited in the appended claims.
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。It should be noted that: in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step in other embodiments. describe.
区块链通常是由若干个区块构成。在这些区块中分别记录有与该区块的创建时刻对应的时间戳,所有的区块严格按照区块中记录的时间戳,构成一条在时间上有序的数据链条。A blockchain is usually composed of several blocks. Timestamps corresponding to the creation time of the blocks are respectively recorded in these blocks, and all blocks form a time-ordered data chain strictly according to the timestamps recorded in the blocks.
对于链外产生的数据,可以将其构建成区块链所支持的标准的交易(transaction)格式,然后发布至区块链,由区块链中的节点设备对该交易进行共识,并在达成共识后,由区块链中作为记账节点的节点设备,将这笔交易打包进区块,在区块链中进行持久化存证。For the data generated outside the chain, it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain. After the consensus, the node device in the blockchain as the accounting node will package the transaction into the block and store the certificate persistently in the blockchain.
目前的区块链系统通常包括两种主流的交易模型;其中,一种是UTXO(UnspentTransaction Output,未花费的交易输出)模型;而另外一种则是账户模型。The current blockchain system usually includes two mainstream transaction models; one is the UTXO (UnspentTransaction Output, unspent transaction output) model; the other is the account model.
其中,以上两类区块链如果想要实现数据存证,通常可以采用如下的存证方式:Among them, if the above two types of blockchains want to realize the data storage certificate, the following storage methods can usually be adopted:
对于采用UTXO模型的区块链,支持的原生交易通常只包括转账交易,在基于转账交易进行转账的过程中,用户可以通过在转账交易中的交易附言(即转账附言)中来填充额外的数据,来将该额外的数据在区块链上进行存证。For blockchains using the UTXO model, the supported native transactions usually only include transfer transactions. In the process of transferring funds based on transfer transactions, users can fill in additional transactions in the transaction postscript (ie, transfer postscript) in the transfer transaction. to store the additional data on the blockchain.
对于采用账户模型的区块链,需要存储和维护的区块链数据,通常包括区块数据、区块链中的区块链账户对应的账户状态数据;而区块数据又可以进一步包括区块头数据、区块中的区块交易数据、以及与区块中的区块交易数据对应的交易收据,等等。而在存储以上示出的各种区块链数据时,通常可以将上述各种区块链数据以key-value键值对的形式,组织成Merkle树在数据库中存储。For the blockchain that adopts the account model, the blockchain data that needs to be stored and maintained usually includes the block data and the account status data corresponding to the blockchain account in the blockchain; and the block data can further include the block header. data, block transaction data in blocks, and transaction receipts corresponding to block transaction data in blocks, etc. When storing the various blockchain data shown above, the various blockchain data described above can usually be organized into a Merkle tree in the form of key-value pairs and stored in the database.
在这类区块链模型中,可以在区块链上部署用于进行数据存证的智能合约,用户可以通过调用智能合约的方式,将需要存证的数据作为该智能合约对应的合约账户的账户状态,存储到与该智能合约对应的Merkle树中。In this type of blockchain model, a smart contract for data storage can be deployed on the blockchain, and users can call the smart contract to use the data that needs to be stored as the contract account corresponding to the smart contract. Account status, stored in the Merkle tree corresponding to the smart contract.
例如,以账户模型的区块链网络为例,通常采用一种特殊的称之为MPT树的特殊的Merkle树来存储和维护区块链数据;其中,对于账户状态数据,可以组织成MPT状态树(俗称世界状态)在数据库中存储;MPT状态树上存储了以账户地址为key,以账户状态数据为value的key-value键值对。而智能合约对应的合约账户中存储的数据内容,也会被进一步组织成storage树(一种用于存储数据的MPT存储树)在数据库中存储;storage树的根节点的hash值,会作为与该合约账户对应的账户状态数据的一部分,填充到MPT状态树中;而MPT状态树的根节点的hash会被作为认证根,进一步填充到区块头中。当用户需要进行数据存证时,可以通过调用智能合约的方式,将需要存证的数据作为该智能合约对应的合约账户的账户状态数据,存储到与该智能合约对应的storage树中。For example, taking the blockchain network of the account model as an example, a special Merkle tree called MPT tree is usually used to store and maintain blockchain data; among them, the account status data can be organized into MPT status The tree (commonly known as the world state) is stored in the database; the MPT state tree stores the key-value pair with the account address as the key and the account state data as the value. The data content stored in the contract account corresponding to the smart contract will also be further organized into a storage tree (an MPT storage tree for storing data) and stored in the database; the hash value of the root node of the storage tree will be used as a Part of the account state data corresponding to the contract account is filled into the MPT state tree; and the hash of the root node of the MPT state tree will be used as the authentication root and further filled into the block header. When the user needs to store the data, the data that needs to be stored can be stored in the storage tree corresponding to the smart contract as the account status data of the contract account corresponding to the smart contract by invoking the smart contract.
在区块链领域,有一个重要的概念就是账户(Account);账户模型的区块链网络通常将账户划分为外部账户和合约账户两类;外部账户就是由用户直接控制的账户,也称之为用户账户;而合约账户则是由用户通过外部账户创建的,包含合约代码的账户(即智能合约)。In the field of blockchain, an important concept is Account; the blockchain network of the account model usually divides accounts into two types: external accounts and contract accounts; external accounts are accounts directly controlled by users, also known as It is a user account; while a contract account is an account (ie, a smart contract) that is created by the user through an external account and contains the contract code.
对于区块链中的账户而言,通常会通过一个结构体,来维护账户的账户状态。当区块中的交易被执行后,区块链中与该交易相关的账户的状态通常也会发生变化。For an account in the blockchain, a structure is usually used to maintain the account state of the account. When a transaction in a block is executed, the state of the account associated with that transaction in the blockchain usually changes as well.
在一个例子中,账户的结构体通常包括Balance,Nonce,Code和Storage等字段。其中:In one example, the structure of the account usually includes fields such as Balance, Nonce, Code and Storage. in:
Balance字段,用于维护账户目前的账户余额;The Balance field is used to maintain the current account balance of the account;
Nonce字段,用于维护该账户的交易次数;它是用于保障每笔交易能且只能被处理一次的计数器,有效避免重放攻击;The Nonce field is used to maintain the number of transactions of the account; it is a counter used to ensure that each transaction can be processed only once, effectively avoiding replay attacks;
Code字段,用于维护该账户的合约代码;在实际应用中,Code字段中通常仅维护合约代码的hash值;因而,Code字段通常也称之为Codehash字段。The Code field is used to maintain the contract code of the account; in practical applications, the Code field usually only maintains the hash value of the contract code; therefore, the Code field is usually also called the Codehash field.
Storage字段,用于维护该账户的存储内容;对于合约账户而言,通常会分配一个独立的存储空间,用以存储该合约账户的存储内容;该独立的存储空间通常称之为该合约账户的账户存储。The Storage field is used to maintain the storage content of the account; for a contract account, an independent storage space is usually allocated to store the storage content of the contract account; the independent storage space is usually referred to as the contract account's storage space. Account storage.
合约账户的存储内容通常会以key-value键值对的形式被构建成MPT(MerklePatricia Trie)树的数据结构存储在上述独立的存储空间之中。MPT树是区块链领域用于存储和维护区块链数据的一种逻辑的树形结构,在这种树形结构中通常包括根节点、中间节点、叶子节点。The storage content of the contract account is usually constructed into a data structure of an MPT (Merkle Patricia Trie) tree in the form of key-value key-value pairs and stored in the above-mentioned independent storage space. MPT tree is a logical tree structure used to store and maintain blockchain data in the blockchain field. This tree structure usually includes root nodes, intermediate nodes, and leaf nodes.
需要说明的是,所谓逻辑的树形结构,是指在数据库的底层物理存储中,并不存在与树形结构完全对应的物理存储结构,而仅在数据库中存储上述树形结构上的各个节点的物理数据以及各个节点之间的链接关系数据,从而可以基于数据库中存储的各个节点的物理数据和链接关系数据,在逻辑层面上还原出上述树形结构。It should be noted that the so-called logical tree structure means that in the underlying physical storage of the database, there is no physical storage structure completely corresponding to the tree structure, but only each node on the above tree structure is stored in the database. The physical data and the link relationship data between each node, so that the above tree structure can be restored at the logical level based on the physical data and link relationship data of each node stored in the database.
其中,基于合约账户的存储内容构建成的MPT树,通常也称之为Storage树。而Storage字段通常仅维护该Storage树的根节点;因此,Storage字段通常也称之为StorageRoot字段。对于外部账户而言,以上示出的Code字段和Storage字段的字段值均为空值。Among them, the MPT tree constructed based on the storage content of the contract account is also commonly referred to as the Storage tree. The Storage field usually only maintains the root node of the Storage tree; therefore, the Storage field is usually also called the StorageRoot field. For an external account, the field values of the Code field and Storage field shown above are all null values.
对于区块链的节点设备来说,需要存储和维护的区块链数据,通常包括区块数据、区块链中的区块链账户对应的账户状态数据;而区块数据又可以进一步包括区块头数据、区块中的区块交易数据、以及与区块中的区块交易数据对应的交易收据,等等。For the node device of the blockchain, the blockchain data that needs to be stored and maintained usually includes the block data and the account status data corresponding to the blockchain account in the blockchain; and the block data can further include the block data. Block header data, block transaction data in the block, and transaction receipts corresponding to the block transaction data in the block, etc.
对于大多数区块链模型,通常都会采用Merkle树;或者,基于Merkle树的数据结构的Merkle树变种等逻辑的树形结构,来存储和维护数据。例如,MPT树,就是一种用来存储和维护区块链数据的,融合了Trie字典树的树形结构的Merkle树变种。For most blockchain models, a Merkle tree is usually used; or a logical tree structure such as a Merkle tree variant based on the data structure of the Merkle tree is used to store and maintain data. For example, the MPT tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree for storing and maintaining blockchain data.
区块链的节点设备在存储以上示出的各种区块链数据时,通常可以将上述各种区块链数据以key-value键值对的形式,组织成上述逻辑的树形结构上的,在数据库中存储。当需要查询节点设备存储的上述各种区块链数据时,可以通过将上述各种区块链数据的key作为查询索引,遍历上述Merkle树来高效的查询数据。When the node device of the blockchain stores the various blockchain data shown above, it can usually organize the above various blockchain data in the form of key-value key-value pairs into the above-mentioned logical tree structure. , stored in the database. When it is necessary to query the above-mentioned various blockchain data stored in the node device, the data can be efficiently queried by traversing the above-mentioned Merkle tree by using the key of the above-mentioned various blockchain data as a query index.
例如,MPT(Merkle Patricia Trie)树,就是一种用来存储和维护区块链数据的,融合了Trie字典树的树形结构的Merkle树变种。For example, the MPT (Merkle Patricia Trie) tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree for storing and maintaining blockchain data.
以下以使用MPT树,来组织和存储区块链数据为例进行说明;The following is an example of using MPT tree to organize and store blockchain data;
其中,需要强调的是,以采用MPT树来组织和存储区块链数据,仅为示例性的。在实际应用中,除了可以采用诸如MPT树等改良版的Merkle树以外,也可以采用其它形式的融合了Trie字典树的Merkle树变种,在本说明书中不再进行一一列举。Among them, it should be emphasized that the use of MPT tree to organize and store blockchain data is only exemplary. In practical applications, in addition to an improved Merkle tree such as an MPT tree, other forms of Merkle tree variants incorporating the Trie dictionary tree can also be used, which will not be listed one by one in this specification.
在一个例子中,区块链中需要存储和维护的区块链数据,通常包括账户状态(state)数据、交易数据和收据数据;因此,在实际应用中,可以分别将上述账户状态数据、交易数据和收据数据以key-value键值对的形式,组成成MPT状态树(即world state)、MPT交易树和MPT收据树等三棵MPT树,分别进行存储和维护。In one example, the blockchain data that needs to be stored and maintained in the blockchain usually includes account state data, transaction data, and receipt data; therefore, in practical applications, the above account state data, transaction data, and transaction data can be stored and maintained, respectively. The data and receipt data are formed into three MPT trees in the form of key-value pairs, namely the MPT state tree (ie world state), the MPT transaction tree and the MPT receipt tree, which are stored and maintained respectively.
其中,除了以上三棵MPT树以外,合约账户对应的存储空间中存储的合约数据,通常也会被构建成为一棵MTP Storage树(以下简称为Storage树)。该Storage树的根节点的hash值,会被添加到与该Storage树对应的合约账户的上述结构体中的Storage字段。Among them, in addition to the above three MPT trees, the contract data stored in the storage space corresponding to the contract account is usually constructed as an MTP Storage tree (hereinafter referred to as the Storage tree). The hash value of the root node of the Storage tree will be added to the Storage field in the above structure of the contract account corresponding to the Storage tree.
MPT状态树,是由区块链中所有账户(包括外部账户和合约账户)的账户状态(state)数据,以key-value键值对的形式组织成的MPT树;MPT交易树,是由区块链中的交易(transaction)数据,以key-value键值对的形式组织成的MPT树;MPT收据树,是区块中的交易在执行完毕后生成的与每笔交易对应的交易(receipt)收据,以key-value键值对的形式组织成的MPT树。The MPT state tree is an MPT tree organized by the account state data of all accounts (including external accounts and contract accounts) in the blockchain in the form of key-value pairs; the MPT transaction tree is composed of The transaction data in the block chain is an MPT tree organized in the form of key-value key-value pairs; the MPT receipt tree is the transaction corresponding to each transaction generated after the transaction in the block is executed. ) receipt, an MPT tree organized in the form of key-value pairs.
以上示出的MPT状态树、MPT交易树和MPT收据树的根节点的hash值,最终都会被添加至对应区块的区块头中。The hash values of the root nodes of the MPT state tree, MPT transaction tree, and MPT receipt tree shown above will eventually be added to the block header of the corresponding block.
其中,MPT交易树和MPT收据树均与区块相对应,即每一个区块都有自己的MPT交易树和MPT收据树。而MPT状态树是一个全局的MPT树,并不与某一个特定的区块相对应,而是涵盖了区块链中所有账户的账户状态数据。Among them, both the MPT transaction tree and the MPT receipt tree correspond to blocks, that is, each block has its own MPT transaction tree and MPT receipt tree. The MPT state tree is a global MPT tree, which does not correspond to a specific block, but covers the account state data of all accounts in the blockchain.
区块链每产生一个最新区块,则在该最新区块中的交易被执行之后,区块链中这些被执行交易的相关账户(可以是外部账户也可以是合约账户)的账户状态,通常也会随之发生变化;Each time the blockchain generates a newest block, after the transactions in the latest block are executed, the account status of the relevant accounts (which can be external accounts or contract accounts) of the executed transactions in the blockchain, usually will also change accordingly;
例如,当区块中的一笔“转账交易”执行完毕后,与该“转账交易”相关的转出方账户和转入方账户的余额(即这些账户的Balance字段的字段值),通常也会随之发生变化。节点设备在区块链产生的最新区块中的交易执行完毕后,由于当前区块链中的账户状态发生了变化,因此节点设备需要根据区块链中所有账户当前的账户状态数据,来构建MPT状态树,用于维护区块链中所有账户的最新状态。For example, when a "transfer transaction" in the block is executed, the balances of the sender's account and the transferer's account related to the "transfer transaction" (that is, the field value of the Balance field of these accounts) are usually also will change accordingly. After the node device executes the transaction in the latest block generated by the blockchain, since the account status in the current blockchain has changed, the node device needs to construct the current account status data based on the current account status data of all accounts in the blockchain. The MPT state tree is used to maintain the latest state of all accounts in the blockchain.
也即,每当区块链中产生一个最新区块,并且该最新区块中的交易执行完毕后,导致区块链中的部分账户的账户状态发生了变化,节点设备需要基于区块链中所有账户最新的账户状态数据,重新构建一棵MPT状态树。换句话说,区块链中每一个区块,都有一个与之对应的MPT状态树;该MPT状态树,维护了在该区块中的交易在执行完毕后,区块链中所有账户最新的账户状态。That is, whenever a newest block is generated in the blockchain and the transaction in the latest block is executed, the account status of some accounts in the blockchain changes, and the node device needs to be based on the The latest account status data of all accounts, and rebuild an MPT status tree. In other words, each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains that after the transaction in the block is executed, all accounts in the blockchain are up-to-date. account status.
请参见图1,图1为本说明书示出的一种将区块链中的各个区块链账户的账户状态数据组织成MPT状态树的示意图。Please refer to FIG. 1. FIG. 1 is a schematic diagram of organizing the account status data of each blockchain account in the blockchain into an MPT state tree shown in this specification.
MPT树,是一种较为传统的经过改良的Merkle树变种,其融合了Merkle树和Trie字典树(也称之为前缀树)两种树形结构的优点。MPT tree is a more traditional and improved variant of Merkle tree, which combines the advantages of two tree structures of Merkle tree and Trie dictionary tree (also called prefix tree).
在MPT树中通常包括三种节点,分别为叶子节点(leaf node),扩展节点(extension node)和分支节点(branch node)。An MPT tree usually includes three kinds of nodes, namely, a leaf node (leaf node), an extension node (extension node) and a branch node (branch node).
其中,扩展节点和分支节点可以统称为字符节点,用于存储区块链数据的key对应的字符串的字符前缀部分;其中,对于MPT树而言,上述字符前缀部分通常是指共享字符前缀;所述共享字符前缀,是指所有区块链账户地址所具有的相同的一个或者多个字符组成的前缀。而上述叶子节点,用于存储区块链数据的key对应的字符串的字符后缀部分和Value(即具体的数据内容)Among them, the extension node and the branch node can be collectively referred to as character nodes, which are used to store the character prefix part of the character string corresponding to the key of the blockchain data; wherein, for the MPT tree, the above character prefix part usually refers to the shared character prefix; The shared character prefix refers to a prefix composed of the same one or more characters that all blockchain account addresses have. The above leaf nodes are used to store the character suffix part and Value (that is, the specific data content) of the string corresponding to the key of the blockchain data.
扩展节点,表示为[key,value]的一个键值对,其中key是种特殊的十六进制编码字符,表示账户地址的共享字符前缀;value是其它节点的hash值(hash指针),也就是说可以通过hash指针链接到其它节点。Extended node, represented as a key-value pair of [key, value], where key is a special hexadecimal coded character, representing the shared character prefix of the account address; value is the hash value (hash pointer) of other nodes, also That is to say, you can link to other nodes through the hash pointer.
分支节点,包含17个元素,前16个元素对应着key中的16个可能的十六进制字符,一个字符对应一个nibble(半字节),分别表示一个账户地址的共享字符前缀(长度为一个字符)。其中,如果有一个[key,value]对在这个分支节点终止,则该分支节点可以充当叶子节点的角色,最后一个元素则代表叶子节点的value值;反之,分支节点的最后一个元素,可以为空值。Branch node, including 17 elements, the first 16 elements correspond to the 16 possible hexadecimal characters in the key, and one character corresponds to a nibble (nibble), which respectively represent the shared character prefix of an account address (length is one character). Among them, if there is a [key, value] pair terminated at this branch node, the branch node can act as a leaf node, and the last element represents the value of the leaf node; otherwise, the last element of the branch node can be Null value.
叶子节点,是表示为[key,value]的一个键值对,其中key也是种特殊的十六进制编码字符,表示账户地址的字符后缀;其中,账户地址的字符后缀和账户地址的共享字符前缀共同组成了一个完整的账户地址;所述字符后缀,是指除了账户地址的共享字符前缀以外的最后一个或者多个字符组成的后缀;value是该叶子节点对应的账户地址的状态数据(即以上示出的结构体)。A leaf node is a key-value pair expressed as [key, value], where key is also a special hexadecimal coded character, representing the character suffix of the account address; among them, the character suffix of the account address and the shared character of the account address The prefix together forms a complete account address; the character suffix refers to the suffix consisting of the last one or more characters except the shared character prefix of the account address; value is the status data of the account address corresponding to the leaf node (ie structure shown above).
由于在MPT树上,从根节点到一个叶子节点的搜索路径上的字符,组成一个完整的账户地址;因此,对于分支节点而言,其既可以是上述搜索路径的终止节点,也可以是上述搜索路径的中间节点。Because on the MPT tree, the characters on the search path from the root node to a leaf node form a complete account address; therefore, for the branch node, it can be either the termination node of the above search path, or the above Intermediate nodes of the search path.
假设需要组织成MTP状态树的账户状态数据如下表1所示:Assume that the account state data that needs to be organized into an MTP state tree is shown in Table 1 below:
表1Table 1
其中,需要说明的是,在表1中,前三行的账户地址对应的区块链账户为外部账户,Codehash和Storage root字段为空值。第4行的账户地址对应的区块链账户为合约账户,Codehash字段维护了该合约账户对应的合约代码的hash值;Storage root字段维护了该合约账户的存储内容构成的Storage树的根节点的hash值。Among them, it should be noted that in Table 1, the blockchain account corresponding to the account address in the first three lines is an external account, and the fields of Codehash and Storage root are empty. The blockchain account corresponding to the account address in
最终按照表1中的账户状态数据组织成的MPT状态树,如图1所示;该MPT状态树是由4个叶子节点,2个分支节点,和2个扩展节点(其中一个扩展节点作为根节点)构成。Finally, the MPT state tree is organized according to the account state data in Table 1, as shown in Figure 1; the MPT state tree consists of 4 leaf nodes, 2 branch nodes, and 2 extension nodes (one of which is the extension node as the root). node) composition.
在图1中,prefix字段为扩展节点和叶子节点共同具有的前缀字段。该prefix字段的不同字段值可以用于表示不同的节点类型。In FIG. 1 , the prefix field is a prefix field shared by the extension node and the leaf node. Different field values of the prefix field can be used to represent different node types.
例如,prefix字段的取值为0,表示包含偶数个nibbles的扩展节点;如前所述,nibble表示半字节,由4位二进制组成,一个nibble可以对应一个组成账户地址的字符。prefix字段的取值为1,表示包含奇数个nibble(s)的扩展节点;prefix字段的取值为2,表示包含偶数个nibbles的叶子节点;prefix字段的取值为3,表示包含奇数个nibble(s)的叶子节点。For example, the value of the prefix field is 0, indicating an extension node containing an even number of nibbles; as mentioned above, a nibble represents a nibble, which is composed of 4-bit binary, and a nibble can correspond to a character that constitutes an account address. The value of the prefix field is 1, which means that the extension node contains an odd number of nibble(s); the value of the prefix field is 2, which means that the leaf node contains an even number of nibbles; the value of the prefix field is 3, which means that it contains an odd number of nibbles. (s) leaf nodes.
而分支节点,由于其是并列单nibble的字符节点,因此分支节点不具有上述prefix字段。The branch node, because it is a parallel single nibble character node, does not have the above prefix field.
扩展节点中的Shared nibble字段,对应该扩展节点所包含的键值对的key值,表示账户地址之间的共同字符前缀;比如,上表中的所有账户地址均具有共同的字符前缀a7。Next Node字段中填充下一个节点的hash值(hash指针)。The Shared nibble field in the extension node corresponds to the key value of the key-value pair contained in the extension node, indicating the common character prefix between account addresses; for example, all account addresses in the above table have a common character prefix a7. The Next Node field is filled with the hash value (hash pointer) of the next node.
分支节点中的16进制字符0~f字段,对应该分支节点所包含的键值对的key值;如果该分支节点为账户地址在MPT树上的搜索路径上的中间节点,则该分支节点的Value字段可以为空值。0~f字段中用于填充下一层节点的hash值。The
叶子节点中的Key-end,对应该叶子节点所包含的键值对的key值,表示账户地址的最后几个字符(账户地址的字符后缀)。从根节点搜索到叶子节点的搜索路径上的各个节点的key值,构成了一个完整的账户地址。该叶子节点的Value字段填充账户地址对应的账户状态数据;例如,可以对上述Balance,Nonce,Code和storage等字段构成的结构体进行编码后,填充至叶子节点的Value字段。The Key-end in the leaf node corresponds to the key value of the key-value pair contained in the leaf node, and represents the last few characters of the account address (the character suffix of the account address). The key value of each node on the search path from the root node to the leaf node constitutes a complete account address. The Value field of the leaf node is filled with the account status data corresponding to the account address; for example, the structure composed of the fields such as Balance, Nonce, Code, and storage can be encoded, and then filled into the Value field of the leaf node.
进一步的,如图1所示的MPT状态树上的node,最终也是以Key-Value键值对的形式存储在数据库中;Further, the nodes on the MPT state tree shown in Figure 1 are ultimately stored in the database in the form of Key-Value key-value pairs;
其中,当MPT状态树上的node在数据库中进行存储时,MPT状态树上的node的键值对中的key,可以为node所包含的数据内容的hash值;MPT状态树上的node的键值对中的Value,为node所包含的数据内容。Among them, when the node on the MPT state tree is stored in the database, the key in the key-value pair of the node on the MPT state tree can be the hash value of the data content contained in the node; the key of the node on the MPT state tree The Value in the value pair is the data content contained in the node.
在将MPT状态树上的node存储至数据库时,可以计算该node所包含的数据内容的hash值(即对node整体进行hash计算),并将计算出的hash值作为key,将该node所包含的数据内容作为value,生成Key-Value键值对;然后,将生成的Key-Value键值对存储至数据库中。When the node on the MPT state tree is stored in the database, the hash value of the data content contained in the node can be calculated (that is, the hash calculation is performed on the entire node), and the calculated hash value can be used as the key. The content of the data is used as value, and a Key-Value key-value pair is generated; then, the generated Key-Value key-value pair is stored in the database.
由于MPT状态树上的node,以Key-value键值对的形式进行存储;其中,Key可以是node所包含的数据内容的hash值,Value可以是node所包含的数据内容;因此,在需要查询MPT状态树上的node时,通常可以基于node所包含的数据内容的hash值作为key来进行内容寻址。Because the nodes on the MPT state tree are stored in the form of key-value pairs; among them, the key can be the hash value of the data content contained in the node, and the value can be the data content contained in the node; therefore, when you need to query When a node on the MPT state tree is used, content addressing can usually be performed based on the hash value of the data content contained in the node as a key.
请参见图2,图2为本说明书示出的一种将合约账户对应的存储空间中存储的合约数据组织成MPT storage树的示意图。Please refer to FIG. 2, which is a schematic diagram of organizing contract data stored in a storage space corresponding to a contract account into an MPT storage tree shown in this specification.
请继续参见表1,表1中示出的账户地址为“a77d397”的账户为合约账户,因此该合约账户对应的存储空间中存储的合约数据会被组织成一颗storage树;其中,该storage树的根节点的hash值S1,会被添加到图1示出的MTP状态树中与该合约账户对应的叶子节点中的storage root字段里。Please continue to refer to Table 1. The account whose account address is "a77d397" shown in Table 1 is a contract account, so the contract data stored in the storage space corresponding to the contract account will be organized into a storage tree; among them, the storage tree The hash value S1 of the root node will be added to the storage root field in the leaf node corresponding to the contract account in the MTP state tree shown in Figure 1.
假设该合约账户的存储空间中存储的合约数据如下表2所示:Assume that the contract data stored in the storage space of the contract account is shown in Table 2 below:
表2Table 2
需要说明的是,合约账户的存储空间中存储的合约数据,通常可以是状态变量的形式;在进行存储时,可以将状态变量名的hash值作为key,将状态变量名对应的变量取值作为value,以key-value键值对的形式组织成如图2所示的storage树进行存储。其中,图2示出的storage树的基本结构与图1示出的MTP状态树相似,在本说明书中不再赘述。It should be noted that the contract data stored in the storage space of the contract account can usually be in the form of state variables; when storing, the hash value of the state variable name can be used as the key, and the value of the variable corresponding to the state variable name can be used as the key. The value is organized into a storage tree as shown in Figure 2 in the form of key-value key-value pairs for storage. The basic structure of the storage tree shown in FIG. 2 is similar to the MTP state tree shown in FIG. 1 , and will not be repeated in this specification.
通过上述图1和图2的描述可知,基于MPT树的树形结构设计,分支节点可以存储所有账户地址的共享字符前缀中的其中一个字符;而扩展节点则可以存储所有账户地址的共享字符前缀中的一个或者多个字符。As can be seen from the descriptions of Figures 1 and 2 above, based on the tree structure design of the MPT tree, the branch node can store one of the characters in the shared character prefixes of all account addresses; and the extension node can store the shared character prefixes of all account addresses. one or more characters in .
在实际应用中,MPT树上存储的所有数据的key的共享字符前缀的字符长度,通常并不固定;而且,当MPT树上写入了新增的数据之后,可能导致上述共享字符前缀的字符长度,也会随之发生变化;因此,这就可能会导致MPT树上的扩展节点发生分裂,分裂出新的分支节点;也即,MPT树上的节点的分裂条件是,上述共享字符前缀的字符长度发生变化;In practical applications, the character length of the shared character prefix of the keys of all data stored in the MPT tree is usually not fixed; moreover, when the newly added data is written to the MPT tree, the characters of the above shared character prefix may be caused The length will also change accordingly; therefore, this may cause the expansion node on the MPT tree to split and split into new branch nodes; that is, the split condition of the nodes on the MPT tree is that the above-mentioned shared character prefix character length changes;
例如,以图1示出的MPT状态树为例,假设上述MPT状态树上新增了一个账户地址的前两位字符为“a8”的账户地址的账户状态数据,那么图1中示出的作为根节点的扩展节点的“Shared nible”字段存储的共享字符前缀,就会由“a7”,改变为“a”;按照MPT状态树的节点的分裂条件,这个作为根节点的扩展节点,会分裂成一个存储的共享字符前缀为“a”的扩展节点;和一个字符“8”被占用的分支节点。For example, taking the MPT state tree shown in FIG. 1 as an example, assuming that an account state data of an account address whose first two characters of the account address are “a8” is added to the MPT state tree, then the MPT state tree shown in FIG. 1 The shared character prefix stored in the "Shared nible" field of the extension node of the root node will be changed from "a7" to "a"; according to the splitting conditions of the nodes of the MPT state tree, this extension node as the root node will be Split into an extension node where the shared character prefix "a" is stored; and a branch node where the character "8" is occupied.
在可编程的区块链中,可以通过面向用户提供智能合约(Smart contract)的功能,以支持用户在区块链网络中创建并调用一些复杂的逻辑。所谓智能合约是在区块链上可以被交易触发执行的程序。In a programmable blockchain, users can create and invoke some complex logic in the blockchain network by providing users with smart contracts. The so-called smart contract is a program on the blockchain that can be triggered and executed by a transaction.
在可编程的区块链中,每一个节点设备都可以搭载一个图灵完备的虚拟机作为智能合约的执行环境,通过它可以实现各种复杂的逻辑。In the programmable blockchain, each node device can be equipped with a Turing-complete virtual machine as the execution environment of smart contracts, through which various complex logics can be realized.
用户在区块链中发布和调用智能合约就是在虚拟机上运行的。实际上,虚拟机直接运行的是虚拟机代码(虚拟机字节码,下简称“字节码”),所以部署在区块链上的智能合约可以是字节码。Users publish and invoke smart contracts in the blockchain that run on virtual machines. In fact, the virtual machine directly runs the virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"), so the smart contract deployed on the blockchain can be bytecode.
如图3所示,Bob可以将一笔包含合约代码的智能合约创建交易发送到区块链网络后,各节点设备均可以在搭载的虚拟机中执行这笔交易。As shown in Figure 3, after Bob can send a smart contract creation transaction containing the contract code to the blockchain network, each node device can execute the transaction in the onboard virtual machine.
其中,图中3中交易的From字段用于记录发起创建智能合约的账户的地址,交易的Data字段的字段值保存的合约代码可以是上述字节码,交易的To字段的字段值为一个null(空)的账户。当节点间通过共识机制达成一致后,这个智能合约成功创建,后续用户可以调用这个智能合约。Among them, the From field of the transaction in Figure 3 is used to record the address of the account that initiated the creation of the smart contract, the contract code stored in the field value of the Data field of the transaction can be the above bytecode, and the field value of the To field of the transaction is a null (empty) account. When the nodes reach an agreement through the consensus mechanism, the smart contract is successfully created, and subsequent users can call the smart contract.
智能合约创建后,区块链上出现一个与该智能合约对应的合约账户,并拥有一个特定的地址;比如,图3中各节点中的“0x68e12cf284…”就代表了创建的这个合约账户的地址;合约代码(Code)和账户存储(Storage)将保存在该合约账户的账户存储中。智能合约的行为由合约代码控制,而智能合约的账户存储则保存了合约的状态。After the smart contract is created, a contract account corresponding to the smart contract appears on the blockchain and has a specific address; for example, "0x68e12cf284..." in each node in Figure 3 represents the address of the created contract account ; The contract code (Code) and account storage (Storage) will be saved in the account storage of the contract account. The behavior of the smart contract is controlled by the contract code, and the account storage of the smart contract saves the state of the contract.
前述提到,包含创建智能合约的交易的Data字段保存的可以是该智能合约的字节码。字节码由一连串的字节组成,每一字节可以标识一个操作。基于开发效率、可读性等多方面考虑,开发者可以不直接书写字节码,而是选择一门高级语言编写智能合约代码。例如,高级语言可以采用诸如Solidity、Serpent、LLL语言等。对于采用高级语言编写的智能合约代码,可以经过编译器编译,生成可以部署到区块链上的字节码。As mentioned above, the Data field containing the transaction that creates the smart contract can store the bytecode of the smart contract. Bytecode consists of a sequence of bytes, each of which can identify an operation. Based on development efficiency, readability and other considerations, developers can choose a high-level language to write smart contract code instead of writing bytecode directly. For example, high-level languages such as Solidity, Serpent, LLL, etc. may be used. For smart contract code written in a high-level language, it can be compiled by a compiler to generate bytecode that can be deployed on the blockchain.
以Solidity语言为例,用其编写的合约代码与面向对象编程语言中的类(Class)很相似,在一个合约中可以声明多种成员,包括状态变量、函数、函数修改器、事件等。状态变量是永久存储在智能合约的账户存储(Storage)字段中的值,用于保存合约的状态。Taking the Solidity language as an example, the contract code written in it is very similar to the class (Class) in the object-oriented programming language. A variety of members can be declared in a contract, including state variables, functions, function modifiers, events, etc. A state variable is a value that is permanently stored in a smart contract's account storage (Storage) field and is used to save the state of the contract.
如图4所示,仍以账户模型的区块链网络为例,Bob将一笔智能合约调用交易发送到账户模型的区块链网络后,各节点设备均可以在搭载的虚拟机中执行这笔交易。As shown in Figure 4, still taking the blockchain network of the account model as an example, after Bob sends a smart contract invocation transaction to the blockchain network of the account model, each node device can execute this function in the onboard virtual machine. transaction.
其中,图4中交易的From字段用于记录发起调用智能合约的账户的地址,To字段用于记录被调用的智能合约的地址,交易的Data字段用于记录调用智能合约的方法和参数。调用智能合约后,合约账户的账户状态可能改变。后续,某个客户端可以通过接入的区块链节点(例如图4中的节点1)查看合约账户的账户状态。Among them, the From field of the transaction in Figure 4 is used to record the address of the account that initiates the call to the smart contract, the To field is used to record the address of the called smart contract, and the Data field of the transaction is used to record the method and parameters of calling the smart contract. After calling the smart contract, the account status of the contract account may change. Subsequently, a client can view the account status of the contract account through the connected blockchain node (for example,
智能合约可以以规定的方式在区块链网络中每个节点独立的执行,所有执行记录和数据都保存在区块链上,所以当这样的交易执行完毕后,区块链上就保存了无法篡改、不会丢失的交易凭证。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. Tampered, never lost transaction credentials.
创建智能合约和调用智能合约的示意图如图5所示。账户模型的区块链网络中要创建一个智能合约,需要经过编写智能合约、变成字节码、部署到区块链等过程。账户模型的区块链网络中调用智能合约,是发起一笔指向智能合约地址的交易,各个节点的EVM可以分别执行该交易,将智能合约代码分布式的运行在账户模型的区块链网络中每个节点的虚拟机中。A schematic diagram of creating a smart contract and calling a smart contract is shown in Figure 5. To create a smart contract in the blockchain network of the account model, it needs to go through the process of writing the smart contract, converting it into bytecode, and deploying it to the blockchain. Invoking a smart contract in the blockchain network of the account model is to initiate a transaction pointing to the address of the smart contract. The EVM of each node can execute the transaction separately and run the smart contract code in a distributed manner in the blockchain network of the account model. in the virtual machine of each node.
在可编程的区块链中,通常可以支持将现实世界中的非货币属性的实体资产,转化为区块链上的数字资产。而将上述实体资产转化为上述数字资产,通常是指将该实体资产与区块链上的数字资产进行“锚定”,作为这些虚拟资产的价值支撑,进而在区块链上产生与实体资产的价值匹配,且能够在区块链上的区块链账户之间进行流通的数字资产的过程。In a programmable blockchain, it is usually possible to support the transformation of non-monetary physical assets in the real world into digital assets on the blockchain. Converting the above-mentioned physical assets into the above-mentioned digital assets usually refers to "anchoring" the physical assets with the digital assets on the blockchain, as the value support of these virtual assets, and then generating the physical assets on the blockchain. The process of digital assets that match the value of and can be circulated between blockchain accounts on the blockchain.
在实现时,可以对区块链支持的账户类型进行扩展,在区块链支持的账户类型的基础上,再扩展出一种资产账户(也称之为资产对象);比如,可以在区块链支持的外部账户、合约账户的基础上,再扩展出一种资产账户;扩展出的该资产账户,可以作为持有与现实世界中的非货币属性的实体资产价值锚定的数字资产的媒介。During implementation, the account types supported by the blockchain can be extended, and on the basis of the account types supported by the blockchain, an asset account (also called an asset object) can be expanded; On the basis of the external account and contract account supported by the chain, an asset account is extended; the extended asset account can be used as a medium for holding digital assets anchored to the value of non-monetary physical assets in the real world .
对于接入区块链的用户而言,除了可以在区块链上完成用户账户、智能合约的创建以外,也可以在区块链上创建一笔与现实世界的非货币属性的实体资产价值匹配的数字资产,在区块链上进行流通;For users who access the blockchain, in addition to completing the creation of user accounts and smart contracts on the blockchain, they can also create a value match with the real-world non-monetary physical asset value on the blockchain. The digital assets are circulated on the blockchain;
例如,用户可以将持有的房产、股票、贷款合同、票据、应收账款等非货币属性的实体资产,转换为价值匹配的数字资产在区块链上流通。For example, users can convert non-monetary physical assets such as real estate, stocks, loan contracts, bills, accounts receivable, etc. they hold into digital assets with matching value to circulate on the blockchain.
其中,对于上述资产账户而言,具体也可以通过一个结构体,来维护账户的账户状态。上述资产账户的结构体所包含的内容,可以与以上描述的结构体相同,当然也可以基于实际的需求进行设计;Among them, for the above asset account, the account status of the account can also be maintained through a structure. The content contained in the structure of the above asset account can be the same as the structure described above, and of course can also be designed based on actual needs;
在一种实现方式中,上述资产账户的结构体也可以包括以上描述的Balance,Nonce,Code和Storage等字段。In an implementation manner, the structure of the asset account may also include fields such as Balance, Nonce, Code, and Storage described above.
需要说明的是,Balance字段通常用于维护账户目前的账户余额;而对于上述资产账户而言,由于其锚定的实体资产,通常可能是无法基于余额进行计数的非余额类资产,因此可以对Balance字段的含义进行扩展,不再表示账户的“余额”,而是用于维护资产的地址信息。其中,在实际应用中,Balance字段中可以维护多笔“数字资产”对应的地址信息。It should be noted that the Balance field is usually used to maintain the current account balance of the account; for the above-mentioned asset accounts, due to the anchored entity assets, they may usually be non-balance assets that cannot be counted based on the balance. The meaning of the Balance field is expanded, and it no longer represents the "balance" of the account, but is used to maintain the address information of the asset. Among them, in practical applications, the address information corresponding to multiple "digital assets" can be maintained in the Balance field.
在这种情况下,以上示出的外部账户、合约账户和资产账户,均可以通过在Balance字段中,添加需要持有的“数字资产”的地址信息,来持有这笔数字资产。即除了外部账户和合约账户以外,资产账户本身也可以持有数字资产。In this case, the external account, contract account and asset account shown above can all hold this digital asset by adding the address information of the "digital asset" to be held in the Balance field. That is, in addition to external accounts and contract accounts, the asset account itself can also hold digital assets.
对于资产账户而言,Nonce,Code字段的字段值可以为空值(也可以不为空);而Storage字段的字段值可以不再是空值;Storage字段可以用于维护与该资产账户对应的“虚拟资产”的资产状态。其中,在Storage字段中维护与该资产账户对应的“虚拟资产”的资产状态的具体方式,可以基于需求灵活的进行设计,不再赘述。For the asset account, the field value of the Nonce and Code fields can be null (or not); the field value of the Storage field can no longer be null; the Storage field can be used to maintain the corresponding asset account. The asset status of the "virtual asset". The specific manner of maintaining the asset state of the "virtual asset" corresponding to the asset account in the Storage field can be flexibly designed based on requirements, and will not be described again.
区块链上部署的智能合约,通常只能访问区块链上存储的数据内容;而在实际应用中,对于一些基于智能合约技术实现的复杂的业务场景,智能合约可能还需要访问链外的数据实体上存储的外部数据。Smart contracts deployed on the blockchain can usually only access the data content stored on the blockchain; however, in practical applications, for some complex business scenarios based on smart contract technology, smart contracts may also need to access off-chain data. External data stored on a data entity.
在这种场景下,区块链上部署的智能合约,可以通过Oracle预言机,来访问链外的数据实体上的数据,进而实现智能合约与真实世界的数据实体之间的数据交互。其中,链外的数据实体,可以包括诸如部署在链外的中心化的服务器或者数据中心,等等。In this scenario, smart contracts deployed on the blockchain can access data on data entities outside the chain through Oracle oracles, thereby realizing data interaction between smart contracts and real-world data entities. The data entities outside the chain may include, for example, centralized servers or data centers deployed outside the chain, and so on.
当机构需要给用户提供信用服务时,会检查用户的特征的数值,当用户特征的值满足预设条件,则允许用户准入,被准入的用户可以获得机构提供的服务。以用户购房前申请住房贷款为例,需要检查的用户特征可以是用户缴纳的住房公积金,用户特征的数值可以是缴纳住房公积金的年限或者公积金的余额。现有的相关技术中,检查用户特征的数值采用的策略是一种“断路”的策略,即如果用户某一特征的数值不满足预设条件,则不允许用户准入;如用户未连续缴纳住房公积金满三年,则不允许获得住房公积金贷款。When the institution needs to provide users with credit services, it will check the value of the user's characteristics. When the value of the user's characteristics meets the preset conditions, the user is allowed to enter, and the admitted user can obtain the service provided by the institution. Taking a user applying for a housing loan before buying a house as an example, the user characteristic to be checked can be the housing provident fund paid by the user, and the value of the user characteristic can be the number of years of housing provident fund payment or the balance of the provident fund. In the existing related art, the strategy adopted for checking the value of the user feature is a "circuit breaker" strategy, that is, if the value of a certain feature of the user does not meet the preset conditions, the user is not allowed to enter; If the housing provident fund has been completed for three years, it is not allowed to obtain a housing provident fund loan.
由于一部分用户特征对用户信用的评判不重要,如果用户仅因为不重要的特征而不予准入,则用户会投诉;同时现有的相关技术检查用户特征的数值的相关代码运行在特定的服务器上,一旦服务器被恶意控制或发生故障,对用户准入的判断会不准确。Since some user characteristics are not important to the user's credit evaluation, if the user is denied access only because of unimportant characteristics, the user will complain; at the same time, the existing related technologies check the value of the user's characteristics. The relevant code runs on a specific server On the other hand, once the server is maliciously controlled or malfunctions, the judgment of user access will be inaccurate.
鉴于运用区块链技术,可以实现存储在区块链上的数据可追溯及不可篡改,并且区块链使用分布式的计算,让区块链运行在多个设备节点上,可以保证运行在区块链上的智能合约代码的安全和可靠。因此本申请提供了一种基于区块链的用户准入方法。In view of the use of blockchain technology, the data stored on the blockchain can be traced and cannot be tampered with, and the blockchain uses distributed computing, allowing the blockchain to run on multiple device nodes, which can ensure that it runs in the region. Security and reliability of smart contract code on the blockchain. Therefore, the present application provides a blockchain-based user access method.
请参考图6,图6是本说明书一示例性实施例示出的一种基于区块链的用户准入系统的示意图。Please refer to FIG. 6 , which is a schematic diagram of a blockchain-based user admission system according to an exemplary embodiment of this specification.
在如图6所示的基于区块链的用户准入系统中,在该区块链上可以部署智能合约。其中,该智能合约可以包括用于执行查询逻辑获取目标用户的信用评估值的智能合约代码。在实际应用中,通过执行查询逻辑获取目标用户的信用评估值的智能合约代码,可以实现获取用户的信用评估值,基于查询得出的信用评估值,确定是否允许用户准入。所述信用评估值,指在智能合约中采用对用户特征的数值进行运算得到的一个数值,该数值用来表征用户的信用好坏;通过信用评估值,可以确定是否能允许用户准入,对用户准入的判断更安全和准确。In the blockchain-based user admission system shown in Figure 6, smart contracts can be deployed on the blockchain. Wherein, the smart contract may include smart contract code for executing query logic to obtain the credit evaluation value of the target user. In practical applications, by executing the query logic to obtain the smart contract code of the target user's credit evaluation value, the user's credit evaluation value can be obtained, and based on the credit evaluation value obtained by the query, it is determined whether the user is allowed to enter. The credit evaluation value refers to a value obtained by calculating the value of the user's characteristics in the smart contract, and this value is used to represent the user's credit; The judgment of user access is more secure and accurate.
需要说明的是,创建和调用智能合约的具体流程可以参考前述智能合约的创建和调用流程,本说明书在此不再赘述。It should be noted that the specific process of creating and invoking a smart contract can refer to the above-mentioned process of creating and invoking a smart contract, which will not be repeated in this manual.
在具体实现时,目标用户可以通过与上述区块链中的节点设备建立连接的客户端发起用于调用该区块链上部署的上述智能合约的交易。该区块链中的节点设备在接收到该交易时,可以将该交易发送给该区块链中的其他节点设备,以对该交易进行共识处理,并在该交易共识通过后,执行该智能合约中的智能合约代码,实现对目标用户的准入操作。During specific implementation, the target user can initiate a transaction for invoking the above-mentioned smart contract deployed on the above-mentioned blockchain through a client that establishes a connection with a node device in the above-mentioned blockchain. When the node device in the blockchain receives the transaction, it can send the transaction to other node devices in the blockchain to perform consensus processing on the transaction, and after the transaction consensus is passed, execute the intelligent The smart contract code in the contract realizes the access operation to the target user.
在实际应用中,上述客户端可以部署在电子设备上,该电子设备可以是服务器、计算机、手机、平板设备、笔记本电脑、掌上电脑(PDAs,Personal Digital Assistants)等;同样地,作为节点设备加入至上述区块链的电子设备也可以是服务器、计算机、手机、平板设备、笔记本电脑、掌上电脑等;本说明书对此不作限制。In practical applications, the above client can be deployed on an electronic device, which can be a server, a computer, a mobile phone, a tablet device, a notebook computer, a PDA (Personal Digital Assistants), etc.; similarly, it is added as a node device The electronic devices connected to the above-mentioned blockchain can also be servers, computers, mobile phones, tablet devices, notebook computers, handheld computers, etc.; this specification does not limit this.
请参考图7,图7是本说明书一示例性实施例示出的一种基于区块链的用户准入方法的流程图。Please refer to FIG. 7. FIG. 7 is a flowchart of a blockchain-based user access method according to an exemplary embodiment of this specification.
结合如图6所示的基于区块链的用户准入系统,上述基于区块链的用户准入方法可以应用于如图6所示的区块链中的节点设备;该基于区块链的用户准入方法可以包括以下步骤:Combined with the blockchain-based user access system shown in Figure 6, the above-mentioned blockchain-based user access method can be applied to the node devices in the blockchain as shown in Figure 6; The user admission method may include the following steps:
步骤702,接收对目标用户的准入评估交易。Step 702: Receive an access evaluation transaction for the target user.
其中,所述准入评估交易用于调用所述智能合约获取与所述目标用户关联的所述用户特征的数值。Wherein, the admission evaluation transaction is used for invoking the smart contract to obtain the value of the user characteristic associated with the target user.
步骤704,响应于所述准入评估交易,调用所述智能合约查询所述目标用户对应的历史信用评估值是否已被存储在区块链的区块中。
步骤706,基于查询结果或调用智能合约确定所述目标用户是否允许准入。
在本实施例中,在上述区块链上可以部署智能合约,目标用户是指需要查询是否可以准入的用户。在本实施例中,该区块链中的节点设备可以响应于所述对目标用户的准入评估交易,即目标用户可以通过与上述区块链中的节点设备建立连接的客户端发起用于调用该区块链上部署的该智能合约的交易该交易即对目标用户的准入评估交易。In this embodiment, a smart contract can be deployed on the above-mentioned blockchain, and the target user refers to a user who needs to check whether access is possible. In this embodiment, the node device in the blockchain can respond to the admission evaluation transaction for the target user, that is, the target user can initiate a connection with the node device in the blockchain through the client The transaction that invokes the smart contract deployed on the blockchain is an admission evaluation transaction for the target user.
步骤702中,智能合约上存在从区块链上的区块中获取与目标用户相关联的特征的数值的代码,通过运行上述代码,在智能合约中可以读取到目标用户的特征的数值。目标用户的特征的数值,由机构预先存储在区块链的区块上。In
作为例子,在执行步骤706时,如果查询到已存储的查询结果,则可以进一步检查所述目标用户关联的用户特征的数值是否匹配,以确定目标用户关联的用户特征的数值是否更改,如果匹配,则说明未更改,则基于该历史信用评估值确定所述目标用户是否允许准入。如果所述目标用户关联的用户特征的数值发生更改,或者未查询到查询结果,也就是目标用户对应的历史信用评估值不存在,则调用智能合约确定出信用评估值,确定所述目标用户是否允许准入,并将所确定出的信用评估值存入所述区块链的区块。As an example, when
一个实施例中,智能合约上存在从区块链的区块中获取目标用户的历史信用评估值的代码,通过运行获取目标用户的历史信用评估值的代码,如果区块链的区块中存在目标用户的历史信用评估值,则就能在智能合约中读取到目标用户的历史信用评估值;如果区块链的区块中不存在目标用户的历史信用评估值,则返回一个目标用户的历史信用评估值不存在的结果。上述代码为智能合约中查询逻辑对应的代码。In one embodiment, there is a code on the smart contract to obtain the historical credit evaluation value of the target user from the block of the blockchain, and by running the code to obtain the historical credit evaluation value of the target user, if there is a code in the block of the blockchain The historical credit evaluation value of the target user, the historical credit evaluation value of the target user can be read in the smart contract; if the historical credit evaluation value of the target user does not exist in the block of the blockchain, a target user's historical credit evaluation value is returned. The result of a historical credit assessment value that does not exist. The above code is the code corresponding to the query logic in the smart contract.
一个实施例中,智能合约上还存在准入评估逻辑对应的代码。准入评估逻辑对应的代码根据查询逻辑对应的代码运行后返回的结果而进行准入评估。当前述步骤返回一个目标用户的历史信用评估值不存在的结果时,准入评估逻辑对应的代码根据前述步骤获取到的用户特征的数值,运行评估逻辑,得到信用评估值,并将信用评估值存入区块链的区块中;当通过前述步骤获得目标用户的历史信用评估值,准入评估逻辑对应的代码检查用户特征的数值是否发生了更改,如果发生了更改,则运行评估逻辑,得到信用评估值,并将信用评估值存入区块链的区块中;如果没发生更改,则返回前述步骤获得的历史信用评估值。In one embodiment, code corresponding to the admission evaluation logic also exists on the smart contract. The code corresponding to the admission evaluation logic performs admission evaluation according to the result returned after the code corresponding to the query logic runs. When the previous step returns a result that the historical credit evaluation value of the target user does not exist, the code corresponding to the admission evaluation logic runs the evaluation logic according to the value of the user characteristics obtained in the previous step, obtains the credit evaluation value, and converts the credit evaluation value Stored in the block of the blockchain; when the historical credit evaluation value of the target user is obtained through the preceding steps, the code corresponding to the admission evaluation logic checks whether the value of the user characteristic has changed, and if there is a change, runs the evaluation logic, Obtain the credit evaluation value and store the credit evaluation value in the block of the blockchain; if there is no change, return to the historical credit evaluation value obtained in the previous steps.
当只获得历史信用评估值时,根据历史信用评估值确定是否允许目标用户准入;当运行准入评估逻辑获得信用评估值时,根据信用评估值确定是否允许目标用户准入。When only the historical credit evaluation value is obtained, it is determined whether the target user is allowed to access according to the historical credit evaluation value; when the credit evaluation value is obtained by running the admission evaluation logic, it is determined whether the target user is allowed to access according to the credit evaluation value.
具体地,参考前述的在区块链中持久化存证数据的过程,上述客户端可以构建用于调用该区块链上部署的上述智能合约的对目标用户的准入评估交易,并将对目标用户的准入评估交易产生的信用评估值发布至该区块链进行存证。也即,与该客户端对接的该区块链中的节点设备可以先接收到对目标用户的准入评估交易,再将对目标用户的准入评估交易发送给该区块链中的其它节点设备。该区块链中的各台节点设备在接收到对目标用户的准入评估交易时,可以对目标用户的准入评估交易进行共识处理。在达成共识之后,该区块链中的节点设备可以将对目标用户的准入评估交易打包进区块,在该区块链中对信用评估值进行持久化存证。Specifically, referring to the aforementioned process of persisting certificate data in the blockchain, the client can construct an access evaluation transaction for the target user for invoking the smart contract deployed on the blockchain, and will The credit evaluation value generated by the target user's access evaluation transaction is released to the blockchain for storage. That is, the node device in the blockchain that is docked with the client can first receive the admission evaluation transaction for the target user, and then send the admission evaluation transaction for the target user to other nodes in the blockchain equipment. When each node device in the blockchain receives the access evaluation transaction of the target user, it can perform consensus processing on the access evaluation transaction of the target user. After reaching a consensus, the node devices in the blockchain can package the target user's access evaluation transaction into a block, and store the credit evaluation value persistently in the blockchain.
对于打包进区块的对目标用户的准入评估交易,可以进行查询,准入评估交易的结果不可篡改,使得当用户的特征不符合准入条件而不允许准入后,除非用户特征的数值发生改变或者机构对智能合约进行了修改,任何人都无法篡改准入评估交易的结果,保证了准入评估结果的安全和可靠。For the access evaluation transaction of the target user packaged into the block, it can be queried, and the result of the access evaluation transaction cannot be tampered with, so that when the user's characteristics do not meet the access conditions and the access is not allowed, unless the value of the user's characteristics In the event of a change or the organization modifies the smart contract, no one can tamper with the result of the access evaluation transaction, which ensures the safety and reliability of the access evaluation result.
在实际应用中,上述目标用户在申请使用相关机构的提供的服务时候发起对目标用户的准入评估交易,相关机构包括银行、金融公司、支付平台等;服务包括融资,信用支付,先用后付等;目标用户可以是自然人也可以是法人;目标用户的特征经用户授权,合法取得,并经用户同意用于为用户提供产品或者服务;并且对用户的特征的使用不超出用户授权的使用范围。目标用户的特征可以是用户自身的特征也可以是人为划分的特征,用户自身的特征包括用户性别,机构性质,用户月收入,用户负债率等,人为划分的特征包括用户申请使用机构的提供的服务的目的,用户申请时所处的地点,用户的网络环境等,本说明书对此不作限制。In practical applications, the above-mentioned target users initiate an access evaluation transaction for the target user when applying for the services provided by the relevant institutions. The relevant institutions include banks, financial companies, payment platforms, etc.; The target user can be a natural person or a legal person; the characteristics of the target user are authorized by the user, obtained legally, and used to provide the user with products or services with the user's consent; and the use of the user's characteristics does not exceed the user's authorization. scope. The characteristics of the target user can be the user's own characteristics or the characteristics of artificial division. The characteristics of the user's own include the user's gender, the nature of the organization, the user's monthly income, and the user's debt ratio. The purpose of the service, the location where the user applies, the network environment of the user, etc., are not limited in this manual.
特征来源广泛,可以是用户使用业务过程中授权使用的信息;也可以是用户使用业务过程中记录下的日志数据,经过统计方法挖掘而来;也可以是第三方提供的信用数据,本说明书对此不作限制,只要是与用户信用相关联的特征都能成为本申请的特征,用户特征的数值为用户特征对应的数值。The features come from a wide range of sources, which can be the information authorized by the user in the process of using the business; it can also be the log data recorded in the process of using the business, which is mined by statistical methods; it can also be the credit data provided by a third party. This is not limited, as long as the features related to the user's credit can become the features of the present application, and the value of the user feature is the value corresponding to the user feature.
由于一些用户特征对于判断是否允许用户准入并不重要,因此为了节省存储空间,在一些实施例中,预先存储的所述用户特征的数值的IV(Information Value,信息量)值不低于预设值。Since some user characteristics are not important for judging whether to allow user access, in order to save storage space, in some embodiments, the IV (Information Value, information value) value of the pre-stored values of the user characteristics is not lower than the predetermined value. set value.
机构可以将用户的特征的数值存入区块链的区块中,在将用户特征的数值存入区块前,通过计算特征的IV值,IV值低于预设值的特征的数值可以不在区块链上存储。The institution can store the value of the user's feature in the block of the blockchain. Before storing the value of the user's feature in the block, by calculating the IV value of the feature, the value of the feature whose IV value is lower than the preset value may not be in the block. stored on the blockchain.
IV值会因业务过程中用户的产生违约的概率变化而发生变化,比如具有相同特征的用户发生大规模的违约了,则该特征的IV值会发生改变。在一些实施例中,开发人员可以提前设置影响特征的数值的IV值的事件,比如:The IV value will change due to the change in the probability of a user's default in the business process. For example, if a user with the same feature defaults on a large scale, the IV value of the feature will change. In some embodiments, the developer can set events that affect the IV value of the value of the feature in advance, such as:
因任一所述历史用户特征不允许相关联的用户准入后产生的投诉事件;因任一所述历史用户特征允许相关联的用户准入后产生的违约事件等事件,研发人员可以根据实际需求,将其中一个事件或者多种事件的组合来综合作为影响IV值的事件。Complaints generated after any one of the historical user features does not allow the associated user to access; events such as default events after any of the historical user features allows the associated user to access, the R&D personnel can Requirement, one of the events or a combination of multiple events is integrated as an event that affects the IV value.
机构在过往批准用户准入业务的过程中,用户往往会因为任一特征不符合准入的条件,而不予准入;用户会对这种情况投诉。因此在选择用户特征,将选择出的用户特征的数值在区块链上存储前,可以计算产生客户投诉的特征的IV值,IV值低于预设值的特征的数值不在区块链上存储。In the process of approving users to access the business in the past, users often refused access because any feature did not meet the access conditions; users would complain about this situation. Therefore, before selecting the user feature and storing the value of the selected user feature on the blockchain, the IV value of the feature that generates customer complaints can be calculated, and the value of the feature whose IV value is lower than the preset value is not stored on the blockchain. .
机构因用户任一特征符合准入的条件,而给予准入后,产生了违约行为。因此在选择特征,将选择出的特征的数值在区块链上存储前,可以计算产生了违约行为的特征的IV值,IV值低于预设值的特征的数值不在区块链上存储。After the institution grants access because any feature of the user meets the access conditions, a breach of contract occurs. Therefore, before selecting a feature and storing the value of the selected feature on the blockchain, the IV value of the feature that caused the default behavior can be calculated, and the value of the feature whose IV value is lower than the preset value is not stored on the blockchain.
特征的数值可以使用不同的存储方式,为了便于管理用户数据,在一些实施例中,不同的用户特征的数值被存储于不同的区块中。The values of the features can be stored in different ways. In order to facilitate the management of user data, in some embodiments, the values of different user features are stored in different blocks.
上述区块可以是UTXO模型的区块链的区块,也可以是账户模型的区块链的区块。将用户特征的数值存储在区块链的区块上时,不同的特征的数值存储在不同的区块上,可以是一个区块只存一种特征的数值;以实现当用户特征的数值有更新的时候,只更新该特征对应的区块。The above block can be a block of the blockchain of the UTXO model, or a block of the blockchain of the account model. When the values of user features are stored on the blocks of the blockchain, the values of different features are stored on different blocks, and a block can store only the values of one feature; in order to realize when the values of user features have When updating, only the block corresponding to the feature is updated.
机构通常存在用户信用情况的数据,并根据信用情况的数据生成一个指定信用参数,这个参数可以是一个具体的数字,也可以是信用评级;比如支付宝里的芝麻信用分,又比如标准普尔公司的标准普尔信用评级。以信用分为例,若用户的信用分低于一个阈值,则不调用准入评估交易的智能合约,并且不允许用户准入;又如用户如果存在一个信用评级,假设最高等级为AAA,其次为AA,最小的评级是A,如果用户的信用评级为A,则不调用准入评估交易的智能合约,并且不允许用户准入。因此,在一些实施例中,响应于所述准入评估交易的步骤还可以包括:如果目标用户的指定信用参数的值低于阈值,则不允许所述准入评估交易的发起方调用所述智能合约。(先做好铺垫再写你的做法会更容易让人有代入感)Institutions usually have data on the user's credit situation, and generate a specified credit parameter based on the data of the credit situation. This parameter can be a specific number or a credit rating; for example, the sesame credit score in Alipay, or the Standard & Poor's company's credit rating. Standard & Poor's credit rating. Taking the credit score as an example, if the user's credit score is lower than a threshold, the smart contract for the access evaluation transaction will not be invoked, and the user will not be allowed to enter; for another example, if the user has a credit rating, it is assumed that the highest rating is AAA, followed by For AA, the minimum rating is A. If the user's credit rating is A, the smart contract for the admission evaluation transaction will not be invoked, and the user will not be allowed to enter. Accordingly, in some embodiments, the step of responding to the admission evaluation transaction may further include: if the value of the target user's specified credit parameter is below a threshold, disallowing the originator of the admission evaluation transaction to invoke the admission evaluation transaction. smart contracts. (It will make it easier for people to have a sense of substitution after doing a good job of laying the groundwork first and then writing about your practice)
当目标用户发起准入业务的请求,区块链中的节点设备接收对目标用户的准入评估交易,调用智能合约的时候,需要根据智能合约代码中对应的准入评估逻辑确定出信用评估值,准入评估逻辑可以采用多种方式实现,在一些实施例中,准入评估逻辑根据查询到的所述目标用户关联的用户特征的数值,对不同的用户特征的数值使用不同的权重系数加权运算,得到所述信用评估值。When the target user initiates a request for admission business, the node device in the blockchain receives the admission evaluation transaction for the target user, and when calling the smart contract, the credit evaluation value needs to be determined according to the corresponding admission evaluation logic in the smart contract code. , the admission evaluation logic can be implemented in various ways. In some embodiments, the admission evaluation logic uses different weighting coefficients to weight the values of different user characteristics according to the queried values of the user characteristics associated with the target user. operation to obtain the credit evaluation value.
以加权公式计算得出信用评估值为例,用户的特征的数值记为pi,特征对应的权重系数记为Ai,最后得出的信用评估值记为R,则R=p1×A1+p2×A2+…+pn×An。此处仅是简单的示例,实际运算时可以使用其他加权运算方式如指数加权,要能通过权重系数调整信用评估值R即可。Taking the credit evaluation value calculated by the weighted formula as an example, the value of the user's feature is recorded as pi, the weight coefficient corresponding to the feature is recorded as Ai, and the final credit evaluation value is recorded as R, then R=p1×A1+p2× A2+…+pn×An. This is just a simple example, other weighting operation methods such as index weighting can be used in actual operation, and the credit evaluation value R can be adjusted by the weight coefficient.
用户特征的数值使用的权重系数,可以根据经验调整,也可以根据统计学方法计算出来,还可以用机器学习模型得出权重系数,在一些实施例中,用户特征的数值使用的权重系数,包括使用机器学习模型得出的计算值。The weight coefficient used by the numerical value of the user feature can be adjusted according to experience, or calculated according to statistical methods, or a machine learning model can be used to obtain the weight coefficient. In some embodiments, the weight coefficient used by the numerical value of the user feature includes: Calculated using a machine learning model.
权重系数可以存储在智能合约中,在智能合约准入评估逻辑的代码被调用时使用。在将权重系数写入智能合约前,可以通过对机器学习模型使用有监督的训练,以进行监督的学习的机器学习模型得出的计算值作为权重系数。The weight factor can be stored in the smart contract and used when the code of the smart contract admission evaluation logic is called. Before writing the weight coefficient into the smart contract, you can use supervised training on the machine learning model to use the calculated value obtained by the machine learning model for supervised learning as the weight coefficient.
需要使用数据才能训练出机器学习模型,在一些实施例中,机器学习模型是以所述用户特征作为样本,以因所述用户特征产生的客户投诉数据和/或资产损失数据为标签的有监督训练的模型。It is necessary to use data to train a machine learning model. In some embodiments, the machine learning model takes the user characteristics as a sample and uses the customer complaint data and/or asset loss data generated by the user characteristics as a supervised supervised model. trained model.
对机器学习模型进行有监督学习包括,以用户特征作为样本,以因用户特征产生的客户投诉数据和资产损失数据合并为一组标签,通过训练,让机器学习模型可以找出用户特征和合并后的标签之间的联系;也可以,以用户特征作为样本,以因用户特征产生的客户投诉数据为一组标签,通过训练,让机器学习模型可以找出用户特征和客户投诉数据的标签之间的联系;还可以,以用户特征作为样本,以因用户特征产生的资产损失数据为一组标签,通过训练,让机器学习模型可以找出用户特征和资产损失数据的标签之间的联系;最终,由于机器学习模型已经找出用户特征和标签之间的联系,当获取只有用户特征而没有标签的数据时,可以判断出用户特征的标签。The supervised learning of the machine learning model includes taking user characteristics as samples, combining customer complaint data and asset loss data generated by user characteristics into a set of labels, and through training, so that the machine learning model can find out user characteristics and merged data. It is also possible to use user characteristics as samples and customer complaint data generated by user characteristics as a set of labels. Through training, the machine learning model can find out the relationship between user characteristics and the labels of customer complaint data. It is also possible to use the user characteristics as a sample and the asset loss data generated by the user characteristics as a set of labels. Through training, the machine learning model can find the relationship between the user characteristics and the labels of the asset loss data; finally , since the machine learning model has found the relationship between user features and labels, when acquiring data with only user features but no labels, the labels of user features can be determined.
机器学习模型可以有多种,在一些实施例中,机器学习模型可以是评分卡模型。There can be many types of machine learning models, and in some embodiments, the machine learning model can be a scorecard model.
评分卡模型包括对数据预处理、变量筛选、变量分箱、模型训练及生成评分卡等步骤,其中在模型训练的时候可以使用有监督的学习方式进行训练。The scorecard model includes steps such as data preprocessing, variable screening, variable binning, model training, and scorecard generation, among which supervised learning can be used during model training.
在对评分卡模型进行有监督的训练的时候,将以用户特征作为样本,以因用户特征产生的客户投诉数据和资产损失数据合并为一组标签的数据集划分为训练集和测试集;也可以,将以用户特征作为样本,以因用户特征产生的客户投诉数据为一组标签的数据集划分为训练集和测试集;还可以,将以用户特征作为样本,以因用户特征产生的资产损失数据为一组标签的数据集划分为训练集和测试集。其中,训练集用于训练模型,得出模型参数;测试集用于检验模型的拟合能力,防止过拟合或欠拟合。可以使用逻辑回归,决策树及GBDT(Gradient Boosting Decision Tree,梯度提升树)等方式在有监督的学习过程构建评分卡模型。In the supervised training of the scorecard model, the data sets that take user characteristics as samples and combine customer complaint data and asset loss data generated by user characteristics into a set of labels are divided into training set and test set; Yes, the data set with user characteristics as samples and customer complaint data generated by user characteristics as a set of labels is divided into training set and test set; it is also possible to use user characteristics as samples and assets generated by user characteristics The loss data is a set of labels and the dataset is divided into training set and test set. Among them, the training set is used to train the model to obtain model parameters; the test set is used to test the fitting ability of the model to prevent overfitting or underfitting. A scorecard model can be built in a supervised learning process using logistic regression, decision tree, and GBDT (Gradient Boosting Decision Tree).
由于数据存在多种标签的时候,可以训练出多个机器学习模型,因此在一些实施例中,计算值包括由两个所述评分卡模型的输出值加权运算后获得;其中一个评分卡模型的标签为所述客户投诉数据,另一个评分卡模型的标签为所述资产损失数据。Since multiple machine learning models can be trained when there are multiple labels in the data, in some embodiments, the calculated value is obtained by weighting the output values of the two scorecard models; The label is the customer complaint data, and another scorecard model is labeled the asset loss data.
即将以用户特征作为样本,以因用户特征产生的客户投诉数据为标签的数据集划分为训练集和测试集,其中,训练集用于训练模型,得出模型参数;测试集用于检验模型的拟合能力,防止过拟合或欠拟合,得出第一个评分卡模型的输出值;将以用户特征作为样本,以因用户特征产生的资产损失数据为标签的数据集划分为训练集和测试集,其中,训练集用于训练模型,得出模型参数;测试集用于检验模型的拟合能力,防止过拟合或欠拟合,得出第二个评分卡模型的输出值;对第一个评分卡模型的输出值和第二个评分卡模型的输出值加权运算,得到计算值。The data set with user characteristics as samples and customer complaint data generated by user characteristics as labels is divided into training set and test set. The training set is used to train the model to obtain model parameters; the test set is used to test the model Fitting ability to prevent over-fitting or under-fitting, and obtain the output value of the first scorecard model; divide the data set with user characteristics as samples and asset loss data due to user characteristics as labels as training sets And the test set, where the training set is used to train the model to obtain the model parameters; the test set is used to test the fitting ability of the model to prevent over-fitting or under-fitting, and obtain the output value of the second scorecard model; The calculated value is obtained by weighting the output value of the first scorecard model and the output value of the second scorecard model.
为了节省训练模型的时间,可以将数据的多种标签合为一种,只训练一个机器学习模型,在一些实施例中,以用户特征作为样本,以因用户特征产生的客户投诉数据和资产损失数据合并为同一组标签的数据集划分为训练集和测试集,其中,训练集用于训练模型,得出模型参数;测试集用于检验模型的拟合能力,防止过拟合或欠拟合,得出评分卡模型的输出值,以输出值为计算值。In order to save the time of training the model, multiple labels of the data can be combined into one, and only one machine learning model can be trained. In some embodiments, the user characteristics are used as samples, and the customer complaint data and asset losses generated by the user characteristics are used as samples. The data set with the same set of labels is divided into training set and test set. The training set is used to train the model to obtain model parameters; the test set is used to test the fitting ability of the model to prevent overfitting or underfitting. , the output value of the scorecard model is obtained, and the output value is the calculated value.
为了进一步解释本申请的基于区块链的用户准入方法,以下结合一个具体的实施例加以解释。In order to further explain the blockchain-based user access method of the present application, the following is explained with reference to a specific embodiment.
在本实施例中,区块链的区块中预先存储有用户特征的数值,区块链的节点设备接收到对目标用户的准入评估交易;其中,准入评估交易用于调用智能合约中的智能合约代码对应的查询逻辑获取与目标用户关联的用户特征的数值;响应于所述准入评估交易,调用智能合约中的智能合约代码对应的查询逻辑,查询目标用户对应的历史信用评估值是否已被存储在区块链的区块中;如果已存储,且与所述目标用户关联的用户特征的数值没有更改,则基于所述历史信用评估值确定所述目标用户是否允许准入;如果不存在或与所述目标用户关联的用户特征的数值发生更改,则调用智能合约代码对应的准入评估逻辑确定出信用评估值,确定所述目标用户是否允许准入,并将所确定出的信用评估值存入所述区块链的区块。In this embodiment, the value of user characteristics is pre-stored in the block of the blockchain, and the node device of the blockchain receives the admission evaluation transaction for the target user; wherein, the admission evaluation transaction is used to call the smart contract The query logic corresponding to the smart contract code in the smart contract obtains the value of the user characteristics associated with the target user; in response to the access evaluation transaction, the query logic corresponding to the smart contract code in the smart contract is invoked to query the historical credit evaluation value corresponding to the target user. Whether it has been stored in the block of the blockchain; if it has been stored, and the value of the user characteristic associated with the target user has not changed, then determine whether the target user is allowed access based on the historical credit evaluation value; If it does not exist or the value of the user characteristic associated with the target user is changed, call the access evaluation logic corresponding to the smart contract code to determine the credit evaluation value, determine whether the target user allows access, and assign the determined value to the user. The credit evaluation value is stored in the block of the blockchain.
作为节点设备加入至上述区块链的电子设备可以是服务器、计算机、手机、平板设备、笔记本电脑、掌上电脑等。Electronic devices added to the above-mentioned blockchain as node devices can be servers, computers, mobile phones, tablet devices, laptops, PDAs, and the like.
本实施例中,预先存储的所述用户特征的数值的IV(Information Value,信息量)值不低于预设值。机构可以将用户的特征的数值存入区块链的区块中,在将用户特征的数值存入区块前,通过计算特征的IV值,IV值低于预设值的特征的数值可以不在区块链上存储。In this embodiment, an IV (Information Value, information amount) value of the pre-stored value of the user feature is not lower than a preset value. The institution can store the value of the user's feature in the block of the blockchain. Before storing the value of the user's feature in the block, by calculating the IV value of the feature, the value of the feature whose IV value is lower than the preset value may not be in the block. stored on the blockchain.
在特征的数值在区块链上存储前,计算产生客户投诉的特征的IV值,IV值低于预设值的特征的数值不在区块链上存储;或,计算用户因任一特征满足准入条件,用户在准入后违约的特征的IV值。Before the value of the feature is stored on the blockchain, calculate the IV value of the feature that generates customer complaints, and the value of the feature whose IV value is lower than the preset value is not stored on the blockchain; The entry condition, the IV value of the feature that the user defaults on after entry.
以用户的年龄作为特征为例,用户因不满30岁而被拒绝准入,并且经常对该种情况进行客户投诉;或者,用户满30岁而被允许准入后,经常产生违约行为。则计算用户的年龄的IV值。对用户的年龄如下表3进行分组:Taking the age of the user as an example, the user is denied access because he is under the age of 30, and customers often complain about this situation; or, after the user is over the age of 30 and is allowed access, there is often a breach of contract. Then calculate the IV value of the user's age. The ages of users are grouped as follows in Table 3:
表3table 3
用户分为好用户和坏用户,具体根据业务类型确定用户好坏,比如如果是对开展共享单车租用服务而查询用户是否可以准入,那么坏客户就是不归还单车或者是不付钱的用户,反之如果是正常使用单车,履行了约定义务的用户则是好用户。第i组用户的标识为Li,好用户数为Gi,坏用户数为Bi,全部的好用户数为Gt,全部的坏用户数为Bt,则第i组的WOE(weight of evidence,证据权重),WOEi的计算公式为WOEi=ln{(Bi/Bt)/(Gi/Gt)},第i组的IV值IVi的计算公式为:Users are divided into good users and bad users, and the quality of the user is determined according to the type of business. For example, if the user is asked whether the user can access the shared bicycle rental service, then the bad customer is the user who does not return the bicycle or does not pay. On the other hand, if the bicycle is used normally, the user who fulfills the agreed obligations is a good user. The identifier of group i is Li, the number of good users is Gi, the number of bad users is Bi, the number of all good users is Gt, and the number of all bad users is Bt, then the WOE (weight of evidence, weight of evidence) of group i is ), the calculation formula of WOE i is WOE i =ln{(Bi/Bt)/(Gi/Gt)}, and the calculation formula of the IV value IV i of the i-th group is:
最终得到的IV值为每一组的IVi之和 The final IV value is the sum of the IV i of each group
对于用户IV值小于预定值的特征的数值,不在区块链上存储,对区块链上已经存在的IV值小于预定值的特征的数值不再更新。例如,如果用户年龄的IV值小于0.02,可以认定为用户年龄无效的特征,不在区块链上存储用户的年龄,对区块链上已经存在的用户年龄的数据不再更新。The value of the feature whose IV value of the user is less than the predetermined value is not stored on the blockchain, and the value of the feature whose IV value is less than the predetermined value already existing on the blockchain will not be updated. For example, if the IV value of the user's age is less than 0.02, it can be regarded as an invalid feature of the user's age, the user's age will not be stored on the blockchain, and the existing user's age data on the blockchain will not be updated.
本实施例中,不同的用户特征的数值被存储于不同的区块中。每一个区块都有一个唯一的哈希值对应,即如果用户特征的数值被修改,则唯一的哈希值也会发生改变,以此做到可追溯及不可篡改。In this embodiment, values of different user characteristics are stored in different blocks. Each block corresponds to a unique hash value, that is, if the value of the user feature is modified, the unique hash value will also change, so as to be traceable and non-tamperable.
本实施例中,如果目标用户的指定信用参数的值低于阈值,则不允许所述准入评估交易的发起方调用所述智能合约。以信用分为例,如果目标用户的信用分低于一个阈值,如600,则不允许所述准入评估交易的发起方调用所述智能合约,并且返回不允许用户准入的结果,而不进行区块链相关的调用及存储操作。上述信用分可以是用户日常消费行为数据,经过数据统计的方法得出的一个数值;只要是能表征用户历史的信用情况的数值,评级都可以替换本申请的信用分。In this embodiment, if the value of the specified credit parameter of the target user is lower than the threshold, the initiator of the admission evaluation transaction is not allowed to invoke the smart contract. Taking the credit score as an example, if the target user's credit score is lower than a threshold, such as 600, the initiator of the admission evaluation transaction is not allowed to call the smart contract, and the result that the user is not allowed to be admitted is returned instead of Perform blockchain-related calls and storage operations. The above-mentioned credit score can be a numerical value obtained by the method of data statistics based on the daily consumption behavior data of the user; as long as it is a numerical value that can characterize the user's historical credit situation, the rating can replace the credit score of this application.
接下来,响应于所述准入评估交易,调用智能合约代码对应的准入评估逻辑确定出信用评估值。其中,智能合约根据查询到的所述目标用户关联的用户特征的数值,对不同的用户特征的数值使用不同的权重系数加权运算,得到所述信用评估值。Next, in response to the access evaluation transaction, the access evaluation logic corresponding to the smart contract code is invoked to determine the credit evaluation value. The smart contract obtains the credit evaluation value by applying different weighting coefficients to the values of different user characteristics according to the queried values of the user characteristics associated with the target user.
本实施例中的智能合约以Solidity语言编写,一个合约中包括状态变量、函数、函数修改器等。The smart contract in this embodiment is written in Solidity language, and a contract includes state variables, functions, function modifiers, and the like.
以加权公式计算得出信用评估值为例,用户的特征的数值记为pi,特征对应的权重系数记为Ai,最后得出的信用评估值记为R,则R=p1×A1+p2×A2+…+pn×An。智能合约存储有特征对应的权重系数,Taking the credit evaluation value calculated by the weighted formula as an example, the value of the user's feature is recorded as pi, the weight coefficient corresponding to the feature is recorded as Ai, and the final credit evaluation value is recorded as R, then R=p1×A1+p2× A2+…+pn×An. The smart contract stores the weight coefficient corresponding to the feature,
智能合约中存在一个计算信用评估值的函数,该函数接收特征的数值,返回一个信用评估值,并将信用评估值存储至区块链的区块。该智能合约中还存在一个比较函数,比较用户的特征数值是否有更新,如果没有更新,则直接从区块链的区块中读取历史信用评估值并返回;如果有更新,则比较函数调用计算信用评估值的函数。当特征对应的权重系数需要修改时,则创建新的智能合约,原有的智能合约不再使用。本实施例还可以将特征对应的权重系数存储在区块链的区块上,智能合约存储权重系数所在区块的哈希地址,当需要读取权重系数时,根据哈希地址读取对应区块的权重系数,当特征对应的权重系数需要更新时,则发起一个交易,更新区块上的权重系数。There is a function to calculate the credit evaluation value in the smart contract. The function receives the value of the feature, returns a credit evaluation value, and stores the credit evaluation value in the block of the blockchain. There is also a comparison function in the smart contract to compare whether the user's characteristic value has been updated. If there is no update, the historical credit evaluation value will be directly read from the block of the blockchain and returned; if there is an update, the comparison function will be called. A function that calculates a credit rating. When the weight coefficient corresponding to the feature needs to be modified, a new smart contract is created, and the original smart contract is no longer used. In this embodiment, the weight coefficient corresponding to the feature can also be stored on the block of the blockchain, and the smart contract stores the hash address of the block where the weight coefficient is located. When the weight coefficient needs to be read, the corresponding area is read according to the hash address. The weight coefficient of the block. When the weight coefficient corresponding to the feature needs to be updated, a transaction is initiated to update the weight coefficient on the block.
本实施例中,权重系数可以是机器学习模型经过有监督的训练得出的计算值。本实施例中的机器学习模型可以是评分卡模型。以用户特征作为样本,以因用户特征产生的客户投诉数据和资产损失数据为标签的数据集划分为训练集和测试集。其中,将客户投诉数据和资产损失数据合并为同一组标签。如,存在客户投诉和资产损失的一组数据的标签为1,存在客户投诉但是没有资产损失的一组数据的标签为0.5,不存在客户投诉但是有资产损失的一组数据的标签为0.5,既不存在客户投诉又没有资产损失的数据的标签为0,这里的标签仅仅是示例性的,实际可根据具体情况调整。以月收入、用户年龄及家庭人数三个特征为样本的数据集最终的数据如下表4所示:In this embodiment, the weight coefficient may be a calculated value obtained by the machine learning model through supervised training. The machine learning model in this embodiment may be a scorecard model. Using user characteristics as samples, the data set with customer complaint data and asset loss data generated by user characteristics as labels is divided into training set and test set. Among them, customer complaint data and asset loss data are combined into the same set of labels. For example, the label of a group of data with customer complaints and asset loss is 1, the label of a group of data with customer complaints but no asset loss is 0.5, and the label of a group of data without customer complaints but with asset loss is 0.5, The label of data with neither customer complaints nor asset loss is 0. The labels here are only exemplary and can be adjusted according to specific situations. The final data of the dataset with the three characteristics of monthly income, user age and family size as samples are shown in Table 4 below:
表4Table 4
本实施例中将70%的数据集作为训练集,30%的数据集作为测试集,其中,训练集用于训练模型,得出模型参数;测试集用于检验模型的拟合能力,防止过拟合或欠拟合。训练集和测试集的比例可以根据需要调整,比如可以调整为6:4。In this embodiment, 70% of the data set is used as the training set, and 30% of the data set is used as the test set, wherein the training set is used to train the model to obtain model parameters; the test set is used to test the fitting ability of the model to prevent excessive Fit or underfit. The ratio of training set and test set can be adjusted as needed, for example, it can be adjusted to 6:4.
本实施例中,使用逻辑回归构建评分卡模型。通过梯度下降法求解sigmoid函数的代价函数,得到sigmoid函数的参数值,即为评分卡模型的输出值。In this embodiment, logistic regression is used to construct a scorecard model. The cost function of the sigmoid function is solved by the gradient descent method, and the parameter value of the sigmoid function is obtained, which is the output value of the scorecard model.
Sigmoid函数的参数可以如下表5所示:The parameters of the sigmoid function can be shown in Table 5 below:
表5table 5
以一个月收入8000元,年龄为40岁,家庭人数为5人的用户为例,根据上述确定的权重系数,智能合约计算信用评估指定函数计算出用户的信用评估值等于8000×A1+40×A2+5×A3,将该信用评估值存储至区块链的区块,保证准入信用评估值可追溯及不可篡改,实现用户准入的安全和可靠;Taking a user with a monthly income of 8,000 yuan, an age of 40, and a family of 5 people as an example, according to the weight coefficient determined above, the smart contract calculates the credit evaluation specified function to calculate the user's credit evaluation value equal to 8000×A1+40× A2+5×A3, store the credit evaluation value in the block of the blockchain to ensure that the access credit evaluation value can be traced back and cannot be tampered with, so as to realize the safety and reliability of user access;
将信用评估值返回至节点设备,若信用评估值小于预设值,则不允许用户准入;若信用评估值大于等于预设值,则允许用户准入,通过本方法计算出的信用评估值对用户准入的判断更准确,减少用户投诉率,提升用户的准入概率。Return the credit evaluation value to the node device. If the credit evaluation value is less than the preset value, the user is not allowed to enter; if the credit evaluation value is greater than or equal to the preset value, the user is allowed to enter, and the credit evaluation value calculated by this method is used. The judgment of user access is more accurate, the user complaint rate is reduced, and the user's access probability is improved.
与上述用户准入方法相对应,本说明实施例还提供了一种基于区块链的用户准入装置,如图8所示是本说明一示例性实施例示出的一种基于区块链的用户准入装置的框图,该基于区块链的用户准入装置80可以应用于如图9所示的电子设备,该电子设备可以作为与所述区块链中的节点设备。所述装置80应用于所述区块链中的节点设备;所述区块链中部署有用于对用户进行准入评估的智能合约,所述区块链的区块中预先存储有用户特征的数值;所述装置80包括:Corresponding to the above-mentioned user access method, this embodiment of the present description also provides a blockchain-based user access device, as shown in FIG. A block diagram of a user access device, the blockchain-based user access device 80 can be applied to an electronic device as shown in FIG. 9 , and the electronic device can be used as a node device in the blockchain. The device 80 is applied to the node equipment in the blockchain; the blockchain is deployed with a smart contract for evaluating user access, and the blocks of the blockchain are pre-stored with user characteristics. Numerical value; the device 80 includes:
接收模块801,用于接收对目标用户的准入评估交易;其中,所述准入评估交易用于调用所述智能合约获取与所述目标用户关联的所述用户特征的数值;A receiving module 801, configured to receive an access evaluation transaction for a target user; wherein, the access evaluation transaction is used to call the smart contract to obtain the value of the user characteristic associated with the target user;
查询模块802,用于响应于所述准入评估交易,调用所述智能合约查询所述目标用户对应的历史信用评估值是否已被存储在区块链的区块中;基于查询结果或调用智能合约确定所述目标用户是否允许准入。The query module 802 is configured to, in response to the admission evaluation transaction, call the smart contract to query whether the historical credit evaluation value corresponding to the target user has been stored in the block of the blockchain; The contract determines whether the target user is allowed access.
在一些实施例中,查询模块802调用智能合约代码确定出信用评估值的步骤包括:In some embodiments, the step of invoking the smart contract code by the query module 802 to determine the credit evaluation value includes:
根据查询到的所述目标用户关联的用户特征的数值,对不同的用户特征的数值使用不同的权重系数加权运算,得到所述信用评估值。According to the queried value of the user feature associated with the target user, the value of different user features is weighted with different weighting coefficients to obtain the credit evaluation value.
在一些实施例中,预先存储的所述用户特征的数值的IV值不低于预设值。In some embodiments, the IV value of the pre-stored value of the user characteristic is not lower than a preset value.
在一些实施例中,影响所述用户特征的数值的IV值的事件包括至少以下任一:因任一所述历史用户特征不允许相关联的用户准入后产生的投诉事件;因任一所述历史用户特征允许相关联的用户准入后产生的违约事件。In some embodiments, the events that affect the IV value of the value of the user feature include at least one of the following: a complaint event generated after any one of the historical user features does not allow the associated user to access; The aforementioned historical user feature allows default events generated after the associated user accesses.
在一些实施例中,不同的用户特征的数值被存储于不同的区块中。In some embodiments, values for different user characteristics are stored in different blocks.
在一些实施例中,接收模块801响应于所述准入评估交易的步骤包括:如果目标用户的指定信用参数的值低于阈值,则不允许所述准入评估交易的发起方调用所述智能合约。In some embodiments, the step of receiving module 801 in response to the admission evaluation transaction includes: if the value of the target user's specified credit parameter is below a threshold, disallowing the initiator of the admission evaluation transaction to invoke the intelligent contract.
在一些实施例中,所述用户特征的数值使用的权重系数,包括使用机器学习模型得出的计算值。In some embodiments, the weight coefficient used by the value of the user feature includes a calculated value obtained by using a machine learning model.
在一些实施例中,机器学习模型是以所述用户特征作为样本,以因所述用户特征产生的客户投诉数据和/或资产损失数据为标签的有监督学习的模型。In some embodiments, the machine learning model is a supervised learning model using the user characteristics as samples and the customer complaint data and/or asset loss data generated by the user characteristics as labels.
在一些实施例中,所述机器学习模型包括评分卡模型。In some embodiments, the machine learning model includes a scorecard model.
在一些实施例中,所述计算值包括由两个所述评分卡模型的输出值加权运算后获得;其中一个评分卡模型的标签为所述客户投诉数据,另一个评分卡模型的标签为所述资产损失数据。In some embodiments, the calculated value is obtained by weighting the output values of the two scorecard models; the label of one scorecard model is the customer complaint data, and the label of the other scorecard model is the Asset loss data.
上述装置中各个模块的功能和作用的实现过程具体详见上述方法中对应步骤的实现过程,在此不再赘述。For details of the implementation process of the functions and functions of each module in the above-mentioned device, please refer to the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.
对于装置实施例而言,由于其基本对应于方法实施例,所以相关之处参见方法实施例的部分说明即可。以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本说明书方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。For the apparatus embodiments, since they basically correspond to the method embodiments, reference may be made to the partial descriptions of the method embodiments for related parts. The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in One place, or it can be distributed over multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution in this specification. Those of ordinary skill in the art can understand and implement it without creative effort.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules or units described in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, email sending and receiving device, game control desktop, tablet, wearable device, or a combination of any of these devices.
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-persistent memory in computer readable media, random access memory (RAM) and/or non-volatile memory in the form of, for example, read only memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-permanent, removable and non-removable media, and storage of information may be implemented by any method or technology. Information may be computer readable instructions, data structures, modules of programs, 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 tape cartridges, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, article or device comprising a series of elements includes not only those elements, but also Other elements not expressly listed, or which are inherent to such a process, method, article of manufacture, or apparatus are also included. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article of manufacture, or device that includes the element.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. Additionally, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terminology used in one or more embodiments of this specification is for the purpose of describing a particular embodiment only and is not intended to limit the one or more embodiments of this specification. As used in the specification or embodiments and the appended claims, the singular forms "a," "the," and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It will be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, such information should not be limited by these terms. These terms are only used to distinguish the same type of information from each other. For example, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information without departing from the scope of one or more embodiments of the present specification. Depending on the context, the word "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determining."
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。The above descriptions are only preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. All within the spirit and principles of one or more embodiments of this specification, Any modifications, equivalent replacements, improvements, etc. made should be included within the protection scope of one or more embodiments of this specification.
Claims (14)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210028059.6A CN114444097A (en) | 2022-01-11 | 2022-01-11 | Blockchain-based user access method, device, electronic device and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210028059.6A CN114444097A (en) | 2022-01-11 | 2022-01-11 | Blockchain-based user access method, device, electronic device and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114444097A true CN114444097A (en) | 2022-05-06 |
Family
ID=81367931
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210028059.6A Pending CN114444097A (en) | 2022-01-11 | 2022-01-11 | Blockchain-based user access method, device, electronic device and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114444097A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116070279A (en) * | 2023-03-22 | 2023-05-05 | 深圳市于易点科技有限公司 | Block chain-based network security information sharing method and system |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108667632A (en) * | 2018-04-19 | 2018-10-16 | 阿里巴巴集团控股有限公司 | Based on the credit record sharing method and device of block chain, electronic equipment |
CN110135844A (en) * | 2019-04-28 | 2019-08-16 | 阿里巴巴集团控股有限公司 | Credit record, querying method and device and electronic equipment based on block chain |
CN110597908A (en) * | 2019-09-10 | 2019-12-20 | 腾讯科技(深圳)有限公司 | A blockchain-based credit reporting method, device, and storage medium |
CN111681007A (en) * | 2020-05-28 | 2020-09-18 | 中国工商银行股份有限公司 | Credit scoring method for block chain, transaction method and related device |
CN111709801A (en) * | 2020-06-11 | 2020-09-25 | 上海坤振集成电路有限公司 | Credit evaluation method and device, block chain system, equipment and storage medium |
CN112330181A (en) * | 2020-11-17 | 2021-02-05 | 支付宝(杭州)信息技术有限公司 | Enterprise credit evaluation method and device based on block chain |
CN112651745A (en) * | 2020-12-30 | 2021-04-13 | 杭州趣链科技有限公司 | Credit evaluation method of financial block chain, electronic equipment and storage medium |
CN112822267A (en) * | 2021-01-05 | 2021-05-18 | 支付宝(杭州)信息技术有限公司 | Data processing method and device based on block chain |
-
2022
- 2022-01-11 CN CN202210028059.6A patent/CN114444097A/en active Pending
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108667632A (en) * | 2018-04-19 | 2018-10-16 | 阿里巴巴集团控股有限公司 | Based on the credit record sharing method and device of block chain, electronic equipment |
CN110135844A (en) * | 2019-04-28 | 2019-08-16 | 阿里巴巴集团控股有限公司 | Credit record, querying method and device and electronic equipment based on block chain |
CN110597908A (en) * | 2019-09-10 | 2019-12-20 | 腾讯科技(深圳)有限公司 | A blockchain-based credit reporting method, device, and storage medium |
CN111681007A (en) * | 2020-05-28 | 2020-09-18 | 中国工商银行股份有限公司 | Credit scoring method for block chain, transaction method and related device |
CN111709801A (en) * | 2020-06-11 | 2020-09-25 | 上海坤振集成电路有限公司 | Credit evaluation method and device, block chain system, equipment and storage medium |
CN112330181A (en) * | 2020-11-17 | 2021-02-05 | 支付宝(杭州)信息技术有限公司 | Enterprise credit evaluation method and device based on block chain |
CN112651745A (en) * | 2020-12-30 | 2021-04-13 | 杭州趣链科技有限公司 | Credit evaluation method of financial block chain, electronic equipment and storage medium |
CN112822267A (en) * | 2021-01-05 | 2021-05-18 | 支付宝(杭州)信息技术有限公司 | Data processing method and device based on block chain |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116070279A (en) * | 2023-03-22 | 2023-05-05 | 深圳市于易点科技有限公司 | Block chain-based network security information sharing method and system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20220051238A1 (en) | Method and apparatus for verifying commodities in batches based on blockchain, and electronic device | |
CN113836227B (en) | Asset purchasing method and device based on blockchain and electronic equipment | |
US11032215B2 (en) | Allocating virtual resource based on block chain | |
US11410159B2 (en) | Upgradeable security token | |
WO2021017438A1 (en) | Blockchain-based electronic bill cancellation method and apparatus, and electronic device | |
US20220058732A1 (en) | Cryptographic-asset collateral management | |
US11361054B2 (en) | Blockchain-based infringement detection method, apparatus, and electronic device | |
US11556924B2 (en) | Blockchain-based payment withholding and agreement signing method, apparatus, and electronic device | |
TWI733349B (en) | Block chain-based bill number distribution method, device and electronic equipment | |
CN110020542B (en) | Data reading and writing method and device and electronic equipment | |
WO2021017439A1 (en) | Block chain-based electronic bill number application method and apparatus, and electronic device | |
WO2020125233A1 (en) | Field updating method and device and electronic apparatus | |
WO2021017442A1 (en) | Method and device for electronic negotiable instrument reimbursement based on blockchain, and electronic device | |
US11429983B2 (en) | Blockchain-based bill write-off method, apparatus, electronic device, and storage medium | |
US10846765B2 (en) | Blockchain-based e-bill number application method, apparatus, and electronic device | |
CN112330181A (en) | Enterprise credit evaluation method and device based on block chain | |
WO2022077186A1 (en) | Execution method and apparatus for smart contract in blockchain, and electronic device | |
CN111383122A (en) | Asset management method and device based on block chain and electronic equipment | |
US20200193397A1 (en) | Blockchain-based withholding operations | |
CN112100588A (en) | Blockchain-based digital seal application method, device and electronic device | |
US20200279309A1 (en) | Blockchain-based electronic bill cancellation method, apparatus, and electronic device | |
CN114444097A (en) | Blockchain-based user access method, device, electronic device and storage medium | |
CN113763175A (en) | Asset management method and device based on block chain and electronic equipment | |
US12045825B2 (en) | Linguistic transformation based relationship discovery for transaction validation | |
US20230409979A1 (en) | Machine learning-based graph analytics for user evaluation |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |