feat: verify with roots

This commit is contained in:
Richard Ramos 2022-10-07 17:56:11 -04:00
parent f1211c1b07
commit 310a9442c4
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
13 changed files with 43 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -52,6 +52,11 @@ bool verify_rln_proof(const struct RLN *ctx,
const struct Buffer *proof_buffer,
bool *proof_is_valid_ptr);
bool verify_with_roots(const struct RLN *ctx,
const struct Buffer *proof_buffer,
const struct Buffer *roots_buffer,
bool *proof_is_valid_ptr);
bool key_gen(const struct RLN *ctx, struct Buffer *output_buffer);
bool seeded_key_gen(const struct RLN *ctx,

View File

@ -221,15 +221,38 @@ func (r *RLN) GenerateProof(data []byte, key MembershipKeyPair, index Membership
// Verify verifies a proof generated for the RLN.
// proof [ proof<128>| root<32>| epoch<32>| share_x<32>| share_y<32>| nullifier<32> | signal_len<8> | signal<var> ]
func (r *RLN) Verify(data []byte, proof RateLimitProof) bool {
func (r *RLN) Verify(data []byte, proof RateLimitProof) (bool, error) {
proofBytes := proof.serialize(data)
proofBuf := toCBufferPtr(proofBytes)
res := C.bool(false)
if !bool(C.verify_rln_proof(r.ptr, proofBuf, &res)) {
return false
return false, errors.New("could not verify rln proof")
}
return bool(res)
return bool(res), nil
}
func serializeRoots(roots [][32]byte) []byte {
var result []byte
for _, r := range roots {
result = append(result, r[:]...)
}
return result
}
func (r *RLN) VerifyWithRoots(data []byte, proof RateLimitProof, roots [][32]byte) (bool, error) {
proofBytes := proof.serialize(data)
proofBuf := toCBufferPtr(proofBytes)
rootBytes := serializeRoots(roots)
rootBuf := toCBufferPtr(rootBytes)
res := C.bool(false)
if !bool(C.verify_with_roots(r.ptr, proofBuf, rootBuf, &res)) {
return false, errors.New("could not verify with roots")
}
return bool(res), nil
}
// InsertMember adds the member to the tree

View File

@ -183,8 +183,16 @@ func (s *RLNSuite) TestValidProof() {
s.NoError(err)
// verify the proof
verified := rln.Verify(msg, *proofRes)
verified, err := rln.Verify(msg, *proofRes)
s.NoError(err)
s.True(verified)
// verify with roots
root, err := rln.GetMerkleRoot()
s.NoError(err)
verified, err = rln.VerifyWithRoots(msg, *proofRes, [][32]byte{root})
s.NoError(err)
s.True(verified)
}
@ -227,8 +235,8 @@ func (s *RLNSuite) TestInvalidProof() {
s.NoError(err)
// verify the proof (should not be verified)
verified := rln.Verify(msg, *proofRes)
verified, err := rln.Verify(msg, *proofRes)
s.NoError(err)
s.False(verified)
}

@ -1 +1 @@
Subproject commit a5aa4e8d4f02b2f0ff12f74ffdb0ce4fde2ec636
Subproject commit b95b151a1c2407c897d486dbab2c480684ae2b7e