From 7dfa3effc8c3c1de35335e93640b5b920071df83 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 8 Mar 2021 16:37:18 +0300 Subject: [PATCH 01/13] Use CARGO_CFG_TARGET_ARCH instead TARGET in build.rs Backport of https://github.com/rust-bitcoin/rust-secp256k1/pull/284 --- secp256k1-zkp-sys/build.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/secp256k1-zkp-sys/build.rs b/secp256k1-zkp-sys/build.rs index 811023f9..e0fc7082 100644 --- a/secp256k1-zkp-sys/build.rs +++ b/secp256k1-zkp-sys/build.rs @@ -63,11 +63,9 @@ fn main() { } } - match &env::var("TARGET").unwrap() as &str { - "wasm32-unknown-unknown" | "wasm32-wasi" => { - base_config.include("wasm-sysroot"); - } - _ => {} + // Header files. WASM only. + if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "wasm32" { + base_config.include("wasm-sysroot"); } // secp256k1 From fe804871d289444e3bc6f39f14b4e14715d46642 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Sat, 19 Mar 2022 10:22:28 +1100 Subject: [PATCH 02/13] Re-name nightly CI job to Nightly In line with the `Tests` job and for the fact that this job does stuff with the nightly toolchain other than bench. Re-name nightly CI job from `bench_nightly`to `Nightly`. Backport of a8a679ed7dbfa4871270de779aee78b3cdaeebd6: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (2/9) --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ff7f5025..2df5b338 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,7 +3,7 @@ on: [push, pull_request] name: Continuous integration jobs: - bench_nightly: + Nightly: name: Nightly - ASan + Bench runs-on: ubuntu-latest strategy: From cd5225b960e2a29622fb082ccb7412a08135bb11 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Sat, 19 Mar 2022 10:24:00 +1100 Subject: [PATCH 03/13] Remove unnecessary matrix We use a matrix with a single element, this is unnecessary. Backport of 96685c571da4f3c64d178e0f0d3a02ce99de9136: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (3/9) --- .github/workflows/rust.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2df5b338..39d92b12 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,10 +6,6 @@ jobs: Nightly: name: Nightly - ASan + Bench runs-on: ubuntu-latest - strategy: - matrix: - rust: - - nightly steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -17,7 +13,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: nightly override: true components: rust-src - name: Running address sanitizer From 77ea0661233d7327806402f0f66636b845ba059f Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Sat, 19 Mar 2022 10:24:57 +1100 Subject: [PATCH 04/13] Install clang to run adress sanitizer The address sanitizer job is silently failing at the moment because we do not install clang. Install clang so the address sanitizer job can run. Do not fix the silent failure, that will be done later on. Backport of f7bc7d3728326e6de0d2462dfba9705b93a1f55e: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (4/9) --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 39d92b12..b0e02dfb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,6 +9,8 @@ jobs: steps: - name: Checkout Crate uses: actions/checkout@v2 + - name: Install clang for ASan + run: sudo apt-get install -y clang - name: Checkout Toolchain uses: actions-rs/toolchain@v1 with: From 7085fb9ed332f7a297a88088294026aa3303e267 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Sat, 19 Mar 2022 10:27:48 +1100 Subject: [PATCH 05/13] Do docs build in Nightly job We have a separate CI job for things that require a nightly toolchain. Building the docs requires a nightly toolchain (because of `--cfg docsrc` flag). It makes more sense to run the docs build in the `Nightly` job instead of hidden in the `Tests` job. Do the docs build in the `Nightly` job instead of in the `Tests` job. Backport of 946ac3b51ebb8191b051c8d80bd27bee1656993e: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (5/9) --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b0e02dfb..70bdea94 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -4,7 +4,7 @@ name: Continuous integration jobs: Nightly: - name: Nightly - ASan + Bench + name: Nightly - ASan + Bench + Docs runs-on: ubuntu-latest steps: - name: Checkout Crate @@ -26,6 +26,10 @@ jobs: env: DO_BENCH: true run: ./contrib/test.sh + - name: Building docs + env: + DO_DOCS: true + run: ./contrib/test.sh # wasm: # name: Stable - Docs / WebAssembly Build From 47e2268fa0b468a0b48c92a27426904911705e14 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 8 Jun 2023 02:02:37 +0000 Subject: [PATCH 06/13] Run WASM for multiple toolchains WASM is supported by Rust 1.30. We can therefore run the WASM tests on any all the toolchains except MSRV (1.29.0). This has benefit of catching nightly/beta issues before they get to stable. Done as a separate CI job since it is conceptually different to the `Tests` job. Run WASM for nightly, beta, and stable toolchains. Backport of 58db1b67536794b24cdc0bf8149460509a247b31: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (6/9) --- .github/workflows/rust.yml | 60 +++++++++++++++----------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 70bdea94..cf56a672 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,43 +31,6 @@ jobs: DO_DOCS: true run: ./contrib/test.sh - # wasm: - # name: Stable - Docs / WebAssembly Build - # strategy: - # matrix: - # target: [ x86_64-unknown-linux-gnu, x86_64-apple-darwin ] - # include: - # - target: x86_64-unknown-linux-gnu - # os: ubuntu-latest - # cc: clang-12 - # ar: ar - # - target: x86_64-apple-darwin - # os: macos-latest - # cc: /usr/local/opt/llvm/bin/clang - # ar: /usr/local/opt/llvm/bin/llvm-ar - # runs-on: ${{ matrix.os }} - # steps: - # - name: Checkout Crate - # uses: actions/checkout@v2 - # - name: Checkout Toolchain - # uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - # - name: Building docs - # env: - # DO_DOCS: true - # run: ./contrib/test.sh - # - name: Install wasm-pack - # run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - # - name: Running WASM build - # env: - # DO_WASM: true - # CC: ${{ matrix.cc }} - # AR: ${{ matrix.ar }} - # run: ./contrib/test.sh - Tests: name: Tests strategy: @@ -100,6 +63,29 @@ jobs: DO_FEATURE_MATRIX: true run: ./contrib/test.sh + WASM: + name: WASM + runs-on: ubuntu-latest + strategy: + matrix: + rust: [stable, beta, nightly] # No 1.29 because WASM requires Rust 1.30 + steps: + - name: Checkout Crate + uses: actions/checkout@v2 + - name: Install clang + run: sudo apt-get install -y clang-9 + - name: Checkout Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + components: rust-src + - name: Running WASM tests + env: + DO_WASM: true + run: ./contrib/test.sh + ReleaseTests: name: Release tests with global context enabled strategy: From 00c6cc128c75530412fae2a93549e790ecc8cbc7 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Thu, 17 Mar 2022 10:30:36 +1100 Subject: [PATCH 07/13] test.sh: explicitly return 0 As per UNIX convention a Bash script should exit with status code 0 if it completes successfully. Backport of 7bec31c3a6eb43068f0b28db5f351b079751b2e2: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (7/9) --- contrib/test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 6ccb6fd9..ed912872 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -79,3 +79,5 @@ then cargo fmt --all -- --check ) fi + +exit 0 From b92f6f056bdbfabdc61b89df302f45a6fc0aaf2e Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 22 Mar 2022 10:12:30 +1100 Subject: [PATCH 08/13] Run correct clang --version For the test that uses `clang-9` do the sanity call using `clang-9` instead of `clang`. For the test that uses `clang` add a sanity call to `clang --version`. Backport of 97dc0ea9acdc308cc2cadc11e4787d07ec9b2c79: https://github.com/rust-bitcoin/rust-secp256k1/pull/284 (9/9) --- contrib/test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/test.sh b/contrib/test.sh index ed912872..4c4e9df6 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -59,6 +59,7 @@ fi # Address Sanitizer if [ "$DO_ASAN" = true ]; then + clang --version cargo clean CC='clang -fsanitize=address -fno-omit-frame-pointer' \ RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ From 5844f8ab1f5e62bade560b63473640ab9e498a73 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 25 Jul 2022 14:34:41 +0000 Subject: [PATCH 09/13] Reinstate missing "install wasm-pack" step from CI This was added in e0a4d2c1a108dfe4af43a31d2f291f909ea2de0e (no associated PR) (Dec 2020). --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cf56a672..05b694f2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -81,6 +81,8 @@ jobs: toolchain: ${{ matrix.rust }} override: true components: rust-src + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Running WASM tests env: DO_WASM: true From abb92e1991bca8cc0263f341dc74f1bdaa6a6fb0 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 8 Jun 2023 02:07:13 +0000 Subject: [PATCH 10/13] more clippy fixes (2023 06) --- src/lib.rs | 4 ++-- src/zkp/generator.rs | 4 ++-- src/zkp/rangeproof.rs | 1 + src/zkp/surjection_proof.rs | 1 + src/zkp/whitelist.rs | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f333cbd1..1e14b950 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ #![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![cfg_attr(all(test, feature = "unstable"), feature(test))] -#[macro_use] +/// Re-export secp256k1_zkp_sys pub extern crate secp256k1_zkp_sys; pub use secp256k1_zkp_sys as ffi; @@ -49,7 +49,7 @@ pub use secp256k1::hashes; extern crate core; #[cfg(any(test, feature = "rand"))] pub extern crate rand; -#[cfg(any(test))] +#[cfg(test)] extern crate rand_core; #[cfg(feature = "serde")] pub extern crate serde; diff --git a/src/zkp/generator.rs b/src/zkp/generator.rs index d673141f..7077ee49 100644 --- a/src/zkp/generator.rs +++ b/src/zkp/generator.rs @@ -11,7 +11,7 @@ use rand::Rng; #[derive(Default, Copy, Clone)] #[cfg_attr(not(fuzzing), derive(Eq, PartialEq))] pub struct Tweak([u8; constants::SECRET_KEY_SIZE]); -impl_array_newtype!(Tweak, u8, constants::SECRET_KEY_SIZE); +secp256k1_zkp_sys::impl_array_newtype!(Tweak, u8, constants::SECRET_KEY_SIZE); /// The zero Tweak pub const ZERO_TWEAK: Tweak = Tweak([ @@ -21,7 +21,7 @@ pub const ZERO_TWEAK: Tweak = Tweak([ impl fmt::Debug for Tweak { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Tweak(")?; - for i in self[..].iter().cloned() { + for i in self[..].iter() { write!(f, "{:02x}", i)?; } write!(f, ")") diff --git a/src/zkp/rangeproof.rs b/src/zkp/rangeproof.rs index 11020246..e85d5942 100644 --- a/src/zkp/rangeproof.rs +++ b/src/zkp/rangeproof.rs @@ -65,6 +65,7 @@ impl RangeProof { } /// Prove that `commitment` hides a value within a range, with the lower bound set to `min_value`. + #[allow(clippy::too_many_arguments)] pub fn new( secp: &Secp256k1, min_value: u64, diff --git a/src/zkp/surjection_proof.rs b/src/zkp/surjection_proof.rs index ad48830d..ba87ec74 100644 --- a/src/zkp/surjection_proof.rs +++ b/src/zkp/surjection_proof.rs @@ -143,6 +143,7 @@ impl SurjectionProof { } /// Find the length of surjection proof when serialized + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { unsafe { ffi::secp256k1_surjectionproof_serialized_size( diff --git a/src/zkp/whitelist.rs b/src/zkp/whitelist.rs index ca28d4ee..ea0e5254 100644 --- a/src/zkp/whitelist.rs +++ b/src/zkp/whitelist.rs @@ -18,7 +18,7 @@ pub struct WhitelistSignature(ffi::WhitelistSignature); impl WhitelistSignature { /// Number of keys in the whitelist. pub fn n_keys(&self) -> usize { - self.0.n_keys as usize + self.0.n_keys } /// Serialize to bytes. From 88837ff467ad8f4f3219d4723baf79f7d76b57fc Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 8 Jun 2023 02:08:42 +0000 Subject: [PATCH 11/13] ci: stop using clang-9 --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 05b694f2..3b60d5ba 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -73,7 +73,7 @@ jobs: - name: Checkout Crate uses: actions/checkout@v2 - name: Install clang - run: sudo apt-get install -y clang-9 + run: sudo apt-get install -y clang - name: Checkout Toolchain uses: actions-rs/toolchain@v1 with: From 597b0b78edb4db1ebe939aa92e829cc39e6bdef3 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 8 Jun 2023 02:11:52 +0000 Subject: [PATCH 12/13] add some more CI-required doccomments; remove some #[deny]s --- src/lib.rs | 7 +++---- src/zkp/whitelist.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1e14b950..95fe2411 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,10 +29,6 @@ //! // Coding conventions -#![deny(non_upper_case_globals)] -#![deny(non_camel_case_types)] -#![deny(non_snake_case)] -#![deny(unused_mut)] #![warn(missing_docs)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![cfg_attr(all(test, feature = "unstable"), feature(test))] @@ -47,10 +43,13 @@ extern crate secp256k1; pub use secp256k1::hashes; #[cfg(any(test, feature = "std"))] extern crate core; +/// Re-export rand #[cfg(any(test, feature = "rand"))] pub extern crate rand; +/// Re-export rand_core #[cfg(test)] extern crate rand_core; +/// Re-export serde #[cfg(feature = "serde")] pub extern crate serde; #[cfg(all(test, feature = "serde"))] diff --git a/src/zkp/whitelist.rs b/src/zkp/whitelist.rs index ea0e5254..ff1c8555 100644 --- a/src/zkp/whitelist.rs +++ b/src/zkp/whitelist.rs @@ -339,7 +339,7 @@ mod tests { // wrong n_keys let sig = unsafe { let sig = correct_signature.clone(); - let mut ptr = sig.as_c_ptr() as *mut ffi::WhitelistSignature; + let ptr = sig.as_c_ptr() as *mut ffi::WhitelistSignature; (*ptr).n_keys -= 1; sig }; From b0a1a693bb6c4c83ae3e8bd974afa5d66d0217e5 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 8 Jun 2023 02:15:42 +0000 Subject: [PATCH 13/13] wasm: enable `js` feature of `getrandom` --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 11cbc397..4da84a8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ serde_test = "1.0" [target.wasm32-unknown-unknown.dev-dependencies] wasm-bindgen-test = "0.3" rand = { version = "0.8" } +getrandom = { version = "0.2", features = ["js"] } [lib] crate-type = ["cdylib", "rlib"]