diff --git a/circuits/README.md b/circuits/README.md index 40a833e7..a1f48f6f 100644 --- a/circuits/README.md +++ b/circuits/README.md @@ -35,6 +35,10 @@ Folder containing the implementation of sha256 hash circuit. +### Shamir Secret Sharing + +Folder containng the implementation of shamir secret sharing. + ### smt Folder containing the circuit implementation of Sparse Merkle Trees. @@ -207,19 +211,22 @@ Arithmetic on [Baby Jubjub elliptic curve](https://github.com/barryWhiteHat/baby - `IsZero() ` - - DESCRIPTION + - DESCRIPTION : + Checks whether the argument is zero or not. - SCHEMA - - INPUT - - OUTPUT + - INPUT: + - OUTPUT : Returns 1 if true, 0 otherwise - BENCHMARKS - - EXAMPLE + - EXAMPLE - `IsEqual()` - - DESCRIPTION + - DESCRIPTION : + Checks whether the two inputs (first element at in[0], second at in[1]) are equal or not - SCHEMA - INPUT - - OUTPUT + - OUTPUT : + Returns 1 if true, 0 otherwise - BENCHMARKS - EXAMPLE @@ -234,28 +241,31 @@ Arithmetic on [Baby Jubjub elliptic curve](https://github.com/barryWhiteHat/baby - `LessThan()` - - DESCRIPTION + - DESCRIPTION : Compares the input[0] < input[1]. Returns 1 if true, 0 otherwise - SCHEMA - INPUT - - OUTPUT + - OUTPUT : + Returns 1 if true, 0 otherwise - BENCHMARKS - EXAMPLE - `GreaterThan()` - - DESCRIPTION + - DESCRIPTION : Compares the input[0] > input[1]. - SCHEMA - INPUT - - OUTPUT + - OUTPUT : + Returns 1 if true, 0 otherwise - BENCHMARKS - EXAMPLE - `GreaterEqThan()` - - DESCRIPTION + - DESCRIPTION : Compares the input[0] >= input[1]. Returns 1 if true, 0 otherwise - SCHEMA - INPUT - - OUTPUT + - OUTPUT : + Returns 1 if true, 0 otherwise - BENCHMARKS - EXAMPLE diff --git a/circuits/ShamirSecretSharing/validateshares.circom b/circuits/ShamirSecretSharing/validateshares.circom new file mode 100644 index 00000000..0fb041bc --- /dev/null +++ b/circuits/ShamirSecretSharing/validateshares.circom @@ -0,0 +1,55 @@ +/* Shamir Secret Sharing + The purpose of shamir secret sharing is to share a secret message with n parties, and none of them know each others share value. On combining the shares using lagrange bases, we get the message back. Here we make lagrange basis polynomials and evaluate it at 0 (becoz constant term is our goal). + + Example: + 1. Suppose we have message = 14. + 2. And we sample random values from the Field Fp and make a polynomial (deg = n-1, where n = #shares) with message=14 as the constant term. + Example equation P(x)= 7x^3 + 6x^2 + 4x + 14. + 3. This program verifies that the evaluations of P(x) at points in x[], is correct. Suppose "x": [1,2,3,4], "shares":[31,102,269,574]. + 4. Then on combining the shares using the lagrange bases on x, we must get the message back. +*/ +pragma circom 2.1.8; +include "../comparators.circom"; + +// Objective: Find the univariate lagrange basis polynomial evaluations at 0 using the distintct set of points in[] +template LagrangeBasis(n){ + signal input in[n]; //evaluation points + signal output out[n]; // outs lagrange bases eval at point 0 + signal stmp[n]; + signal one<--1; + for (var i=0;i