SNARK-friendly Asymmetric Encryption
For the use in anonymity revoking we require a SNARK-friendly asymmetric encryption. Recall that we use the BN254 curve for our cryptography. Let's denote the scalar field of BN254 by — a prime field with r
elements. In pseudocode we use the Scalar
type — this is exactly the same as
Grumpkin Curve
For asymmetric encryption we use the familiar ElGamal cryptosystem, however to make it snark-friendly we need a specific choice of the group we work with. Specifically let be the Grumpkin elliptic curve — see Grumpkin. This group has the following properties:
The base field of Grumpkin is thus in other words, the group consists of pairs (affine coordinates) or triples (projective coordinates) of elements of that satisfy a certain simply arithmetic condition. Similarly, the group operation is defined in terms of a small constant number of arithmetic operations in .
The cardinality of is with being a prime, roughly .
ElGamal Encryption
Let us denote any canonical generator of by (this is in principle any element of the group that is not the identity element, but it is typically chosen in a specific way). The ElGamal cryptosystem that we use is characterized by the following procedures.
Key generation. The procedure
KeyGen()
outputs the private key uniformly at random. Moreover, the public key is then computed and published.Encryption. Any party having access to the public key can encrypt a message . We assume the messages come from itself.
where is chosen uniformly at random from .
Decryption. The private key holder, given the ciphertext
(c1, c2)
computes:and as one can easily verify, the original message is recovered this way.
Encoding into the message space
Note that the message space in ElGamal above is a little weird — points on the Grumpkin Curve . In circuits we deal with elements in hence ideally we would like to encode elements of into . That task however is unfortunately not that simple, because the encoding must be also snark-friendly. Recall that
The simplest encoding would be then with chosen so as to make this point on curve. This however doesn't work, because not every element is the first coordinate of some grumpkin element. However, it ALMOST works, in the sense that for a random the probability that exists is close to 1/2. This way half of all scalars can be trivially encoded into .
In our application of ElGamal, we need to encrypt key(id)
a scalar element that is pseudorandomly generated from id
. We require that id
has this property that key(id)
is encodeable as a group element in the sense above, otherwise the id
is considered invalid. A user can use only a valid id
for its account because validity is checked in the first transaction.
Last updated
Was this helpful?