This repo contains circuits to build ElGamal scheme over the Baby Jubjub curve.
The code to conduct the general elliptic curve operations is a custiom twisted edwards curve from the noble-curves package to prove compliant results to the field elements dependant circom-circuits.
The protocol in general aims to realize zero knowledge encryption/decryption that offers linear homomorphic properties.
The decoding algorithm in this repo is inspired from solana-zk-token that uses baby-step/giant-step algorithm to break the discrete log of a 32-bit scalar multiplication to the base point.
Fearless Concurrency
to break the 32-bit ECDL as fast as possible.yarn install
to install the dependencies.
yarn ptau
to download a powerssOfTau file directly for a direct and swift compilation to build circuits later.
yarn build-circuits
to build deterministic development circuits.
yarn precompute-lookupTable <size>
to precompute a lookupTable used to help break the discrete log of the base multiplied by a 32-bit scalar.
yarn test
to run different circuit tests for EC operations as well as ElGamal encryption and decryption.
yarn test-circuits
to run circuit tests only.
yarn test-elgamal
to run ElGamal Encrypt/Decrypt & Encode/Decode tests only.
Note: What is meant by "Testing compliance of Encrypt/Decrypt circuits" is that getting the output of the "encrypt" circuit and using it as the input of the "decrypt" circuit result in a decrypted message that is identical to the original message used as an input in the "encrypt" circuit.
Note: You can run the following commands individually or just read a summary of the benchmarks in the benchmarks README
yarn r1cs-info-elgamal
to log all important Encrypt/Decrypt circuit infos;
yarn benchmark-babyjub
to benchmark Baby Jubjub EC addition and multiplication between noble & circomlibjs packages.
yarn benchmark-decode
to benchmark decoding speed using different lookup table sizes.
yarn benchmark-circom_tester
to benchmark the speed between snarkjs and circom_tester for circuit testing purposes.
yarn delete-lookupTables
to delete all the lookupTables.
The ptau
and build-all-circuits
scripts make it much easier to compile all circuit and manage the derived files in an organized way by combining Circom and SnarkJS workflow into a single command.
By providing configuration containing your Phase 1 Powers of Tau and circuits, this plugin will:
Compile the circuits
Apply the final beacon
Output your wasm
and zkey
files
`weak curve attacks
.Rho method
Additive and multiplicative transfers
High discriminant
@noble/curves
offers securtiy against time attacks
for EC multiplication that is explicitly included in its API.invalid curve attacks
(same logic applied for the ts code).If you want to learn about the details of ElGamal Scheme over Elliptic Curves, feel free to visit this Notion Page.