mirror of https://github.com/waku-org/go-rln.git
added tree funcs
This commit is contained in:
parent
5659b24134
commit
466f01b835
|
@ -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
|
Binary file not shown.
|
@ -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
|
Binary file not shown.
|
@ -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
|
Binary file not shown.
19
rln/librln.h
19
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);
|
||||
|
|
49
rln/rln.go
49
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{
|
||||
|
|
Loading…
Reference in New Issue