field: Static-assert that int args affecting magnitude are constant #1345

pull real-or-random wants to merge 1 commits into bitcoin-core:master from real-or-random:202306-magnitude-const changing 6 files +43 −18
  1. real-or-random commented at 11:40 AM on June 13, 2023: contributor

    See #1001.

    Try to revert the lines in tests.c to see the error message in action.

  2. field: Static-assert that int args affecting magnitude are constant
    See #1001.
    be8ff3a02a
  3. real-or-random added the label assurance on Jun 13, 2023
  4. sipa commented at 11:54 PM on June 20, 2023: contributor

    ACK be8ff3a02aeff87c60d49883a1b2afa8b2999bbe. Verified by introducing some non-constant expressions and seeing compilation fail.

  5. theStack approved
  6. theStack commented at 10:52 PM on June 26, 2023: contributor

    ACK be8ff3a02aeff87c60d49883a1b2afa8b2999bbe

    Tested with clang 13.0.0 using the following (non C-90 conform) patch:

    diff --git a/src/group_impl.h b/src/group_impl.h
    index 44d9843..31e1820 100644
    --- a/src/group_impl.h
    +++ b/src/group_impl.h
    @@ -140,7 +140,8 @@ static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a) {
         secp256k1_ge_verify(a);
         *r = *a;
         secp256k1_fe_normalize_weak(&r->y);
    -    secp256k1_fe_negate(&r->y, &r->y, 1);
    +    int one = 1;
    +    secp256k1_fe_negate(&r->y, &r->y, one);
         secp256k1_ge_verify(r);
     }
     
    @@ -372,7 +373,8 @@ static SECP256K1_INLINE void secp256k1_gej_double(secp256k1_gej *r, const secp25
         secp256k1_fe_mul(&r->z, &a->z, &a->y); /* Z3 = Y1*Z1 (1) */
         secp256k1_fe_sqr(&s, &a->y);           /* S = Y1^2 (1) */
         secp256k1_fe_sqr(&l, &a->x);           /* L = X1^2 (1) */
    -    secp256k1_fe_mul_int(&l, 3);           /* L = 3*X1^2 (3) */
    +    int three = 3;
    +    secp256k1_fe_mul_int(&l, three);       /* L = 3*X1^2 (3) */
         secp256k1_fe_half(&l);                 /* L = 3/2*X1^2 (2) */
         secp256k1_fe_negate(&t, &s, 1);        /* T = -S (2) */
         secp256k1_fe_mul(&t, &t, &a->x);       /* T = -X1*S (1) */
    

    The compilation error messages are straight to the point (even without the macro expansions shown after):

    src/group_impl.h:144:39: error: expression is not an integer constant expression
        secp256k1_fe_negate(&r->y, &r->y, one);
                                          ^~~
    ......
    ......
    src/group_impl.h:377:30: error: expression is not an integer constant expression
        secp256k1_fe_mul_int(&l, three);       /* L = 3*X1^2 (3) */
                                 ^~~~~
    .....
    .....
    
  7. real-or-random merged this on Jun 27, 2023
  8. real-or-random closed this on Jun 27, 2023

  9. vmta referenced this in commit 8f03457eed on Jul 1, 2023
  10. fanquake referenced this in commit 56c05c5ec4 on Jul 17, 2023
  11. fanquake referenced this in commit ff061fde18 on Jul 18, 2023
  12. hebasto referenced this in commit 270d2b37b8 on Jul 21, 2023
  13. delta1 referenced this in commit 3f32c20932 on Aug 8, 2023
  14. delta1 referenced this in commit 31ac0c1081 on Aug 31, 2023
  15. janus referenced this in commit 476a2176e7 on Sep 11, 2023
  16. div72 referenced this in commit af627d47c3 on Apr 12, 2025
  17. str4d referenced this in commit 3b49801869 on Jun 4, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-19 06:52 UTC