Created
June 20, 2019 05:09
-
-
Save tyler-smith/44fa129223108a42af086f6cc8a1615e to your computer and use it in GitHub Desktop.
Simple ECMH inclusion proof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/gcash/bchd/bchec" | |
) | |
func main() { | |
// Create set (1, 2, 3) | |
set := bchec.NewMultiset(bchec.S256()) | |
set.Add([]byte{1}) | |
set.Add([]byte{2}) | |
set.Add([]byte{3}) | |
fmt.Println("Created set (1, 2, 3)") | |
// Create commitment to the set | |
commitment := set.Hash() | |
fmt.Println("Commitment:", commitment) | |
// Create proof of inclusion for subset (2, 3) | |
set.Remove([]byte{2}) | |
set.Remove([]byte{3}) | |
proof := set.Hash() | |
fmt.Println("Proof of inclusion of subset (2, 3):", proof) | |
// Validate proof by adding (2, 3) to the proof and comparing to commitment | |
set.Add([]byte{2}) | |
set.Add([]byte{3}) | |
commitmentCheck := set.Hash() | |
fmt.Println("Commitment check:", commitmentCheck) | |
fmt.Println("Proof is valid:", commitment == commitmentCheck) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go run . | |
Created set (1, 2, 3) | |
Commitment: c0851454e965d8209e95219290d53f1df35bbb90a58877723793d149a0d09fb9 | |
Proof of inclusion of subset (2, 3): 8286b613eab8d42fdf7c8213ffba59b15b3f4ed4e4b948980b7fb079227b9b37 | |
Commitment check: c0851454e965d8209e95219290d53f1df35bbb90a58877723793d149a0d09fb9 | |
Proof is valid: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment