Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Created June 20, 2019 05:09
Show Gist options
  • Save tyler-smith/44fa129223108a42af086f6cc8a1615e to your computer and use it in GitHub Desktop.
Save tyler-smith/44fa129223108a42af086f6cc8a1615e to your computer and use it in GitHub Desktop.
Simple ECMH inclusion proof
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)
}
> 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