Skip to content

Commit e8d53f7

Browse files
committed
fix missing rand impl on wasm; bump RustCrypto crates;
ditch rand impl in `sigma_protocol::crypto_utils` in favor of k256 bundled rand_core;
1 parent c98e70e commit e8d53f7

File tree

7 files changed

+44
-27
lines changed

7 files changed

+44
-27
lines changed

bindings/ergo-lib-wasm/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ default = ["console_error_panic_hook"]
1515

1616
[dependencies]
1717
serde = { version = "1.0", features = ["derive"]}
18-
ergo-lib = { version = "^0.13.0", path = "../../ergo-lib" }
18+
ergo-lib = { version = "^0.13.0", path = "../../ergo-lib"}
1919
serde_json = "1.0"
2020
js-sys = "0.3"
2121
syn = "=1.0.65" # workaround for https://github.com/rustwasm/wasm-bindgen/issues/2508
2222

23-
# used in elliptic-curve(in ergo-lib), compiled here with WASM support
24-
getrandom = {version = "0.1", features = ["wasm-bindgen"]}
2523
# The `console_error_panic_hook` crate provides better debugging of panics by
2624
# logging them with `console.error`. This is great for development, but requires
2725
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
@@ -42,7 +40,6 @@ features = ["serde-serialize"]
4240
[dev-dependencies]
4341
wasm-bindgen-test = "0.3.22"
4442
ergotree-ir = { version = "^0.13.0", path = "../../ergotree-ir", features = ["arbitrary"] }
45-
ergotree-interpreter = { version = "^0.13.0", path = "../../ergotree-interpreter", features = ["arbitrary"] }
4643
ergo-lib = { version = "^0.13.0", path = "../../ergo-lib", features = ["arbitrary"] }
4744

4845
[dev-dependencies.proptest]

ergo-lib/Cargo.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2525
serde_json = { version = "1.0", optional = true }
2626
thiserror = "1"
2727
derive_more = "0.99"
28-
proptest = {version = "1.0.0", optional = true }
2928
proptest-derive = {version = "0.3.0", optional = true }
3029

30+
[dependencies.proptest]
31+
# wasm support, via https://altsysrq.github.io/proptest-book/proptest/wasm.html
32+
version = "1.0.0"
33+
# The default feature set includes things like process forking which are not
34+
# supported in Web Assembly.
35+
default-features = false
36+
# Enable using the `std` crate.
37+
features = ["std"]
38+
optional = true
39+
3140
[dependencies.serde_with]
3241
version = "1.9.1"
3342
features = [ "json" ]
@@ -41,17 +50,9 @@ arbitrary = ["proptest", "proptest-derive"]
4150

4251
[dev-dependencies]
4352
wasm-bindgen-test = "0.3.10"
44-
rand = "0.7.3"
53+
rand = "0.8.3"
4554
ergotree-ir = { version = "^0.13.0", path = "../ergotree-ir", features = ["arbitrary"] }
4655
ergotree-interpreter = { version = "^0.13.0", path = "../ergotree-interpreter", features = ["arbitrary"] }
4756
sigma-test-util = { version = "0.2.0", path = "../sigma-test-util" }
4857
pretty_assertions = "0.7.2"
4958

50-
[dev-dependencies.proptest]
51-
# wasm support, via https://altsysrq.github.io/proptest-book/proptest/wasm.html
52-
version = "1.0.0"
53-
# The default feature set includes things like process forking which are not
54-
# supported in Web Assembly.
55-
default-features = false
56-
# Enable using the `std` crate.
57-
features = ["std"]

ergotree-interpreter/Cargo.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@ crate-type = ["cdylib", "rlib"]
1717
sigma-util = { version = "^0.2.0", path = "../sigma-util" }
1818
ergotree-ir = { version = "^0.13.0", path = "../ergotree-ir" }
1919
indexmap = "1.3.2"
20-
k256 = { version = "0.7.2", features = ["zeroize", "arithmetic", "ecdsa"] }
21-
elliptic-curve = {version = "0.9.6", features = [ "zeroize"]}
20+
k256 = { version = "0.9.5", features = ["zeroize", "arithmetic", "ecdsa"] }
21+
elliptic-curve = {version = "0.10.5", features = ["zeroize"]}
2222
blake2 = "0.9"
23-
rand = "0.7"
2423
lazy_static = "1.4"
2524
thiserror = "1"
2625
derive_more = "0.99"
2726
num-traits = "0.2.14"
28-
proptest = {version = "1.0.0", optional = true }
2927
proptest-derive = {version = "0.3.0", optional = true }
3028
base16 = "0.2.1"
3129
num-bigint = "0.4.0"
3230

