| 1 | Monotone Span Programs |
| 2 | ====================== |
| 3 | |
| 4 | - [Introduction](#monotone-span-programs) |
| 5 | - [Types of Predicates](#types-of-predicates) |
| 6 | - [Documentation](#documentation) |
| 7 | - [User Databases](#user-databases) |
| 8 | - [Building Predicates](#building-predicates) |
| 9 | - [Splitting & Reconstructing Secrets](#splitting--reconstructing-secrets) |
| 10 | |
| 11 | A *Monotone Span Program* (or *MSP*) is a cryptographic technique for splitting |
| 12 | a secret into several *shares* that are then distributed to *parties* or |
| 13 | *users*. (Have you heard of [Shamir's Secret Sharing](http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing)? It's like that.) |
| 14 | |
| 15 | Unlike Shamir's Secret Sharing, MSPs allow *arbitrary monotone access |
| 16 | structures*. An access structure is just a boolean predicate on a set of users |
| 17 | that tells us whether or not that set is allowed to recover the secret. A |
| 18 | monotone access structure is the same thing, but with the invariant that adding |
| 19 | a user to a set will never turn the predicate's output from `true` to |
| 20 | `false`--negations or boolean `nots` are disallowed. |
| 21 | |
| 22 | **Example:** `(Alice or Bob) and Carl` is good, but `(Alice or Bob) and !Carl` |
| 23 | is not because excluding people is rude. |
| 24 | |
| 25 | MSPs are fundamental and powerful primitives. They're well-suited for |
| 26 | distributed commitments (DC), verifiable secret sharing (VSS) and multi-party |
| 27 | computation (MPC). |
| 28 | |
| 29 | |
| 30 | #### Types of Predicates |
| 31 | |
| 32 | An MSP itself is a type of predicate and the reader is probably familiar with |
| 33 | raw boolean predicates like in the example above, but another important type is |
| 34 | a *formatted boolean predicate*. |
| 35 | |
| 36 | Formatted boolean predicates are isomorphic to all MSPs and therefore all |
| 37 | monotone raw boolean predicates. They're built by nesting threshold gates. |
| 38 | |
| 39 | **Example:** Let `(2, Alice, Bob, Carl)` denote that at least 2 members of the |
| 40 | set `{Alice, Bob, Carl}` must be present to recover the secret. Then, |
| 41 | `(2, (1, Alice, Bob), Carl)` is the formatted version of |
| 42 | `(Alice or Bob) and Carl`. |
| 43 | |
| 44 | It is possible to convert between different types of predicates (and its one of |
| 45 | the fundamental operations of splitting secrets with an MSP), but circuit |
| 46 | minimization is a non-trivial and computationally complex problem. The code can |
| 47 | do a small amount of compression, but the onus is on the user to design |
| 48 | efficiently computable predicates. |
| 49 | |
| 50 | |
| 51 | #### To Do |
| 52 | |
| 53 | 1. Anonymous secret generation / secret homomorphisms |
| 54 | 2. Non-interactive verifiable secret sharing / distributed commitments |
| 55 | |
| 56 | |
| 57 | Documentation |
| 58 | ------------- |
| 59 | |
| 60 | ### User Databases |
| 61 | |
| 62 | ```go |
| 63 | type UserDatabase interface { |
| 64 | ValidUser(string) bool // Is this the name of an existing user? |
| 65 | CanGetShare(string) bool // Can I get this user's share? |
| 66 | GetShare(string) ([][]byte, error) // Retrieves a user's shares. |
| 67 | } |
| 68 | ``` |
| 69 | |
| 70 | User databases are an abstraction over the primitive name -> share map that |
| 71 | hopefully offer a bit more flexibility in implementing secret sharing schemes. |
| 72 | `CanGetShare(name)` should be faster and less binding than `GetShare(name)`. |
| 73 | `CanGetShare(name)` may be called a large number of times, but `GetShare(name)` |
| 74 | will be called the absolute minimum number of times possible. |
| 75 | |
| 76 | Depending on the predicate used, a name may be associated to multiple shares of |
| 77 | a secret, hence `[][]byte` as opposed to one share (`[]byte`). |
| 78 | |
| 79 | For test/play purposes there's a cheaty implementation of `UserDatabase` in |
| 80 | `msp_test.go` that just wraps the `map[string][][]byte` returned by |
| 81 | `DistributeShares(...)` |
| 82 | |
| 83 | ### Building Predicates |
| 84 | |
| 85 | ```go |
| 86 | type Raw struct { ... } |
| 87 | |
| 88 | func StringToRaw(string) (Raw, error) { ... } |
| 89 | func (r Raw) String() string { .. .} |
| 90 | func (r Raw) Formatted() Formatted { ... } |
| 91 | |
| 92 | |
| 93 | type Formatted struct { ... } |
| 94 | |
| 95 | func StringToFormatted(string) (Formatted, error) |
| 96 | func (f Formatted) String() string |
| 97 | ``` |
| 98 | |
| 99 | Building predicates is extremely easy--just write it out in a string and have |
| 100 | one of the package methods parse it. |
| 101 | |
| 102 | Raw predicates take the `&` (logical AND) and `|` (logical OR) operators, but |
| 103 | are otherwise the same as discussed above. Formatted predicates are exactly the |
| 104 | same as above--just nested threshold gates. |
| 105 | |
| 106 | ```go |
| 107 | r1, _ := msp.StringToRaw("(Alice | Bob) & Carl") |
| 108 | r2, _ := msp.StringToRaw("Alice & Bob & Carl") |
| 109 | |
| 110 | fmt.Printf("%v\n", r1.Formatted()) // (2, (1, Alice, Bob), Carl) |
| 111 | fmt.Printf("%v\n", r2.Formatted()) // (3, Alice, Bob, Carl) |
| 112 | ``` |
| 113 | |
| 114 | ### Splitting & Reconstructing Secrets |
| 115 | |
| 116 | ```go |
| 117 | type MSP Formatted |
| 118 | |
| 119 | func (m MSP) DistributeShares(sec []byte, db *UserDatabase) (map[string][][]byte, error) {} |
| 120 | func (m MSP) RecoverSecret(db *UserDatabase) ([]byte, error) {} |
| 121 | ``` |
| 122 | |
| 123 | To switch from predicate-mode to secret-sharing-mode, just cast your formatted |
| 124 | predicate into an MSP something like this: |
| 125 | ```go |
| 126 | predicate := msp.StringToFormatted("(3, Alice, Bob, Carl)") |
| 127 | sss := msp.MSP(predicate) |
| 128 | ``` |
| 129 | |
| 130 | Calling `DistributeShares` on it returns a map from a party's name to their set |
| 131 | of shares which should be given to that party and integrated into the |
| 132 | `UserDatabase` somehow. When you're ready to reconstruct the secret, you call |
| 133 | `RecoverSecret`, which does some prodding about and hopefully gives you back |
| 134 | what you put in. |