LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_vote_program.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 76 1315 5.8 %
Date: 2026-07-01 06:01:22 Functions: 4 27 14.8 %

          Line data    Source code
       1             : #include "fd_vote_program.h"
       2             : #include "../fd_runtime.h"
       3             : #include "../fd_borrowed_account.h"
       4             : #include "../fd_executor.h"
       5             : #include "../fd_pubkey_utils.h"
       6             : #include "../sysvar/fd_sysvar_rent.h"
       7             : #include "../sysvar/fd_sysvar_cache.h"
       8             : #include "../sysvar/fd_sysvar.h"
       9             : #include "../fd_system_ids.h"
      10             : #include "vote/fd_authorized_voters.h"
      11             : #include "vote/fd_vote_utils.h"
      12             : #include "vote/fd_vote_codec.h"
      13             : #include "vote/fd_vote_state_versioned.h"
      14             : #include "vote/fd_vote_state_v4.h"
      15             : #include "../../../ballet/bls/fd_bls12_381.h"
      16             : 
      17             : #include <limits.h>
      18             : #include <math.h>
      19             : #include <stdio.h>
      20             : #include <string.h>
      21             : 
      22             : // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L36
      23           0 : #define INITIAL_LOCKOUT 2UL
      24             : 
      25             : // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L51
      26             : #define VOTE_CREDITS_MAXIMUM_PER_SLOT_OLD 8
      27             : 
      28             : // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/clock.rs#L147
      29             : #define SLOT_DEFAULT 0UL
      30             : 
      31             : // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/clock.rs#L147
      32             : #define SLOT_MAX ULONG_MAX
      33             : 
      34             : #define ACCOUNTS_MAX 4 /* Vote instructions take in at most 4 accounts */
      35             : 
      36             : #define DEFAULT_COMPUTE_UNITS 2100UL
      37             : #define COMPUTE_UNITS_POP    34500UL
      38             : 
      39             : /**********************************************************************/
      40             : /* VoteStateHandler                                                   */
      41             : /**********************************************************************/
      42             : 
      43             : /* Check the vote state, deserialize it as V4 and convert older versions
      44             :    to V4 in-place.
      45             :    https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_state/mod.rs#L45-L77 */
      46             : static int
      47             : get_vote_state_handler_checked( fd_borrowed_account_t const * vote_account,
      48             :                                 int                           target_version,
      49             :                                 uchar                         check_initialized,
      50           0 :                                 fd_vote_state_versioned_t *   vote_state_versioned ) {
      51           0 :   (void)target_version;
      52           0 :   (void)check_initialized; /* V4 vote states are always initialized */
      53             : 
      54           0 :   int rc = fd_vsv_deserialize( vote_account->acc, vote_state_versioned );
      55           0 :   if( FD_UNLIKELY( rc ) ) return rc;
      56             : 
      57           0 :   if( FD_UNLIKELY( fd_vsv_is_uninitialized( vote_state_versioned ) ) ) {
      58           0 :     return FD_EXECUTOR_INSTR_ERR_UNINITIALIZED_ACCOUNT;
      59           0 :   }
      60             : 
      61           0 :   rc = fd_vsv_try_convert_to_v4( vote_state_versioned, (fd_pubkey_t*)vote_account->acc->pubkey );
      62           0 :   if( FD_UNLIKELY( rc ) ) return rc;
      63             : 
      64           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
      65           0 : }
      66             : 
      67             : /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_state/handler.rs#L379-L393 */
      68             : static int
      69             : check_vote_account_length( fd_borrowed_account_t const * vote_account,
      70           6 :                            int                           target_version ) {
      71           6 :   (void)target_version;
      72           6 :   ulong length = fd_borrowed_account_get_data_len( vote_account );
      73           6 :   if( FD_UNLIKELY( length!=FD_VOTE_STATE_V4_SZ ) ) {
      74           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA;
      75           0 :   }
      76           6 :   return FD_EXECUTOR_INSTR_SUCCESS;
      77           6 : }
      78             : 
      79             : /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_state/handler.rs#L327-L342 */
      80             : static int
      81             : init_vote_account_state( fd_exec_instr_ctx_t *         ctx,
      82             :                          fd_borrowed_account_t *       vote_account,
      83             :                          fd_vote_state_versioned_t *   versioned,
      84             :                          int                           target_version,
      85             :                          fd_vote_init_t *              vote_init,
      86           6 :                          fd_sol_sysvar_clock_t const * clock ) {
      87           6 :   (void)target_version;
      88           6 :   fd_vote_state_v4_create_new_with_defaults( (fd_pubkey_t*)vote_account->acc->pubkey, vote_init, clock, versioned );
      89           6 :   return fd_vote_state_v4_set_vote_account_state( ctx, vote_account, versioned );
      90           6 : }
      91             : 
      92             : /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_state/handler.rs#L344-L362 */
      93             : static int
      94             : init_vote_account_state_v2( fd_exec_instr_ctx_t *         ctx,
      95             :                             fd_borrowed_account_t *       vote_account,
      96             :                             fd_vote_state_versioned_t *   versioned,
      97             :                             int                           target_version,
      98             :                             fd_vote_init_v2_t *           vote_init_v2,
      99           0 :                             fd_sol_sysvar_clock_t const * clock ) {
     100           0 :   (void)target_version;
     101           0 :   fd_vote_state_v4_create_new( vote_init_v2, clock, versioned );
     102           0 :   return fd_vote_state_v4_set_vote_account_state( ctx, vote_account, versioned );
     103           0 : }
     104             : 
     105             : /**********************************************************************/
     106             : /* mod vote_state                                                    */
     107             : /**********************************************************************/
     108             : 
     109             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L82-L324 */
     110             : static int
     111             : check_and_filter_proposed_vote_state( fd_exec_instr_ctx_t *       ctx,
     112             :                                       fd_vote_state_versioned_t * versioned,
     113             :                                       fd_vote_lockout_t *         proposed_lockouts,
     114             :                                       uchar *                     proposed_has_root,
     115             :                                       ulong *                     proposed_root,
     116             :                                       fd_hash_t const *           proposed_hash,
     117           0 :                                       fd_slot_hashes_t const *    slot_hashes ) {
     118           0 :   fd_landed_vote_t const * votes         = fd_vsv_get_votes( versioned );
     119           0 :   ulong const *            root_slot     = fd_vsv_get_root_slot( versioned );
     120           0 :   uchar                    has_root_slot = !!(root_slot!=NULL);
     121             : 
     122             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L208
     123           0 :   if( FD_UNLIKELY( deq_fd_vote_lockout_t_empty( proposed_lockouts ) ) ) {
     124           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_EMPTY_SLOTS;
     125           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     126           0 :   }
     127           0 :   fd_landed_vote_t const * last_vote = NULL;
     128           0 :   if( !deq_fd_landed_vote_t_empty( votes ) ) {
     129             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L212
     130           0 :     last_vote = deq_fd_landed_vote_t_peek_tail_const( votes );
     131           0 :   }
     132             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L218
     133           0 :   if( FD_LIKELY( last_vote ) ) {
     134           0 :     if( FD_UNLIKELY( deq_fd_vote_lockout_t_peek_tail_const( proposed_lockouts )->slot <=
     135           0 :                      last_vote->lockout.slot ) ) {
     136           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_VOTE_TOO_OLD;
     137           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     138           0 :     }
     139           0 :   }
     140             : 
     141             :   /* must be nonempty, checked above */
     142           0 :   ulong last_vote_state_update_slot = deq_fd_vote_lockout_t_peek_tail_const( proposed_lockouts )->slot;
     143             : 
     144             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L224
     145           0 :   if( FD_UNLIKELY( !slot_hashes->cnt ) ) {
     146           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_MISMATCH;
     147           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     148           0 :   }
     149             : 
     150             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L227
     151           0 :   ulong earliest_slot_hash_in_history = slot_hashes->elems[ slot_hashes->cnt-1UL ].slot;
     152             : 
     153             :   /* Check if the proposed vote is too old to be in the SlotHash history */
     154             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L230
     155           0 :   if( FD_UNLIKELY( last_vote_state_update_slot < earliest_slot_hash_in_history ) ) {
     156           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_VOTE_TOO_OLD;
     157           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     158           0 :   }
     159             : 
     160             :   /* Check if the proposed root is too old */
     161             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L237
     162           0 :   if( *proposed_has_root ) {
     163           0 :     ulong const proposed_root_ = *proposed_root;
     164             :     /* If the new proposed root `R` is less than the earliest slot hash in the history
     165             :        such that we cannot verify whether the slot was actually was on this fork, set
     166             :        the root to the latest vote in the current vote that's less than R. */
     167             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L242
     168           0 :     if( proposed_root_ < earliest_slot_hash_in_history ) {
     169           0 :       *proposed_has_root = has_root_slot;
     170           0 :       if( has_root_slot ) {
     171           0 :         *proposed_root   = *root_slot;
     172           0 :       }
     173           0 :       for( deq_fd_landed_vote_t_iter_t iter = deq_fd_landed_vote_t_iter_init_rev( votes );
     174           0 :                                              !deq_fd_landed_vote_t_iter_done_rev( votes, iter );
     175           0 :                                        iter = deq_fd_landed_vote_t_iter_prev( votes, iter ) ) {
     176             :         /* Ensure we're iterating from biggest to smallest vote in the
     177             :            current vote state */
     178           0 :         fd_landed_vote_t const * vote = deq_fd_landed_vote_t_iter_ele_const( votes, iter );
     179             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L248
     180           0 :         if( vote->lockout.slot <= proposed_root_ ) {
     181           0 :           *proposed_has_root = 1;
     182           0 :           *proposed_root     = vote->lockout.slot;
     183           0 :           break;
     184           0 :         }
     185           0 :       }
     186           0 :     }
     187           0 :   }
     188             : 
     189             :   /* Index into the new proposed vote state's slots, starting with the root if it exists then
     190             :      we use this mutable root to fold checking the root slot into the below loop for performance */
     191           0 :   int   has_root_to_check       = *proposed_has_root;
     192             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L259
     193           0 :   ulong root_to_check           = *proposed_root;
     194           0 :   ulong proposed_lockouts_index = 0UL;
     195           0 :   ulong lockouts_len = deq_fd_vote_lockout_t_cnt( proposed_lockouts );
     196             : 
     197             :   /* Index into the slot_hashes, starting at the oldest known slot hash */
     198             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L264
     199           0 :   ulong slot_hashes_index = slot_hashes->cnt;
     200             : 
     201             :   /* proposed_lockouts_indexes_to_filter's size is bounded by the length
     202             :      of the proposed lockouts provided in the instruction data. */
     203           0 :   ulong proposed_lockouts_indexes_to_filter[ FD_VOTE_INSTR_MAX_LOCKOUT_OFFSETS_LEN ];
     204           0 :   ulong filter_index = 0UL;
     205             : 
     206             :   /* Note:
     207             : 
     208             :     1) `vote_state_update.lockouts` is sorted from oldest/smallest vote to newest/largest
     209             :     vote, due to the way votes are applied to the vote state (newest votes
     210             :     pushed to the back).
     211             : 
     212             :     2) Conversely, `slot_hashes` is sorted from newest/largest vote to
     213             :     the oldest/smallest vote.
     214             : 
     215             :     Unlike for vote updates, vote state updates here can't only check votes older than the last vote
     216             :     because have to ensure that every slot is actually part of the history, not just the most
     217             :     recent ones */
     218             : 
     219             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L279
     220           0 :   while( proposed_lockouts_index < lockouts_len && slot_hashes_index > 0 ) {
     221           0 :     ulong proposed_vote_slot =
     222           0 :       fd_ulong_if( has_root_to_check,
     223             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L281
     224           0 :         root_to_check,
     225             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L283
     226           0 :         deq_fd_vote_lockout_t_peek_index_const( proposed_lockouts,
     227           0 :           proposed_lockouts_index )
     228           0 :         ->slot );
     229             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L285
     230           0 :     if( !has_root_to_check && proposed_lockouts_index > 0UL &&
     231           0 :       proposed_vote_slot <=
     232           0 :       deq_fd_vote_lockout_t_peek_index_const(
     233           0 :         proposed_lockouts,
     234           0 :           fd_ulong_checked_sub_expect(
     235           0 :             proposed_lockouts_index,
     236           0 :               1,
     237           0 :               "`proposed_lockouts_index` is positive when checking `SlotsNotOrdered`" ) )
     238           0 :       ->slot ) {
     239             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L293
     240           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_NOT_ORDERED;
     241           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     242           0 :     }
     243             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L295
     244           0 :     ulong ancestor_slot =
     245           0 :       slot_hashes->elems[
     246           0 :           fd_ulong_checked_sub_expect(
     247           0 :             slot_hashes_index,
     248           0 :               1UL,
     249           0 :               "`slot_hashes_index` is positive when computing `ancestor_slot`" ) ]
     250           0 :       .slot;
     251             :     /* Find if this slot in the proposed vote state exists in the SlotHashes history
     252             :        to confirm if it was a valid ancestor on this fork */
     253             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L303
     254           0 :     if( proposed_vote_slot < ancestor_slot ) {
     255           0 :       if( slot_hashes_index == slot_hashes->cnt ) {
     256             :         /* The vote slot does not exist in the SlotHashes history because it's too old,
     257             :            i.e. older than the oldest slot in the history. */
     258           0 :         if( proposed_vote_slot >= earliest_slot_hash_in_history ) {
     259           0 :           ctx->txn_out->err.custom_err = 0;
     260           0 :           return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     261           0 :         }
     262             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L310
     263           0 :         if( !fd_vote_contains_slot( votes, proposed_vote_slot ) && !has_root_to_check ) {
     264             :           /* If the vote slot is both:
     265             :              1) Too old
     266             :              2) Doesn't already exist in vote state
     267             :              Then filter it out */
     268           0 :           proposed_lockouts_indexes_to_filter[filter_index++] = proposed_lockouts_index;        }
     269             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L318
     270           0 :         if( has_root_to_check ) {
     271           0 :           ulong new_proposed_root = root_to_check;
     272             :           /* 1. Because `root_to_check.is_some()`, then we know that
     273             :              we haven't checked the root yet in this loop, so
     274             :              `proposed_vote_slot` == `new_proposed_root` == `vote_state_update.root` */
     275           0 :           FD_TEST( new_proposed_root == proposed_vote_slot );
     276             :           /* 2. We know from the assert earlier in the function that
     277             :              `proposed_vote_slot < earliest_slot_hash_in_history`,
     278             :              so from 1. we know that `new_proposed_root < earliest_slot_hash_in_history` */
     279           0 :           if( new_proposed_root >= earliest_slot_hash_in_history ) {
     280           0 :             ctx->txn_out->err.custom_err = 0;
     281           0 :             return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     282           0 :           }
     283             : 
     284             :           // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L329
     285           0 :           has_root_to_check = 0;
     286           0 :           root_to_check     = ULONG_MAX;
     287           0 :         } else {
     288             :           // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L331
     289           0 :           proposed_lockouts_index = fd_ulong_checked_add_expect(
     290           0 :             proposed_lockouts_index,
     291           0 :               1,
     292           0 :               "`proposed_lockouts_index` is bounded by `MAX_LOCKOUT_HISTORY` when "
     293           0 :               "`proposed_vote_slot` is too old to be in SlotHashes history" );
     294           0 :         }
     295           0 :         continue;
     296           0 :       } else {
     297             :         /* If the vote slot is new enough to be in the slot history,
     298             :            but is not part of the slot history, then it must belong to another fork,
     299             :            which means this vote state update is invalid. */
     300             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L340
     301           0 :         if( has_root_to_check ) {
     302           0 :           ctx->txn_out->err.custom_err = FD_VOTE_ERR_ROOT_ON_DIFFERENT_FORK;
     303           0 :           return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     304           0 :         } else {
     305           0 :           ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_MISMATCH;
     306           0 :           return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     307           0 :         }
     308           0 :       }
     309           0 :     } else if( proposed_vote_slot > ancestor_slot ) {
     310             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L347
     311             : 
     312             :       /* Decrement `slot_hashes_index` to find newer slots in the SlotHashes history */
     313           0 :       slot_hashes_index = fd_ulong_checked_sub_expect(
     314           0 :         slot_hashes_index,
     315           0 :           1,
     316           0 :           "`slot_hashes_index` is positive when finding newer slots in SlotHashes history" );
     317           0 :       continue;
     318           0 :     } else {
     319             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L354
     320             : 
     321             :       /* Once the slot in `vote_state_update.lockouts` is found, bump to the next slot
     322             :          in `vote_state_update.lockouts` and continue. If we were checking the root,
     323             :          start checking the vote state instead. */
     324           0 :       if( has_root_to_check ) {
     325           0 :         has_root_to_check = 0;
     326           0 :         root_to_check     = ULONG_MAX;
     327           0 :       } else {
     328           0 :         proposed_lockouts_index = fd_ulong_checked_add_expect(
     329           0 :           proposed_lockouts_index,
     330           0 :             1,
     331           0 :             "`proposed_lockouts_index` is bounded by `MAX_LOCKOUT_HISTORY` "
     332           0 :             "when match is found in SlotHashes history" );
     333           0 :         slot_hashes_index = fd_ulong_checked_sub_expect(
     334           0 :           slot_hashes_index,
     335           0 :             1,
     336           0 :             "`slot_hashes_index` is positive when match is found in SlotHashes history" );
     337           0 :       }
     338           0 :     }
     339           0 :   }
     340             : 
     341             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L372
     342           0 :   if( proposed_lockouts_index != deq_fd_vote_lockout_t_cnt( proposed_lockouts ) ) {
     343             :     /* The last vote slot in the update did not exist in SlotHashes */
     344           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_MISMATCH;
     345           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     346           0 :   }
     347             : 
     348             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L401
     349           0 :   if( memcmp( &slot_hashes->elems[ slot_hashes_index ].hash,
     350           0 :       proposed_hash,
     351           0 :       sizeof( fd_hash_t ) ) != 0 ) {
     352             :     /* This means the newest vote in the slot has a match that
     353             :        doesn't match the expected hash for that slot on this fork */
     354           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_HASH_MISMATCH;
     355           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     356           0 :   }
     357             : 
     358             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L418
     359             :   /* Filter out the irrelevant votes */
     360           0 :   proposed_lockouts_index = 0UL;
     361           0 :   ulong filter_votes_index = deq_fd_vote_lockout_t_cnt( proposed_lockouts );
     362             : 
     363             :   /* We need to iterate backwards here because proposed_lockouts_indexes_to_filter[ i ] is a
     364             :      strictly increasing value. Forward iterating can lead to the proposed lockout indicies to get
     365             :      shifted leading to popping the wrong proposed lockouts or out of bounds accessing. We need
     366             :      to be sure of handling underflow in this case. */
     367             : 
     368           0 :   for( ulong i=filter_index; i>0UL && filter_votes_index>0UL; i-- ) {
     369           0 :     proposed_lockouts_index = i - 1UL;
     370           0 :     if( FD_UNLIKELY( proposed_lockouts_indexes_to_filter[ proposed_lockouts_index ]>=filter_votes_index ) ) {
     371           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_PROGRAM_ID;
     372           0 :     }
     373             : 
     374           0 :     deq_fd_vote_lockout_t_pop_idx_tail( proposed_lockouts, proposed_lockouts_indexes_to_filter[ proposed_lockouts_index ] );
     375           0 :     filter_votes_index--;
     376           0 :   }
     377             : 
     378           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
     379           0 : }
     380             : 
     381             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L440
     382             : static int
     383             : check_slots_are_valid( fd_exec_instr_ctx_t *       ctx,
     384             :                        fd_vote_state_versioned_t * versioned,
     385             :                        ulong const *               vote_slots,
     386             :                        fd_hash_t const *           vote_hash,
     387           0 :                        fd_slot_hashes_t const *    slot_hashes ) {
     388           0 :   ulong i              = 0;
     389           0 :   ulong j              = slot_hashes->cnt;
     390           0 :   ulong vote_slots_len = deq_ulong_cnt( vote_slots );
     391             : 
     392             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L462
     393           0 :   while( i < vote_slots_len && j > 0 ) {
     394           0 :     ulong const * last_voted_slot_ = fd_vsv_get_last_voted_slot( versioned );
     395           0 :     if( FD_UNLIKELY( last_voted_slot_ &&
     396           0 :                      *deq_ulong_peek_index_const( vote_slots, i ) <= *last_voted_slot_ ) ) {
     397             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L469
     398           0 :       i = fd_ulong_checked_add_expect(
     399           0 :           i, 1, "`i` is bounded by `MAX_LOCKOUT_HISTORY` when finding larger slots" );
     400           0 :       continue;
     401           0 :     }
     402             : 
     403             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L476
     404           0 :     if( FD_UNLIKELY(
     405           0 :             *deq_ulong_peek_index_const( vote_slots, i ) !=
     406           0 :             slot_hashes->elems[
     407           0 :               fd_ulong_checked_sub_expect( j, 1, "`j` is positive" ) ]
     408           0 :                 .slot ) ) {
     409           0 :       j = fd_ulong_checked_sub_expect( j, 1, "`j` is positive when finding newer slots" );
     410           0 :       continue;
     411           0 :     }
     412             : 
     413             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L486
     414           0 :     i = fd_ulong_checked_add_expect(
     415           0 :         i, 1, "`i` is bounded by `MAX_LOCKOUT_HISTORY` when hash is found" );
     416           0 :     j = fd_ulong_checked_sub_expect( j, 1, "`j` is positive when hash is found" );
     417           0 :   }
     418             : 
     419             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L494
     420           0 :   if( FD_UNLIKELY( j == slot_hashes->cnt ) ) {
     421           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_VOTE_TOO_OLD;
     422           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     423           0 :   }
     424           0 :   if( FD_UNLIKELY( i != vote_slots_len ) ) {
     425           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_MISMATCH;
     426           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     427           0 :   }
     428             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L514
     429           0 :   if( FD_UNLIKELY( 0 != memcmp( &slot_hashes->elems[ j ].hash,
     430           0 :                                 vote_hash,
     431           0 :                                 32UL ) ) ) {
     432           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_HASH_MISMATCH;
     433           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     434           0 :   }
     435           0 :   return 0;
     436           0 : }
     437             : 
     438             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L565
     439             : static int
     440             : process_new_vote_state( fd_exec_instr_ctx_t *       ctx,
     441             :                         fd_vote_state_versioned_t * versioned,
     442             :                         fd_landed_vote_t *          new_state,
     443             :                         int                         has_new_root,
     444             :                         ulong                       new_root,
     445             :                         int                         has_timestamp,
     446             :                         long                        timestamp,
     447             :                         ulong                       epoch,
     448           0 :                         ulong                       current_slot ) {
     449           0 :   int rc;
     450           0 :   fd_landed_vote_t * votes         = fd_vsv_get_votes_mutable( versioned );
     451           0 :   ulong const *      root_slot     = fd_vsv_get_root_slot( versioned );
     452           0 :   uchar              has_root_slot = !!(root_slot!=NULL);
     453             : 
     454           0 :   FD_TEST( !deq_fd_landed_vote_t_empty( new_state ) );
     455             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L575
     456           0 :   if( FD_UNLIKELY( deq_fd_landed_vote_t_cnt( new_state ) > MAX_LOCKOUT_HISTORY ) ) {
     457           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_TOO_MANY_VOTES;
     458           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     459           0 :   };
     460             : 
     461             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L579
     462           0 :   if( FD_UNLIKELY( has_new_root && has_root_slot ) ) {
     463             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L581
     464           0 :     if( FD_UNLIKELY( new_root<*root_slot ) ) {
     465           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_ROOT_ROLL_BACK;
     466           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     467           0 :     }
     468           0 :   } else if( FD_UNLIKELY( !has_new_root && has_root_slot ) ) {
     469             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L586
     470           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_ROOT_ROLL_BACK;
     471           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     472           0 :   } else {
     473             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L588
     474             :     /* no-op */
     475           0 :   }
     476             : 
     477           0 :   fd_landed_vote_t * previous_vote = NULL;
     478           0 :   for( deq_fd_landed_vote_t_iter_t iter = deq_fd_landed_vote_t_iter_init( new_state );
     479           0 :        !deq_fd_landed_vote_t_iter_done( new_state, iter );
     480           0 :        iter = deq_fd_landed_vote_t_iter_next( new_state, iter ) ) {
     481           0 :     fd_landed_vote_t * vote = deq_fd_landed_vote_t_iter_ele( new_state, iter );
     482           0 :     if( FD_LIKELY( vote->lockout.confirmation_count == 0 ) ) {
     483           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_ZERO_CONFIRMATIONS;
     484           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     485           0 :     } else if( FD_UNLIKELY( vote->lockout.confirmation_count > MAX_LOCKOUT_HISTORY ) ) {
     486           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_CONFIRMATION_TOO_LARGE;
     487           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     488           0 :     } else if( FD_LIKELY( has_new_root ) ) {
     489           0 :       if( FD_UNLIKELY( vote->lockout.slot <= new_root && new_root != SLOT_DEFAULT ) ) {
     490           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOT_SMALLER_THAN_ROOT;
     491           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     492           0 :       }
     493           0 :     }
     494             : 
     495           0 :     if( FD_LIKELY( previous_vote ) ) {
     496           0 :       if( FD_UNLIKELY( previous_vote->lockout.slot >= vote->lockout.slot ) ) {
     497           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_SLOTS_NOT_ORDERED;
     498           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     499           0 :       } else if( FD_UNLIKELY( previous_vote->lockout.confirmation_count <=
     500           0 :                               vote->lockout.confirmation_count ) ) {
     501           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_CONFIRMATIONS_NOT_ORDERED;
     502           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     503           0 :       } else if( FD_UNLIKELY( vote->lockout.slot >
     504           0 :                               fd_vote_lockout_last_locked_out_slot( &previous_vote->lockout ) ) ) {
     505           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_NEW_VOTE_STATE_LOCKOUT_MISMATCH;
     506           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     507           0 :       }
     508           0 :     }
     509           0 :     previous_vote = vote;
     510           0 :   }
     511             : 
     512           0 :   ulong current_vote_state_index = 0;
     513           0 :   ulong new_vote_state_index     = 0;
     514             : 
     515             :   /* Accumulate credits earned by newly rooted slots.  The behavior changes with
     516             :      timely_vote_credits: prior to this feature, there was a bug that counted a new root slot as 1
     517             :      credit even if it had never been voted on. timely_vote_credits fixes this bug by only awarding
     518             :      credits for slots actually voted on and finalized. */
     519             : 
     520             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L635
     521             : 
     522             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L641
     523           0 :   ulong earned_credits      = 0;
     524             : 
     525           0 :   if( FD_LIKELY( has_new_root ) ) {
     526           0 :     for( deq_fd_landed_vote_t_iter_t iter = deq_fd_landed_vote_t_iter_init( votes );
     527           0 :                                            !deq_fd_landed_vote_t_iter_done( votes, iter );
     528           0 :                                      iter = deq_fd_landed_vote_t_iter_next( votes, iter ) ) {
     529           0 :       fd_landed_vote_t const * current_vote = deq_fd_landed_vote_t_iter_ele_const( votes, iter );
     530             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L647
     531           0 :       if( FD_UNLIKELY( current_vote->lockout.slot <= new_root ) ) {
     532             :         // this is safe because we're inside if has_new_root
     533           0 :         earned_credits = fd_ulong_checked_add_expect(
     534           0 :             fd_vote_credits_for_vote_at_index(
     535           0 :                 votes,
     536           0 :                 current_vote_state_index
     537           0 :             ),
     538           0 :             earned_credits,
     539           0 :             "`earned_credits` does not overflow" );
     540           0 :         current_vote_state_index = fd_ulong_checked_add_expect(
     541           0 :             current_vote_state_index,
     542           0 :             1,
     543           0 :             "`current_vote_state_index` is bounded by `MAX_LOCKOUT_HISTORY` "
     544           0 :             "when processing new root" );
     545           0 :         continue;
     546           0 :       }
     547           0 :       break;
     548           0 :     }
     549           0 :   }
     550             : 
     551             :   // For any slots newly added to the new vote state, the vote latency of that slot is not provided by the
     552             :   // vote instruction contents, but instead is computed from the actual latency of the vote
     553             :   // instruction. This prevents other validators from manipulating their own vote latencies within their vote states
     554             :   // and forcing the rest of the cluster to accept these possibly fraudulent latency values.  If the
     555             :   // timly_vote_credits feature is not enabled then vote latency is set to 0 for new votes.
     556             :   //
     557             :   // For any slot that is in both the new state and the current state, the vote latency of the new state is taken
     558             :   // from the current state.
     559             :   //
     560             :   // Thus vote latencies are set here for any newly vote-on slots when a vote instruction is received.
     561             :   // They are copied into the new vote state after every vote for already voted-on slots.
     562             :   // And when voted-on slots are rooted, the vote latencies stored in the vote state of all the rooted slots is used
     563             :   // to compute credits earned.
     564             :   // All validators compute the same vote latencies because all process the same vote instruction at the
     565             :   // same slot, and the only time vote latencies are ever computed is at the time that their slot is first voted on;
     566             :   // after that, the latencies are retained unaltered until the slot is rooted.
     567             : 
     568             :   // All the votes in our current vote state that are missing from the new vote state
     569             :   // must have been expired by later votes. Check that the lockouts match this assumption.
     570             : 
     571             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L686
     572           0 :   while( current_vote_state_index < deq_fd_landed_vote_t_cnt( votes ) &&
     573           0 :          new_vote_state_index < deq_fd_landed_vote_t_cnt( new_state ) ) {
     574           0 :     fd_landed_vote_t const * current_vote = deq_fd_landed_vote_t_peek_index_const( votes, current_vote_state_index );
     575             : 
     576             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L690
     577           0 :     fd_landed_vote_t * new_vote =
     578           0 :         deq_fd_landed_vote_t_peek_index( new_state, new_vote_state_index );
     579             : 
     580             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L696
     581           0 :     if( FD_LIKELY( current_vote->lockout.slot < new_vote->lockout.slot ) ) {
     582             :       /* The agave implementation of calculating the last locked out
     583             :          slot does not calculate a min between the current vote's
     584             :          confirmation count and max lockout history. The reason we do
     585             :          this is to make sure that the fuzzers continue working:
     586             :          the max lockout history can not be > MAX_LOCKOUT_HISTORY. */
     587           0 :       ulong confirmation_count   = fd_ulong_min( current_vote->lockout.confirmation_count, MAX_LOCKOUT_HISTORY );
     588           0 :       ulong last_locked_out_slot = fd_ulong_sat_add( current_vote->lockout.slot,
     589           0 :                                                      (ulong)pow( INITIAL_LOCKOUT, (double)confirmation_count ) );
     590             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L697
     591           0 :       if( last_locked_out_slot >= new_vote->lockout.slot ) {
     592             :         // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L698
     593           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_LOCKOUT_CONFLICT;
     594           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     595           0 :       }
     596             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L700
     597           0 :       current_vote_state_index =
     598           0 :           fd_ulong_checked_add_expect( current_vote_state_index,
     599           0 :                                        1,
     600           0 :                                        "`current_vote_state_index` is bounded by "
     601           0 :                                        "`MAX_LOCKOUT_HISTORY` when slot is less than proposed" );
     602             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L704
     603           0 :     } else if( FD_UNLIKELY( current_vote->lockout.slot == new_vote->lockout.slot ) ) {
     604             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L707
     605           0 :       if( new_vote->lockout.confirmation_count < current_vote->lockout.confirmation_count ) {
     606           0 :         ctx->txn_out->err.custom_err = FD_VOTE_ERR_CONFIRMATION_ROLL_BACK;
     607           0 :         return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     608           0 :       }
     609             : 
     610             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L712
     611           0 :       new_vote->latency = deq_fd_landed_vote_t_peek_index_const( votes, current_vote_state_index )->latency;
     612             : 
     613             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L714
     614           0 :       current_vote_state_index =
     615           0 :           fd_ulong_checked_add_expect( current_vote_state_index,
     616           0 :                                        1,
     617           0 :                                        "`current_vote_state_index` is bounded by "
     618           0 :                                        "`MAX_LOCKOUT_HISTORY` when slot is equal to proposed" );
     619             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L717
     620           0 :       new_vote_state_index =
     621           0 :           fd_ulong_checked_add_expect( new_vote_state_index,
     622           0 :                                        1,
     623           0 :                                        "`new_vote_state_index` is bounded by `MAX_LOCKOUT_HISTORY` "
     624           0 :                                        "when slot is equal to proposed" );
     625           0 :     } else {
     626             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L722
     627           0 :       new_vote_state_index =
     628           0 :           fd_ulong_checked_add_expect( new_vote_state_index,
     629           0 :                                        1,
     630           0 :                                        "`new_vote_state_index` is bounded by `MAX_LOCKOUT_HISTORY` "
     631           0 :                                        "when slot is greater than proposed" );
     632           0 :     }
     633           0 :   }
     634             : 
     635             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L737
     636           0 :   for( deq_fd_landed_vote_t_iter_t iter = deq_fd_landed_vote_t_iter_init( new_state );
     637           0 :         !deq_fd_landed_vote_t_iter_done( new_state, iter );
     638           0 :         iter = deq_fd_landed_vote_t_iter_next( new_state, iter ) ) {
     639           0 :     fd_landed_vote_t * new_vote = deq_fd_landed_vote_t_iter_ele( new_state, iter );
     640             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L738
     641           0 :     if( FD_UNLIKELY( new_vote->latency == 0 ) ) {
     642             :       // this is unlikely because as validators upgrade, it should converge to the new vote state
     643             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L739
     644           0 :       new_vote->latency = fd_vote_compute_vote_latency( new_vote->lockout.slot, current_slot );
     645           0 :     }
     646           0 :   }
     647             : 
     648             :   // doesn't matter what the value of slot if `is_some = 0` i.e. `Option::None`
     649             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L744
     650           0 :   int both_none = !has_root_slot && !has_new_root;
     651           0 :   if( ( !both_none && ( has_root_slot!=has_new_root ||
     652           0 :                         *root_slot!=new_root ) ) ) {
     653           0 :     fd_vsv_increment_credits( versioned, epoch, earned_credits );
     654           0 :   }
     655             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L750
     656           0 :   if( FD_LIKELY( has_timestamp ) ) {
     657             :     /* new_state asserted nonempty at function beginning */
     658           0 :     if( FD_UNLIKELY( deq_fd_landed_vote_t_empty( new_state ) ) ) {
     659           0 :       FD_LOG_CRIT(( "invariant violation: landed votes is empty" ));
     660           0 :     }
     661           0 :     ulong last_slot = deq_fd_landed_vote_t_peek_tail( new_state )->lockout.slot;
     662           0 :     rc              = fd_vsv_process_timestamp( ctx, versioned, last_slot, timestamp );
     663           0 :     if( FD_UNLIKELY( rc ) ) { return rc; }
     664           0 :   }
     665             : 
     666             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L754
     667           0 :   fd_vsv_set_root_slot( versioned, has_new_root ? &new_root : NULL );
     668             : 
     669             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L755
     670           0 :   deq_fd_landed_vote_t_remove_all( votes );
     671           0 :   for( deq_fd_landed_vote_t_iter_t iter = deq_fd_landed_vote_t_iter_init( new_state );
     672           0 :        !deq_fd_landed_vote_t_iter_done( new_state, iter );
     673           0 :        iter = deq_fd_landed_vote_t_iter_next( new_state, iter ) ) {
     674           0 :     fd_landed_vote_t * landed_vote = deq_fd_landed_vote_t_iter_ele( new_state, iter );
     675           0 :     deq_fd_landed_vote_t_push_tail_wrap( votes, *landed_vote );
     676           0 :   }
     677             : 
     678           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
     679           0 : }
     680             : 
     681             : __attribute__((weak)) int
     682             : fd_bls12_381_proof_of_possession_verify( uchar const msg[],
     683             :                                          ulong       msg_sz,
     684             :                                          uchar const proof[ static FD_BLS_PROOF_OF_POSSESSION_COMPRESSED_SZ ],
     685           0 :                                          uchar const public_key[ static FD_BLS_PUBKEY_COMPRESSED_SZ ] ) {
     686           0 :   (void)msg; (void)msg_sz; (void)proof; (void)public_key;
     687           0 :   FD_LOG_ERR(( "This build does not include BLST, which is required to run a validator.\n"
     688           0 :                "To install BLST, re-run ./deps.sh, make distclean, and make -j" ));
     689           0 : }
     690             : 
     691             : /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1059-L1108 */
     692             : #define FD_VOTE_BLS_MSG_SZ ( 9 + 32 + 48 )
     693             : static int
     694             : fd_vote_verify_bls_proof_of_possession( fd_exec_instr_ctx_t * ctx,
     695             :                                         uchar const           vote_account_pubkey[ static 32 ],
     696             :                                         uchar const           bls_pubkey[ static FD_BLS_PUBKEY_COMPRESSED_SZ ],
     697           0 :                                         uchar const           bls_proof[ static FD_BLS_PROOF_OF_POSSESSION_COMPRESSED_SZ ] ) {
     698             :   /* Consume CUs for proof of possession */
     699           0 :   FD_EXEC_CU_UPDATE( ctx, COMPUTE_UNITS_POP );
     700             : 
     701             :   /* Build message */
     702           0 :   uchar msg[ FD_VOTE_BLS_MSG_SZ ];
     703           0 :   memcpy( msg, "ALPENGLOW", 9 );
     704           0 :   memcpy( msg+9, vote_account_pubkey, 32 );
     705           0 :   memcpy( msg+9+32, bls_pubkey, 48 );
     706             : 
     707             :   /* Verify */
     708           0 :   if( FD_UNLIKELY( fd_bls12_381_proof_of_possession_verify(
     709           0 :     msg,
     710           0 :     FD_VOTE_BLS_MSG_SZ,
     711           0 :     bls_proof,
     712           0 :     bls_pubkey
     713           0 :   )!=FD_BLS_SUCCESS ) ) {
     714           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
     715           0 :   }
     716           0 :   return 0;
     717           0 : }
     718             : #undef FD_VOTE_BLS_MSG_SZ
     719             : 
     720             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L716-L759 */
     721             : static int
     722             : authorize( fd_exec_instr_ctx_t *         ctx,
     723             :            fd_borrowed_account_t *       vote_account,
     724             :            int                           target_version,
     725             :            fd_pubkey_t const *           authorized,
     726             :            fd_vote_authorize_t const *   vote_authorize,
     727             :            fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
     728             :            ulong                         signers_cnt,
     729             :            fd_sol_sysvar_clock_t const * clock,
     730           0 :            int                           is_vote_authorize_with_bls_enabled ) {
     731           0 :   fd_vote_state_versioned_t * vote_state_versioned = &ctx->runtime->vote_program.authorize.vote_state;
     732             : 
     733             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L724-L727 */
     734           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 0, vote_state_versioned );
     735           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     736             : 
     737             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L729-L756 */
     738           0 :   switch( vote_authorize->discriminant ) {
     739             : 
     740             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L730-L750 */
     741           0 :     case fd_vote_authorize_enum_voter: {
     742             : 
     743             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L741-L743 */
     744           0 :       if( FD_UNLIKELY( is_vote_authorize_with_bls_enabled && fd_vsv_has_bls_pubkey( vote_state_versioned ) ) ) {
     745           0 :         return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
     746           0 :       }
     747             : 
     748             :       /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L731-L732 */
     749           0 :       int authorized_withdrawer_signer = !fd_vote_verify_authorized_signer(
     750           0 :           fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     751           0 :           signers,
     752           0 :           signers_cnt
     753           0 :       );
     754             : 
     755             :       /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L737-L740 */
     756           0 :       ulong target_epoch;
     757           0 :       rc = fd_ulong_checked_add( clock->leader_schedule_epoch, 1UL, &target_epoch );
     758           0 :       if( FD_UNLIKELY( rc!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
     759           0 :         return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA;
     760           0 :       }
     761             : 
     762             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L747 */
     763           0 :       rc = fd_vsv_set_new_authorized_voter(
     764           0 :           ctx,
     765           0 :           vote_state_versioned,
     766           0 :           authorized,
     767           0 :           clock->epoch,
     768           0 :           target_epoch,
     769           0 :           NULL, /* no BLS pubkey */
     770           0 :           authorized_withdrawer_signer,
     771           0 :           signers,
     772           0 :           signers_cnt
     773           0 :       );
     774           0 :       if( FD_UNLIKELY( rc ) ) return rc;
     775           0 :       break;
     776           0 :     }
     777             : 
     778             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L751-L756 */
     779           0 :     case fd_vote_authorize_enum_withdrawer: {
     780           0 :       rc = fd_vote_verify_authorized_signer(
     781           0 :           fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     782           0 :           signers,
     783           0 :           signers_cnt
     784           0 :       );
     785           0 :       if( FD_UNLIKELY( rc ) ) return rc;
     786           0 :       fd_vsv_set_authorized_withdrawer( vote_state_versioned, authorized );
     787           0 :       break;
     788           0 :     }
     789             : 
     790             :     /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L770 */
     791           0 :     case fd_vote_authorize_enum_voter_with_bls: {
     792             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L771-L773 */
     793           0 :       if( FD_UNLIKELY( !is_vote_authorize_with_bls_enabled ) ) {
     794           0 :         return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
     795           0 :       }
     796             : 
     797             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L774-L775 */
     798           0 :       int authorized_withdrawer_signer = !fd_vote_verify_authorized_signer(
     799           0 :           fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     800           0 :           signers,
     801           0 :           signers_cnt
     802           0 :       );
     803             : 
     804             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L777-L782 */
     805           0 :       rc = fd_vote_verify_bls_proof_of_possession(
     806           0 :         ctx,
     807           0 :         vote_account->acc->pubkey,
     808           0 :         vote_authorize->voter_with_bls.bls_pubkey,
     809           0 :         vote_authorize->voter_with_bls.bls_proof_of_possession
     810           0 :       );
     811           0 :       if( FD_UNLIKELY( rc ) ) {
     812           0 :         return rc;
     813           0 :       }
     814             : 
     815             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L787-L790 */
     816           0 :       ulong target_epoch;
     817           0 :       rc = fd_ulong_checked_add( clock->leader_schedule_epoch, 1UL, &target_epoch );
     818           0 :       if( FD_UNLIKELY( rc!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
     819           0 :         return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA;
     820           0 :       }
     821             : 
     822             :       /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L784 */
     823           0 :       rc = fd_vsv_set_new_authorized_voter(
     824           0 :           ctx,
     825           0 :           vote_state_versioned,
     826           0 :           authorized,
     827           0 :           clock->epoch,
     828           0 :           target_epoch,
     829           0 :           vote_authorize->voter_with_bls.bls_pubkey,
     830           0 :           authorized_withdrawer_signer,
     831           0 :           signers,
     832           0 :           signers_cnt
     833           0 :       );
     834           0 :       if( FD_UNLIKELY( rc ) ) return rc;
     835             : 
     836           0 :       break;
     837           0 :     }
     838             : 
     839           0 :     default:
     840           0 :       FD_LOG_CRIT(( "unsupported vote_authorize discriminant: %u", vote_authorize->discriminant ));
     841           0 :   }
     842             : 
     843             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L758 */
     844           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, vote_state_versioned );
     845           0 : }
     846             : 
     847             : /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L808-L835 */
     848             : static int
     849             : update_validator_identity( fd_exec_instr_ctx_t *   ctx,
     850             :                            int                     target_version,
     851             :                            fd_borrowed_account_t * vote_account,
     852             :                            fd_pubkey_t const *     node_pubkey,
     853             :                            fd_pubkey_t const *     signers[static FD_TXN_SIG_MAX],
     854             :                            ulong                   signers_cnt,
     855           0 :                            int                     custom_commission_collector_enabled ) {
     856           0 :   fd_vote_state_versioned_t * vote_state_versioned = &ctx->runtime->vote_program.update_validator_identity.vote_state;
     857             : 
     858             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L768-L771 */
     859           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 0, vote_state_versioned );
     860           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     861             : 
     862             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L774 */
     863           0 :   rc = fd_vote_verify_authorized_signer(
     864           0 :       fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     865           0 :       signers,
     866           0 :       signers_cnt
     867           0 :   );
     868           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     869             : 
     870             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L777 */
     871           0 :   rc = fd_vote_verify_authorized_signer( node_pubkey, signers, signers_cnt );
     872           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     873             : 
     874             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L826 */
     875           0 :   fd_vsv_set_node_pubkey( vote_state_versioned, node_pubkey );
     876             : 
     877             :   /* Before SIMD-0232, block_revenue_collector is always synced with node_pubkey.
     878             :      After SIMD-0232, the collector can be set independently.
     879             :      https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L828-L832 */
     880           0 :   if( !custom_commission_collector_enabled ) {
     881           0 :     fd_vsv_set_block_revenue_collector( vote_state_versioned, node_pubkey );
     882           0 :   }
     883             : 
     884             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L834 */
     885           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, vote_state_versioned );
     886           0 : }
     887             : 
     888             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L971
     889             : static int
     890           0 : is_commission_update_allowed( ulong slot, fd_epoch_schedule_t const * epoch_schedule ) {
     891           0 :   if( FD_LIKELY( epoch_schedule->slots_per_epoch > 0UL ) ) {
     892           0 :     ulong relative_slot = fd_ulong_sat_sub( slot, epoch_schedule->first_normal_slot );
     893             :     // TODO underflow and overflow edge cases in addition to div by 0
     894           0 :     relative_slot %= epoch_schedule->slots_per_epoch;
     895           0 :     return fd_ulong_sat_mul( relative_slot, 2 ) <= epoch_schedule->slots_per_epoch;
     896           0 :   } else {
     897           0 :     return 1;
     898           0 :   }
     899           0 : }
     900             : 
     901             : /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L838-L869 */
     902             : static int
     903             : update_commission( fd_exec_instr_ctx_t *         ctx,
     904             :                    int                           target_version,
     905             :                    fd_borrowed_account_t *       vote_account,
     906             :                    uchar                         commission,
     907             :                    fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
     908             :                    ulong                         signers_cnt,
     909             :                    fd_epoch_schedule_t const *   epoch_schedule,
     910             :                    fd_sol_sysvar_clock_t const * clock,
     911           0 :                    int                           disable_commission_update_rule ) {
     912             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L796-L799 */
     913           0 :   int rc         = 0;
     914           0 :   int get_vsv_rc = get_vote_state_handler_checked(
     915           0 :       vote_account,
     916           0 :       target_version,
     917           0 :       false,
     918           0 :       &ctx->runtime->vote_program.update_commission.vote_state
     919           0 :   );
     920             : 
     921             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L851-L855 */
     922           0 :   fd_vote_state_versioned_t * vote_state_versioned           = NULL;
     923           0 :   int                         enforce_commission_update_rule = !disable_commission_update_rule;
     924           0 :   if( FD_LIKELY( get_vsv_rc==FD_EXECUTOR_INSTR_SUCCESS ) ) {
     925           0 :     vote_state_versioned           = &ctx->runtime->vote_program.update_commission.vote_state;
     926           0 :     enforce_commission_update_rule = (!disable_commission_update_rule) && (commission>fd_vsv_get_commission( vote_state_versioned ));
     927           0 :   }
     928             : 
     929             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L806-L808 */
     930           0 :   if( FD_UNLIKELY( enforce_commission_update_rule && !is_commission_update_allowed( clock->slot, epoch_schedule ) ) ) {
     931           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_COMMISSION_UPDATE_TOO_LATE;
     932           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     933           0 :   }
     934             : 
     935             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L810 */
     936           0 :   if( FD_UNLIKELY( get_vsv_rc ) ) return get_vsv_rc;
     937             : 
     938             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L813 */
     939           0 :   rc = fd_vote_verify_authorized_signer(
     940           0 :       fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     941           0 :       signers,
     942           0 :       signers_cnt
     943           0 :   );
     944           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     945             : 
     946             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L815 */
     947           0 :   fd_vsv_set_commission( vote_state_versioned, commission );
     948             : 
     949             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L817 */
     950           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, vote_state_versioned );
     951           0 : }
     952             : 
     953             : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.6/programs/vote/src/vote_state/mod.rs#L871-L906 */
     954             : static int
     955             : update_commission_bps( fd_exec_instr_ctx_t *                    ctx,
     956             :                        fd_borrowed_account_t *                  vote_account,
     957             :                        int                                      target_version,
     958             :                        fd_update_commission_bps_args_t const *  args,
     959             :                        fd_pubkey_t const *                      signers[static FD_TXN_SIG_MAX],
     960             :                        ulong                                    signers_cnt,
     961           0 :                        int                                      block_revenue_sharing ) {
     962           0 :   fd_vote_state_versioned_t * vote_state_versioned = &ctx->runtime->vote_program.update_commission_bps.vote_state;
     963             : 
     964             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.6/programs/vote/src/vote_state/mod.rs#L882-L884 */
     965           0 :   if( FD_UNLIKELY( args->kind.discriminant==fd_commission_kind_enum_block_revenue && !block_revenue_sharing ) ) {
     966           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
     967           0 :   }
     968             : 
     969             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.6/programs/vote/src/vote_state/mod.rs#L886-L889 */
     970           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, false, vote_state_versioned );
     971           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     972             : 
     973             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.6/programs/vote/src/vote_state/mod.rs#L894 */
     974           0 :   rc = fd_vote_verify_authorized_signer(
     975           0 :     fd_vsv_get_authorized_withdrawer( vote_state_versioned ),
     976           0 :     signers,
     977           0 :     signers_cnt
     978           0 :   );
     979           0 :   if( FD_UNLIKELY( rc ) ) return rc;
     980             : 
     981             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.6/programs/vote/src/vote_state/mod.rs#L896-L903 */
     982           0 :   switch( args->kind.discriminant ) {
     983           0 :     case fd_commission_kind_enum_inflation_rewards: {
     984           0 :       fd_vsv_set_inflation_rewards_commission_bps( vote_state_versioned, args->commission_bps );
     985           0 :       break;
     986           0 :     }
     987           0 :     case fd_commission_kind_enum_block_revenue: {
     988           0 :       fd_vsv_set_block_revenue_commission_bps( vote_state_versioned, args->commission_bps );
     989           0 :       break;
     990           0 :     }
     991           0 :     default: {
     992           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
     993           0 :     }
     994           0 :   }
     995             : 
     996           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, vote_state_versioned );
     997           0 : }
     998             : 
     999             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L848C8-L903 */
    1000             : static int
    1001             : withdraw( fd_exec_instr_ctx_t *         ctx,
    1002             :           fd_borrowed_account_t *       vote_account,
    1003             :           int                           target_version,
    1004             :           ulong                         lamports,
    1005             :           ushort                        to_account_index,
    1006             :           fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1007             :           ulong                         signers_cnt,
    1008             :           fd_rent_t const *             rent_sysvar,
    1009             :           fd_sol_sysvar_clock_t const * clock,
    1010           0 :           int *                         deinitialized ) {
    1011           0 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.withdraw.vote_state;
    1012           0 :   *deinitialized = 0;
    1013             : 
    1014             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L860-L863 */
    1015           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 0, versioned );
    1016           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1017             : 
    1018             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L865 */
    1019           0 :   rc = fd_vote_verify_authorized_signer(
    1020           0 :       fd_vsv_get_authorized_withdrawer( versioned ),
    1021           0 :       signers,
    1022           0 :       signers_cnt
    1023           0 :   );
    1024           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1025             : 
    1026             :   /* Always zero until SIMD-0123 is activated.
    1027             :      https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1136 */
    1028           0 :   ulong pending_delegator_rewards = fd_vsv_get_pending_delegator_rewards( versioned );
    1029             : 
    1030             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L867-L870 */
    1031           0 :   ulong vote_account_lamports = fd_borrowed_account_get_lamports( vote_account );
    1032           0 :   if( FD_UNLIKELY( lamports>vote_account_lamports ) ) {
    1033           0 :     return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS;
    1034           0 :   }
    1035           0 :   ulong remaining_balance = vote_account_lamports-lamports;
    1036             : 
    1037             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L872-L896 */
    1038           0 :   if( FD_UNLIKELY( remaining_balance==0UL ) ) {
    1039             :     /* SIMD-0123: vote account cannot be closed if pending_delegator_rewards > 0.
    1040             :        https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1139-L1143 */
    1041           0 :     if( FD_UNLIKELY( pending_delegator_rewards > 0 ) ) {
    1042           0 :       return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS;
    1043           0 :     }
    1044             : 
    1045             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L873-L883 */
    1046           0 :     fd_vote_epoch_credits_t const * epoch_credits = fd_vsv_get_epoch_credits( versioned );
    1047           0 :     ulong                           last_epoch_with_credits;
    1048           0 :     int                             reject_active_vote_account_close = 0;
    1049           0 :     if( FD_LIKELY( !deq_fd_vote_epoch_credits_t_empty( epoch_credits ) ) ) {
    1050           0 :       ulong current_epoch              = clock->epoch;
    1051           0 :       last_epoch_with_credits          = deq_fd_vote_epoch_credits_t_peek_tail_const( epoch_credits )->epoch;
    1052           0 :       reject_active_vote_account_close = fd_ulong_sat_sub( current_epoch, last_epoch_with_credits )<2UL;
    1053           0 :     }
    1054             : 
    1055             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L885-L890 */
    1056           0 :     if( FD_UNLIKELY( reject_active_vote_account_close ) ) {
    1057           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_ACTIVE_VOTE_ACCOUNT_CLOSE;
    1058           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
    1059           0 :     } else {
    1060           0 :       rc = fd_vsv_deinitialize_vote_account_state(
    1061           0 :           ctx,
    1062           0 :           vote_account,
    1063           0 :           target_version
    1064           0 :       );
    1065           0 :       if( FD_UNLIKELY( rc ) ) return rc;
    1066           0 :       *deinitialized = 1;
    1067           0 :     }
    1068           0 :   } else {
    1069             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L892-L895 */
    1070           0 :     ulong min_rent_exempt_balance = fd_rent_exempt_minimum_balance( rent_sysvar, fd_borrowed_account_get_data_len( vote_account ) );
    1071             : 
    1072             :     /* SIMD-0123: withdrawable balance when pending_delegator_rewards > 0
    1073             :        is lamports - pending_delegator_rewards - rent_exempt_minimum.
    1074             :        https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1164-L1169 */
    1075           0 :     ulong min_balance;
    1076           0 :     if( FD_UNLIKELY( fd_ulong_checked_add( min_rent_exempt_balance, pending_delegator_rewards, &min_balance ) ) ) {
    1077           0 :       return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW;
    1078           0 :     }
    1079             : 
    1080           0 :     if( FD_UNLIKELY( remaining_balance<min_balance ) ) {
    1081           0 :       return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS;
    1082           0 :     }
    1083           0 :   }
    1084             : 
    1085             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L898 */
    1086           0 :   rc = fd_borrowed_account_checked_sub_lamports( vote_account, lamports );
    1087           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1088             : 
    1089             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L899 */
    1090           0 :   fd_borrowed_account_drop( vote_account );
    1091             : 
    1092             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L900 */
    1093           0 :   fd_guarded_borrowed_account_t to = {0};
    1094           0 :   FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( ctx, to_account_index, &to );
    1095             : 
    1096             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L901 */
    1097           0 :   rc = fd_borrowed_account_checked_add_lamports( &to, lamports );
    1098           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1099             : 
    1100           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
    1101           0 : }
    1102             : 
    1103             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L638-L651 */
    1104             : static int
    1105             : process_vote_unfiltered( fd_exec_instr_ctx_t *       ctx,
    1106             :                          fd_vote_state_versioned_t * versioned,
    1107             :                          ulong *                     vote_slots,
    1108             :                          fd_vote_t const *           vote,
    1109             :                          fd_slot_hashes_t const *    slot_hashes,
    1110             :                          ulong                       epoch,
    1111           0 :                          ulong                       current_slot ) {
    1112           0 :   int rc;
    1113             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L770
    1114           0 :   rc = check_slots_are_valid( ctx, versioned, vote_slots, &vote->hash, slot_hashes );
    1115           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1116           0 :   for( deq_ulong_iter_t iter = deq_ulong_iter_init( vote_slots );
    1117           0 :        !deq_ulong_iter_done( vote_slots, iter );
    1118           0 :        iter = deq_ulong_iter_next( vote_slots, iter ) ) {
    1119           0 :     ulong * ele = deq_ulong_iter_ele( vote_slots, iter );
    1120             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L772
    1121           0 :     fd_vsv_process_next_vote_slot( versioned, *ele, epoch, current_slot );
    1122           0 :   }
    1123           0 :   return 0;
    1124           0 : }
    1125             : 
    1126             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L783
    1127             : static int
    1128             : process_vote( fd_exec_instr_ctx_t *       ctx,
    1129             :               fd_vote_state_versioned_t * versioned,
    1130             :               fd_vote_t const *           vote,
    1131             :               fd_slot_hashes_t const *    slot_hashes,
    1132             :               ulong                       epoch,
    1133           0 :               ulong                       current_slot ) {
    1134             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L792
    1135           0 :   if( FD_UNLIKELY( deq_ulong_empty( vote->slots ) ) ) {
    1136           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_EMPTY_SLOTS;
    1137           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
    1138           0 :   }
    1139             : 
    1140             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L795
    1141           0 :   ulong earliest_slot_in_history = 0;
    1142           0 :   if( FD_UNLIKELY( !!slot_hashes->cnt ) ) {
    1143           0 :     earliest_slot_in_history = slot_hashes->elems[ slot_hashes->cnt-1UL ].slot;
    1144           0 :   }
    1145             : 
    1146             :   /* We know that the size of the vote_slots is bounded by the number of
    1147             :      slots that can fit inside of an instruction.  A very loose bound is
    1148             :      assuming that the entire transaction is just filled with a vote
    1149             :      slot deque (1232 bytes per transaction/8 bytes per slot) == 154
    1150             :      slots.  The footprint of a deque is as follows:
    1151             :      fd_ulong_align_up( fd_ulong_align_up( 32UL, alignof(DEQUE_T) ) + sizeof(DEQUE_T)*max, alignof(DEQUE_(private_t)) );
    1152             :      So, the footprint in our case is:
    1153             :      fd_ulong_align_up( fd_ulong_align_up( 32UL, alignof(ulong) ) + sizeof(ulong)*154, alignof(DEQUE_(private_t)) );
    1154             :      Which is equal to
    1155             :      fd_ulong_align_up( 32UL + 154 * 8UL, 8UL ) = 1264UL; */
    1156           0 :   #define VOTE_SLOTS_MAX             (FD_TXN_MTU/sizeof(ulong))
    1157           0 :   #define VOTE_SLOTS_DEQUE_FOOTPRINT (1264UL )
    1158           0 :   #define VOTE_SLOTS_DEQUE_ALIGN     (8UL)
    1159           0 :   FD_TEST( deq_ulong_footprint( VOTE_SLOTS_MAX ) == VOTE_SLOTS_DEQUE_FOOTPRINT );
    1160           0 :   FD_TEST( deq_ulong_align()                     == 8UL );
    1161           0 :   FD_TEST( deq_ulong_cnt( vote->slots )          <= VOTE_SLOTS_MAX );
    1162           0 :   uchar * vote_slots_mem[ VOTE_SLOTS_DEQUE_FOOTPRINT ] __attribute__((aligned(VOTE_SLOTS_DEQUE_ALIGN)));
    1163             : 
    1164             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L796
    1165           0 :   ulong * vote_slots = deq_ulong_join( deq_ulong_new( vote_slots_mem, deq_ulong_cnt( vote->slots ) ) );
    1166           0 :   for( deq_ulong_iter_t iter = deq_ulong_iter_init( vote->slots );
    1167           0 :        !deq_ulong_iter_done( vote->slots, iter );
    1168           0 :        iter = deq_ulong_iter_next( vote->slots, iter ) ) {
    1169           0 :     ulong * ele = deq_ulong_iter_ele( vote->slots, iter );
    1170           0 :     if( FD_UNLIKELY( *ele >= earliest_slot_in_history ) ) {
    1171           0 :       vote_slots = deq_ulong_push_tail_wrap( vote_slots, *ele );
    1172           0 :     }
    1173           0 :   }
    1174             : 
    1175             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L802
    1176           0 :   if( FD_UNLIKELY( deq_ulong_cnt( vote_slots ) == 0 ) ) {
    1177           0 :     ctx->txn_out->err.custom_err = FD_VOTE_ERR_VOTES_TOO_OLD_ALL_FILTERED;
    1178           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
    1179           0 :   }
    1180             : 
    1181             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L805
    1182           0 :   return process_vote_unfiltered(
    1183           0 :       ctx,
    1184           0 :       versioned,
    1185           0 :       vote_slots,
    1186           0 :       vote,
    1187           0 :       slot_hashes,
    1188           0 :       epoch,
    1189           0 :       current_slot
    1190           0 :   );
    1191           0 : }
    1192             : 
    1193             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L905-L926 */
    1194             : static int
    1195             : initialize_account( fd_exec_instr_ctx_t *         ctx,
    1196             :                     fd_borrowed_account_t *       vote_account,
    1197             :                     int                           target_version,
    1198             :                     fd_vote_init_t *              vote_init,
    1199             :                     fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1200             :                     ulong                         signers_cnt,
    1201           6 :                     fd_sol_sysvar_clock_t const * clock ) {
    1202           6 :   int rc;
    1203           6 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.init_account.vote_state;
    1204             : 
    1205             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L915 */
    1206           6 :   rc = check_vote_account_length( vote_account, target_version );
    1207           6 :   if( FD_UNLIKELY( rc ) ) return rc;
    1208             : 
    1209             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L916 */
    1210           6 :   rc = fd_vsv_get_state( vote_account->acc, versioned );
    1211           6 :   if( FD_UNLIKELY( rc ) ) return rc;
    1212             : 
    1213             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L918-L920 */
    1214           6 :   if( FD_UNLIKELY( !fd_vsv_is_uninitialized( versioned ) ) ) {
    1215           0 :     return FD_EXECUTOR_INSTR_ERR_ACC_ALREADY_INITIALIZED;
    1216           0 :   }
    1217             : 
    1218             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L923 */
    1219           6 :   rc = fd_vote_verify_authorized_signer( &vote_init->node_pubkey, signers, signers_cnt );
    1220           6 :   if( FD_UNLIKELY( rc ) ) {
    1221           0 :     return rc;
    1222           0 :   }
    1223             : 
    1224             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L925 */
    1225           6 :   return init_vote_account_state( ctx, vote_account, versioned, target_version, vote_init, clock );
    1226           6 : }
    1227             : 
    1228             : /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1182-L1216
    1229             :    Note: this is very similar to initialize_account() but also does verify_bls_proof_of_possession() */
    1230             : static int
    1231             : initialize_account_v2( fd_exec_instr_ctx_t *         ctx,
    1232             :                        fd_borrowed_account_t *       vote_account,
    1233             :                        int                           target_version,
    1234             :                        fd_vote_init_v2_t *           vote_init_v2,
    1235             :                        fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1236             :                        ulong                         signers_cnt,
    1237           0 :                        fd_sol_sysvar_clock_t const * clock ) {
    1238           0 :   int rc;
    1239           0 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.init_account.vote_state;
    1240             : 
    1241             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1198 */
    1242           0 :   rc = check_vote_account_length( vote_account, target_version );
    1243           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1244             : 
    1245           0 :   rc = fd_vsv_get_state( vote_account->acc, versioned );
    1246           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1247             : 
    1248           0 :   if( FD_UNLIKELY( !fd_vsv_is_uninitialized( versioned ) ) ) {
    1249           0 :     return FD_EXECUTOR_INSTR_ERR_ACC_ALREADY_INITIALIZED;
    1250           0 :   }
    1251             : 
    1252           0 :   rc = fd_vote_verify_authorized_signer( &vote_init_v2->node_pubkey, signers, signers_cnt );
    1253           0 :   if( FD_UNLIKELY( rc ) ) {
    1254           0 :     return rc;
    1255           0 :   }
    1256             : 
    1257             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1208-L1213 */
    1258           0 :   rc = fd_vote_verify_bls_proof_of_possession(
    1259           0 :     ctx,
    1260           0 :     vote_account->acc->pubkey,
    1261           0 :     vote_init_v2->authorized_voter_bls_pubkey,
    1262           0 :     vote_init_v2->authorized_voter_bls_proof_of_possession
    1263           0 :   );
    1264           0 :   if( FD_UNLIKELY( rc ) ) {
    1265           0 :     return rc;
    1266           0 :   }
    1267             : 
    1268             :   /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_state/mod.rs#L1215 */
    1269           0 :   return init_vote_account_state_v2( ctx, vote_account, versioned, target_version, vote_init_v2, clock );
    1270           0 : }
    1271             : 
    1272             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L928-L953 */
    1273             : static int
    1274             : process_vote_with_account( fd_exec_instr_ctx_t *         ctx,
    1275             :                            fd_borrowed_account_t *       vote_account,
    1276             :                            int                           target_version,
    1277             :                            fd_slot_hashes_t const *      slot_hashes,
    1278             :                            fd_sol_sysvar_clock_t const * clock,
    1279             :                            fd_vote_t *                   vote,
    1280             :                            fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1281           0 :                            ulong                         signers_cnt ) {
    1282           0 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.process_vote.vote_state;
    1283             : 
    1284             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L936-L939 */
    1285           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 1, versioned );
    1286           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1287             : 
    1288             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L941 */
    1289           0 :   fd_pubkey_t * authorized_voter = NULL;
    1290           0 :   rc = fd_authorized_voters_get_and_update_authorized_voter( versioned, clock->epoch, &authorized_voter );
    1291           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1292             : 
    1293             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L942 */
    1294           0 :   rc = fd_vote_verify_authorized_signer( authorized_voter, signers, signers_cnt );
    1295           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1296             : 
    1297             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L944 */
    1298           0 :   rc = process_vote( ctx, versioned, vote, slot_hashes, clock->epoch, clock->slot );
    1299           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1300             : 
    1301             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L945-L951 */
    1302           0 :   if( FD_LIKELY( vote->has_timestamp ) ) {
    1303             :     /* Calling max() on an empty iterator returns None */
    1304           0 :     if( FD_UNLIKELY( deq_ulong_cnt( vote->slots )==0 ) ) {
    1305           0 :       ctx->txn_out->err.custom_err = FD_VOTE_ERR_EMPTY_SLOTS;
    1306           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
    1307           0 :     }
    1308             : 
    1309             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L948 */
    1310           0 :     ulong max = 0UL;
    1311           0 :     for( deq_ulong_iter_t iter = deq_ulong_iter_init( vote->slots );
    1312           0 :                                 !deq_ulong_iter_done( vote->slots, iter );
    1313           0 :                           iter = deq_ulong_iter_next( vote->slots, iter ) ) {
    1314           0 :       ulong * ele = deq_ulong_iter_ele( vote->slots, iter );
    1315           0 :       max         = fd_ulong_max( max, *ele );
    1316           0 :     }
    1317             : 
    1318             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L950 */
    1319           0 :     rc = fd_vsv_process_timestamp( ctx, versioned, max, vote->timestamp );
    1320           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1321           0 :   }
    1322             : 
    1323             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L952 */
    1324           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, versioned );
    1325           0 : }
    1326             : 
    1327             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1156
    1328             : static int
    1329             : do_process_vote_state_update( fd_exec_instr_ctx_t *       ctx,
    1330             :                               fd_vote_state_versioned_t * versioned,
    1331             :                               fd_slot_hashes_t const *    slot_hashes,
    1332             :                               ulong                       epoch,
    1333             :                               ulong                       slot,
    1334           0 :                               fd_vote_state_update_t *    vote_state_update ) {
    1335           0 :   int rc;
    1336             : 
    1337             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1164
    1338           0 :   rc = check_and_filter_proposed_vote_state(
    1339           0 :       ctx,
    1340           0 :       versioned,
    1341           0 :       vote_state_update->lockouts,
    1342           0 :       &vote_state_update->has_root,
    1343           0 :       &vote_state_update->root,
    1344           0 :       &vote_state_update->hash,
    1345           0 :       slot_hashes
    1346           0 :   );
    1347           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1348             : 
    1349             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1177
    1350           0 :   fd_landed_vote_t * landed_votes = deq_fd_landed_vote_t_join( deq_fd_landed_vote_t_new( ctx->runtime->vote_program.process_vote.vs_update_landed_votes_mem, deq_fd_vote_lockout_t_cnt( vote_state_update->lockouts ) ) );
    1351           0 :   for( deq_fd_vote_lockout_t_iter_t iter =
    1352           0 :            deq_fd_vote_lockout_t_iter_init( vote_state_update->lockouts );
    1353           0 :        !deq_fd_vote_lockout_t_iter_done( vote_state_update->lockouts, iter );
    1354           0 :        iter = deq_fd_vote_lockout_t_iter_next( vote_state_update->lockouts, iter ) ) {
    1355           0 :     fd_vote_lockout_t * lockout =
    1356           0 :         deq_fd_vote_lockout_t_iter_ele( vote_state_update->lockouts, iter );
    1357           0 :     deq_fd_landed_vote_t_push_tail_wrap( landed_votes,
    1358           0 :                                     ( fd_landed_vote_t ){ .latency = 0, .lockout = *lockout } );
    1359           0 :   }
    1360             : 
    1361             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L1171
    1362           0 :   return process_new_vote_state(
    1363           0 :       ctx,
    1364           0 :       versioned,
    1365           0 :       landed_votes,
    1366           0 :       vote_state_update->has_root,
    1367           0 :       vote_state_update->root,
    1368           0 :       vote_state_update->has_timestamp,
    1369           0 :       vote_state_update->timestamp,
    1370           0 :       epoch,
    1371           0 :       slot
    1372           0 :   );
    1373           0 : }
    1374             : 
    1375             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L955-L979 */
    1376             : static int
    1377             : process_vote_state_update( fd_exec_instr_ctx_t *         ctx,
    1378             :                            fd_borrowed_account_t *       vote_account,
    1379             :                            int                           target_version,
    1380             :                            fd_slot_hashes_t const *      slot_hashes,
    1381             :                            fd_sol_sysvar_clock_t const * clock,
    1382             :                            fd_vote_state_update_t *      vote_state_update,
    1383             :                            fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1384           0 :                            ulong                         signers_cnt ) {
    1385           0 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.process_vote.vote_state;
    1386             : 
    1387             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L963-L966 */
    1388           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 1, versioned );
    1389           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1390             : 
    1391             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L968 */
    1392           0 :   fd_pubkey_t * authorized_voter = NULL;
    1393           0 :   rc = fd_authorized_voters_get_and_update_authorized_voter( versioned, clock->epoch, &authorized_voter );
    1394           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1395             : 
    1396             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L969 */
    1397           0 :   rc = fd_vote_verify_authorized_signer( authorized_voter, signers, signers_cnt );
    1398           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1399             : 
    1400             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L971-L977 */
    1401           0 :   rc = do_process_vote_state_update(
    1402           0 :       ctx,
    1403           0 :       versioned,
    1404           0 :       slot_hashes,
    1405           0 :       clock->epoch,
    1406           0 :       clock->slot,
    1407           0 :       vote_state_update
    1408           0 :   );
    1409           0 :   if( FD_UNLIKELY( rc ) ) {
    1410           0 :     return rc;
    1411           0 :   }
    1412             : 
    1413             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L978 */
    1414           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, versioned );
    1415           0 : }
    1416             : 
    1417             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1035-L1061 */
    1418             : static int
    1419             : do_process_tower_sync( fd_exec_instr_ctx_t *       ctx,
    1420             :                        fd_vote_state_versioned_t * versioned,
    1421             :                        fd_slot_hashes_t const *    slot_hashes,
    1422             :                        ulong                       epoch,
    1423             :                        ulong                       slot,
    1424           0 :                        fd_tower_sync_t *           tower_sync ) {
    1425             : 
    1426             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1042-L1048 */
    1427           0 :   int rc = check_and_filter_proposed_vote_state(
    1428           0 :       ctx,
    1429           0 :       versioned,
    1430           0 :       tower_sync->lockouts,
    1431           0 :       &tower_sync->has_root,
    1432           0 :       &tower_sync->root,
    1433           0 :       &tower_sync->hash,
    1434           0 :       slot_hashes
    1435           0 :   );
    1436           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1437             : 
    1438             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1049-L1060 */
    1439           0 :   return process_new_vote_state(
    1440           0 :       ctx,
    1441           0 :       versioned,
    1442           0 :       fd_vote_lockout_landed_votes_from_lockouts( tower_sync->lockouts, ctx->runtime->vote_program.tower_sync.tower_sync_landed_votes_mem ),
    1443           0 :       tower_sync->has_root,
    1444           0 :       tower_sync->root,
    1445           0 :       tower_sync->has_timestamp,
    1446           0 :       tower_sync->timestamp,
    1447           0 :       epoch,
    1448           0 :       slot
    1449           0 :   );
    1450           0 : }
    1451             : 
    1452             : /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1009-L1033 */
    1453             : static int
    1454             : process_tower_sync( fd_exec_instr_ctx_t *         ctx,
    1455             :                     fd_borrowed_account_t *       vote_account,
    1456             :                     int                           target_version,
    1457             :                     fd_slot_hashes_t const *      slot_hashes,
    1458             :                     fd_sol_sysvar_clock_t const * clock,
    1459             :                     fd_tower_sync_t *             tower_sync,
    1460             :                     fd_pubkey_t const *           signers[static FD_TXN_SIG_MAX],
    1461           0 :                     ulong                         signers_cnt ) {
    1462           0 :   fd_vote_state_versioned_t * versioned = &ctx->runtime->vote_program.tower_sync.vote_state;
    1463             : 
    1464             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1017-L1020 */
    1465           0 :   int rc = get_vote_state_handler_checked( vote_account, target_version, 1, versioned );
    1466           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1467             : 
    1468             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1022 */
    1469           0 :   fd_pubkey_t * authorized_voter = NULL;
    1470           0 :   rc = fd_authorized_voters_get_and_update_authorized_voter( versioned, clock->epoch, &authorized_voter );
    1471           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1472             : 
    1473             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1023 */
    1474           0 :   rc = fd_vote_verify_authorized_signer( authorized_voter, signers, signers_cnt );
    1475           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1476             : 
    1477             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1025-L1031 */
    1478           0 :   rc = do_process_tower_sync(
    1479           0 :       ctx,
    1480           0 :       versioned,
    1481           0 :       slot_hashes,
    1482           0 :       clock->epoch,
    1483           0 :       clock->slot,
    1484           0 :       tower_sync
    1485           0 :   );
    1486           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1487             : 
    1488             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_state/mod.rs#L1032 */
    1489           0 :   return fd_vsv_set_vote_account_state( ctx, vote_account, versioned );
    1490           0 : }
    1491             : 
    1492             : /**********************************************************************/
    1493             : /* FD-only encoders / decoders (doesn't map directly to Labs impl)    */
    1494             : /**********************************************************************/
    1495             : 
    1496             : int
    1497             : fd_vote_decode_compact_update( fd_compact_vote_state_update_t * compact_update,
    1498             :                                fd_vote_state_update_t *         vote_update,
    1499           0 :                                fd_exec_instr_ctx_t const *      ctx ) {
    1500             :   // Taken from:
    1501             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L954
    1502           0 :   if( compact_update->root != ULONG_MAX ) {
    1503           0 :     vote_update->has_root = 1;
    1504           0 :     vote_update->root     = compact_update->root;
    1505           0 :   } else {
    1506           0 :     vote_update->has_root = 0;
    1507           0 :     vote_update->root     = ULONG_MAX;
    1508           0 :   }
    1509             : 
    1510           0 :   ulong lockouts_len = compact_update->lockouts_len;
    1511           0 :   ulong lockouts_max = fd_ulong_max( lockouts_len, MAX_LOCKOUT_HISTORY );
    1512             : 
    1513           0 :   vote_update->lockouts = deq_fd_vote_lockout_t_join( deq_fd_vote_lockout_t_new( ctx->runtime->vote_program.process_vote.compact_vs_lockout_mem, lockouts_max ) );
    1514           0 :   ulong slot            = fd_ulong_if( vote_update->has_root, vote_update->root, 0 );
    1515             : 
    1516           0 :   for( ulong i=0; i < lockouts_len; ++i ) {
    1517           0 :     fd_vote_lockout_t *   elem        = deq_fd_vote_lockout_t_push_tail_nocopy( vote_update->lockouts );
    1518           0 :     fd_lockout_offset_t * lock_offset = &compact_update->lockouts[i];
    1519             : 
    1520           0 :     ulong next_slot;
    1521           0 :     if( FD_UNLIKELY( __builtin_uaddl_overflow( slot, lock_offset->offset, &next_slot ) ) ) {
    1522           0 :       return 0;
    1523           0 :     }
    1524             : 
    1525           0 :     elem->slot = slot        = next_slot;
    1526           0 :     elem->confirmation_count = (uint)lock_offset->confirmation_count;
    1527           0 :   }
    1528             : 
    1529           0 :   vote_update->hash          = compact_update->hash;
    1530           0 :   vote_update->has_timestamp = compact_update->has_timestamp;
    1531           0 :   vote_update->timestamp     = compact_update->timestamp;
    1532             : 
    1533           0 :   return 1;
    1534           0 : }
    1535             : 
    1536             : /**********************************************************************/
    1537             : /* mod vote_processor                                                 */
    1538             : /**********************************************************************/
    1539             : 
    1540             : /* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L21-L51 */
    1541             : static int
    1542             : process_authorize_with_seed_instruction( /* invoke_context */
    1543             :                                          fd_exec_instr_ctx_t *       ctx,
    1544             :                                          int                         target_version,
    1545             :                                          fd_borrowed_account_t *     vote_account,
    1546             :                                          fd_pubkey_t const *         new_authority,
    1547             :                                          fd_vote_authorize_t const * authorization_type,
    1548             :                                          fd_pubkey_t const *         current_authority_derived_key_owner,
    1549             :                                          uchar const *               current_authority_derived_key_seed,
    1550             :                                          ulong                       current_authority_derived_key_seed_len,
    1551           0 :                                          int                         is_vote_authorize_with_bls_enabled ) {
    1552           0 :   int rc = 0;
    1553             : 
    1554             :   /* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L31 */
    1555           0 :   rc = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_clock_id );
    1556           0 :   if( FD_UNLIKELY( rc ) ) return rc;
    1557             : 
    1558           0 :   fd_sol_sysvar_clock_t clock_;
    1559           0 :   fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1560           0 :   if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1561             : 
    1562           0 :   fd_pubkey_t * expected_authority_keys[FD_TXN_SIG_MAX] = { 0 };
    1563           0 :   ulong         expected_authority_keys_cnt             = 0UL;
    1564           0 :   fd_pubkey_t   single_signer                           = { 0 };
    1565             : 
    1566             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_processor.rs#L30-L42 */
    1567           0 :   if( fd_instr_acc_is_signer_idx( ctx->instr, 2, &rc ) ) {
    1568             : 
    1569             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_processor.rs#L31 */
    1570           0 :     fd_pubkey_t const * base_pubkey = NULL;
    1571           0 :     rc = fd_exec_instr_ctx_get_key_of_account_at_index( ctx, 2UL, &base_pubkey );
    1572           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1573             : 
    1574             :     /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_processor.rs#L34-L40 */
    1575           0 :     expected_authority_keys[0] = &single_signer;
    1576           0 :     rc = fd_pubkey_create_with_seed( ctx,
    1577           0 :                                      base_pubkey->uc,
    1578           0 :                                      (char const *)current_authority_derived_key_seed,
    1579           0 :                                      current_authority_derived_key_seed_len,
    1580           0 :                                      current_authority_derived_key_owner->uc,
    1581           0 :                                      /* insert */ expected_authority_keys[0]->uc );
    1582           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1583           0 :     expected_authority_keys_cnt = 1UL;
    1584           0 :   }
    1585             : 
    1586             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_processor.rs#L43-L50 */
    1587           0 :   return authorize(
    1588           0 :       ctx,
    1589           0 :       vote_account,
    1590           0 :       target_version,
    1591           0 :       new_authority,
    1592           0 :       authorization_type,
    1593           0 :       (fd_pubkey_t const **)expected_authority_keys,
    1594           0 :       expected_authority_keys_cnt,
    1595           0 :       clock,
    1596           0 :       is_vote_authorize_with_bls_enabled
    1597           0 :   );
    1598           0 : }
    1599             : 
    1600             : /**********************************************************************/
    1601             : /* Entry point for the Vote Program                                   */
    1602             : /**********************************************************************/
    1603             : 
    1604             : // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L57
    1605             : int
    1606          12 : fd_vote_program_execute( fd_exec_instr_ctx_t * ctx ) {
    1607             :   /* FD-specific init */
    1608          12 :   int rc = FD_EXECUTOR_INSTR_SUCCESS;
    1609             : 
    1610             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L57
    1611          12 :   FD_EXEC_CU_UPDATE( ctx, DEFAULT_COMPUTE_UNITS );
    1612             : 
    1613             :   /* https://github.com/anza-xyz/agave/blob/v3.1.1/programs/vote/src/vote_processor.rs#L64-L67 */
    1614          12 :   fd_guarded_borrowed_account_t me = {0};
    1615          12 :   FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( ctx, 0, &me );
    1616          12 :   if( FD_UNLIKELY( !fd_pubkey_eq( fd_borrowed_account_get_owner( &me ), &fd_solana_vote_program_id ) ) ) {
    1617           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_OWNER;
    1618           0 :   }
    1619             : 
    1620             :   /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_processor.rs#L118-L119 */
    1621          12 :   int target_version = VOTE_STATE_TARGET_VERSION_V4;
    1622             : 
    1623             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L69
    1624          12 :   fd_pubkey_t const * signers[FD_TXN_SIG_MAX] = { 0 };
    1625          12 :   ulong               signers_cnt             = 0UL;
    1626          12 :   fd_exec_instr_ctx_get_signers( ctx, signers, &signers_cnt );
    1627             : 
    1628             :   /* Some of these features are not implemented yet. As such, they are
    1629             :      not in feature_map.json.
    1630             : 
    1631             :      TODO: don't hardcode these when the features are implemented. */
    1632          12 :   int bls_pubkey_management_in_vote_account = FD_FEATURE_ACTIVE_BANK( ctx->bank, bls_pubkey_management_in_vote_account );
    1633          12 :   int delay_commission_updates              = FD_FEATURE_ACTIVE_BANK( ctx->bank, delay_commission_updates );
    1634          12 :   int commission_rate_in_basis_points       = FD_FEATURE_ACTIVE_BANK( ctx->bank, commission_rate_in_basis_points );
    1635          12 :   int custom_commission_collector           = 0;
    1636          12 :   int block_revenue_sharing                 = 0;
    1637          12 :   int vote_account_initialize_v2            = 0;
    1638             : 
    1639             :   /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_processor.rs#L72-L76 */
    1640          12 :   int is_vote_authorize_with_bls_enabled = bls_pubkey_management_in_vote_account;
    1641             : 
    1642             :   /* https://github.com/anza-xyz/agave/blob/v4.1.0-alpha.0/programs/vote/src/vote_processor.rs#L63-L70 */
    1643          12 :   int is_init_account_v2_enabled =
    1644          12 :       bls_pubkey_management_in_vote_account &&
    1645          12 :       commission_rate_in_basis_points &&
    1646          12 :       custom_commission_collector &&
    1647          12 :       block_revenue_sharing &&
    1648          12 :       vote_account_initialize_v2;
    1649             : 
    1650          12 :   fd_vote_instruction_t instruction[1];
    1651          12 :   if( FD_UNLIKELY( !fd_vote_instruction_deserialize( instruction, ctx->instr->data, fd_ulong_min( ctx->instr->data_sz, FD_TXN_MTU ) ) ) ) {
    1652           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    1653           0 :   }
    1654             : 
    1655             :   /* PLEASE PRESERVE SWITCH-CASE ORDERING TO MIRROR LABS IMPL:
    1656             :    */
    1657          12 :   switch( instruction->discriminant ) {
    1658             : 
    1659             :   /* InitializeAccount
    1660             :    *
    1661             :    * Instruction:
    1662             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L32
    1663             :    *
    1664             :    * Processor:
    1665             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L71
    1666             :    */
    1667           6 :   case fd_vote_instruction_enum_initialize_account: {
    1668             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L72
    1669           6 :     rc = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_rent_id );
    1670           6 :     if( FD_UNLIKELY( rc ) ) return rc;
    1671           6 :     fd_rent_t rent_;
    1672           6 :     fd_rent_t const * rent = fd_sysvar_cache_rent_read( ctx->sysvar_cache, &rent_ );
    1673           6 :     if( FD_UNLIKELY( !rent ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1674             : 
    1675           6 :     if( FD_UNLIKELY( fd_borrowed_account_get_lamports( &me ) <
    1676           6 :                      fd_rent_exempt_minimum_balance( rent, fd_borrowed_account_get_data_len( &me ) ) ) )
    1677           0 :       return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS;
    1678             : 
    1679             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L76
    1680           6 :     rc = fd_sysvar_instr_acct_check( ctx, 2, &fd_sysvar_clock_id );
    1681           6 :     if( FD_UNLIKELY( rc ) ) return rc;
    1682           6 :     fd_sol_sysvar_clock_t clock_;
    1683           6 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1684           6 :     if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1685             : 
    1686             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L78
    1687           6 :     rc = initialize_account( ctx, &me, target_version, &instruction->initialize_account, signers, signers_cnt, clock );
    1688             : 
    1689           6 :     if( FD_LIKELY( !rc ) ) {
    1690           6 :       ctx->txn_out->accounts.new_vote[ ctx->instr->accounts[0].index_in_transaction ] = 1;
    1691           6 :       ctx->txn_out->accounts.rm_vote[ ctx->instr->accounts[0].index_in_transaction ] = 0;
    1692           6 :     }
    1693             : 
    1694           6 :     break;
    1695           6 :   }
    1696             : 
    1697             :   /* Authorize
    1698             :    *
    1699             :    * Instruction:
    1700             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L40
    1701             :    *
    1702             :    * Processor:
    1703             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L86
    1704             :    *
    1705             :    * Notes:
    1706             :    * - Up to two signers: the vote authority and the authorized withdrawer.
    1707             :    */
    1708           0 :   case fd_vote_instruction_enum_authorize: {
    1709           0 :     fd_pubkey_t const * voter_pubkey   = &instruction->authorize.pubkey;
    1710             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L87
    1711           0 :     rc = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_clock_id );
    1712           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1713           0 :     fd_sol_sysvar_clock_t clock_;
    1714           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1715           0 :     if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1716             : 
    1717           0 :     rc = authorize( ctx, &me, target_version, voter_pubkey, &instruction->authorize.vote_authorize, signers, signers_cnt, clock, is_vote_authorize_with_bls_enabled );
    1718             : 
    1719           0 :     break;
    1720           0 :   }
    1721             : 
    1722             :   /* AuthorizeWithSeed
    1723             :    *
    1724             :    * Instruction:
    1725             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L117
    1726             :    *
    1727             :    * Processor:
    1728             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L98
    1729             :    */
    1730           0 :   case fd_vote_instruction_enum_authorize_with_seed: {
    1731           0 :     fd_vote_authorize_with_seed_args_t * args = &instruction->authorize_with_seed;
    1732             : 
    1733             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L99
    1734           0 :     if( FD_UNLIKELY( ctx->instr->acct_cnt < 3 ) ) {
    1735           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    1736           0 :       break;
    1737           0 :     }
    1738             : 
    1739           0 :     rc = process_authorize_with_seed_instruction(
    1740           0 :         ctx,
    1741           0 :         target_version,
    1742           0 :         &me,
    1743           0 :         &args->new_authority,
    1744           0 :         &args->authorization_type,
    1745           0 :         &args->current_authority_derived_key_owner,
    1746           0 :         args->current_authority_derived_key_seed,
    1747           0 :         args->current_authority_derived_key_seed_len,
    1748           0 :         is_vote_authorize_with_bls_enabled
    1749           0 :     );
    1750             : 
    1751           0 :     break;
    1752           0 :   }
    1753             : 
    1754             :   /* AuthorizeCheckedWithSeed
    1755             :    *
    1756             :    * Instruction:
    1757             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L131
    1758             :    *
    1759             :    * Processor:
    1760             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L111
    1761             :    */
    1762           0 :   case fd_vote_instruction_enum_authorize_checked_with_seed: {
    1763           0 :     fd_vote_authorize_checked_with_seed_args_t const * args = &instruction->authorize_checked_with_seed;
    1764             : 
    1765             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L112
    1766           0 :     if( FD_UNLIKELY( ctx->instr->acct_cnt < 4 ) ) {
    1767           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    1768           0 :       break;
    1769           0 :     }
    1770             : 
    1771             :     // https://github.com/anza-xyz/agave/blob/v2.1.14/programs/vote/src/vote_processor.rs#L99-L100
    1772           0 :     fd_pubkey_t const * new_authority = NULL;
    1773           0 :     rc = fd_exec_instr_ctx_get_key_of_account_at_index( ctx, 3UL, &new_authority );
    1774           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1775             : 
    1776             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L116
    1777           0 :     if( FD_UNLIKELY( !fd_instr_acc_is_signer_idx( ctx->instr, 3, &rc ) ) ) {
    1778             :       /* https://github.com/anza-xyz/agave/blob/v3.0.3/transaction-context/src/lib.rs#L789 */
    1779           0 :       if( FD_UNLIKELY( !!rc ) ) break;
    1780             :       // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L117
    1781           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_REQUIRED_SIGNATURE;
    1782           0 :       break;
    1783           0 :     }
    1784             : 
    1785             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L119
    1786           0 :     rc = process_authorize_with_seed_instruction(
    1787           0 :         ctx,
    1788           0 :         target_version,
    1789           0 :         &me,
    1790           0 :         new_authority,
    1791           0 :         &args->authorization_type,
    1792           0 :         &args->current_authority_derived_key_owner,
    1793           0 :         args->current_authority_derived_key_seed,
    1794           0 :         args->current_authority_derived_key_seed_len,
    1795           0 :         is_vote_authorize_with_bls_enabled );
    1796             : 
    1797           0 :     break;
    1798           0 :   }
    1799             : 
    1800             :   /* UpdateValidatorIdentity
    1801             :    *
    1802             :    * Instruction:
    1803             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L65
    1804             :    *
    1805             :    * Processor:
    1806             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L130
    1807             :    */
    1808           0 :   case fd_vote_instruction_enum_update_validator_identity: {
    1809             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L131
    1810           0 :     if( FD_UNLIKELY( ctx->instr->acct_cnt < 2 ) ) {
    1811           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    1812           0 :       break;
    1813           0 :     }
    1814             : 
    1815             :     // https://github.com/anza-xyz/agave/blob/v2.1.14/programs/vote/src/vote_processor.rs#L118-L120
    1816           0 :     fd_pubkey_t const * node_pubkey = NULL;
    1817           0 :     rc = fd_exec_instr_ctx_get_key_of_account_at_index( ctx, 1UL, &node_pubkey );
    1818           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    1819             : 
    1820             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L135
    1821           0 :     rc = update_validator_identity( ctx, target_version, &me, node_pubkey, signers, signers_cnt, custom_commission_collector );
    1822             : 
    1823           0 :     break;
    1824           0 :   }
    1825             : 
    1826             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L142
    1827           0 :   case fd_vote_instruction_enum_update_commission: {
    1828             : 
    1829             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L149
    1830           0 :     fd_epoch_schedule_t epoch_schedule_;
    1831           0 :     fd_epoch_schedule_t const * epoch_schedule = fd_sysvar_cache_epoch_schedule_read( ctx->sysvar_cache, &epoch_schedule_ );
    1832           0 :     if( FD_UNLIKELY( !epoch_schedule ) ) {
    1833           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1834           0 :     }
    1835             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L150
    1836             : 
    1837           0 :     fd_sol_sysvar_clock_t clock_;
    1838           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1839           0 :     if( FD_UNLIKELY( !clock ) ) {
    1840           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1841           0 :     }
    1842             : 
    1843             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L145
    1844           0 :     rc = update_commission(
    1845           0 :         ctx,
    1846           0 :         target_version,
    1847           0 :         &me,
    1848           0 :         instruction->update_commission,
    1849           0 :         signers,
    1850           0 :         signers_cnt,
    1851           0 :         epoch_schedule,
    1852           0 :         clock,
    1853           0 :         delay_commission_updates
    1854           0 :     );
    1855             : 
    1856           0 :     break;
    1857           0 :   }
    1858             : 
    1859             :   /* Vote
    1860             :    *
    1861             :    * Instruction:
    1862             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L49
    1863             :    */
    1864           0 :   case fd_vote_instruction_enum_vote:;
    1865             :     /* clang-format off */
    1866           0 :     __attribute__((fallthrough));
    1867             :     /* clang-format on */
    1868             : 
    1869             :   /* VoteSwitch
    1870             :    *
    1871             :    * Instruction:
    1872             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L81
    1873             :    *
    1874             :    * Processor:
    1875             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L154
    1876             :    */
    1877           0 :   case fd_vote_instruction_enum_vote_switch: {
    1878           0 :     if( FD_FEATURE_ACTIVE_BANK( ctx->bank, deprecate_legacy_vote_ixs ) ) {
    1879           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    1880           0 :     }
    1881             : 
    1882           0 :     fd_vote_t * vote;
    1883           0 :     if( instruction->discriminant == fd_vote_instruction_enum_vote ) {
    1884           0 :       vote = &instruction->vote;
    1885           0 :     } else if( instruction->discriminant == fd_vote_instruction_enum_vote_switch ) {
    1886           0 :       vote = &instruction->vote_switch.vote;
    1887           0 :     } else {
    1888           0 :       FD_LOG_CRIT(( "unsupported instruction discriminant: %u", instruction->discriminant ));
    1889           0 :     }
    1890             : 
    1891             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L155
    1892           0 :     int err;
    1893           0 :     err = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_slot_hashes_id );
    1894           0 :     if( FD_UNLIKELY( err ) ) return err;
    1895             : 
    1896           0 :     if( FD_UNLIKELY( !fd_sysvar_cache_slot_hashes_is_valid( ctx->sysvar_cache ) ) ) {
    1897           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1898           0 :     }
    1899             : 
    1900             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L157
    1901           0 :     err = fd_sysvar_instr_acct_check( ctx, 2, &fd_sysvar_clock_id );
    1902           0 :     if( FD_UNLIKELY( err ) ) return err;
    1903           0 :     fd_sol_sysvar_clock_t clock_;
    1904           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1905           0 :     if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1906             : 
    1907           0 :     fd_slot_hashes_t slot_hashes_[1];
    1908           0 :     fd_slot_hashes_t const * slot_hashes = fd_sysvar_cache_slot_hashes_view( ctx->sysvar_cache, slot_hashes_ );
    1909           0 :     if( FD_UNLIKELY( !slot_hashes ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1910           0 :     rc = process_vote_with_account(
    1911           0 :         ctx,
    1912           0 :         &me,
    1913           0 :         target_version,
    1914           0 :         slot_hashes,
    1915           0 :         clock,
    1916           0 :         vote,
    1917           0 :         signers,
    1918           0 :         signers_cnt
    1919           0 :     );
    1920             : 
    1921           0 :     break;
    1922           0 :   }
    1923             : 
    1924             :   /* UpdateVoteState
    1925             :    *
    1926             :    * Instruction:
    1927             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L100
    1928             :    */
    1929           0 :   case fd_vote_instruction_enum_update_vote_state:;
    1930             :     /* clang-format off */
    1931           0 :     __attribute__((fallthrough));
    1932             :     /* clang-format on */
    1933             : 
    1934             :   /* UpdateVoteStateSwitch
    1935             :    *
    1936             :    * Instruction:
    1937             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L107
    1938             :    *
    1939             :    * Processor:
    1940             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L169
    1941             :    */
    1942           0 :   case fd_vote_instruction_enum_update_vote_state_switch: {
    1943           0 :     if( FD_FEATURE_ACTIVE_BANK( ctx->bank, deprecate_legacy_vote_ixs ) ) {
    1944           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    1945           0 :     }
    1946             : 
    1947           0 :     fd_vote_state_update_t * vote_state_update;
    1948           0 :     switch( instruction->discriminant ) {
    1949           0 :     case fd_vote_instruction_enum_update_vote_state:
    1950           0 :       vote_state_update = &instruction->update_vote_state;
    1951           0 :       break;
    1952           0 :     case fd_vote_instruction_enum_update_vote_state_switch:
    1953           0 :       vote_state_update = &instruction->update_vote_state_switch.vote_state_update;
    1954           0 :       break;
    1955           0 :     default:
    1956           0 :       FD_LOG_CRIT(( "unsupported instruction discriminant: %u", instruction->discriminant ));
    1957           0 :     }
    1958             : 
    1959             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L171
    1960           0 :     if( FD_UNLIKELY( !fd_sysvar_cache_slot_hashes_is_valid( ctx->sysvar_cache ) ) ) {
    1961           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1962           0 :     }
    1963             : 
    1964             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L172
    1965           0 :     fd_sol_sysvar_clock_t clock_;
    1966           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    1967           0 :     if( FD_UNLIKELY( !clock ) )
    1968           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1969             : 
    1970             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L173
    1971           0 :     fd_slot_hashes_t slot_hashes_[1];
    1972           0 :     fd_slot_hashes_t const * slot_hashes = fd_sysvar_cache_slot_hashes_view( ctx->sysvar_cache, slot_hashes_ );
    1973           0 :     if( FD_UNLIKELY( !slot_hashes ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    1974           0 :     rc = process_vote_state_update(
    1975           0 :         ctx,
    1976           0 :         &me,
    1977           0 :         target_version,
    1978           0 :         slot_hashes,
    1979           0 :         clock,
    1980           0 :         vote_state_update,
    1981           0 :         signers,
    1982           0 :         signers_cnt
    1983           0 :     );
    1984             : 
    1985           0 :     break;
    1986           0 :   }
    1987             : 
    1988             :   /* CompactUpdateVoteState
    1989             :    *
    1990             :    * Instruction:
    1991             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L139
    1992             :    *
    1993             :    * Notes:
    1994             :    * - Up to three signers: the vote authority, the authorized withdrawer, and the new authority.
    1995             :    * - Feature gated, but live on mainnet.
    1996             :    */
    1997           0 :   case fd_vote_instruction_enum_compact_update_vote_state:;
    1998           0 :     __attribute__((fallthrough));
    1999             : 
    2000             :   /* CompactUpdateVoteStateSwitch
    2001             :    *
    2002             :    * Instruction:
    2003             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L146
    2004             :    *
    2005             :    * Processor:
    2006             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L183
    2007             :    *
    2008             :    * Notes:
    2009             :    * - Up to three signers: the vote authority, the authorized withdrawer, and the new authority.
    2010             :    * - Feature gated, but live on mainnet.
    2011             :    */
    2012           0 :   case fd_vote_instruction_enum_compact_update_vote_state_switch: {
    2013             :     /* https://github.com/anza-xyz/agave/blob/dc4b9dcbbf859ff48f40d00db824bde063fdafcc/programs/vote/src/vote_processor.rs#L183-L191 */
    2014           0 :     if( FD_FEATURE_ACTIVE_BANK( ctx->bank, deprecate_legacy_vote_ixs ) ) {
    2015           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2016           0 :     }
    2017             : 
    2018           0 :     fd_compact_vote_state_update_t * vote_state_update = NULL;
    2019           0 :     if( instruction->discriminant == fd_vote_instruction_enum_compact_update_vote_state ) {
    2020           0 :       vote_state_update = &instruction->compact_update_vote_state;
    2021           0 :     } else if( instruction->discriminant ==
    2022           0 :                fd_vote_instruction_enum_compact_update_vote_state_switch ) {
    2023           0 :       vote_state_update =
    2024           0 :           &instruction->compact_update_vote_state_switch.compact_vote_state_update;
    2025           0 :     }
    2026             : 
    2027           0 :     fd_vote_state_update_t vote_update = {0};
    2028           0 :     if( FD_UNLIKELY( !fd_vote_decode_compact_update( vote_state_update, &vote_update, ctx ) ) )
    2029           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2030             : 
    2031             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L185
    2032           0 :     if( FD_UNLIKELY( !fd_sysvar_cache_slot_hashes_is_valid( ctx->sysvar_cache ) ) ) {
    2033           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2034           0 :     }
    2035             : 
    2036           0 :     fd_sol_sysvar_clock_t clock_;
    2037           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    2038           0 :     if( FD_UNLIKELY( !clock ) )
    2039           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2040             : 
    2041             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L187
    2042           0 :     fd_slot_hashes_t slot_hashes_[1];
    2043           0 :     fd_slot_hashes_t const * slot_hashes = fd_sysvar_cache_slot_hashes_view( ctx->sysvar_cache, slot_hashes_ );
    2044           0 :     if( FD_UNLIKELY( !slot_hashes ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2045           0 :     rc = process_vote_state_update(
    2046           0 :         ctx,
    2047           0 :         &me,
    2048           0 :         target_version,
    2049           0 :         slot_hashes,
    2050           0 :         clock,
    2051           0 :         &vote_update,
    2052           0 :         signers,
    2053           0 :         signers_cnt
    2054           0 :     );
    2055             : 
    2056           0 :     break;
    2057           0 :   }
    2058             : 
    2059             :   /* TowerSync(Switch)
    2060             :    *
    2061             :    * Instruction:
    2062             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L151-L157
    2063             :    *
    2064             :    * Processor:
    2065             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L196-L215
    2066             :    */
    2067             : 
    2068           0 :   case fd_vote_instruction_enum_tower_sync:
    2069           0 :   case fd_vote_instruction_enum_tower_sync_switch: {
    2070           0 :     fd_tower_sync_t * tower_sync = (instruction->discriminant == fd_vote_instruction_enum_tower_sync)
    2071           0 :         ? &instruction->tower_sync
    2072           0 :         : &instruction->tower_sync_switch.tower_sync;
    2073             : 
    2074           0 :     if( FD_UNLIKELY( !fd_sysvar_cache_slot_hashes_is_valid( ctx->sysvar_cache ) ) ) {
    2075           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2076           0 :     }
    2077             : 
    2078           0 :     fd_sol_sysvar_clock_t clock_;
    2079           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    2080           0 :     if( FD_UNLIKELY( !clock ) ) {
    2081           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2082           0 :     }
    2083             : 
    2084           0 :     fd_slot_hashes_t slot_hashes_[1];
    2085           0 :     fd_slot_hashes_t const * slot_hashes = fd_sysvar_cache_slot_hashes_view( ctx->sysvar_cache, slot_hashes_ );
    2086           0 :     if( FD_UNLIKELY( !slot_hashes ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2087           0 :     rc = process_tower_sync(
    2088           0 :         ctx,
    2089           0 :         &me,
    2090           0 :         target_version,
    2091           0 :         slot_hashes,
    2092           0 :         clock,
    2093           0 :         tower_sync,
    2094           0 :         signers,
    2095           0 :         signers_cnt
    2096           0 :     );
    2097             : 
    2098           0 :     break;
    2099           0 :   }
    2100             : 
    2101             :   /* Withdraw
    2102             :    *
    2103             :    * Instruction:
    2104             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L57
    2105             :    *
    2106             :    * Processor:
    2107             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L216
    2108             :    */
    2109           0 :   case fd_vote_instruction_enum_withdraw: {
    2110           0 :     if( FD_UNLIKELY( ctx->instr->acct_cnt < 2 ) ) {
    2111           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    2112           0 :       break;
    2113           0 :     }
    2114           0 :     fd_rent_t rent_;
    2115           0 :     fd_rent_t const * rent_sysvar = fd_sysvar_cache_rent_read( ctx->sysvar_cache, &rent_ );
    2116           0 :     if( FD_UNLIKELY( !rent_sysvar ) )
    2117           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2118           0 :     fd_sol_sysvar_clock_t clock_;
    2119           0 :     fd_sol_sysvar_clock_t const * clock_sysvar = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    2120           0 :     if( FD_UNLIKELY( !clock_sysvar ) )
    2121           0 :       return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2122             : 
    2123           0 :     int deinitialized = 0;
    2124           0 :     rc = withdraw(
    2125           0 :         ctx,
    2126           0 :         &me,
    2127           0 :         target_version,
    2128           0 :         instruction->withdraw,
    2129           0 :         1UL,
    2130           0 :         signers,
    2131           0 :         signers_cnt,
    2132           0 :         rent_sysvar,
    2133           0 :         clock_sysvar,
    2134           0 :         &deinitialized
    2135           0 :     );
    2136             : 
    2137           0 :     if( FD_LIKELY( !rc && deinitialized ) ) {
    2138           0 :       ctx->txn_out->accounts.new_vote[ ctx->instr->accounts[0].index_in_transaction ] = 0;
    2139           0 :       ctx->txn_out->accounts.rm_vote[ ctx->instr->accounts[0].index_in_transaction ] = 1;
    2140           0 :     }
    2141             : 
    2142             : 
    2143           0 :     break;
    2144           0 :   }
    2145             : 
    2146             :   /* AuthorizeChecked
    2147             :    *
    2148             :    * Instruction:
    2149             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/instruction.rs#L93
    2150             :    *
    2151             :    * Processor:
    2152             :    * https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L234
    2153             :    *
    2154             :    * Notes:
    2155             :    * - Up to three signers: the vote authority, the authorized withdrawer, and the new authority.
    2156             :    * - Feature gated, but live on mainnet.
    2157             :    */
    2158           0 :   case fd_vote_instruction_enum_authorize_checked: {
    2159           0 :     if( FD_UNLIKELY( ctx->instr->acct_cnt < 4 ) ) {
    2160           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
    2161           0 :       break;
    2162           0 :     }
    2163             : 
    2164             :     // https://github.com/anza-xyz/agave/blob/v2.1.14/programs/vote/src/vote_processor.rs#L243-L245
    2165           0 :     fd_pubkey_t const * voter_pubkey = NULL;
    2166           0 :     rc = fd_exec_instr_ctx_get_key_of_account_at_index( ctx, 3UL, &voter_pubkey );
    2167           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    2168             : 
    2169             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L239
    2170           0 :     if( FD_UNLIKELY( !fd_instr_acc_is_signer_idx( ctx->instr, 3, &rc ) ) ) {
    2171             :       /* https://github.com/anza-xyz/agave/blob/v3.0.3/transaction-context/src/lib.rs#L789 */
    2172           0 :       if( FD_UNLIKELY( !!rc ) ) break;
    2173             : 
    2174           0 :       rc = FD_EXECUTOR_INSTR_ERR_MISSING_REQUIRED_SIGNATURE;
    2175           0 :       break;
    2176           0 :     }
    2177             : 
    2178             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L242
    2179           0 :     rc = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_clock_id );
    2180           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    2181           0 :     fd_sol_sysvar_clock_t clock_;
    2182           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    2183           0 :     if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2184             : 
    2185           0 :     rc = authorize(
    2186           0 :         ctx,
    2187           0 :         &me,
    2188           0 :         target_version,
    2189           0 :         voter_pubkey,
    2190           0 :         &instruction->authorize_checked,
    2191           0 :         signers,
    2192           0 :         signers_cnt,
    2193           0 :         clock,
    2194           0 :         is_vote_authorize_with_bls_enabled
    2195           0 :     );
    2196           0 :     break;
    2197           0 :   }
    2198             : 
    2199             :   /* InitializeAccountV2
    2200             :    *
    2201             :    * Instruction:
    2202             :    * https://github.com/anza-xyz/solana-sdk/blob/vote-interface%40v5.0.0/vote-interface/src/instruction.rs#L195-L200
    2203             :    *
    2204             :    * Processor:
    2205             :    * https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L307-L324
    2206             :    *
    2207             :    * Notes:
    2208             :    * - The code is identical to InitializeAccount, except calling the actual initialize_account_v2
    2209             :    * - Feature gated.
    2210             :    */
    2211           6 :   case fd_vote_instruction_enum_initialize_account_v2: {
    2212             :     /* https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L308-L310 */
    2213           6 :     if( FD_UNLIKELY( !is_init_account_v2_enabled ) ) {
    2214           6 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2215           6 :     }
    2216             : 
    2217           0 :     rc = fd_sysvar_instr_acct_check( ctx, 1, &fd_sysvar_rent_id );
    2218           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    2219           0 :     fd_rent_t rent_;
    2220           0 :     fd_rent_t const * rent = fd_sysvar_cache_rent_read( ctx->sysvar_cache, &rent_ );
    2221           0 :     if( FD_UNLIKELY( !rent ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2222             : 
    2223           0 :     if( FD_UNLIKELY( fd_borrowed_account_get_lamports( &me ) <
    2224           0 :                      fd_rent_exempt_minimum_balance( rent, fd_borrowed_account_get_data_len( &me ) ) ) )
    2225           0 :       return FD_EXECUTOR_INSTR_ERR_INSUFFICIENT_FUNDS;
    2226             : 
    2227           0 :     rc = fd_sysvar_instr_acct_check( ctx, 2, &fd_sysvar_clock_id );
    2228           0 :     if( FD_UNLIKELY( rc ) ) return rc;
    2229           0 :     fd_sol_sysvar_clock_t clock_;
    2230           0 :     fd_sol_sysvar_clock_t const * clock = fd_sysvar_cache_clock_read( ctx->sysvar_cache, &clock_ );
    2231           0 :     if( FD_UNLIKELY( !clock ) ) return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
    2232             : 
    2233           0 :     rc = initialize_account_v2( ctx, &me, target_version, &instruction->initialize_account_v2, signers, signers_cnt, clock );
    2234             : 
    2235           0 :     if( FD_LIKELY( !rc ) ) {
    2236           0 :       ctx->txn_out->accounts.new_vote[ ctx->instr->accounts[0].index_in_transaction ] = 1;
    2237           0 :       ctx->txn_out->accounts.rm_vote[ ctx->instr->accounts[0].index_in_transaction ] = 0;
    2238           0 :     }
    2239             : 
    2240           0 :     break;
    2241           0 :   }
    2242             : 
    2243             :   /* UpdateCommissionBps (commission_rate_in_basis_points feature)
    2244             :    *
    2245             :    * Instruction:
    2246             :    * https://github.com/anza-xyz/solana-sdk/blob/vote-interface%40v5.0.0/vote-interface/src/instruction.rs#L212-L221
    2247             :    *
    2248             :    * Processor:
    2249             :    * https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L325-L347
    2250             :    *
    2251             :    */
    2252           0 :   case fd_vote_instruction_enum_update_commission_bps: {
    2253           0 :     if( FD_UNLIKELY( !commission_rate_in_basis_points
    2254           0 :                   || !delay_commission_updates ) ) {
    2255           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2256           0 :     }
    2257             : 
    2258           0 :     rc = update_commission_bps( ctx, &me, target_version, &instruction->update_commission_bps, signers, signers_cnt, block_revenue_sharing );
    2259             : 
    2260           0 :     break;
    2261           0 :   }
    2262             : 
    2263             :   /* UpdateCommissionCollector
    2264             :    *
    2265             :    * Instruction:
    2266             :    * https://github.com/anza-xyz/solana-sdk/blob/vote-interface%40v5.0.0/vote-interface/src/instruction.rs#L202-L210
    2267             :    *
    2268             :    * Processor:
    2269             :    * https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L348-L376
    2270             :    *
    2271             :    * Notes:
    2272             :    * - Unimplemented (gated on custom_commission_collector)
    2273             :    */
    2274           0 :   case fd_vote_instruction_enum_update_commission_collector: {
    2275           0 :     if( FD_UNLIKELY( !custom_commission_collector ) ) {
    2276           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2277           0 :     }
    2278             : 
    2279             :     /* TODO: fill in when implementing custom_commission_collector */
    2280           0 :     FD_LOG_CRIT(( "unimplemented: update_commission_collector" ));
    2281           0 :   }
    2282             : 
    2283             :   /* DepositDelegatorRewards
    2284             :    *
    2285             :    * Instruction:
    2286             :    * https://github.com/anza-xyz/solana-sdk/blob/vote-interface%40v5.0.0/vote-interface/src/instruction.rs#L223-L228
    2287             :    *
    2288             :    * Processor:
    2289             :    * https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L377-L395
    2290             :    *
    2291             :    * Notes:
    2292             :    * - Unimplemented (gated on block_revenue_sharing)
    2293             :    */
    2294           0 :   case fd_vote_instruction_enum_deposit_delegator_rewards: {
    2295           0 :     if( FD_UNLIKELY( !commission_rate_in_basis_points
    2296           0 :                   || !custom_commission_collector
    2297           0 :                   || !block_revenue_sharing ) ) {
    2298           0 :       return FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA;
    2299           0 :     }
    2300             : 
    2301             :     /* TODO: fill in when implementing block_revenue_sharing */
    2302           0 :     FD_LOG_CRIT(( "unimplemented: deposit_delegator_rewards" ));
    2303           0 :   }
    2304             : 
    2305           0 :   default:
    2306           0 :     FD_LOG_CRIT(( "unsupported vote instruction: %u", instruction->discriminant ));
    2307          12 :   }
    2308             : 
    2309           6 :   return rc;
    2310          12 : }

Generated by: LCOV version 1.14