solidity Dapp Merkle-based selective disclosure contract - mine or mine

In today’s life, for the sake of privacy, we don’t want to directly show our personal information to others. For example, when we go to a hotel, we need to register our name and ID number information, but if we directly give our ID card to the front desk staff, the front desk staff can see our ethnicity, address and other information. So what can we do? Selective disclosure of user attributes can reduce risk.

1. Generate attribute Merkle tree

For an introduction to the Merkle Tree Merkle tree, you can refer to this document . The Merkle tree can form a hash value for all transactions in a block, and put the hash value in the block header. Any tampering with the transaction will cause the hash value to change. We can use the user's attributes as transactions and calculate the Merkle tree of all attributes. For example, we want to build a Merkle tree for personal attributes:

The following is the construction of the merkle tree when the contract is initialized.

2. Generate proof

If you are going to an Internet cafe now, and the network administrator wants to verify that your age is greater than 18, you can generate a corresponding proof (disclosure field, merkleproof, disclosure field index), in which only the age is exposed, and other identity attributes are not exposed. Examples are as follows:

The composition of the proof:

  • Hash path, hash0, hash5

  • Actual age, such as 19;

The following is the proof of the generated user;

3. Verification

After receiving the proof submitted by you, the network administrator needs to verify it, which mainly includes the following steps:

  1. Find authoritative contracts published by third parties, such as public security, civil affairs, etc.;

  1. Obtain the user's corresponding merkleroot from the contract; the blue part in the above picture;

3. Use the disclosure field (age), field serial number index, MerkleProof, MerkleRoot, etc. for Merkle verification.

4. The verification is passed, and the credible disclosure content is displayed as true.

The network administrator verifies your age, but does not obtain other identity information other than age, thus achieving selective disclosure.

Summarize

Above we explained that when the user identity has multiple attributes, the user only selectively exposes one of the attributes.

Guess you like

Origin blog.csdn.net/xq723310/article/details/128598805