LCOV - code coverage report
Current view: top level - choreo/eqvoc - fd_eqvoc.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 77 0.0 %
Date: 2025-01-08 12:08:44 Functions: 0 50 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_choreo_eqvoc_fd_eqvoc_h
       2             : #define HEADER_fd_src_choreo_eqvoc_fd_eqvoc_h
       3             : 
       4             : #include "../../ballet/shred/fd_shred.h"
       5             : #include "../../flamenco/leaders/fd_leaders.h"
       6             : #include "../fd_choreo_base.h"
       7             : #include "../../flamenco/runtime/fd_blockstore.h"
       8             : 
       9             : /* fd_eqvoc presents an API for detecting and sending / receiving proofs
      10             :    of equivocation.
      11             : 
      12             :    APIs prefixed with `fd_eqvoc_proof` relate to constructing and
      13             :    verifying equivocation proofs from shreds.
      14             : 
      15             :    APIs prefixed with `fd_eqvoc_fec` relate to shred and FEC set
      16             :    metadata indexing to detect equivocating shreds.
      17             : 
      18             :    Equivocation is when a shred producer produces two or more versions
      19             :    of a shred for the same (slot, idx).  An equivocation proof comprises
      20             :    two shreds that conflict in a way that imply the shreds' producer
      21             :    equivocated.
      22             : 
      23             :    The proof can be both direct and indirect (implied).  A direct proof,
      24             :    for example, contains two shreds with the same shred index but
      25             :    different data payloads.  An indirect proof contains two shreds with
      26             :    different shred indices, and the metadata on the shreds implies there
      27             :    must be two or more versions of a block for that slot.  See
      28             :    `fd_eqvoc_proof_verify` for more details.
      29             : 
      30             :    Every FEC set must have the same signature for every shred in the
      31             :    set, so a different signature would indicate equivocation.  Note in
      32             :    the case of merkle shreds, the shred signature is signed on the FEC
      33             :    set's merkle root, so every shred in the same FEC set must have the
      34             :    same signature. */
      35             : 
      36             : /* FD_EQVOC_USE_HANDHOLDING:  Define this to non-zero at compile time
      37             :    to turn on additional runtime checks and logging. */
      38             : 
      39             : #ifndef FD_EQVOC_USE_HANDHOLDING
      40             : #define FD_EQVOC_USE_HANDHOLDING 1
      41             : #endif
      42             : 
      43           0 : #define FD_EQVOC_FEC_MAX ( 67UL )
      44             : 
      45             : struct fd_slot_fec {
      46             :   ulong slot;
      47             :   uint  fec_set_idx;
      48             : };
      49             : typedef struct fd_slot_fec fd_slot_fec_t;
      50             : 
      51             : /* clang-format off */
      52             : static const fd_slot_fec_t     fd_slot_fec_null = { 0 };
      53             : #define FD_SLOT_FEC_NULL       fd_slot_fec_null
      54             : #define FD_SLOT_FEC_INVAL(key) (!((key).slot) & !((key).fec_set_idx))
      55           0 : #define FD_SLOT_FEC_EQ(k0,k1)  (!(((k0).slot) ^ ((k1).slot))) & !(((k0).fec_set_idx) ^ (((k1).fec_set_idx)))
      56           0 : #define FD_SLOT_FEC_HASH(key)  ((uint)(((key).slot)<<15UL) | (((key).fec_set_idx)))
      57             : /* clang-format on */
      58             : 
      59             : struct fd_eqvoc_fec {
      60             :   fd_slot_fec_t    key;
      61             :   ulong            next;
      62             :   ulong            code_cnt;
      63             :   ulong            data_cnt;
      64             :   uint             last_idx;
      65             :   fd_ed25519_sig_t sig;
      66             : };
      67             : typedef struct fd_eqvoc_fec fd_eqvoc_fec_t;
      68             : 
      69             : #define POOL_NAME fd_eqvoc_fec_pool
      70           0 : #define POOL_T    fd_eqvoc_fec_t
      71             : #include "../../util/tmpl/fd_pool.c"
      72             : 
      73             : /* clang-format off */
      74             : #define MAP_NAME               fd_eqvoc_fec_map
      75             : #define MAP_ELE_T              fd_eqvoc_fec_t
      76             : #define MAP_KEY_T              fd_slot_fec_t
      77           0 : #define MAP_KEY_EQ(k0,k1)      (FD_SLOT_FEC_EQ(*k0,*k1))
      78           0 : #define MAP_KEY_HASH(key,seed) (FD_SLOT_FEC_HASH(*key)^seed)
      79             : #include "../../util/tmpl/fd_map_chain.c"
      80             : /* clang-format on */
      81             : 
      82           0 : #define FD_EQVOC_PROOF_MAX ( 2*FD_SHRED_MAX_SZ + 2*sizeof(ulong) ) /* 2 shreds prefixed with sz */
      83             : 
      84             : /* This is the standard MTU
      85             : 
      86             :    IPv6 MTU - IP / UDP headers = 1232
      87             :    DuplicateShredMaxPayloadSize = 1232 - 115
      88             :    DuplicateShred headers = 63
      89             : 
      90             :    https://github.com/anza-xyz/agave/blob/v2.0.3/gossip/src/cluster_info.rs#L113 */
      91           0 : #define FD_EQVOC_PROOF_CHUNK_MAX ( 1232UL - 115UL - 63UL )
      92           0 : #define FD_EQVOC_PROOF_CHUNK_CNT ( ( FD_EQVOC_PROOF_MAX / FD_EQVOC_PROOF_CHUNK_MAX ) + 1 ) /* 3 */
      93             : 
      94             : /* The chunk_cnt is encoded in a UCHAR_MAX, so you can have at most
      95             :    UCHAR_MAX chunks */
      96             : #define FD_EQVOC_PROOF_CHUNK_MIN ( ( FD_EQVOC_PROOF_MAX / UCHAR_MAX ) + 1 ) /* 20 */
      97             : 
      98           0 : #define FD_EQVOC_PROOF_VERIFY_FAILURE           (0)
      99           0 : #define FD_EQVOC_PROOF_VERIFY_SUCCESS_SIGNATURE (1)
     100           0 : #define FD_EQVOC_PROOF_VERIFY_SUCCESS_META      (2)
     101           0 : #define FD_EQVOC_PROOF_VERIFY_SUCCESS_LAST      (3)
     102           0 : #define FD_EQVOC_PROOF_VERIFY_SUCCESS_OVERLAP   (4)
     103           0 : #define FD_EQVOC_PROOF_VERIFY_SUCCESS_CHAINED   (5)
     104             : 
     105           0 : #define FD_EQVOC_PROOF_VERIFY_ERR_SLOT      (-1) /* different slot */
     106           0 : #define FD_EQVOC_PROOF_VERIFY_ERR_VERSION   (-2) /* different shred version */
     107           0 : #define FD_EQVOC_PROOF_VERIFY_ERR_TYPE      (-3) /* wrong shred type (must be chained {resigned} merkle) */
     108           0 : #define FD_EQVOC_PROOF_VERIFY_ERR_MERKLE    (-4) /* merkle root failed */
     109           0 : #define FD_EQVOC_PROOF_VERIFY_ERR_SIGNATURE (-5) /* sig verify of shred producer failed */
     110             : 
     111             : #define SET_NAME fd_eqvoc_proof_set
     112             : #define SET_MAX  256
     113             : #include "../../util/tmpl/fd_set.c"
     114             : 
     115             : struct fd_eqvoc_proof {
     116             :   fd_slot_pubkey_t     key;
     117             :   ulong                prev; /* reserved for data structure use */
     118             :   ulong                next; /* reserved for data structure use*/
     119             : 
     120             :   fd_pubkey_t         producer;   /* producer of shreds' pubkey */
     121             :   void *              bmtree_mem; /* scratch space for reconstructing
     122             :                                      the merkle root */
     123             :   ulong               wallclock;  /* `wallclock` */
     124             :   ulong               chunk_cnt;  /* `num_chunks` */
     125             :   ulong               chunk_sz;   /* `chunk_len` */
     126             : 
     127             :   /* static declaration of an fd_set that occupies 4 words ie. 256 bits
     128             :      that tracks which proof chunks have been received. */
     129             : 
     130             :   fd_eqvoc_proof_set_t set[UCHAR_MAX / sizeof( ulong )];
     131             : 
     132             :   /* DuplicateShred messages are serialized in the following format:
     133             : 
     134             :      ---------
     135             :      shred1_sz
     136             :      ---------
     137             :      shred1
     138             :      ---------
     139             :      shred2_sz
     140             :      ---------
     141             :      shred2
     142             :      ---------
     143             : 
     144             :      Each shred is prepended with its size in bytes, before being
     145             :      chunked.
     146             :   */
     147             : 
     148             :    uchar shreds[2 * FD_SHRED_MAX_SZ + 2 * sizeof(ulong)];
     149             : };
     150             : typedef struct fd_eqvoc_proof fd_eqvoc_proof_t;
     151             : 
     152             : #define POOL_NAME fd_eqvoc_proof_pool
     153           0 : #define POOL_T    fd_eqvoc_proof_t
     154             : #include "../../util/tmpl/fd_pool.c"
     155             : 
     156             : /* clang-format off */
     157             : #define MAP_NAME               fd_eqvoc_proof_map
     158             : #define MAP_ELE_T              fd_eqvoc_proof_t
     159             : #define MAP_KEY_T              fd_slot_pubkey_t
     160           0 : #define MAP_KEY_EQ(k0,k1)      (FD_SLOT_PUBKEY_EQ(k0,k1))
     161           0 : #define MAP_KEY_HASH(key,seed) (FD_SLOT_PUBKEY_HASH(key,seed))
     162             : #include "../../util/tmpl/fd_map_chain.c"
     163             : /* clang-format on */
     164             : 
     165             : struct fd_eqvoc {
     166             : 
     167             :   /* primitives */
     168             : 
     169             :   fd_pubkey_t me; /* our pubkey */
     170             :   ulong fec_max;
     171             :   ulong proof_max;
     172             :   ulong shred_version; /* shred version we expect in all shreds in eqvoc-related msgs. */
     173             : 
     174             :   /* owned */
     175             : 
     176             :   fd_eqvoc_fec_t *       fec_pool;
     177             :   fd_eqvoc_fec_map_t *   fec_map;
     178             :   // fd_eqvoc_fec_dlist_t * fec_dlist;
     179             :   fd_eqvoc_proof_t *     proof_pool;
     180             :   fd_eqvoc_proof_map_t * proof_map;
     181             :   fd_sha512_t *          sha512;
     182             :   void *                 bmtree_mem;
     183             : 
     184             :   /* borrowed  */
     185             : 
     186             :   fd_epoch_leaders_t const * leaders;
     187             : };
     188             : typedef struct fd_eqvoc fd_eqvoc_t;
     189             : 
     190             : /* clang-format off */
     191             : 
     192             : /* fd_eqvoc_{align,footprint} return the required alignment and
     193             :    footprint of a memory region suitable for use as eqvoc with up to
     194             :    node_max nodes and vote_max votes. */
     195             : 
     196             : FD_FN_CONST static inline ulong
     197           0 : fd_eqvoc_align( void ) {
     198           0 :   return alignof(fd_eqvoc_t);
     199           0 : }
     200             : 
     201             : FD_FN_CONST static inline ulong
     202           0 : fd_eqvoc_footprint( ulong fec_max, ulong proof_max ) {
     203           0 :   return FD_LAYOUT_FINI(
     204           0 :     FD_LAYOUT_APPEND(
     205           0 :     FD_LAYOUT_APPEND(
     206           0 :     FD_LAYOUT_APPEND(
     207           0 :     FD_LAYOUT_APPEND(
     208           0 :     FD_LAYOUT_APPEND(
     209           0 :     FD_LAYOUT_APPEND(
     210           0 :     FD_LAYOUT_APPEND(
     211           0 :     FD_LAYOUT_INIT,
     212           0 :       alignof(fd_eqvoc_t),         sizeof(fd_eqvoc_t) ),
     213           0 :       fd_eqvoc_fec_pool_align(),   fd_eqvoc_fec_pool_footprint( fec_max ) ),
     214           0 :       fd_eqvoc_fec_map_align(),    fd_eqvoc_fec_map_footprint( fec_max ) ),
     215           0 :       fd_eqvoc_proof_pool_align(), fd_eqvoc_proof_pool_footprint( proof_max ) ),
     216           0 :       fd_eqvoc_proof_map_align(),  fd_eqvoc_proof_map_footprint( proof_max ) ),
     217           0 :       fd_sha512_align(),           fd_sha512_footprint() ),
     218           0 :       fd_bmtree_commit_align(),    fd_bmtree_commit_footprint( FD_SHRED_MERKLE_LAYER_CNT ) ),
     219           0 :    fd_eqvoc_align() );
     220           0 : }
     221             : /* clang-format on */
     222             : 
     223             : /* fd_eqvoc_new formats an unused memory region for use as a eqvoc.
     224             :    mem is a non-NULL pointer to this region in the local address space
     225             :    with the required footprint and alignment. */
     226             : 
     227             : void *
     228             : fd_eqvoc_new( void * shmem, ulong fec_max, ulong proof_max, ulong seed );
     229             : 
     230             : /* fd_eqvoc_join joins the caller to the eqvoc.  eqvoc points to the
     231             :    first byte of the memory region backing the eqvoc in the caller's
     232             :    address space.
     233             : 
     234             :    Returns a pointer in the local address space to eqvoc on success. */
     235             : 
     236             : fd_eqvoc_t *
     237             : fd_eqvoc_join( void * sheqvoc );
     238             : 
     239             : /* fd_eqvoc_leave leaves a current local join.  Returns a pointer to the
     240             :    underlying shared memory region on success and NULL on failure (logs
     241             :    details).  Reasons for failure include eqvoc is NULL. */
     242             : 
     243             : void *
     244             : fd_eqvoc_leave( fd_eqvoc_t const * eqvoc );
     245             : 
     246             : /* fd_eqvoc_delete unformats a memory region used as a eqvoc.
     247             :    Assumes only the nobody is joined to the region.  Returns a
     248             :    pointer to the underlying shared memory region or NULL if used
     249             :    obviously in error (e.g. eqvoc is obviously not a eqvoc ... logs
     250             :    details).  The ownership of the memory region is transferred to the
     251             :    caller. */
     252             : 
     253             : void *
     254             : fd_eqvoc_delete( void * sheqvoc );
     255             : 
     256             : /* fd_eqvoc_init initializes eqvoc with the expected shred version. */
     257             : 
     258             : void
     259             : fd_eqvoc_init( fd_eqvoc_t * eqvoc, ulong shred_version );
     260             : 
     261             : /* fd_eqvoc_fec_query queries for FEC set metadata on (slot,
     262             :    fec_set_idx).  At least one coding shred most be inserted to populate
     263             :    code_cnt, data_cnt, and the last data shred in the slot to populate
     264             :    last_idx.  Otherwise fields are defaulted to 0, 0, FD_SHRED_IDX_NULL
     265             :    respectively.  Callers should check whether fields are the default
     266             :    values before using them. */
     267             : 
     268             : FD_FN_PURE static inline fd_eqvoc_fec_t const *
     269           0 : fd_eqvoc_fec_query( fd_eqvoc_t const * eqvoc, ulong slot, uint fec_set_idx ) {
     270           0 :   fd_slot_fec_t key = { slot, fec_set_idx };
     271           0 :   return fd_eqvoc_fec_map_ele_query_const( eqvoc->fec_map, &key, NULL, eqvoc->fec_pool );
     272           0 : }
     273             : 
     274             : /* fd_eqvoc_fec_insert inserts a new FEC entry into eqvoc, indexed by
     275             :    (slot, fec_set_idx). */
     276             : 
     277             : fd_eqvoc_fec_t *
     278             : fd_eqvoc_fec_insert( fd_eqvoc_t * eqvoc, ulong slot, uint fec_set_idx );
     279             : 
     280             : /* fd_eqvoc_fec_search searches for whether `shred` implies equivocation
     281             :    by checking for a conflict in the currently indexed FEC sets. Returns
     282             :    the conflicting entry if there is one, NULL otherwise.
     283             : 
     284             :    A FEC set "overlaps" with another if they both contain a data shred
     285             :    at the samed idx.  For example, say we have a FEC set containing data
     286             :    shreds in the idx interval [13, 15] and another containing idxs [15,
     287             :    20].  The first FEC set has fec_set_idx 13 and data_cnt 3. The second
     288             :    FEC set has fec_set_idx 15 and data_cnt 6.  They overlap because they
     289             :    both contain a data shred at idx 15.  Therefore, these two FEC sets
     290             :    imply equivocation.
     291             : 
     292             :    This overlap can be detected arithmetically by adding the data_cnt to
     293             :    the fec_set_idx that starts earlier.  If the result is greater than
     294             :    the fec_set_idx that starts later, we know at least one data shred
     295             :    idx must overlap.  In this example, 13 + 3 > 15, which indicates
     296             :    equivocation.
     297             : 
     298             :    We can check for this overlap both backwards and forwards.  We know
     299             :    the max number of data shred idxs in a valid FEC set is 67.  So we
     300             :    need to look back at most 67 FEC set idxs to find the previous FEC
     301             :    set.  Similarly, we look forward at most data_cnt idxs to find the
     302             :    next FEC set. */
     303             : 
     304             : fd_eqvoc_fec_t const *
     305             : fd_eqvoc_fec_search( fd_eqvoc_t const * eqvoc, fd_shred_t const * shred );
     306             : 
     307             : /* fd_eqvoc_proof_query queries for the proof at (slot, from). */
     308             : 
     309             : FD_FN_PURE static inline fd_eqvoc_proof_t *
     310           0 : fd_eqvoc_proof_query( fd_eqvoc_t * eqvoc, ulong slot, fd_pubkey_t const * from ) {
     311           0 :   fd_slot_pubkey_t key = { slot, *from };
     312           0 :   return fd_eqvoc_proof_map_ele_query( eqvoc->proof_map, &key, NULL, eqvoc->proof_pool );
     313           0 : }
     314             : 
     315             : /* fd_eqvoc_proof_query_const is the const version of the above. */
     316             : 
     317             : FD_FN_PURE static inline fd_eqvoc_proof_t const *
     318           0 : fd_eqvoc_proof_query_const( fd_eqvoc_t const * eqvoc, ulong slot, fd_pubkey_t const * from ) {
     319           0 :   fd_slot_pubkey_t key = { slot, *from };
     320           0 :   return fd_eqvoc_proof_map_ele_query_const( eqvoc->proof_map, &key, NULL, eqvoc->proof_pool );
     321           0 : }
     322             : 
     323             : /* fd_eqvoc_proof_insert inserts a proof entry into eqvoc, keyed by
     324             :    (slot, from) where from is the pubkey that generated the proof. */
     325             : 
     326             : fd_eqvoc_proof_t *
     327             : fd_eqvoc_proof_insert( fd_eqvoc_t * eqvoc, ulong slot, fd_pubkey_t const * from );
     328             : 
     329             : void
     330             : fd_eqvoc_proof_init( fd_eqvoc_proof_t * proof, fd_pubkey_t const * producer, ulong wallclock, ulong chunk_cnt, ulong chunk_sz, void * bmtree_mem );
     331             : 
     332             : /* fd_eqvoc_proof_chunk_insert inserts a proof chunk into the proof.
     333             :    Proofs are divided into chunks before they are transmitted via
     334             :    gossip, so this function is necessary for reconstruction. */
     335             : 
     336             : void
     337             : fd_eqvoc_proof_chunk_insert( fd_eqvoc_proof_t * proof, fd_gossip_duplicate_shred_t const * chunk );
     338             : 
     339             : /* fd_eqvoc_shreds_chunk_insert is a lower-level API for the above. */
     340             : 
     341             : void
     342             : fd_eqvoc_shreds_chunk_insert( fd_shred_t * shred1, fd_shred_t * shred2, fd_gossip_duplicate_shred_t const * chunk );
     343             : 
     344             : /* fd_eqvoc_proof_remove removes the proof entry associated with key. */
     345             : 
     346             : void
     347             : fd_eqvoc_proof_remove( fd_eqvoc_t * eqvoc, fd_slot_pubkey_t const * key );
     348             : 
     349             : /* fd_eqvoc_proof_complete checks whether the proof has received all
     350             :    chunks ie. is complete.  Returns 1 if so, 0 otherwise. */
     351             : 
     352             : static inline int
     353           0 : fd_eqvoc_proof_complete( fd_eqvoc_proof_t const * proof ) {
     354           0 :   for( uchar i = 0; i < proof->chunk_cnt; i++ ) {
     355           0 :     if( !fd_eqvoc_proof_set_test( proof->set, i ) ) return 0;
     356           0 :   }
     357           0 :   return 1;
     358           0 : }
     359             : 
     360             : /* fd_eqvoc_proof_verify verifies that the two shreds contained in
     361             :    `proof` do in fact equivocate.
     362             : 
     363             :    Returns: FD_EQVOC_VERIFY_FAILURE if they do not
     364             :      FD_EQVOC_VERIFY_SUCCESS_{REASON} if they do
     365             :      FD_EQVOC_VERIFY_ERR_{REASON} if the shreds were not valid inputs
     366             : 
     367             :    Two shreds equivocate if they satisfy any of the following:
     368             : 
     369             :    1. They are in the same FEC set but have different signatures.
     370             :    2. They are in the same FEC set and are both coding shreds, but have
     371             :       different coding metadata ie. code_cnt, data_cnt, first_code_idx.
     372             :    3. They are in the same FEC set and are both data shreds.  One shred
     373             :       is marked as the last data shred in the slot
     374             :       (FD_SHRED_DATA_FLAG_SLOT_COMPLETE), but the other shred has a
     375             :       higher data shred index.
     376             :    4. They are in different FEC sets and the shred with a lower FEC set
     377             :       index is a coding shred, whereas the shred with the higher FEC set
     378             :       index is either a coding or data shred.  The lower coding shred's
     379             :       `data_cnt` implies the lower FEC set intersects with the higher
     380             :       FEC set ie. the FEC sets are overlapping.
     381             :    5. They are in different FEC sets and the shred with a lower FEC set
     382             :       index is a coding shred, and the FEC sets are adjacent ie. the
     383             :       last data shred index in the lower FEC set is one less than the
     384             :       first data shred index in the higher FEC set.  The merkle root of
     385             :       the lower FEC set is different from the chained merkle root of the
     386             :       higher FEC set.
     387             : 
     388             :    Note: two shreds are in the same FEC set if they have the same slot
     389             :    and same FEC set index.
     390             : 
     391             :    To prevent false positives, this function also performs the following
     392             :    input validation on the shreds:
     393             : 
     394             :    1. shred1 and shred2 are both the expected shred_version.
     395             :    2. shred1 and shred2 are for the same slot.
     396             :    3. shred1 and shred2 are either chained merkle or chained resigned
     397             :       merkle variants.
     398             :    4. shred1 and shred2 contain valid signatures signed by the same
     399             :       producer pubkey.
     400             : 
     401             :    If any of the above input validation fail, this function returns
     402             :    FD_EQVOC_VERIFY_ERR_{REASON} for the appropriate reason. */
     403             : 
     404             : int
     405             : fd_eqvoc_proof_verify( fd_eqvoc_proof_t const * proof );
     406             : 
     407             : /* fd_eqvoc_proof_shreds_verify is a lower-level API for
     408             :    fd_eqvoc_proof_verify.  Refer above for documentation.  */
     409             : 
     410             : int
     411             : fd_eqvoc_shreds_verify( fd_shred_t const * shred1, fd_shred_t const * shred2, fd_pubkey_t const * producer, void * bmtree_mem );
     412             : 
     413             : /* fd_eqvoc_proof_shred1 returns a pointer to shred1 in `proof`. */
     414             : 
     415             : static inline fd_shred_t *
     416           0 : fd_eqvoc_proof_shred1( fd_eqvoc_proof_t * proof ) {
     417           0 :   return (fd_shred_t *)fd_type_pun_const( proof->shreds + sizeof(ulong) );
     418           0 : }
     419             : 
     420             : /* fd_eqvoc_proof_shred1_const returns a const pointer to shred1 in
     421             :    `proof`. */
     422             : 
     423             : static inline fd_shred_t const *
     424           0 : fd_eqvoc_proof_shred1_const( fd_eqvoc_proof_t const * proof ) {
     425           0 :   return (fd_shred_t const *)fd_type_pun_const( proof->shreds + sizeof(ulong) );
     426           0 : }
     427             : 
     428             : /* fd_eqvoc_proof_shred2 returns a pointer to shred2 in `proof`. */
     429             : 
     430             : static inline fd_shred_t *
     431           0 : fd_eqvoc_proof_shred2( fd_eqvoc_proof_t * proof ) {
     432           0 :   ulong shred1_sz = *(ulong *)fd_type_pun( proof->shreds );
     433           0 :   return (fd_shred_t *)fd_type_pun( proof->shreds + shred1_sz + 2*sizeof(ulong) );
     434           0 : }
     435             : 
     436             : /* fd_eqvoc_proof_shred2_const returns a const pointer to shred2 in `proof`. */
     437             : 
     438             : static inline fd_shred_t const *
     439           0 : fd_eqvoc_proof_shred2_const( fd_eqvoc_proof_t const * proof ) {
     440           0 :   ulong shred1_sz = *(ulong const *)fd_type_pun_const( proof->shreds );
     441           0 :   return (fd_shred_t const *)fd_type_pun_const( proof->shreds + shred1_sz + 2*sizeof(ulong) );
     442           0 : }
     443             : 
     444             : /* fd_eqvoc_verify verifies `slot` has FEC sets with merkle roots that
     445             :    correctly chain, including that the first FEC set in slot's merkle
     446             :    hash chains from the last FEC set in parent slot's merkle hash. */
     447             : 
     448             : int
     449             : fd_eqvoc_slot_verify( fd_eqvoc_t const * eqvoc, fd_blockstore_t * blockstore, ulong slot );
     450             : 
     451             : /* fd_eqvoc_from_chunks reconstructs shred1_out and shred2_out from
     452             :    `chunks` which is an array of "duplicate shred" gossip msgs. Shred1
     453             :    and shred2 comprise a "duplicate shred proof", ie. proof of two
     454             :    shreds that conflict and therefore demonstrate the shreds' producer
     455             :    has equivocated.
     456             : 
     457             :    Assumes `chunks` is non-NULL and contains at least one valid array
     458             :    member chunks[0] to extract header information.  Caller's
     459             :    responsibility to guarantee this.  Also assumes the `chunk` field in
     460             :    `fd_gossip_duplicate_shred_t` is a pointer to valid memory and
     461             :    consistent with the metadata presented in the header of the first
     462             :    array member, eg. if the header says there are 4 chunks then this
     463             :    implementation assumes this is true.  These assumptions should be
     464             :    already upheld by caller if using deserializers in `fd_types.h`.
     465             :    Behavior is undefined otherwise.
     466             : 
     467             :    Does additional sanity-check validation eg. checking chunk_len <=
     468             :    FD_eqvoc_proof_MAX.
     469             : 
     470             :    This function is expected to be deprecated once chunks are specified
     471             :    to be fixed-length in the gossip protocol. */
     472             : 
     473             : void
     474             : fd_eqvoc_proof_from_chunks( fd_gossip_duplicate_shred_t const * chunks,
     475             :                             fd_eqvoc_proof_t * proof_out );
     476             : 
     477             : /* fd_eqvoc_to_chunks constructs an array of DuplicateShred gossip msgs
     478             :    (`chunks_out`) from shred1 and shred2.
     479             : 
     480             :    Shred1 and shred2 are concatenated (the concatenation is implemented
     481             :    virtually) and then spliced into chunks of FD_EQVOC_PROOF_CHUNK_MAX
     482             :    size. These chunks are embedded in the body of each DuplicateShred
     483             :    msg, along with a common header across all msgs.
     484             : 
     485             :    Caller supplies `chunks_out`, which is an array that MUST contain
     486             :    `ceil(shred1_payload_sz + shred2_payload_sz /
     487             :    FD_EQVOC_PROOF_CHUNK_MAX)` elements.  Each chunk in `chunks_out` MUST
     488             :    have a buffer of at least `chunk_len` size available in its `chunk`
     489             :    pointer field.  Behavior is undefined otherwise.
     490             : 
     491             :    IMPORTANT SAFETY TIP!  The lifetime of each chunk in `chunks_out`
     492             :    must be at least as long as the lifetime of the array of
     493             :    duplicate_shreds.  Caller is responsible for ensuring this memory
     494             :    safety guarantee. */
     495             : 
     496             : void
     497             : fd_eqvoc_proof_to_chunks( fd_eqvoc_proof_t * proof, fd_gossip_duplicate_shred_t * chunks_out );
     498             : 
     499             : #endif /* HEADER_fd_src_choreo_eqvoc_fd_eqvoc_h */

Generated by: LCOV version 1.14