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:

     0diff --git a/src/group_impl.h b/src/group_impl.h
     1index 44d9843..31e1820 100644
     2--- a/src/group_impl.h
     3+++ b/src/group_impl.h
     4@@ -140,7 +140,8 @@ static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a) {
     5     secp256k1_ge_verify(a);
     6     *r = *a;
     7     secp256k1_fe_normalize_weak(&r->y);
     8-    secp256k1_fe_negate(&r->y, &r->y, 1);
     9+    int one = 1;
    10+    secp256k1_fe_negate(&r->y, &r->y, one);
    11     secp256k1_ge_verify(r);
    12 }
    13 
    14@@ -372,7 +373,8 @@ static SECP256K1_INLINE void secp256k1_gej_double(secp256k1_gej *r, const secp25
    15     secp256k1_fe_mul(&r->z, &a->z, &a->y); /* Z3 = Y1*Z1 (1) */
    16     secp256k1_fe_sqr(&s, &a->y);           /* S = Y1^2 (1) */
    17     secp256k1_fe_sqr(&l, &a->x);           /* L = X1^2 (1) */
    18-    secp256k1_fe_mul_int(&l, 3);           /* L = 3*X1^2 (3) */
    19+    int three = 3;
    20+    secp256k1_fe_mul_int(&l, three);       /* L = 3*X1^2 (3) */
    21     secp256k1_fe_half(&l);                 /* L = 3/2*X1^2 (2) */
    22     secp256k1_fe_negate(&t, &s, 1);        /* T = -S (2) */
    23     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):

    0src/group_impl.h:144:39: error: expression is not an integer constant expression
    1    secp256k1_fe_negate(&r->y, &r->y, one);
    2                                      ^~~
    3......
    4......
    5src/group_impl.h:377:30: error: expression is not an integer constant expression
    6    secp256k1_fe_mul_int(&l, three);       /* L = 3*X1^2 (3) */
    7                             ^~~~~
    8.....
    9.....
    
  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. real-or-random cross-referenced this on Jul 11, 2023 from issue Make fe magnitude implied statically by real-or-random
  11. fanquake referenced this in commit 56c05c5ec4 on Jul 17, 2023
  12. fanquake referenced this in commit ff061fde18 on Jul 18, 2023
  13. hebasto referenced this in commit 270d2b37b8 on Jul 21, 2023

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: 2024-10-30 05:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me