31+
[dependencies.proptest]
32+
# wasm support, via https://altsysrq.github.io/proptest-book/proptest/wasm.html
33+
version = "1.0.0"
34+
# The default feature set includes things like process forking which are not
35+
# supported in Web Assembly.
36+
default-features = false
37+
# Enable using the `std` crate.
38+
features = ["std"]
39+
optional = true
40+
3341
[features]
3442
default = []
3543
arbitrary = ["proptest", "proptest-derive"]

ergotree-interpreter/src/sigma_protocol/crypto_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Generate cryptographically secure random bytes
22
pub fn secure_random_bytes(how_many: usize) -> Vec<u8> {
3-
use rand::rngs::OsRng;
4-
use rand::RngCore;
3+
use k256::elliptic_curve::rand_core::OsRng;
4+
use k256::elliptic_curve::rand_core::RngCore;
55
let mut bytes: Vec<u8> = vec![0; how_many];
66
OsRng.fill_bytes(&mut bytes);
77
bytes

ergotree-interpreter/src/sigma_protocol/private_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Private input types for the prover's secrets
22
use std::convert::TryInto;
33

4+
use elliptic_curve::group::ff::PrimeField;
45
use ergotree_ir::sigma_protocol::dlog_group;
56
use ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;
67

7-
use k256::elliptic_curve::ff::PrimeField;
88
use k256::Scalar;
99

1010
extern crate derive_more;

ergotree-ir/Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ crate-type = ["cdylib", "rlib"]
1616
[dependencies]
1717
sigma-ser = { version = "^0.2.0", path = "../sigma-ser" }
1818
sigma-util = { version = "^0.2.0", path = "../sigma-util" }
19-
k256 = { version = "0.7.2", features = ["zeroize", "arithmetic", "ecdsa"] }
20-
elliptic-curve = {version = "0.9.12", features = ["zeroize"]}
19+
k256 = { version = "0.9.5", features = ["zeroize", "arithmetic", "ecdsa"] }
20+
elliptic-curve = {version = "0.10.5", features = ["zeroize"]}
2121
thiserror = "1"
22-
rand = "0.7"
22+
# used in elliptic-curve(in ergo-lib), compiled here with WASM support
23+
getrandom = {version = "0.2.3", features = ["js"]}
2324
lazy_static = "1.4"
2425
derive_more = "0.99"
2526
impl-trait-for-tuples = "0.2.0"
26-
proptest = {version = "1.0.0", optional = true }
2727
proptest-derive = {version = "0.3.0", optional = true }
2828
bs58 = "0.4.0"
2929
base16 = "0.2.1"
3030
num-bigint = "0.4.0"
3131
# bounded-vec = { git = "https://github.com/ergoplatform/bounded-vec", rev="78f1c83" }
3232
bounded-vec = { version = "^0.3.0" }
3333

34+
[dependencies.proptest]
35+
# wasm support, via https://altsysrq.github.io/proptest-book/proptest/wasm.html
36+
version = "1.0.0"
37+
# The default feature set includes things like process forking which are not
38+
# supported in Web Assembly.
39+
default-features = false
40+
# Enable using the `std` crate.
41+
features = ["std"]
42+
optional = true
43+
3444
[features]
3545
default = []
3646
arbitrary = ["proptest", "proptest-derive"]

ergotree-ir/src/sigma_protocol/dlog_group.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use crate::serialization::SigmaSerializeResult;
2020
use crate::serialization::{
2121
sigma_byte_reader::SigmaByteRead, SigmaParsingError, SigmaSerializable,
2222
};
23-
use k256::elliptic_curve::ff::PrimeField;
23+
use elliptic_curve::group::ff::PrimeField;
24+
use elliptic_curve::group::prime::PrimeCurveAffine;
2425
use k256::elliptic_curve::sec1::ToEncodedPoint;
2526
use k256::{ProjectivePoint, PublicKey, Scalar};
2627
use num_bigint::{BigInt, Sign};
@@ -111,7 +112,7 @@ pub fn exponentiate(base: &EcPoint, exponent: &Scalar) -> EcPoint {
111112

112113
/// Creates a random scalar, a big-endian integer in the range [0, n), where n is group order
113114
pub fn random_scalar_in_group_range() -> Scalar {
114-
use rand::rngs::OsRng;
115+
use k256::elliptic_curve::rand_core::OsRng;
115116
Scalar::generate_vartime(&mut OsRng)
116117
}
117118

0 commit comments

Comments
 (0)