Skip to content

Commit

Permalink
one more insn
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhatt-jumptrading committed Aug 5, 2024
1 parent cadfbcc commit c117638
Showing 1 changed file with 51 additions and 64 deletions.
115 changes: 51 additions & 64 deletions src/flamenco/runtime/program/fd_address_lookup_table_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,103 +728,90 @@ deactivate_lookup_table( fd_exec_instr_ctx_t * ctx ) {
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L346-L351 */

/* try_borrow_instruction_account => get_index_of_instruction_account_in_transaction */
if( FD_UNLIKELY( ctx->instr->acct_cnt < ACC_IDX_LUT+1UL ) )
return FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS;
fd_borrowed_account_t * lut_acct = NULL;
fd_instr_borrowed_account_view_idx( ctx, ACC_IDX_LUT, &lut_acct ); /* check error? */
FD_TEST( lut_acct );

/* try_borrow_instruction_account => RefCell::try_borrow_mut (see above note)
(See https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L346-L347) */
if( FD_UNLIKELY( !fd_borrowed_account_acquire_write_is_safe( lut_acct ) ) )
return FD_EXECUTOR_INSTR_ERR_ACC_BORROW_FAILED;
FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, ACC_IDX_LUT, lut_acct ) {

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L348-L350 */
if( FD_UNLIKELY( 0!=memcmp( lut_acct->const_meta->info.owner, fd_solana_address_lookup_table_program_id.key, sizeof(fd_pubkey_t) ) ) )
return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_OWNER;

} FD_BORROWED_ACCOUNT_DROP( lut_acct );

/* Prepare authority account ****************************************/
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L353-L360 */

/* try_borrow_account => get_index_of_instruction_account_in_transaction */
if( FD_UNLIKELY( ctx->instr->acct_cnt < ACC_IDX_AUTHORITY+1UL ) )
return FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS;
fd_borrowed_account_t * authority_acct = NULL;
fd_instr_borrowed_account_view_idx( ctx, ACC_IDX_AUTHORITY, &authority_acct ); /* check error? */
FD_TEST( authority_acct );

/* try_borrow_instruction_account => RefCell::try_borrow_mut (see above note)
(See https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L353-L354) */
if( FD_UNLIKELY( !fd_borrowed_account_acquire_write_is_safe( authority_acct ) ) )
return FD_EXECUTOR_INSTR_ERR_ACC_BORROW_FAILED;
fd_pubkey_t const * authority_key = NULL;
FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, ACC_IDX_AUTHORITY, authority_acct ) {

fd_pubkey_t const * authority_key = authority_acct->pubkey;
authority_key = authority_acct->pubkey;

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L356-L359 */
if( FD_UNLIKELY( !fd_instr_acc_is_signer_idx( ctx->instr, ACC_IDX_AUTHORITY ) ) ) {
/* TODO Log: "Authority account must be a signer" */
FD_LOG_WARNING(( "Authority account must be a signer" ));
return FD_EXECUTOR_INSTR_ERR_MISSING_REQUIRED_SIGNATURE;
}

} FD_BORROWED_ACCOUNT_DROP( authority_acct );

/* Update lookup table account **************************************/

