You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update Merkle tree documentation for v3.0 and blockchain attestation
Major updates to Merkle tree documentation to reflect v3.0 improvements and blockchain attestation features:
- Update README.md:
- Clarify Merkle tree as "Merkle-Inspired Hash Set" optimized for small records
- Add v3.0 security improvements and interoperability features
- Add new section on blockchain attestation and verification flow
- Update usage examples to use MerkleTreeVersionStrings.V3_0
- Update selective-disclosure.md:
- Add detailed v3.0 security improvements section
- Add security guarantees and processing requirements
- Add blockchain attestation section with process and properties
- Update examples to use v3.0 format and features
- Enhance verification section with v3.0 specifics
- Update MerkleTree.cs:
- Add comprehensive documentation for v3.0 features
- Document security improvements and interoperability features
- Add use cases section
These changes better reflect the security and interoperability improvements in v3.0, particularly around the protected header leaf and blockchain attestation capabilities.
The Merkle tree implementation is designed to work seamlessly with blockchain attestations:
82
+
83
+
1.**Root Hash Attestation**: The root hash of a Merkle tree can be attested on a blockchain, providing a tamper-proof record of the tree's state at a specific point in time.
84
+
85
+
2.**Verification Flow**:
86
+
- A Merkle tree is created and its root hash is attested on the blockchain
87
+
- The complete tree can be shared with users or stored privately
88
+
- When verification is needed, the tree is parsed from JSON
89
+
- The parsed tree's root is verified against the attested hash on the blockchain
90
+
91
+
3.**Selective Disclosure with Attestation**:
92
+
- Users can create selectively disclosed versions of the tree
93
+
- The disclosed tree maintains the same root hash
94
+
- Verifiers can confirm the disclosed tree matches the attested root
95
+
96
+
This pattern is particularly valuable for:
97
+
- Digital identity documents
98
+
- Credential verification
99
+
- Document attestation
100
+
- Supply chain tracking
101
+
- Any scenario requiring both privacy and verifiability
102
+
52
103
For a complete usage example, see the [Complete Example section in the Selective Disclosure documentation](./selective-disclosure.md#complete-example-digital-passport).
53
104
54
105
For more detailed implementation information, examine the source code in:
Our implementation provides a clean, elegant solution to this problem through a technique we call "private leaves" - leaves whose content is withheld while their cryptographic presence is maintained.
28
28
29
+
## Version 3.0 Security Improvements
30
+
31
+
Version 3.0 introduces a protected header leaf that significantly enhances security by preventing several critical attacks:
32
+
33
+
1.**Single Leaf Attack Prevention**
34
+
- The header leaf forces all valid trees to have at least two leaves
35
+
- This prevents an attacker from creating a single-leaf tree that matches a known root hash
36
+
- The header leaf must be valid JSON, making it harder to fake
37
+
38
+
2.**Leaf Count Protection**
39
+
- The header leaf contains the exact number of leaves expected
40
+
- This prevents attackers from adding or removing leaves to find hash collisions
41
+
- The leaf count is cryptographically protected by being part of the tree structure
42
+
43
+
3.**Algorithm Protection**
44
+
- The hash algorithm is included in the protected header leaf
45
+
- This prevents attackers from switching to weaker algorithms
46
+
- The algorithm choice is cryptographically bound to the tree structure
47
+
48
+
4.**Document Type Safety**
49
+
- The `exchange` field specifies the type of document (e.g., "passport", "invoice")
50
+
- This prevents mixing different types of records in the same tree
51
+
- Helps prevent attacks where a proof of one document type is used as another
52
+
53
+
5.**Metadata Protection**
54
+
- All critical metadata is stored in the first leaf of the tree
55
+
- This metadata is cryptographically protected by the tree's structure
56
+
- Makes it impossible to modify metadata without breaking the tree's integrity
57
+
58
+
### Security Guarantees
59
+
60
+
The v3.0 design provides security through two difficult problems for attackers:
61
+
62
+
1.**Finding Private Leaf Hashes**
63
+
- Attackers must find correct hash values for private leaves
64
+
- These hashes must combine to produce the known root hash
65
+
- This is computationally infeasible due to the cryptographic properties of the hash function
66
+
67
+
2.**Finding Data/Salt Combinations**
68
+
- Attackers must find data and salt combinations that either:
69
+
- Produce the original hash for a leaf
70
+
- Or produce a different hash that still solves for the root hash
71
+
- This is prevented by the use of cryptographically secure random salts
72
+
73
+
### Processing Requirements
74
+
75
+
When processing v3.0 trees, verifiers must:
76
+
77
+
1. Ensure there are at least two leaf nodes
78
+
2. Verify the first leaf contains valid JSON metadata
79
+
3. Validate the algorithm is known, supported, and secure
80
+
4. Confirm the leaf count matches the actual number of leaves
81
+
5. Verify all leaf hashes can be recomputed from their data and salt
82
+
6. Validate data formats and content (e.g., postal codes, dates)
83
+
7. Challenge users to provide details from the original document
84
+
85
+
This comprehensive validation ensures the tree's integrity and prevents various attacks while maintaining the efficiency of selective disclosure.
86
+
29
87
## Important: Security Through Unique Salts
30
88
31
89
> **SECURITY BEST PRACTICE**: Each leaf in a Merkle tree should have its own unique random salt.
@@ -41,6 +99,7 @@ We've implemented a simple yet powerful solution that enables any subset of leav
41
99
2.**Clean Serialization**: Private leaves contain only their hash, omitting data, salt, and content type
42
100
3.**Seamless Verification**: Standard verification algorithms still work with private leaves
43
101
4.**Flexible Privacy Control**: Any combination of leaves can be made private or public
102
+
5.**Efficient Proofs**: Generates compact proofs with O(log n) hashes for verification
44
103
45
104
## Implementation Details
46
105
@@ -95,6 +154,31 @@ This selective disclosure approach is particularly valuable for:
95
154
2.**Credential Validation**: Verify qualifications without exposing all credential details
96
155
3.**Document Attestation**: Cryptographically verify specific document attributes
97
156
4.**Blockchain Applications**: Reduce on-chain data while maintaining verifiability
157
+
5.**Private Storage**: Store full structure (data, salts, hashes) for quick proof reissuance
158
+
159
+
## Blockchain Attestation
160
+
161
+
The selective disclosure implementation is designed to work seamlessly with blockchain attestations:
162
+
163
+
1.**Attestation Process**:
164
+
- Create a Merkle tree with all required data
165
+
- Compute and verify the root hash
166
+
- Attest the root hash on the blockchain
167
+
- Store or share the complete tree with users
168
+
169
+
2.**Verification Process**:
170
+
- Parse the selectively disclosed tree from JSON
171
+
- Verify the tree's structure and integrity
172
+
- Compare the tree's root hash with the attested hash on the blockchain
173
+
- Validate the disclosed data against the attested root
174
+
175
+
3.**Security Properties**:
176
+
- The attested root hash provides a tamper-proof record
177
+
- Selective disclosure maintains the same root hash
178
+
- The header leaf in v3.0 prevents various attacks
179
+
- The verification process ensures data integrity
180
+
181
+
This pattern enables privacy-preserving verification while maintaining the security guarantees of blockchain attestation.
98
182
99
183
## Security Considerations
100
184
@@ -125,6 +209,10 @@ Let's walk through a complete example of implementing selective disclosure with
125
209
First, we'll create a Merkle tree containing various passport data fields:
Note that in v3.0, the header leaf (first leaf) contains protected metadata about the tree, including the hash algorithm, leaf count, and document type. This metadata is cryptographically protected by the tree's structure, preventing tampering with critical tree parameters.
338
+
251
339
### Verifying a Tree with Private Leaves
252
340
253
-
The verification process works the same way with private leaves:
341
+
The verification process works the same way with private leaves, but with enhanced security in v3.0:
254
342
255
343
```csharp
256
344
// Parse the selectively disclosed JSON
@@ -260,7 +348,11 @@ var parsedTree = MerkleTree.Parse(jsonWithPrivacy);
260
348
boolisStillValid=parsedTree.VerifySha256Root(); // Should be true
261
349
```
262
350
263
-
The verification works because when a leaf is private (has no data or salt), the verification algorithm uses the provided hash directly.
351
+
The verification works because:
352
+
1. When a leaf is private (has no data or salt), the verification algorithm uses the provided hash directly
353
+
2. In v3.0, the header leaf's metadata (algorithm, leaf count, document type) is verified as part of the tree structure
354
+
3. The parser validates that the leaf count matches the actual number of leaves
355
+
4. The hash algorithm specified in the header leaf is used for verification
264
356
265
357
### Creating a Proof for a Specific Claim
266
358
@@ -289,7 +381,7 @@ There are two ways to create private leaves in a Merkle tree:
289
381
1.**Using AddPrivateLeaf**: Create a leaf that is private from the start:
0 commit comments