From e44e8df1e76a32049ea6fb2864d97e213293d44a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:36:02 +0100 Subject: [PATCH 1/2] Add `tools/check_header.sh` to check whether headers are self-contained --- .github/workflows/ci.yml | 12 ++++++++++++ tools/check_header.sh | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 tools/check_header.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9a9eaa82e..7738aadc64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -765,6 +765,18 @@ jobs: g++ -Werror include/*.h clang -Werror -x c++-header include/*.h + headers: + name: "Self-contained headers" + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Test script + run: | + ./tools/check_header.sh src/field.h + sage: name: "SageMath prover" runs-on: ubuntu-latest diff --git a/tools/check_header.sh b/tools/check_header.sh new file mode 100755 index 0000000000..4e724a19d2 --- /dev/null +++ b/tools/check_header.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -u + +for header in "$@"; do + source_file=${header%.h}.c + object_file=${header%.h}.o + mv "$header" "$source_file" + gcc -c "$source_file" -o "$object_file" + exit_code=$? + mv "$source_file" "$header" + if [ $exit_code -ne 0 ]; then + exit $exit_code + fi + echo "$header... OK" +done From 652afd396010f0ab2f79ed5a8a37d724b410f319 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:39:24 +0100 Subject: [PATCH 2/2] refactor: Make `field_NxM.h` headers self-contained --- .github/workflows/ci.yml | 2 +- src/field.h | 7 ------- src/field_10x26.h | 5 ++++- src/field_5x52.h | 5 ++++- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7738aadc64..c3d9dd8861 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -775,7 +775,7 @@ jobs: - name: Test script run: | - ./tools/check_header.sh src/field.h + ./tools/check_header.sh src/field.h src/field_5x52.h src/field_10x26.h sage: name: "SageMath prover" diff --git a/src/field.h b/src/field.h index ccd228e1ae..bfd1267d08 100644 --- a/src/field.h +++ b/src/field.h @@ -29,13 +29,6 @@ * implementation also provides a secp256k1_fe_verify routine to verify that * these fields match the run-time value and perform internal consistency * checks. */ -#ifdef VERIFY -# define SECP256K1_FE_VERIFY_FIELDS \ - int magnitude; \ - int normalized; -#else -# define SECP256K1_FE_VERIFY_FIELDS -#endif #if defined(SECP256K1_WIDEMUL_INT128) #include "field_5x52.h" diff --git a/src/field_10x26.h b/src/field_10x26.h index 203c10167c..c01d92c10b 100644 --- a/src/field_10x26.h +++ b/src/field_10x26.h @@ -30,7 +30,10 @@ typedef struct { * sum(i=0..9, n[i] << (i*26)) < p * (together these imply n[9] <= 2^22 - 1) */ - SECP256K1_FE_VERIFY_FIELDS +#ifdef VERIFY + int magnitude; + int normalized; +#endif } secp256k1_fe; /* Unpacks a constant into a overlapping multi-limbed FE element. */ diff --git a/src/field_5x52.h b/src/field_5x52.h index f20c246fdd..30cdf3bb10 100644 --- a/src/field_5x52.h +++ b/src/field_5x52.h @@ -30,7 +30,10 @@ typedef struct { * sum(i=0..4, n[i] << (i*52)) < p * (together these imply n[4] <= 2^48 - 1) */ - SECP256K1_FE_VERIFY_FIELDS +#ifdef VERIFY + int magnitude; + int normalized; +#endif } secp256k1_fe; /* Unpacks a constant into a overlapping multi-limbed FE element. */