LCOV - code coverage report
Current view: top level - ballet/ed25519 - fd_ed25519_verifier.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2026-12-02 04:32:07 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_ed25519_fd_ed25519_verifier_h
       2             : #define HEADER_fd_src_ballet_ed25519_fd_ed25519_verifier_h
       3             : 
       4             : /* Signature verifier: the object a tile verifies Ed25519 signatures
       5             :    with.  It owns the scratch and the optional signer cache the
       6             :    verification takes, and every result it gives is what
       7             :    fd_ed25519_verify returns for that signature.  Callers collect
       8             :    FD_ED25519_VERIFIER_GROUP signatures per
       9             :    fd_ed25519_verifier_verify_sigs call. */
      10             : 
      11             : #include "fd_ed25519.h"
      12             : #include "../txn/fd_txn.h"
      13             : 
      14             : /* FD_ED25519_VERIFIER_CACHE_{DEFAULT,OFF} are values of cache_ent_cnt
      15             :    selecting the default signer cache (2048 entries) and no cache at
      16             :    all.  Any other value is a cache entry count, a power of 2 in
      17             :    [4,2^20]. */
      18             : 
      19         666 : #define FD_ED25519_VERIFIER_CACHE_DEFAULT (0UL)
      20         456 : #define FD_ED25519_VERIFIER_CACHE_OFF     (ULONG_MAX)
      21             : 
      22         681 : #define FD_ED25519_VERIFIER_ALIGN (128UL)
      23             : 
      24             : /* FD_ED25519_VERIFIER_BATCH is the most signatures a caller is asked
      25             :    to collect per fd_ed25519_verifier_verify_sigs call, whatever the
      26             :    build; it sizes the callers' staging. */
      27             : 
      28      318654 : #define FD_ED25519_VERIFIER_BATCH (8UL)
      29             : 
      30             : /* FD_ED25519_VERIFIER_SIG_MAX is the most signatures one
      31             :    fd_ed25519_verifier_verify_sigs call takes.  Callers collecting
      32             :    transactions add one while the total stays within a group, so a set
      33             :    of several transactions has at most FD_ED25519_VERIFIER_GROUP
      34             :    signatures and only a lone transaction can bring FD_TXN_SIG_MAX
      35             :    (the most signatures a transaction can carry). */
      36             : 
      37     2431944 : #define FD_ED25519_VERIFIER_SIG_MAX (FD_TXN_SIG_MAX)
      38             : FD_STATIC_ASSERT( FD_ED25519_VERIFIER_BATCH<=FD_ED25519_VERIFIER_SIG_MAX, verifier_sig_max );
      39             : 
      40             : /* FD_ED25519_VERIFIER_GROUP is the signature count a caller collects
      41             :    before one fd_ed25519_verifier_verify_sigs call, in
      42             :    [1,FD_ED25519_VERIFIER_BATCH].  It is the group size the Ed25519
      43             :    implementation of the build verifies fastest: a caller that has it
      44             :    calls, one that has fewer waits for more unless none can come. */
      45             : 
      46         531 : #define FD_ED25519_VERIFIER_GROUP (1UL)
      47             : FD_STATIC_ASSERT( 1UL<=FD_ED25519_VERIFIER_GROUP && FD_ED25519_VERIFIER_GROUP<=FD_ED25519_VERIFIER_BATCH, verifier_group );
      48             : 
      49             : /* A transaction verifier (the exec tiles') keeps the default cache. */
      50             : 
      51          42 : #define FD_ED25519_VERIFIER_TXN_CACHE (FD_ED25519_VERIFIER_CACHE_DEFAULT)
      52             : 
      53             : struct fd_ed25519_verifier;
      54             : typedef struct fd_ed25519_verifier fd_ed25519_verifier_t;
      55             : 
      56             : FD_PROTOTYPES_BEGIN
      57             : 
      58             : /* fd_ed25519_verifier_{align,footprint} give the required alignment
      59             :    and footprint of a memory region for a verifier with cache_ent_cnt
      60             :    cache entries (see FD_ED25519_VERIFIER_CACHE_*).  footprint returns
      61             :    0 for an invalid cache_ent_cnt. */
      62             : 
      63             : FD_FN_CONST ulong
      64             : fd_ed25519_verifier_align( void );
      65             : 
      66             : FD_FN_CONST ulong
      67             : fd_ed25519_verifier_footprint( ulong cache_ent_cnt );
      68             : 
      69             : /* fd_ed25519_verifier_new formats mem as a verifier.  seed randomizes
      70             :    the cache placement.  Returns mem on success and NULL on failure
      71             :    (logs details).  join, leave and delete are the usual. */
      72             : 
      73             : void *
      74             : fd_ed25519_verifier_new( void * mem,
      75             :                          ulong  cache_ent_cnt,
      76             :                          ulong  seed );
      77             : 
      78             : fd_ed25519_verifier_t *
      79             : fd_ed25519_verifier_join( void * shverifier );
      80             : 
      81             : void *
      82             : fd_ed25519_verifier_leave( fd_ed25519_verifier_t * verifier );
      83             : 
      84             : void *
      85             : fd_ed25519_verifier_delete( void * shverifier );
      86             : 
      87             : /* fd_ed25519_verifier_verify returns what fd_ed25519_verify returns
      88             :    for msg, sig and public_key. */
      89             : 
      90             : int
      91             : fd_ed25519_verifier_verify( fd_ed25519_verifier_t * verifier,
      92             :                             uchar const             msg[], /* msg_sz */
      93             :                             ulong                   msg_sz,
      94             :                             uchar const             sig[ 64 ],
      95             :                             uchar const             public_key[ 32 ] );
      96             : 
      97             : /* fd_ed25519_verifier_verify_sigs sets results[j] to what
      98             :    fd_ed25519_verify returns for (msgs[j], msg_szs[j], sigs[j],
      99             :    public_keys[j]), for j in [0,sig_cnt), sig_cnt in
     100             :    [1,FD_ED25519_VERIFIER_SIG_MAX] (asserted), error precedence
     101             :    included, for every input and cache state.  The input requirements
     102             :    are fd_ed25519_verify_batch8's: inputs may alias each other but not
     103             :    results, and only results[0,sig_cnt) and the verifier are written.
     104             :    A verifier is used by one thread at a time. */
     105             : 
     106             : void
     107             : fd_ed25519_verifier_verify_sigs( fd_ed25519_verifier_t * verifier,
     108             :                                  uchar const * const     msgs[],        /* sig_cnt */
     109             :                                  ulong const             msg_szs[],     /* sig_cnt */
     110             :                                  uchar const * const     sigs[],        /* sig_cnt */
     111             :                                  uchar const * const     public_keys[], /* sig_cnt */
     112             :                                  int                     results[],     /* sig_cnt */
     113             :                                  ulong                   sig_cnt );
     114             : 
     115             : /* fd_ed25519_verifier_{hit,miss,insert}_cnt are the signer cache
     116             :    counters (see fd_ed25519_cache_{hit,miss,insert}_cnt), 0 without a
     117             :    cache. */
     118             : 
     119             : ulong fd_ed25519_verifier_hit_cnt   ( fd_ed25519_verifier_t const * verifier );
     120             : ulong fd_ed25519_verifier_miss_cnt  ( fd_ed25519_verifier_t const * verifier );
     121             : ulong fd_ed25519_verifier_insert_cnt( fd_ed25519_verifier_t const * verifier );
     122             : 
     123             : FD_PROTOTYPES_END
     124             : 
     125             : #endif /* HEADER_fd_src_ballet_ed25519_fd_ed25519_verifier_h */

Generated by: LCOV version 1.14