chore: add makefile

This commit is contained in:
rymnc 2024-03-14 14:51:21 +05:30
parent a50fcb1898
commit 8375f36066
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
3 changed files with 13 additions and 133 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
run:
go run ./main.go
test:
go test ./rln -v

View File

@ -11,7 +11,13 @@ Merkle tree Inclusion proof taken from [here](https://github.com/reilabs/gnark-l
## Usage
```bash
go run main.go
make run
```
## Test
```bash
make test
```
## Output

View File

@ -4,8 +4,7 @@ import (
"testing"
"github.com/consensys/gnark-crypto/ecc"
bls12_377Fr "github.com/consensys/gnark-crypto/ecc/bls12-377/fr"
bn254Fr "github.com/consensys/gnark-crypto/ecc/bn254/fr"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
@ -13,136 +12,6 @@ import (
// TODO: get kats for other curves
func GetBn254PathElements() [20]frontend.Variable {
rawPathElements := [20]string{
"14082964758224722211945379872337797638951236517417253447686770846170014042825",
"6628418579821163687428454604867534487917867918886059133241840211975892987309",
"12745863228198753394445659605634840709296716381893463421165313830643281758511",
"56118267389743063830320351452083247040583061493621478539311100137113963555",
"3648731943306935051357703221473866306053186513730785325303257057776816073765",
"10548621390442503192989374711060717107954536293658152583621924810330521179016",
"11741160669079729961275351458682156164905457324981803454515784688429276743441",
"17165464309215350864730477596846156251863702878546777829650812432906796008534",
"18947162586829418653666557598416458949428989734998924978331450666032720066913",
"8809427088917589399897132358419395928548406347152047718919154153577297139202",
"6261460226929242970747566981077801929281729646713842579109271945192964422300",
"13871468675790284383809887052382100311103716176061564908030808887079542722597",
"10413964486611723004584705484327518190402370933255450052832412709168190985805",
"3978387560092078849178760154060822400741873818692524912249877867958842934383",
"14014915591348694328771517896715085647041518432952027841088176673715002508448",
"17680675606519345547327984724173632294904524423937145835611954334756161077843",
"17107175244885276119916848057745382329169223109661217238296871427531065458152",
"18326186549441826262593357123467931475982067066825042001499291800252145875109",
"7043961192177345916232559778383741091053414803377017307095275172896944935996",
"2807630271073553218355393059254209097448243975722083008310815929736065268921",
}
pathElements := [20]frontend.Variable{}
// iterate over pathElements and replace with fr.Modulus().SetString("...") for eac, 10h element
for i := 0; i < len(pathElements); i++ {
pathElements[i] = Bn254FrFromStr(rawPathElements[i])
}
return pathElements
}
func Bn254FrFromStr(s string) frontend.Variable {
x, ret := bn254Fr.Modulus().SetString(s, 10)
if !ret {
panic("failed to parse fr from string")
}
return frontend.Variable(x)
}
func Bls12_377FrFromStr(s string) frontend.Variable {
x, ret := bls12_377Fr.Modulus().SetString(s, 10)
if !ret {
panic("failed to parse fr from string")
}
return frontend.Variable(x)
}
func GetBn254Y() frontend.Variable {
return Bn254FrFromStr("16401008481486069296141645075505218976370369489687327284155463920202585288271")
}
func GetBn254Nullifier() frontend.Variable {
return Bn254FrFromStr("9102791780887227194595604713537772536258726662792598131262022534710887343694")
}
func GetBn254Root() frontend.Variable {
return Bn254FrFromStr("8502402278351299594663821509741133196466235670407051417832304486953898514733")
}
func GetBn254X() frontend.Variable {
return Bn254FrFromStr("20645213238265527935869146898028115621427162613172918400241870500502509785943")
}
func GetBn254ExternalNullifier() frontend.Variable {
return Bn254FrFromStr("21074405743803627666274838159589343934394162804826017440941339048886754734203")
}
func GetBn254IdentitySecret() frontend.Variable {
return Bn254FrFromStr("2301650865650889795878889082892690584512243988708213561328369865554257051708")
}
func GetBls12_377PathElements() [20]frontend.Variable {
rawPathElements := [20]string{
"14082964758224722211945379872337797638951236517417253447686770846170014042825",
"6628418579821163687428454604867534487917867918886059133241840211975892987309",
"12745863228198753394445659605634840709296716381893463421165313830643281758511",
"56118267389743063830320351452083247040583061493621478539311100137113963555",
"3648731943306935051357703221473866306053186513730785325303257057776816073765",
"10548621390442503192989374711060717107954536293658152583621924810330521179016",
"11741160669079729961275351458682156164905457324981803454515784688429276743441",
"17165464309215350864730477596846156251863702878546777829650812432906796008534",
"18947162586829418653666557598416458949428989734998924978331450666032720066913",
"8809427088917589399897132358419395928548406347152047718919154153577297139202",
"6261460226929242970747566981077801929281729646713842579109271945192964422300",
"13871468675790284383809887052382100311103716176061564908030808887079542722597",
"10413964486611723004584705484327518190402370933255450052832412709168190985805",
"3978387560092078849178760154060822400741873818692524912249877867958842934383",
"14014915591348694328771517896715085647041518432952027841088176673715002508448",
"17680675606519345547327984724173632294904524423937145835611954334756161077843",
"17107175244885276119916848057745382329169223109661217238296871427531065458152",
"18326186549441826262593357123467931475982067066825042001499291800252145875109",
"7043961192177345916232559778383741091053414803377017307095275172896944935996",
"2807630271073553218355393059254209097448243975722083008310815929736065268921",
}
pathElements := [20]frontend.Variable{}
// iterate over pathElements and replace with fr.Modulus().SetString("...") for eac, 10h element
for i := 0; i < len(pathElements); i++ {
pathElements[i] = Bls12_377FrFromStr(rawPathElements[i])
}
return pathElements
}
func GetBls12_377X() frontend.Variable {
return Bls12_377FrFromStr("20645213238265527935869146898028115621427162613172918400241870500502509785943")
}
func GetBls12_377ExternalNullifier() frontend.Variable {
return Bls12_377FrFromStr("21074405743803627666274838159589343934394162804826017440941339048886754734203")
}
func GetBls12_377IdentitySecret() frontend.Variable {
return Bls12_377FrFromStr("2301650865650889795878889082892690584512243988708213561328369865554257051708")
}
func GetBls12_377Root() frontend.Variable {
return Bls12_377FrFromStr("8072112116574792760444558283100829445880964551173634213849140407066845417406")
}
func GetBls12_377Nullifier() frontend.Variable {
return Bls12_377FrFromStr("876257700701563447380672578054931872982248733109675901894654371450836742275")
}
func GetBls12_377Y() frontend.Variable {
return Bls12_377FrFromStr("1363155474730118727426662020141552125273305162602216677592749750619552418376")
}
func TestRlnCircuit(t *testing.T) {
assert := test.NewAssert(t)