diff --git a/libs/aarch64-apple-darwin/librln.d b/libs/aarch64-apple-darwin/librln.d deleted file mode 100644 index 863f40b..0000000 --- a/libs/aarch64-apple-darwin/librln.d +++ /dev/null @@ -1 +0,0 @@ -/Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/target/aarch64-apple-darwin/release/librln.dylib: /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/mod.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/polynomial.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/rln.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/ffi.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/lib.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/merkle.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/public.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/utils.rs diff --git a/libs/aarch64-apple-darwin/librln.rlib b/libs/aarch64-apple-darwin/librln.rlib deleted file mode 100644 index 365a45b..0000000 Binary files a/libs/aarch64-apple-darwin/librln.rlib and /dev/null differ diff --git a/libs/x86_64-apple-darwin/librln.d b/libs/x86_64-apple-darwin/librln.d deleted file mode 100644 index eca7915..0000000 --- a/libs/x86_64-apple-darwin/librln.d +++ /dev/null @@ -1 +0,0 @@ -/Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/target/x86_64-apple-darwin/release/librln.dylib: /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/mod.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/polynomial.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/rln.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/ffi.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/lib.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/merkle.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/public.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/utils.rs diff --git a/libs/x86_64-apple-darwin/librln.rlib b/libs/x86_64-apple-darwin/librln.rlib deleted file mode 100644 index fd0c68a..0000000 Binary files a/libs/x86_64-apple-darwin/librln.rlib and /dev/null differ diff --git a/libs/x86_64-unknown-linux-musl/librln.d b/libs/x86_64-unknown-linux-musl/librln.d deleted file mode 100644 index 5baae82..0000000 --- a/libs/x86_64-unknown-linux-musl/librln.d +++ /dev/null @@ -1 +0,0 @@ -/Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/target/x86_64-unknown-linux-musl/release/librln.rlib: /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/mod.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/polynomial.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/rln.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/ffi.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/lib.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/merkle.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/public.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/utils.rs diff --git a/libs/x86_64-unknown-linux-musl/librln.rlib b/libs/x86_64-unknown-linux-musl/librln.rlib deleted file mode 100644 index 3878b0b..0000000 Binary files a/libs/x86_64-unknown-linux-musl/librln.rlib and /dev/null differ diff --git a/rln/librln.h b/rln/librln.h index 8cca80a..3d38d57 100644 --- a/rln/librln.h +++ b/rln/librln.h @@ -14,22 +14,31 @@ typedef struct Buffer { uintptr_t len; } Buffer; +typedef struct Auth { + const struct Buffer *secret_buffer; + uintptr_t index; +} Auth; + bool new_circuit_from_params(uintptr_t merkle_depth, const struct Buffer *parameters_buffer, struct RLN_Bn256 **ctx); +bool get_root(const struct RLN_Bn256 *ctx, struct Buffer *output_buffer); + +bool update_next_member(struct RLN_Bn256 *ctx, const struct Buffer *input_buffer); + +bool delete_member(struct RLN_Bn256 *ctx, uintptr_t index); + bool generate_proof(const struct RLN_Bn256 *ctx, const struct Buffer *input_buffer, + const struct Auth *auth, struct Buffer *output_buffer); -bool verify(const struct RLN_Bn256 *ctx, - const struct Buffer *proof_buffer, - const struct Buffer *public_inputs_buffer, - uint32_t *result_ptr); +bool verify(const struct RLN_Bn256 *ctx, struct Buffer *proof_buffer, uint32_t *result_ptr); bool hash(const struct RLN_Bn256 *ctx, const struct Buffer *inputs_buffer, - const uintptr_t *input_len, + uintptr_t input_len, struct Buffer *output_buffer); bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *keypair_buffer); diff --git a/rln/rln.go b/rln/rln.go index b2a6712..dae79f5 100644 --- a/rln/rln.go +++ b/rln/rln.go @@ -25,6 +25,8 @@ type KeyPair struct { Commitment [32]byte } +// @TODO THINK ABOUT AUTH OBJECT + // New returns a new RLN generated from the passed depth and parameters. func New(depth int, parameters []byte) (*RLN, error) { r := &RLN{} @@ -69,21 +71,27 @@ func (r *RLN) Hash(input []byte) ([]byte, error) { *in = toBuffer(input) out := (*C.Buffer)(C.malloc(C.size_t(size))) - if !bool(C.hash(r.ptr, in, &in.len, out)) { + if !bool(C.hash(r.ptr, in, in.len, out)) { return nil, errors.New("failed to hash") } return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)), nil } -// GenerateProof generates a proof for the RLN. -func (r *RLN) GenerateProof(input []byte) ([]byte, error) { +// GenerateProof generates a proof for the RLN given a KeyPair and the index in a merkle tree. +func (r *RLN) GenerateProof(input []byte, key *KeyPair, index uint) ([]byte, error) { inputBuf := toBuffer(input) var output []byte out := toBuffer(output) - if !bool(C.generate_proof(r.ptr, &inputBuf, &out)) { + keybuf := toBuffer(key.Key[:]) + auth := &C.Auth{ + secret_buffer: &keybuf, + index: C.ulong(index), + } + + if !bool(C.generate_proof(r.ptr, &inputBuf, auth, &out)) { return nil, errors.New("failed to generate proof") } @@ -91,13 +99,12 @@ func (r *RLN) GenerateProof(input []byte) ([]byte, error) { } // Verify verifies a proof generated for the RLN. -func (r *RLN) Verify(proof []byte, publicInputs []byte) bool { +func (r *RLN) Verify(proof []byte) bool { proofBuf := toBuffer(proof) - inputs := toBuffer(publicInputs) result := uint32(0) res := C.uint(result) - if !bool(C.verify(r.ptr, &proofBuf, &inputs, &res)) { + if !bool(C.verify(r.ptr, &proofBuf, &res)) { // @TODO THINK ABOUT ERROR? return false } @@ -105,6 +112,34 @@ func (r *RLN) Verify(proof []byte, publicInputs []byte) bool { return uint32(res) == 0 } +func (r *RLN) UpdateNextMember(input []byte) error { + buf := toBuffer(input) + if !bool(C.update_next_member(r.ptr, &buf)) { + return errors.New("failed to update next member") + } + + return nil +} + +func (r *RLN) DeleteMember(index int) error { + if !bool(C.delete_member(r.ptr, C.ulong(index))) { + return errors.New("failed to delete member") + } + + return nil +} + +func (r *RLN) GetRoot() ([]byte, error) { + var output []byte + out := toBuffer(output) + + if !bool(C.get_root(r.ptr, &out)) { + return nil, errors.New("failed to get root") + } + + return C.GoBytes(unsafe.Pointer(out.ptr), C.int(out.len)), nil +} + func toBuffer(data []byte) C.Buffer { dataPtr, dataLen := sliceToPtr(data) return C.Buffer{