Open pranavkirtani88 opened 5 years ago
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?
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.
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?
cargo test
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());
just take the code from the tests "as is".
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
ofcourse it allow to subtract: https://github.com/KZen-networks/curv/blob/master/src/elliptic/curves/secp256_k1.rs#L732
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
looks like you are trying to subtract vectors of points instead of points. you should subtract elements of the vectors
@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 encodeencode
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 decodedecode
from trait
...
1382 | impl Decodable for path::PathBuf {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing decode
in implementation
An investigation revealed it was due to this: https://github.com/rustwasm/wasm-bindgen/issues/1488
Anyway I can proceed?
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.
Hi, how about wasm? would it be good enough? also - can you check out the work Vitaly has done on ecdsa - https://github.com/KZen-networks/multi-party-ecdsa/pull/59 , see if this helps?