Skip to content

Commit

Permalink
repo restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Dec 2, 2024
1 parent 73919dd commit 440afa3
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 338 deletions.
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

A set of custom circuits writted in [Gnark](https://github.com/ConsenSys/gnark) that are required to support anonymous voting on [Vocdoni](https://github.com/vocdoni).

## Libs included

1. Hash Poseidon ([source code](./poseidon)).
2. SMT Verifier port from [@iden3/circomlib](https://github.com/iden3/circomlib/blob/master/circuits/smt/smtverifier.circom) ([source code](./smt)).
3. Arbo (by [@arnaucube](https://github.com/arnaucube)) proof checker from [@vocdoni/arbo](https://github.com/vocdoni/vocdoni-node/tree/main/tree/arbo) ([source code](./arbo))
- This is compatible with the SMT Verifier.
4. Homomorphic Addition (using point reduction of TwistedEdwards curve to transform circom BabyJubJub points into Gnark BabyJubJub points) ([source code](./hadd)) ([helpers source code](./twistededwards))
5. Address derivation from ECDSA public key (hash the key coords with Keccak256 and take the last 20 bytes) ([source code](./address)).

**SMT Verifier vs. Arbo**

| | SMT Verifier | Arbo |
|:---:|---:|---:|
| *Inputs* | 4 | 5 |
| *Constrains* | 42316 | 41373 (🏆) |
| *Solver time* | 169.192292ms (🏆) | 211.738333ms |


## Primitives included

* Hash Poseidon ([source code](./hash/bn254/poseidon)).
* SMT Verifier port from [@iden3/circomlib](https://github.com/iden3/circomlib/blob/master/circuits/smt/smtverifier.circom) ([source code](./tree/smt)).
* Arbo (by [@arnaucube](https://github.com/arnaucube)) proof checker from [@vocdoni/arbo](https://github.com/vocdoni/vocdoni-node/tree/main/tree/arbo) ([source code](./tree/arbo))
- This is also compatible with the circomlib SMT Verifier.
* Homomorphic Addition (using point reduction of TwistedEdwards curve to transform circom BabyJubJub points into Gnark BabyJubJub points) ([source code](./hommomorphic/add.go)) ([helpers source code](./emulated/bn254/twistededwards/twistededwards.go))
* Address derivation from ECDSA public key (hash the key coords with Keccak256 and take the last 20 bytes) ([source code](./emulated/ecdsa/address.go)).
* Some other helper functions that are useful in previous primitives ([source code](./utils))
---

## DISCLAIMER
Expand Down
15 changes: 0 additions & 15 deletions address/README.md

This file was deleted.

85 changes: 0 additions & 85 deletions address/address.go

This file was deleted.

43 changes: 0 additions & 43 deletions arbo/hints.go

This file was deleted.

139 changes: 0 additions & 139 deletions arbo/verifier.go

This file was deleted.

23 changes: 23 additions & 0 deletions emulated/bn254/twistededwards/mimc7/mimc_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package mimc7

import (
"fmt"
"log"
"math/big"
"testing"
"time"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/consensys/gnark/profile"
"github.com/consensys/gnark/std/algebra/emulated/sw_bn254"
"github.com/consensys/gnark/std/math/emulated"
"github.com/consensys/gnark/test"
Expand Down Expand Up @@ -35,12 +40,30 @@ func TestMiMC(t *testing.T) {
input := new(big.Int).SetInt64(12)
hash, err := mimc7.Hash([]*big.Int{input}, nil)
c.Assert(err, qt.IsNil)
c.Assert(printConstrains(&testMiMCCircuit{}), qt.IsNil)
// create a witness
witness := testMiMCCircuit{
Preimage: emulated.ValueOf[sw_bn254.ScalarField](input),
Hash: emulated.ValueOf[sw_bn254.ScalarField](hash),
}
// run the test
assert := test.NewAssert(t)
now := time.Now()
assert.SolvingSucceeded(&testMiMCCircuit{}, &witness, test.WithCurves(ecc.BLS12_377), test.WithBackends(backend.GROTH16))
fmt.Println("solving tooks", time.Since(now))
}

func printConstrains(placeholder frontend.Circuit) error {
// compile circuit
p := profile.Start()
now := time.Now()
_, err := frontend.Compile(ecc.BLS12_377.ScalarField(), r1cs.NewBuilder, placeholder)
if err != nil {
log.Println(err)
return err
}
fmt.Println("compilation tooks", time.Since(now))
p.Stop()
fmt.Println("constrains", p.NbConstraints())
return nil
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// twistededwards package provides helper circuit functions to transform points
// (x, y) from the TwistedEdwards format to Reduced TwistedEdwards format and
// vice versa, over BabyJubJub curve. These functions are required because
// Gnark uses the Reduced TwistedEdwards formula while Iden3 uses the standard
// TwistedEdwards formula.
//
// Read more about this here: https://github.com/bellesmarta/baby_jubjub
package twistededwards

import "github.com/consensys/gnark/frontend"
Expand Down
File renamed without changes.
Loading

0 comments on commit 440afa3

Please sign in to comment.