From 38b7ad1daf56c43f293782e329157f46c6528f1c Mon Sep 17 00:00:00 2001 From: Josh Siegel Date: Thu, 27 Jun 2024 12:25:44 +0000 Subject: [PATCH] pool_hardening: idx_acquire and ele_acquire dont check to see if the pool is empty --- src/flamenco/runtime/program/fd_vote_program.c | 10 ++++++++++ src/flamenco/runtime/sysvar/fd_sysvar_clock.c | 3 +++ src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/flamenco/runtime/program/fd_vote_program.c b/src/flamenco/runtime/program/fd_vote_program.c index f24e051d4e..fab7576d54 100644 --- a/src/flamenco/runtime/program/fd_vote_program.c +++ b/src/flamenco/runtime/program/fd_vote_program.c @@ -212,6 +212,9 @@ authorized_voters_new( ulong epoch, fd_vote_authorized_voters_t * authorized_voters /* out */ ) { authorized_voters->pool = fd_vote_authorized_voters_pool_alloc ( valloc, FD_VOTE_AUTHORIZED_VOTERS_MIN ); authorized_voters->treap = fd_vote_authorized_voters_treap_alloc( valloc, FD_VOTE_AUTHORIZED_VOTERS_MIN ); + if( 0 == fd_vote_authorized_voters_pool_free( authorized_voters->pool) ) { + FD_LOG_ERR(( "Authorized_voter pool is empty" )); + } fd_vote_authorized_voter_t * ele = fd_vote_authorized_voters_pool_ele_acquire( authorized_voters->pool ); ele->epoch = epoch; @@ -320,6 +323,9 @@ authorized_voters_get_and_cache_authorized_voter_for_epoch( fd_vote_authorized_v if( !res ) return NULL; if( !existed ) { /* insert cannot fail because !existed */ + if( 0 == fd_vote_authorized_voters_pool_free( self->pool) ) { + FD_LOG_ERR(( "Authorized_voter pool is empty" )); + } fd_vote_authorized_voter_t * ele = fd_vote_authorized_voters_pool_ele_acquire( self->pool ); ele->epoch = epoch; memcpy( &ele->pubkey, &res->pubkey, sizeof( fd_pubkey_t ) ); @@ -724,6 +730,10 @@ set_new_authorized_voter( fd_vote_state_t * self, } // https://github.com/firedancer-io/solana/blob/da470eef4652b3b22598a1f379cacfe82bd5928d/sdk/program/src/vote/state/mod.rs#L581-L582 + if( 0 == fd_vote_authorized_voters_pool_free( self->authorized_voters.pool) ) { + FD_LOG_ERR(( "Authorized_voter pool is empty" )); + } + fd_vote_authorized_voter_t * ele = fd_vote_authorized_voters_pool_ele_acquire( self->authorized_voters.pool ); ele->epoch = target_epoch; diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_clock.c b/src/flamenco/runtime/sysvar/fd_sysvar_clock.c index b222096bb5..d3e9ff2d19 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_clock.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_clock.c @@ -291,6 +291,9 @@ fd_calculate_stake_weighted_timestamp( if ( FD_LIKELY( treap_idx < ULONG_MAX ) ) { pool[ treap_idx ].stake += n->elem.stake; } else { + if( 0 == stake_ts_pool_free( pool ) ) { + FD_LOG_ERR(( "stake_ts_pool is empty" )); + } ulong idx = stake_ts_pool_idx_acquire( pool ); pool[ idx ].timestamp = estimate; pool[ idx ].stake = n->elem.stake; diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c index 55dae861ac..9cf92a6414 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c @@ -66,6 +66,10 @@ fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx, fd_stake_history_pool_ele_release( stake_history.pool, ele ); } + if( 0 == fd_stake_history_pool_free( stake_history.pool ) ) { + FD_LOG_ERR(( "stake_history.pool is empty" )); + } + ulong idx = fd_stake_history_pool_idx_acquire( stake_history.pool ); stake_history.pool[ idx ].epoch = entry->epoch;