Skip to content

Commit

Permalink
fix tests with new proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
vmidyllic committed Jan 11, 2022
1 parent 38c2257 commit d4ef511
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 113 deletions.
Empty file removed circuits/metadata.go
Empty file.
Empty file removed circuits/verification_keys.go
Empty file.
50 changes: 12 additions & 38 deletions communication/auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,26 @@ func TestVerify(t *testing.T) {
Type: types.ZeroKnowledgeProofType,
CircuitID: circuits.KycBySignaturesCircuitID,
}

zkpProof.ProofData = &types.ProofData{
A: []string{"15410252994758206156331933443865902387659457159831652500594192431349076893658",
"20150829872771081060142254046116588090324284033366663360366174697329414878949",
A: []string{"10441536817202584897377823144827964642356918402871315490038163167310235469676",
"3188873104904010906845899057040012497857652125001996465924027367142766788060",
"1"},
B: [][]string{{"9417153075860115376893693247142868897300054298656960914587138216866082643706",
"10202816620941554744739718000741718724240818496129635422271960203010394413915",
}, {"15503138617167966595249072003849677537923997283726290430496888985000900792650",
"6173958614668002844023250887062625456639056306855696879145959593623787348506",
B: [][]string{{"10259767950868305572343651918722890484304440255374794205464892311274784569874",
"18113532891970083775734522192028652126404157383671158241782353379080674688210",
}, {
"20011188305329655231409527762393912898857036946232895893305954758470171745705",
"19212224402431449690017436050830610655559646158634403540885275057516508525272",
}, {
"1",
"0",
}},
C: []string{
"14084349531001200150970271267870661180690655641091539571582685666559667846160",
"6506935406401708938070550600218341978561747347886649538986407400386963731317",
C: []string{"17410066358263445906462947561105622363737416663317734129930901016400750644236",
"10889346016675221860511647187111664354773325795907973404602900127856769668544",
"1",
},
}
zkpProof.PubSignals = []string{
"26592849444054787445766572449338308165040390141345377877344569181291872256",
"12345",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"840",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"2021",
"4",
"25",
"18",
}
zkpProof.PubSignals = []string{"12345", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "840", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "2021", "4", "25"}
message.Data.Scope = []interface{}{zkpProof}

err := Verify(&message)
Expand Down Expand Up @@ -186,7 +160,7 @@ func TestExtractData(t *testing.T) {
token, err := ExtractMetadata(&message)
assert.Nil(t, err)

assert.Equal(t, "12345", token.Challenge)
assert.Equal(t, "26592849444054787445766572449338308165040390141345377877344569181291872256", token.Challenge)

}

Expand Down
48 changes: 24 additions & 24 deletions communication/credentials/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestVerifyCredentialFetchRequest(t *testing.T) {

var message types.CredentialFetchRequest
message.Type = CredentialFetchRequestMessageType
message.Data = types.CredentialFetchRequestMessageData{}
message.Data = types.CredentialFetchRequestMessageData{ClaimID: "992fc184-c902-4f9a-af62-b383cc5e1eb4", Schema: "KYCAgeCredential"}

zkpProof := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
Expand All @@ -20,32 +20,32 @@ func TestVerifyCredentialFetchRequest(t *testing.T) {

zkpProof.ProofData = &types.ProofData{
A: []string{
"18936271973117240691705559585769592974936923569213179030272017872877809039923",
"18422345941126925346404589344471685526481812474926428421192486541362664918772",
"11130843150540789299458990586020000719280246153797882843214290541980522375072",
"1300841912943781723022032355836893831132920783788455531838254465784605762713",
"1"},
B: [][]string{
{
"21330507917605771112737495332384182754017872671331663255035774134477307177657",
"11462448334617588029347704885403867272225695665465848309095217964693916030466",
"20615768536988438336537777909042352056392862251785722796637590212160561351656",
"10371144806107778890538857700855108667622042215096971747203105997454625814080",
},
{
"6840720762741964372185603768831031763412571244452731103935719626324813065968",
"21706573949504402596589372160652940106962129670251783730794239678073827564253",
"19598541350804478549141207835028671111063915635580679694907635914279928677812",
"15264553045517065669171584943964322117397645147006909167427809837929458012913",
},
{
"1",
"0",
}},
C: []string{
"17548802242159422756497011319050257549779839182737330954154562317224853077096",
"16720285840459139191823107762843332365012723866736056448880671648502165007589",
"16443309279825508893086251290003936935077348754097470818523558082502364822049",
"2984180227766048100510120407150752052334571876681304999595544138155611963273",
"1",
},
}
zkpProof.PubSignals = []string{
"360506537017543098982364518145035624387547643177965411252793105868750389248",
"12345",
"12051733342209181702880711377819237050140862582923079913097401558944144010618",
"1",
"18311560525383319719311394957064820091354976310599818797157189568621466950811",
"323416925264666217617288569742564703632850816035761084002720090377353297920",
}
message.Data.Scope = []interface{}{zkpProof}

Expand All @@ -66,38 +66,38 @@ func TestExtractDataFromCredentialFetchRequest(t *testing.T) {

zkpProof.ProofData = &types.ProofData{
A: []string{
"18936271973117240691705559585769592974936923569213179030272017872877809039923",
"18422345941126925346404589344471685526481812474926428421192486541362664918772",
"11130843150540789299458990586020000719280246153797882843214290541980522375072",
"1300841912943781723022032355836893831132920783788455531838254465784605762713",
"1"},
B: [][]string{
{
"21330507917605771112737495332384182754017872671331663255035774134477307177657",
"11462448334617588029347704885403867272225695665465848309095217964693916030466",
"20615768536988438336537777909042352056392862251785722796637590212160561351656",
"10371144806107778890538857700855108667622042215096971747203105997454625814080",
},
{
"6840720762741964372185603768831031763412571244452731103935719626324813065968",
"21706573949504402596589372160652940106962129670251783730794239678073827564253",
"19598541350804478549141207835028671111063915635580679694907635914279928677812",
"15264553045517065669171584943964322117397645147006909167427809837929458012913",
},
{
"1",
"0",
}},
C: []string{
"17548802242159422756497011319050257549779839182737330954154562317224853077096",
"16720285840459139191823107762843332365012723866736056448880671648502165007589",
"16443309279825508893086251290003936935077348754097470818523558082502364822049",
"2984180227766048100510120407150752052334571876681304999595544138155611963273",
"1",
},
}
zkpProof.PubSignals = []string{
"360506537017543098982364518145035624387547643177965411252793105868750389248",
"12345",
"12051733342209181702880711377819237050140862582923079913097401558944144010618",
"1",
"18311560525383319719311394957064820091354976310599818797157189568621466950811",
"323416925264666217617288569742564703632850816035761084002720090377353297920",
}
message.Data.Scope = []interface{}{zkpProof}

token, err := ExtractMetadataFromCredentialFetchRequest(&message)
assert.Nil(t, err)
assert.Equal(t, "12345", token.Challenge)
assert.Equal(t, "1", token.Challenge)
assert.Equal(t, "992fc184-c902-4f9a-af62-b383cc5e1eb4", token.ClaimID)
assert.Equal(t, "KYCAgeCredential", token.ClaimSchema)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
github.com/ethereum/go-ethereum v1.10.13
github.com/iden3/go-circom-prover-verifier v0.0.1
github.com/iden3/go-circuits v0.0.9
github.com/iden3/go-iden3-core v0.0.11
github.com/iden3/go-merkletree-sql v1.0.0-pre8
github.com/pkg/errors v0.9.1
Expand All @@ -20,7 +21,6 @@ require (
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/iden3/go-circuits v0.0.5 // indirect
github.com/iden3/go-iden3-crypto v0.0.11 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/iden3/go-circom-prover-verifier v0.0.1 h1:gfmAwhvUB0Wya++dGfgvMYPsLzJf34Yw6x269CnhOP0=
github.com/iden3/go-circom-prover-verifier v0.0.1/go.mod h1:1FkpX4nUXxYcY2fpzqd27wHHEnWeo1v1nwDnz2TgBRo=
github.com/iden3/go-circuits v0.0.5 h1:wOpVFQSyO9GfQRq2WoSIS2puinj8KrbIHy6baLGgdBQ=
github.com/iden3/go-circuits v0.0.5/go.mod h1:0bUcReAD+GPUIa1SfxiAJNNHp9hYp3dN8bfjtH2KLe8=
github.com/iden3/go-circuits v0.0.9 h1:jCrrrM2Owa2PME1Ff0A9kL9vGv2ECR9RQDwcD+WbpOY=
github.com/iden3/go-circuits v0.0.9/go.mod h1:0bUcReAD+GPUIa1SfxiAJNNHp9hYp3dN8bfjtH2KLe8=
github.com/iden3/go-iden3-core v0.0.11 h1:Msi8F6n5e755OMer+7ZV03z04GnQtoTNboKwfrDgB9A=
github.com/iden3/go-iden3-core v0.0.11/go.mod h1:Ou51YR716WqeBJ3Z4BkGVAJROgSYgfnl4i8x3mfLOeY=
github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
Expand Down Expand Up @@ -312,7 +312,6 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
Expand Down
2 changes: 1 addition & 1 deletion proofs/zeroknowledge/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var supportedCircuits = map[circuits.CircuitID]types.CircuitData{
ID: circuits.KycBySignaturesCircuitID,
Description: "circuit for kyc claims verification",
VerificationKey: circuits.KycBySignaturesVerificationKey,
Metadata: circuits.KycPublicSignalsSchema,
Metadata: circuits.KycBySignaturesPublicSignalsSchema,
},
circuits.AuthCircuitID: {
ID: circuits.AuthCircuitID,
Expand Down
48 changes: 11 additions & 37 deletions proofs/zeroknowledge/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,25 @@ func TestVerifyProof(t *testing.T) {
proofMessage := &types.ZeroKnowledgeProof{}
proofMessage.CircuitID = circuits.KycBySignaturesCircuitID
proofMessage.ProofData = &types.ProofData{
A: []string{"15410252994758206156331933443865902387659457159831652500594192431349076893658",
"20150829872771081060142254046116588090324284033366663360366174697329414878949",
A: []string{"10441536817202584897377823144827964642356918402871315490038163167310235469676",
"3188873104904010906845899057040012497857652125001996465924027367142766788060",
"1"},
B: [][]string{{"9417153075860115376893693247142868897300054298656960914587138216866082643706",
"10202816620941554744739718000741718724240818496129635422271960203010394413915",
}, {"15503138617167966595249072003849677537923997283726290430496888985000900792650",
"6173958614668002844023250887062625456639056306855696879145959593623787348506",
B: [][]string{{"10259767950868305572343651918722890484304440255374794205464892311274784569874",
"18113532891970083775734522192028652126404157383671158241782353379080674688210",
}, {
"20011188305329655231409527762393912898857036946232895893305954758470171745705",
"19212224402431449690017436050830610655559646158634403540885275057516508525272",
}, {
"1",
"0",
}},
C: []string{
"14084349531001200150970271267870661180690655641091539571582685666559667846160",
"6506935406401708938070550600218341978561747347886649538986407400386963731317",
C: []string{"17410066358263445906462947561105622363737416663317734129930901016400750644236",
"10889346016675221860511647187111664354773325795907973404602900127856769668544",
"1",
},
}
proofMessage.PubSignals = []string{
"26592849444054787445766572449338308165040390141345377877344569181291872256",
"12345",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"840",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"164414642845063686862221124543185217840281790633605788367384240953047711744",
"20826763141600863538041346956386832863527621891653741934199228821528372364336",
"2021",
"4",
"25",
"18",
}
proofMessage.PubSignals = []string{"12345", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "840", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "372902514040400364441393275265861152892555341750332828757240276565437644800", "19443506635601976434000063402326775248489014592264899338419890539515181882284", "2021", "4", "25"}

proofMessage.Type = "zeroknowledge"

err = VerifyProof(proofMessage)
Expand Down
15 changes: 6 additions & 9 deletions verification/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package verification

import (
"github.com/iden3/go-circom-prover-verifier/parsers"
types2 "github.com/iden3/go-circom-prover-verifier/types"
"github.com/iden3/go-circom-prover-verifier/verifier"
"github.com/iden3/go-circuits"
"github.com/stretchr/testify/assert"
Expand All @@ -12,22 +11,20 @@ import (

func TestVerify(t *testing.T) {
// verifyGroth16 the proofs
vkJSON := []byte(circuits.KycBySignaturesCircuitID)
vkJSON := []byte(circuits.KycBySignaturesVerificationKey)

publicJSON := []byte(`["411744492472830263284610159093112301866082562595864436469836164448155795456","12345","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","840","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","123776615674577205629582240968408410063074486679712932519574537196926599168","11688539338838797595201345228132404230382121068811390693927054959014251630145","2021","4","25","18"]`)
publicJSON := []byte(`["12345","372902514040400364441393275265861152892555341750332828757240276565437644800","19443506635601976434000063402326775248489014592264899338419890539515181882284","840","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","372902514040400364441393275265861152892555341750332828757240276565437644800","19443506635601976434000063402326775248489014592264899338419890539515181882284","2021","4","25"]`)

proofJSON := []byte(`{"pi_a":"1d0d50f3df112a8d63fc899f900aa074f7eef2cd8efacf9d5cfee68734289f3a26de558d575bafd06ca5b6b5944d19877e5ea5f3c70c39f855e06069589c835c","pi_b":"2850c86effe287d308edbc711d0340dfae447cf1da1fcdcea93c0619ad73eeae02a0e91a72b7334da417160476ade6bb09d7631da7d76e991f49b59d3ccdd43e2cc4c23b8937a172ad9b3e825a979fce9239a7d5c3eaf3a44496005b6f3d59a6248dae2b3c124f025877062bbf90fbaff48634584c8065c6c14765bd97947e54","pi_c":"242cb3ab3c64530f69303a64eaf74ffa42511b7af16e29189070258d462346491fa67f85df1c16215540e932c85f626fa8a11fb21f14cb12b7b925041c8842a6"}`)

public, err := parsers.ParsePublicSignals(publicJSON)
p := `{"pi_a":["10441536817202584897377823144827964642356918402871315490038163167310235469676","3188873104904010906845899057040012497857652125001996465924027367142766788060","1"],"pi_b":[["10259767950868305572343651918722890484304440255374794205464892311274784569874","18113532891970083775734522192028652126404157383671158241782353379080674688210"],["20011188305329655231409527762393912898857036946232895893305954758470171745705","19212224402431449690017436050830610655559646158634403540885275057516508525272"],["1","0"]],"pi_c":["17410066358263445906462947561105622363737416663317734129930901016400750644236","10889346016675221860511647187111664354773325795907973404602900127856769668544","1"],"protocol":"groth16"}`
proof, err := parsers.ParseProof([]byte(p))
require.Nil(t, err)

var proof types2.Proof
err = proof.UnmarshalJSON(proofJSON)
public, err := parsers.ParsePublicSignals(publicJSON)

require.Nil(t, err)
vk, err := parsers.ParseVk(vkJSON)
require.Nil(t, err)

res := verifier.Verify(vk, &proof, public)
res := verifier.Verify(vk, proof, public)
assert.True(t, res)
}

0 comments on commit d4ef511

Please sign in to comment.