Skip to content

Add internal helper for serializing a non-infinity group element to a compressed public key #1773

@theStack

Description

@theStack

In more recent modules (ellswift, musig and silentpayments), the following pattern of serializing a non-infinity group element to a 33-bytes compressed public key appears repeatedly:

    size_t ser_size = 33;
    int ser_ret;
    .....
    ser_ret = secp256k1_eckey_pubkey_serialize(ge, out33, &ser_size, 1);
#ifdef VERIFY
    VERIFY_CHECK(ser_ret && ser_size == 33);
#else
    (void)ser_ret;
#endif

One could deduplicate these instances by a new function, as suggested by @w0xlt in the latest silentpayments module PR, see #1765 (review). This could simplify the code in the modules quite a bit (less LOC, less variables, less pre-processor blocks). Demo branch: theStack@e023651. It seems a reasonable idea to me, but not sure about the right naming of the function and where to put it. Also, one drawback might be that if the VERIFY_CHECK fails, it's a bit harder to find out the cause if it fails in a helper rather than directly in the module code (not sure if we care about that?). Opening this as an issue first to see if there is conceptual support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions