Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build a javascript interface #15

Open
pranavkirtani88 opened this issue Feb 19, 2019 · 13 comments
Open

build a javascript interface #15

pranavkirtani88 opened this issue Feb 19, 2019 · 13 comments
Assignees

Comments

@pranavkirtani88
Copy link

No description provided.

@omershlo
Copy link
Contributor

Hi,
how about wasm? would it be good enough?
also - can you check out the work Vitaly has done on ecdsa - ZenGo-X/multi-party-ecdsa#59 , see if this helps?

@pranavkirtani88
Copy link
Author

is the repo still active? .I am planning to use the rust library , I am new to rust but it looks like it can be converted to wasm ,any guidance on how?

@omershlo
Copy link
Contributor

very much active yes!
It is also very much possible to convert it to wasm. @vhnatyk is an expert on how to do it (have done it in other rust libraries that are using the same code base).
To start with I suggest you follow any guide on how convert from rust to wasm and let us know if you stuck on an error.

@pranavkirtani88
Copy link
Author

Are there any steps to run the rust code? I cloned the repo and installed rust.I created a sample.rs file with the code provided in readme. How to to run this file I tried rustc,cargo build,cargo run. am I missing any step?

@omershlo
Copy link
Contributor

cargo test

@pranavkirtani88
Copy link
Author

I had run cargo test and tests pass, What I wanted to know is how do I use the code provided as sample :

use curv::arithmetic::traits::{Converter, Samplable};
use curv::cryptographic_primitives::hashing::hash_sha512::HSha512;
use curv::cryptographic_primitives::hashing::traits::;
use curv::elliptic::curves::traits::
;
use curv::BigInt;
use curv::{FE, GE};
use proofs::range_proof::generate_random_point;
use proofs::range_proof::RangeProof;

    bit range
    let n = 8;
    // num of agg proofs
    let m = 4;
    let nm = n * m;
    let KZen: &[u8] = &[75, 90, 101, 110];
    let kzen_label = BigInt::from(KZen);

    let G: GE = ECPoint::generator();
    let label = BigInt::from(1);
    let hash = HSha512::create_hash(&[&label]);
    let H = generate_random_point(&Converter::to_vec(&hash));

    let g_vec = (0..nm)
        .map(|i| {
            let kzen_label_i = BigInt::from(i as u32) + &kzen_label;
            let hash_i = HSha512::create_hash(&[&kzen_label_i]);
            generate_random_point(&Converter::to_vec(&hash_i))
        }).collect::<Vec<GE>>();

    // can run in parallel to g_vec:
    let h_vec = (0..nm)
        .map(|i| {
            let kzen_label_j = BigInt::from(n as u32) + BigInt::from(i as u32) + &kzen_label;
            let hash_j = HSha512::create_hash(&[&kzen_label_j]);
            generate_random_point(&Converter::to_vec(&hash_j))
        }).collect::<Vec<GE>>();

    let range = BigInt::from(2).pow(n as u32);
    let v_vec = (0..m)
        .map(|_| ECScalar::from(&BigInt::sample_below(&range)))
        .collect::<Vec<FE>>();

    let r_vec = (0..m).map(|_| ECScalar::new_random()).collect::<Vec<FE>>();

    let ped_com_vec = (0..m)
        .map(|i| {
            let ped_com = G.clone() * &v_vec[i] + H.clone() * &r_vec[i];
            ped_com
        }).collect::<Vec<GE>>();

    let range_proof = RangeProof::prove(&g_vec, &h_vec, &G, &H, v_vec, &r_vec, n);
    let result = RangeProof::verify(&range_proof, &g_vec, &h_vec, &G, &H, &ped_com_vec, n);
    assert!(result.is_ok());

@omershlo
Copy link
Contributor

just take the code from the tests "as is".

@pranavkirtani88
Copy link
Author

We have ped com for a secret value below:
let ped_com_vec = (0..m)
.map(|i| {
let ped_com = &G * &v_vec[i] + &H * &r_vec[i];
ped_com
}).collect::<Vec>();
I want to generate another pedcom say for another value and subtract it from this one. But it appears the https://github.com/KZen-networks/curv/blob/master/src/elliptic/curves/secp256_k1.rs does not allow addition or subtraction of EC points ,any workaround?

@omershlo
Copy link
Contributor

@pranavkirtani88
Copy link
Author

I had tried that earlier,I get the following error

no method named sub_point found for type std::vec::Vec<curv::elliptic::curves::secp256_k1::Secp256k1Point> in the current scope

For the code:
//original
let ped_com_vec = (0..m)
.map(|i| {
let ped_com = &G * &v_vec[i] + &H * &r_vec[i];
ped_com
}).collect::<Vec>();
//new
let new_ped_com_vec = (0..m)
.map(|i| {
let ped_com = &G * &v_sub_vec[i] + &H * &r_vec[i];
ped_com
}).collect::<Vec>();
let newest_pc=new_ped_com_vec.clone();
//subtraction
let final_ped_com=newest_pc.sub_point(ped_com_vec);

@omershlo
Copy link
Contributor

looks like you are trying to subtract vectors of points instead of points. you should subtract elements of the vectors

@pranavkirtani88
Copy link
Author

@omershlo Thanks I will try that.

@vhnatyk when I try to build wasm i get the following error

not all trait items implemented, missing: encode
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1
|
853 | fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>;
| ---------------------------------------------------------------- encode from trait
...
1358 | impl Encodable for path::Path {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing encode in implementation

error[E0046]: not all trait items implemented, missing: decode
--> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1382:1
|
904 | fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
| ----------------------------------------------------------- decode from trait
...
1382 | impl Decodable for path::PathBuf {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing decode in implementation

An investigation revealed it was due to this:
rustwasm/wasm-bindgen#1488

Anyway I can proceed?

@vhnatyk
Copy link

vhnatyk commented Aug 24, 2019

Hi @pranavkirtani88 - yep, there two ways to proceed with crates that don't support wasm - either to replace them or to make them work with wasm 🙂 Seems rustc-serialize is deprecated (may be wasm support is among top reasons) according to this

Not sure about bulletproofs - but I implemented wasm support for emerald city in my fork. Reason PR was not submitted is that constant time safety is sort of an issue for pure rust crates and for wasm as well. It's not something severe, but definitely worth keeping in mind regarding security. The bitcoin's secp256k1 crate got wasm support btw - so that branch is stale since uses pure rust libsecp256k1 crate, that is not well maintained anymore. But from the point of wasm it's fully functional and can give valid ideas how to proceed - like replacing with serde etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants