Skip to content

tests: Improve _scalar_check_overflow tests #1812

@real-or-random

Description

@real-or-random

At the moment, the only test is this one:

secp256k1/src/tests.c

Lines 2262 to 2267 in 1605b02

/* Does check_overflow check catch all ones? */
static const secp256k1_scalar overflowed = SECP256K1_SCALAR_CONST(
0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL,
0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL
);
CHECK(secp256k1_scalar_check_overflow(&overflowed));

That is, even a blank return 1 would pass the tests.

Some calls to secp256k1_scalar_check_overflow in the tests were removed in #1484 because I deemed them redundant. But that's not entirely true. Their primary purpose was to check for overflows in other test code, and this is indeed redundant. But a secondary effect of these calls was to test secp256k1_scalar_check_overflow itself.

We could revert this, but I think it's better to have a bunch of dedicated tests:

  • Check a handful of static inputs including the edge cases.
  • Check some random inputs. Uniformly random inputs should not overflow. But if we tweak in the right way (e.g., setting top bits), they should overflow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions