Skip to content

Combine PRs for ease of merging #423

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

Closed
wants to merge 11 commits into from
59 changes: 35 additions & 24 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ on: [push, pull_request]
name: Continuous integration

jobs:
bench_nightly:
name: Nightly - ASan + Bench
Nightly:
name: Nightly - ASan + Bench + Docs
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- nightly
steps:
- name: Checkout Crate
- name: Checkout Crate
uses: actions/checkout@v2
- name: Install clang # Needed for ASan.
run: sudo apt-get install -y clang-9
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
toolchain: nightly
override: true
components: rust-src
- name: Running address sanitizer
Expand All @@ -28,27 +26,17 @@ jobs:
env:
DO_BENCH: true
run: ./contrib/test.sh
- name: Building docs
env:
DO_DOCS: true
run: ./contrib/test.sh

Tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rust: stable
env:
DO_FEATURE_MATRIX: true
DO_WASM: true
- rust: beta
env:
DO_FEATURE_MATRIX: true
- rust: nightly
env:
DO_FEATURE_MATRIX: true
DO_DOCS: true
- rust: 1.29.0
env:
DO_FEATURE_MATRIX: true
rust: [stable, beta, nightly, 1.29.0]
steps:
- name: Checkout Crate
uses: actions/checkout@v2
Expand All @@ -62,6 +50,29 @@ jobs:
if: matrix.rust == '1.29.0'
run: cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose
- name: Running cargo
env: ${{ matrix.env }}
env:
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

WASM:
name: WASM
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly] # WASM requires Rust 1.30
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Install clang
run: sudo apt-get install -y clang-10
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rust-src
- name: Running WASM tests
env:
DO_WASM: true
run: ./contrib/test.sh
25 changes: 14 additions & 11 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh -ex

set -e

# TODO: Add "alloc" once we bump MSRV to past 1.29
FEATURES="bitcoin_hashes global-context lowmemory rand recovery serde std"
# These features are typically enabled along with the 'std' feature, so we test
Expand All @@ -15,6 +17,9 @@ fi
cargo --version
rustc --version

# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"

# Make all cargo invocations verbose
export CARGO_TERM_VERBOSE=true

Expand Down Expand Up @@ -64,11 +69,11 @@ fi

# Webassembly stuff
if [ "$DO_WASM" = true ]; then
clang --version &&
CARGO_TARGET_DIR=wasm cargo install --force wasm-pack &&
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml &&
CC=clang-9 wasm-pack build &&
CC=clang-9 wasm-pack test --node;
clang --version
CARGO_TARGET_DIR=wasm cargo install --force wasm-pack
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml
CC=clang wasm-pack build
CC=clang wasm-pack test --node
fi

# Address Sanitizer
Expand All @@ -77,20 +82,18 @@ if [ "$DO_ASAN" = true ]; then
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu &&
cargo clean &&
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
cargo clean
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' \
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu &&
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully"
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
fi

# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"

# Bench
if [ "$DO_BENCH" = true ]; then
cargo bench --all --features="unstable"
fi

exit 0
38 changes: 0 additions & 38 deletions secp256k1-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,3 @@ mod tests {
assert!(mem::align_of::<AlignedType>() >= mem::align_of::<self::libc::max_align_t>());
}
}

#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
pub fn sanity_checks_for_wasm() {
use core::mem::{align_of, size_of};
extern "C" {
pub static WASM32_INT_SIZE: c_uchar;
pub static WASM32_INT_ALIGN: c_uchar;

pub static WASM32_UNSIGNED_INT_SIZE: c_uchar;
pub static WASM32_UNSIGNED_INT_ALIGN: c_uchar;

pub static WASM32_SIZE_T_SIZE: c_uchar;
pub static WASM32_SIZE_T_ALIGN: c_uchar;

pub static WASM32_UNSIGNED_CHAR_SIZE: c_uchar;
pub static WASM32_UNSIGNED_CHAR_ALIGN: c_uchar;

pub static WASM32_PTR_SIZE: c_uchar;
pub static WASM32_PTR_ALIGN: c_uchar;
}
unsafe {
assert_eq!(size_of::<c_int>(), WASM32_INT_SIZE as usize);
assert_eq!(align_of::<c_int>(), WASM32_INT_ALIGN as usize);

assert_eq!(size_of::<c_uint>(), WASM32_UNSIGNED_INT_SIZE as usize);
assert_eq!(align_of::<c_uint>(), WASM32_UNSIGNED_INT_ALIGN as usize);

assert_eq!(size_of::<size_t>(), WASM32_SIZE_T_SIZE as usize);
assert_eq!(align_of::<size_t>(), WASM32_SIZE_T_ALIGN as usize);

assert_eq!(size_of::<c_uchar>(), WASM32_UNSIGNED_CHAR_SIZE as usize);
assert_eq!(align_of::<c_uchar>(), WASM32_UNSIGNED_CHAR_ALIGN as usize);

assert_eq!(size_of::<*const ()>(), WASM32_PTR_SIZE as usize);
assert_eq!(align_of::<*const ()>(), WASM32_PTR_ALIGN as usize);
}
}
17 changes: 0 additions & 17 deletions secp256k1-sys/wasm-sysroot/stdio.h
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
#include <stddef.h>
#define alignof(type) offsetof (struct { char c; type member; }, member)

extern const unsigned char WASM32_INT_SIZE = sizeof(int);
extern const unsigned char WASM32_INT_ALIGN = alignof(int);

extern const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int);
extern const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int);

extern const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t);
extern const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t);

extern const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char);
extern const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char);

extern const unsigned char WASM32_PTR_SIZE = sizeof(void*);
extern const unsigned char WASM32_PTR_ALIGN = alignof(void*);
6 changes: 0 additions & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ mod alloc_only {
/// ```
#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
pub fn gen_new() -> Secp256k1<C> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();

let size = unsafe { ffi::secp256k1_context_preallocated_size(C::FLAGS) };
let layout = alloc::Layout::from_size_align(size, ALIGN_TO).unwrap();
let ptr = unsafe {alloc::alloc(layout)};
Expand Down Expand Up @@ -302,9 +299,6 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
impl<'buf, C: Context + 'buf> Secp256k1<C> {
/// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all)
pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result<Secp256k1<C>, Error> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();

if buf.len() < Self::preallocate_size_gen() {
return Err(Error::NotEnoughMemory);
}
Expand Down