diff --git a/libs/aarch64-apple-darwin/librln.a b/libs/aarch64-apple-darwin/librln.a index bbca21f..aab609a 100644 Binary files a/libs/aarch64-apple-darwin/librln.a and b/libs/aarch64-apple-darwin/librln.a differ diff --git a/libs/aarch64-unknown-linux-gnu/librln.a b/libs/aarch64-unknown-linux-gnu/librln.a index 0664805..b0e5763 100644 Binary files a/libs/aarch64-unknown-linux-gnu/librln.a and b/libs/aarch64-unknown-linux-gnu/librln.a differ diff --git a/libs/arm-unknown-linux-gnueabi/librln.a b/libs/arm-unknown-linux-gnueabi/librln.a index f30f4e2..7b18f74 100644 Binary files a/libs/arm-unknown-linux-gnueabi/librln.a and b/libs/arm-unknown-linux-gnueabi/librln.a differ diff --git a/libs/arm-unknown-linux-gnueabihf/librln.a b/libs/arm-unknown-linux-gnueabihf/librln.a index fc72285..8baea7b 100644 Binary files a/libs/arm-unknown-linux-gnueabihf/librln.a and b/libs/arm-unknown-linux-gnueabihf/librln.a differ diff --git a/libs/i686-unknown-linux-gnu/librln.a b/libs/i686-unknown-linux-gnu/librln.a index 8ec5812..7e68e5d 100644 Binary files a/libs/i686-unknown-linux-gnu/librln.a and b/libs/i686-unknown-linux-gnu/librln.a differ diff --git a/libs/x86_64-apple-darwin/librln.a b/libs/x86_64-apple-darwin/librln.a index 1bdd1d5..f478779 100644 Binary files a/libs/x86_64-apple-darwin/librln.a and b/libs/x86_64-apple-darwin/librln.a differ diff --git a/libs/x86_64-pc-windows-gnu/librln.a b/libs/x86_64-pc-windows-gnu/librln.a index 8f17a9d..9e3bf8a 100644 Binary files a/libs/x86_64-pc-windows-gnu/librln.a and b/libs/x86_64-pc-windows-gnu/librln.a differ diff --git a/libs/x86_64-unknown-linux-gnu/librln.a b/libs/x86_64-unknown-linux-gnu/librln.a index 83b8664..dc7389e 100644 Binary files a/libs/x86_64-unknown-linux-gnu/librln.a and b/libs/x86_64-unknown-linux-gnu/librln.a differ diff --git a/libs/x86_64-unknown-linux-musl/librln.a b/libs/x86_64-unknown-linux-musl/librln.a index 165ca2a..540f268 100644 Binary files a/libs/x86_64-unknown-linux-musl/librln.a and b/libs/x86_64-unknown-linux-musl/librln.a differ diff --git a/rln/librln.h b/rln/librln.h index cf1f017..f806475 100644 --- a/rln/librln.h +++ b/rln/librln.h @@ -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, diff --git a/rln/rln.go b/rln/rln.go index a097a08..e8f9bf0 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -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 ] -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 diff --git a/rln/rln_test.go b/rln/rln_test.go index 85c6164..8afbb0b 100644 --- a/rln/rln_test.go +++ b/rln/rln_test.go @@ -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) } diff --git a/zerokit b/zerokit index a5aa4e8..b95b151 160000 --- a/zerokit +++ b/zerokit @@ -1 +1 @@ -Subproject commit a5aa4e8d4f02b2f0ff12f74ffdb0ce4fde2ec636 +Subproject commit b95b151a1c2407c897d486dbab2c480684ae2b7e