Skip to content

Commit 0a26c15

Browse files
remove extra unrequired things
1 parent 39391f7 commit 0a26c15

File tree

2 files changed

+1
-281
lines changed

2 files changed

+1
-281
lines changed

waku/waku_rln_relay/rln/rln_interface.nim

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ type ffi_RLNProof* = object
4444
share_y*: CFr # Shamir secret share y
4545
nullifier*: CFr # Message nullifier
4646

47-
## Merkle proof structure
48-
type ffi_MerkleProof* = object
49-
path_elements*: Vec[CFr]
50-
indices*: Vec[uint8]
51-
5247
######################################################################
5348
## RLN Zerokit FFI2 APIs
5449
######################################################################
@@ -61,13 +56,6 @@ proc ffi_key_gen*(output: ptr ffi_IdentityCredential): bool {.importc: "ffi_key_
6156
## Output is written directly to the ffi_IdentityCredential struct
6257
## Returns true on success, false on failure
6358

64-
proc ffi_seeded_key_gen*(
65-
seed: ptr Vec[uint8], output: ptr ffi_IdentityCredential
66-
): bool {.importc: "ffi_seeded_key_gen".}
67-
68-
## Generates identity using a seed (hashed with Keccak256, then used with ChaCha20)
69-
## Returns true on success, false on failure
70-
7159
#-------------------------------- Circuit/Context Initialization -----------------------------------------
7260

7361
proc ffi_new*(config_path: cstring, ctx: ptr (ptr RLN)): bool {.importc: "ffi_new".}
@@ -76,16 +64,6 @@ proc ffi_new*(config_path: cstring, ctx: ptr (ptr RLN)): bool {.importc: "ffi_ne
7664
## ctx: pointer to store the created RLN instance
7765
## Returns true on success, false on failure
7866

79-
proc ffi_new_with_params*(
80-
zkey: ptr Vec[uint8], graph: ptr Vec[uint8], ctx: ptr (ptr RLN)
81-
): bool {.importc: "ffi_new_with_params".}
82-
83-
## Creates an RLN instance from raw circuit parameters
84-
## zkey: proving key data
85-
## graph: circuit graph data
86-
## ctx: pointer to store the created RLN instance
87-
## Returns true on success, false on failure
88-
8967
#-------------------------------- Proof Generation -----------------------------------------
9068

9169
proc ffi_generate_rln_proof*(
@@ -101,18 +79,6 @@ proc ffi_generate_rln_proof*(
10179
## output: structured proof output
10280
## Returns true on success, false on failure
10381

104-
proc ffi_generate_rln_proof_stateless*(
105-
zkey: ptr Vec[uint8],
106-
graph: ptr Vec[uint8],
107-
witness: ptr ffi_RLNWitnessInput,
108-
signal: ptr Vec[uint8],
109-
output: ptr ffi_RLNProof,
110-
): bool {.importc: "ffi_generate_rln_proof_stateless".}
111-
112-
## Generates an RLN proof without maintaining context state
113-
## Useful for one-off proof generation
114-
## Returns true on success, false on failure
115-
11682
#-------------------------------- Proof Verification -----------------------------------------
11783

11884
proc ffi_verify_rln_proof*(
@@ -131,55 +97,6 @@ proc ffi_verify_rln_proof*(
13197
## Returns true if verification completed, false on error
13298
## Check is_valid for actual proof validity
13399

134-
#-------------------------------- Merkle Tree Operations -----------------------------------------
135-
136-
proc ffi_set_leaf*(
137-
ctx: ptr RLN, index: csize_t, leaf: ptr CFr
138-
): bool {.importc: "ffi_set_leaf".}
139-
140-
## Sets a leaf at the specified index in the Merkle tree
141-
## Returns true on success, false on failure
142-
143-
proc ffi_get_leaf*(
144-
ctx: ptr RLN, index: csize_t, output: ptr CFr
145-
): bool {.importc: "ffi_get_leaf".}
146-
147-
## Gets the leaf at the specified index from the Merkle tree
148-
## Returns true on success, false on failure
149-
150-
proc ffi_get_root*(ctx: ptr RLN, output: ptr CFr): bool {.importc: "ffi_get_root".}
151-
## Gets the current Merkle tree root
152-
## Returns true on success, false on failure
153-
154-
proc ffi_get_proof*(
155-
ctx: ptr RLN, index: csize_t, output: ptr ffi_MerkleProof
156-
): bool {.importc: "ffi_get_proof".}
157-
158-
## Gets the Merkle proof for the leaf at the specified index
159-
## Returns true on success, false on failure
160-
161-
proc ffi_verify_merkle_proof*(
162-
ctx: ptr RLN, leaf: ptr CFr, proof: ptr ffi_MerkleProof, is_valid: ptr bool
163-
): bool {.importc: "ffi_verify_proof".}
164-
165-
## Verifies a Merkle proof
166-
## is_valid: output parameter - true if proof is valid
167-
## Returns true if verification completed, false on error
168-
169-
proc ffi_set_leaves*(
170-
ctx: ptr RLN, start_index: csize_t, leaves: ptr Vec[CFr]
171-
): bool {.importc: "ffi_set_leaves".}
172-
173-
## Sets multiple leaves starting at start_index
174-
## Returns true on success, false on failure
175-
176-
proc ffi_set_leaves_from*(
177-
ctx: ptr RLN, start_index: csize_t, leaves: ptr Vec[CFr]
178-
): bool {.importc: "ffi_set_leaves_from".}
179-
180-
## Sets leaves from a specific index (alternative batch operation)
181-
## Returns true on success, false on failure
182-
183100
#-------------------------------- Hashing Functions -----------------------------------------
184101

185102
proc ffi_hash_to_field_le*(
@@ -190,13 +107,6 @@ proc ffi_hash_to_field_le*(
190107
## Used to map signals to field elements
191108
## Returns true on success, false on failure
192109

193-
proc ffi_hash_to_field_be*(
194-
input: ptr Vec[uint8], output: ptr CFr
195-
): bool {.importc: "ffi_hash_to_field_be".}
196-
197-
## Hashes arbitrary bytes to a field element (big-endian)
198-
## Returns true on success, false on failure
199-
200110
proc ffi_poseidon_hash_pair*(
201111
a: ptr CFr, b: ptr CFr
202112
): ptr CFr {.importc: "ffi_poseidon_hash_pair".}
@@ -212,54 +122,6 @@ proc cfr_to_bytes_le*(cfr: ptr CFr): Vec[uint8] {.importc: "cfr_to_bytes_le".}
212122
## Serializes a field element to bytes (little-endian)
213123
## Returns Vec[uint8] containing the serialized bytes
214124

215-
proc cfr_to_bytes_be*(cfr: ptr CFr): Vec[uint8] {.importc: "cfr_to_bytes_be".}
216-
217-
## Serializes a field element to bytes (big-endian)
218-
## Returns Vec[uint8] containing the serialized bytes
219-
220-
proc bytes_le_to_cfr*(bytes: ptr Vec[uint8]): ptr CFr {.importc: "bytes_le_to_cfr".}
221-
222-
## Deserializes bytes (little-endian) to a field element
223-
## Returns pointer to boxed CFr (must be freed with cfr_free)
224-
225-
proc bytes_be_to_cfr*(bytes: ptr Vec[uint8]): ptr CFr {.importc: "bytes_be_to_cfr".}
226-
227-
## Deserializes bytes (big-endian) to a field element
228-
## Returns pointer to boxed CFr (must be freed with cfr_free)
229-
230-
proc vec_cfr_to_bytes_le*(
231-
vec: ptr Vec[CFr]
232-
): Vec[uint8] {.importc: "vec_cfr_to_bytes_le".}
233-
234-
## Serializes a vector of field elements to bytes (little-endian)
235-
## Returns Vec[uint8] containing the serialized bytes
236-
237-
proc vec_cfr_to_bytes_be*(
238-
vec: ptr Vec[CFr]
239-
): Vec[uint8] {.importc: "vec_cfr_to_bytes_be".}
240-
241-
## Serializes a vector of field elements to bytes (big-endian)
242-
## Returns Vec[uint8] containing the serialized bytes
243-
244-
## CResult type for functions that can return errors
245-
type CResult*[T, E] = object
246-
ok*: ptr T
247-
err*: ptr E
248-
249-
proc bytes_le_to_vec_cfr*(
250-
bytes: ptr Vec[uint8]
251-
): CResult[ptr Vec[CFr], cstring] {.importc: "bytes_le_to_vec_cfr".}
252-
253-
## Deserializes bytes (little-endian) to a vector of field elements
254-
## Returns CResult with either ok (ptr Vec[CFr]) or err (cstring)
255-
256-
proc bytes_be_to_vec_cfr*(
257-
bytes: ptr Vec[uint8]
258-
): CResult[ptr Vec[CFr], cstring] {.importc: "bytes_be_to_vec_cfr".}
259-
260-
## Deserializes bytes (big-endian) to a vector of field elements
261-
## Returns CResult with either ok (ptr Vec[CFr]) or err (cstring)
262-
263125
proc uint_to_cfr*(value: uint32): ptr CFr {.importc: "uint_to_cfr".}
264126

265127
## Creates a field element from an unsigned integer
@@ -270,17 +132,10 @@ proc cfr_zero*(): ptr CFr {.importc: "cfr_zero".}
270132
## Creates a zero field element
271133
## Returns pointer to boxed CFr (must be freed with cfr_free)
272134

273-
proc cfr_one*(): ptr CFr {.importc: "cfr_one".}
274-
## Creates a one field element
275-
## Returns pointer to boxed CFr (must be freed with cfr_free)
276-
277135
proc cfr_free*(cfr: ptr CFr) {.importc: "cfr_free".}
278136
## Frees a boxed CFr
279137
## Must be called for all CFr pointers returned by the API
280138

281-
proc cfr_debug*(cfr: ptr CFr): cstring {.importc: "cfr_debug".}
282-
## Returns debug string representation of CFr
283-
284139
#-------------------------------- Helper Procedures -----------------------------------------
285140

286141
proc newVec*[T](data: seq[T]): Vec[T] =

waku/waku_rln_relay/rln/wrappers.nim

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -254,139 +254,4 @@ proc extractMetadata*(proof: RateLimitProof): RlnRelayResult[ProofMetadata] =
254254
shareY: proof.shareY,
255255
externalNullifier: externalNullifier,
256256
)
257-
)
258-
259-
######################################################################
260-
## Example: Proof Generation (NEW - shows how to use FFI2)
261-
######################################################################
262-
263-
proc generateProof*(
264-
ctx: ptr RLN,
265-
identitySecret: seq[byte],
266-
userMessageLimit: uint64,
267-
messageId: uint64,
268-
merkleProof: seq[seq[byte]], # path elements
269-
merkleIndices: seq[byte],
270-
externalNullifier: seq[byte],
271-
signal: seq[byte],
272-
): RlnRelayResult[ffi_RLNProof] =
273-
## Example of proof generation using FFI2
274-
## This shows the new structured approach
275-
276-
# Convert identity secret to CFr
277-
var identitySecretVec = newVec(identitySecret)
278-
var identitySecretCFr: CFr
279-
if not ffi_hash_to_field_le(addr identitySecretVec, addr identitySecretCFr):
280-
freeVec(identitySecretVec)
281-
return err("failed to convert identity secret")
282-
freeVec(identitySecretVec)
283-
284-
# Convert user message limit to CFr using new API
285-
let userMessageLimitCFrPtr = uint_to_cfr(userMessageLimit.uint32)
286-
if userMessageLimitCFrPtr == nil:
287-
return err("failed to convert user message limit")
288-
let userMessageLimitCFr = userMessageLimitCFrPtr[]
289-
cfr_free(userMessageLimitCFrPtr)
290-
291-
# Convert message ID to CFr using new API
292-
let messageIdCFrPtr = uint_to_cfr(messageId.uint32)
293-
if messageIdCFrPtr == nil:
294-
return err("failed to convert message ID")
295-
let messageIdCFr = messageIdCFrPtr[]
296-
cfr_free(messageIdCFrPtr)
297-
298-
# Convert merkle proof path elements to CFr
299-
var pathElementsCFr: seq[CFr]
300-
for element in merkleProof:
301-
var elementVec = newVec(element)
302-
var cfr: CFr
303-
if not ffi_hash_to_field_le(addr elementVec, addr cfr):
304-
freeVec(elementVec)
305-
return err("failed to convert path element")
306-
pathElementsCFr.add(cfr)
307-
freeVec(elementVec)
308-
309-
# Convert external nullifier to CFr
310-
var externalNullifierVec = newVec(externalNullifier)
311-
var externalNullifierCFr: CFr
312-
if not ffi_hash_to_field_le(addr externalNullifierVec, addr externalNullifierCFr):
313-
freeVec(externalNullifierVec)
314-
return err("failed to convert external nullifier")
315-
freeVec(externalNullifierVec)
316-
317-
# Compute x (Shamir share x-coordinate) - simplified for example
318-
let xCFrPtr = cfr_zero()
319-
if xCFrPtr == nil:
320-
return err("failed to create x coordinate")
321-
let xCFr = xCFrPtr[]
322-
cfr_free(xCFrPtr)
323-
324-
# Build witness input struct
325-
var witness = ffi_RLNWitnessInput(
326-
identity_secret: identitySecretCFr,
327-
user_message_limit: userMessageLimitCFr,
328-
message_id: messageIdCFr,
329-
path_elements: newVec(pathElementsCFr),
330-
identity_path_index: newVec(merkleIndices),
331-
x: xCFr,
332-
external_nullifier: externalNullifierCFr,
333-
)
334-
335-
# Prepare signal
336-
var signalVec = newVec(signal)
337-
338-
# Generate proof
339-
var proof: ffi_RLNProof
340-
let success = ffi_generate_rln_proof(ctx, addr witness, addr signalVec, addr proof)
341-
342-
# Clean up
343-
freeVec(witness.path_elements)
344-
freeVec(witness.identity_path_index)
345-
freeVec(signalVec)
346-
347-
if not success:
348-
return err("proof generation failed")
349-
350-
return ok(proof)
351-
352-
######################################################################
353-
## Example: Proof Verification (NEW - shows how to use FFI2)
354-
######################################################################
355-
356-
proc verifyProof*(
357-
ctx: ptr RLN,
358-
proof: ffi_RLNProof,
359-
signal: seq[byte],
360-
roots: seq[seq[byte]] = @[] # Optional multiple roots
361-
,
362-
): RlnRelayResult[bool] =
363-
## Example of proof verification using FFI2
364-
365-
var signalVec = newVec(signal)
366-
367-
# Convert roots to CFr if provided
368-
var rootsCFr: seq[CFr]
369-
for root in roots:
370-
var rootVec = newVec(root)
371-
var cfr: CFr
372-
if not ffi_hash_to_field_le(addr rootVec, addr cfr):
373-
freeVec(rootVec)
374-
freeVec(signalVec)
375-
return err("failed to convert root")
376-
rootsCFr.add(cfr)
377-
freeVec(rootVec)
378-
379-
var rootsVec = newVec(rootsCFr)
380-
var isValid: bool
381-
382-
let success = ffi_verify_rln_proof(
383-
ctx, unsafeAddr proof, addr signalVec, addr rootsVec, addr isValid
384-
)
385-
386-
freeVec(signalVec)
387-
freeVec(rootsVec)
388-
389-
if not success:
390-
return err("proof verification call failed")
391-
392-
return ok(isValid)
257+
)

0 commit comments

Comments
 (0)