mirror of
https://github.com/logos-messaging/go-zerokit-rln.git
synced 2026-01-02 13:13:11 +00:00
feat: verify with roots
This commit is contained in:
parent
f1211c1b07
commit
310a9442c4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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,
|
||||
|
||||
29
rln/rln.go
29
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<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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
2
zerokit
2
zerokit
@ -1 +1 @@
|
||||
Subproject commit a5aa4e8d4f02b2f0ff12f74ffdb0ce4fde2ec636
|
||||
Subproject commit b95b151a1c2407c897d486dbab2c480684ae2b7e
|
||||
Loading…
x
Reference in New Issue
Block a user