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

[WIP] Merge our own rust-secp256k1-zkp into rust-bitcoin/rust-secp256k1-zkp #1

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "secp256k1-sys/depend/secp256k1"]
path = secp256k1-sys/depend/secp256k1
url = https://github.com/mimblewimble/secp256k1-zkp.git
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rand-std = ["rand/std"]
recovery = ["secp256k1-sys/recovery"]
lowmemory = ["secp256k1-sys/lowmemory"]
global-context = ["std", "rand-std"]
bullet-proof-sizing = []

[dependencies]
secp256k1-sys = { version = "0.4.0", default-features = false, path = "./secp256k1-sys" }
Expand All @@ -33,6 +34,7 @@ serde = { version = "1.0", default-features = false, optional = true }


[dev-dependencies]
chrono = "0.4"
rand = "0.6"
rand_core = "0.4"
serde_test = "1.0"
Expand Down
23 changes: 0 additions & 23 deletions secp256k1-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@ secp256k1-sys

This crate provides Rust definitions for the FFI structures and methods.


## Vendoring

The default build process is to build using the vendored libsecp256k1 sources in
the depend folder. These sources are prefixed with a special
rust-secp256k1-sys-specific prefix `rustsecp256k1_v1_2_3_`.

This prefix ensures that no symbol collision can happen:
- when a Rust project has two different versions of rust-secp256k1 in its
depepdency tree, or
- when rust-secp256k1 is used for building a static library in a context where
existing libsecp256k1 symbols are already linked.

To update the vendored sources, use the `vendor-libsecp.sh` script:

```
$ ./vendor-libsecp.sh depend <version-code> <rev>
```

- Where `<version-code>` is the secp256k1-sys version number underscored: `0_1_2`.
- Where `<rev>` is the git revision of libsecp256k1 to checkout.


## Linking to external symbols

If you want to compile this library without using the bundled symbols (which may
Expand Down
40 changes: 40 additions & 0 deletions secp256k1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,37 @@ use std::env;

fn main() {
// Actual build
if cfg!(feature = "external-symbols") {
println!("cargo:rustc-link-lib=static=secp256k1-zkp");
return;
}

// Check whether we can use 64-bit compilation
let use_64bit_compilation = if env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "64" {
let check = cc::Build::new().file("depend/check_uint128_t.c")
.cargo_metadata(false)
.try_compile("check_uint128_t")
.is_ok();
if !check {
println!("cargo:warning=Compiling in 32-bit mode on a 64-bit architecture due to lack of uint128_t support.");
}
check
} else {
false
};

let mut base_config = cc::Build::new();
base_config.include("depend/secp256k1/")
.include("depend/secp256k1/include")
.include("depend/secp256k1/src")
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
.define("SECP256K1_BUILD", Some("1"))
.define("ENABLE_MODULE_ECDH", Some("1"))
.define("ENABLE_MODULE_GENERATOR", Some("1"))
.define("ENABLE_MODULE_RECOVERY", Some("1"))
.define("ENABLE_MODULE_RANGEPROOF", Some("1"))
.define("ENABLE_MODULE_BULLETPROOF", Some("1"))
.define("ENABLE_MODULE_AGGSIG", Some("1"))
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
.define("ECMULT_GEN_PREC_BITS", Some("4"))
Expand All @@ -47,6 +71,13 @@ fn main() {
} else {
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
}

if let Ok(target_endian) = env::var("CARGO_CFG_TARGET_ENDIAN") {
if target_endian == "big" {
base_config.define("WORDS_BIGENDIAN", Some("1"));
}
}

base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
#[cfg(feature = "recovery")]
base_config.define("ENABLE_MODULE_RECOVERY", Some("1"));
Expand All @@ -56,6 +87,15 @@ fn main() {
base_config.include("wasm-sysroot");
}

if use_64bit_compilation {
base_config.define("USE_FIELD_5X52", Some("1"))
.define("USE_SCALAR_4X64", Some("1"))
.define("HAVE___INT128", Some("1"));
} else {
base_config.define("USE_FIELD_10X26", Some("1"))
.define("USE_SCALAR_8X32", Some("1"));
}

// secp256k1
base_config.file("depend/secp256k1/contrib/lax_der_parsing.c")
.file("depend/secp256k1/src/secp256k1.c")
Expand Down
26 changes: 0 additions & 26 deletions secp256k1-sys/depend/scratch_impl.h.patch

This file was deleted.

1 change: 1 addition & 0 deletions secp256k1-sys/depend/secp256k1
Submodule secp256k1 added at 8d1f5b
2 changes: 0 additions & 2 deletions secp256k1-sys/depend/secp256k1-HEAD-revision.txt

This file was deleted.

43 changes: 0 additions & 43 deletions secp256k1-sys/depend/secp256k1.c.patch

This file was deleted.

22 changes: 0 additions & 22 deletions secp256k1-sys/depend/secp256k1.h.patch

This file was deleted.

53 changes: 0 additions & 53 deletions secp256k1-sys/depend/secp256k1/.gitignore

This file was deleted.

109 changes: 0 additions & 109 deletions secp256k1-sys/depend/secp256k1/.travis.yml

This file was deleted.

Loading