int lock_ok = fd_borrowed_account_acquire_write( lut_acct );
/* must be paired with release */
FD_TEST( !!lock_ok ); /* Lock would always succeed at this point */
FD_BORROWED_ACCOUNT_TRY_BORROW_IDX( ctx, ACC_IDX_LUT, lut_acct ) {

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L364 */
uchar const * lut_data = lut_acct->const_data;
ulong lut_data_sz = lut_acct->const_meta->dlen;

int err = FD_EXECUTOR_INSTR_SUCCESS;
do { /* with locked account */
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L365 */
fd_addrlut_t lut[1];
int state_err = fd_addrlut_deserialize( lut, (uchar *)lut_data, lut_data_sz );
if( FD_UNLIKELY( state_err ) ) { err = state_err; break; }
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L365 */
fd_addrlut_t lut[1];
int err = fd_addrlut_deserialize( lut, (uchar *)lut_data, lut_data_sz );
if( FD_UNLIKELY( err ) ) {
return err;
}

fd_address_lookup_table_t * state = &lut->state.inner.lookup_table;
fd_address_lookup_table_t * state = &lut->state.inner.lookup_table;

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L367-L370 */
if( FD_UNLIKELY( !state->meta.has_authority ) ) {
/* TODO Log: "Lookup table is already frozen" */
err = FD_EXECUTOR_INSTR_ERR_ACC_IMMUTABLE; break;
}
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L367-L370 */
if( FD_UNLIKELY( !state->meta.has_authority ) ) {
FD_LOG_WARNING(( "Lookup table is already frozen" ));
return FD_EXECUTOR_INSTR_ERR_ACC_IMMUTABLE;
}

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L371-L373 */
if( FD_UNLIKELY( 0!=memcmp( state->meta.authority.key, authority_key->key, sizeof(fd_pubkey_t) ) ) ) {
err = FD_EXECUTOR_INSTR_ERR_INCORRECT_AUTHORITY; break;
}
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L371-L373 */
if( FD_UNLIKELY( 0!=memcmp( state->meta.authority.key, authority_key->key, sizeof(fd_pubkey_t) ) ) ) {
return FD_EXECUTOR_INSTR_ERR_INCORRECT_AUTHORITY;
}

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L374-L377 */
if( FD_UNLIKELY( state->meta.deactivation_slot != ULONG_MAX ) ) {
/* TODO Log: "Lookup table is already deactivated" */
err = FD_EXECUTOR_INSTR_ERR_INVALID_ARG; break;
}
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L374-L377 */
if( FD_UNLIKELY( state->meta.deactivation_slot != ULONG_MAX ) ) {
FD_LOG_WARNING(( "Lookup table is already deactivated" ));
return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
}

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L380 */
fd_sol_sysvar_clock_t clock[1];
if( FD_UNLIKELY( !fd_sysvar_clock_read( clock, ctx->slot_ctx ) ) )
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L380 */
fd_sol_sysvar_clock_t clock[1];
if( FD_UNLIKELY( !fd_sysvar_clock_read( clock, ctx->slot_ctx ) ) ) {
return FD_EXECUTOR_INSTR_ERR_UNSUPPORTED_SYSVAR;
}

uchar *data = NULL;
ulong dlen = 0;
int err = fd_account_get_data_mut ( ctx, ACC_IDX_LUT, &data, &dlen );
if (FD_EXECUTOR_INSTR_SUCCESS != err)
return err;
uchar * data = NULL;
ulong dlen = 0UL;
err = fd_account_get_data_mut ( ctx, ACC_IDX_LUT, &data, &dlen );
if( FD_UNLIKELY( err ) ) {
return err;
}

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L381 */
state->meta.deactivation_slot = clock->slot;
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L381 */
state->meta.deactivation_slot = clock->slot;

/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L383-L386 */
state_err = fd_addrlut_serialize_meta( &lut->state, data, dlen );
if( FD_UNLIKELY( state_err ) ) { err = state_err; break; }
/* https://github.com/solana-labs/solana/blob/v1.17.4/programs/address-lookup-table/src/processor.rs#L383-L386 */
err = fd_addrlut_serialize_meta( &lut->state, data, dlen );
if( FD_UNLIKELY( err ) ) {
return err;
}

err = FD_EXECUTOR_INSTR_SUCCESS;
} while(0);
fd_borrowed_account_release_write( lut_acct );
} FD_BORROWED_ACCOUNT_DROP( lut_acct );

return err;
return FD_EXECUTOR_INSTR_SUCCESS;

# undef ACC_IDX_LUT
# undef ACC_IDX_AUTHORITY
Expand Down

0 comments on commit c117638

Please sign in to comment.