Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bench-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"reclaim_buffer/max_buffers_in_one_instruction": 136652,
"reclaim_buffer/reclaims_multiple_buffers_skipping_funded": 18082,
"reclaim_order/happy_path_returns_lamports_and_closes_pda": 2183,
"settle/finalizes_with_no_pushes": 7152,
"settle/pulls_from_multiple_orders": 20041,
"settle/pulls_funds_to_destination": 13630,
"settle/pulls_to_multiple_destinations": 14771,
"settle/pushes_a_single_order": 12485,
"settle/pushes_several_orders_from_different_buffers": 17749,
"settle/pushes_several_orders_from_one_buffer": 17748,
"settle/settles_a_single_order": 12503,
"settle/settles_multiple_orders": 23060,
"settle/finalizes_with_no_pushes": 7154,
"settle/pulls_from_multiple_orders": 20043,
"settle/pulls_funds_to_destination": 13632,
"settle/pulls_to_multiple_destinations": 14773,
"settle/pushes_a_single_order": 12487,
"settle/pushes_several_orders_from_different_buffers": 17751,
"settle/pushes_several_orders_from_one_buffer": 17750,
"settle/settles_a_single_order": 12505,
"settle/settles_multiple_orders": 23062,
"transfer_authority/manager_can_transfer_manager": 3174,
"transfer_authority/manager_can_transfer_reclaim_authority": 3176,
"transfer_authority/reclaim_authority_can_transfer_itself": 3180
Expand Down
17 changes: 8 additions & 9 deletions programs/settlement/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn check_state_pda(
/// This function is to be used as an alternative for [`with_state_pda_signer`]
/// in the case where the state PDA has been checked in an earlier call.
/// The caller is responsible for having validated the bump against the state
/// PDA (e.g. via [`check_state_pda`] or [`require_solver`]).
/// PDA, via [`check_state_pda`].
///
/// If state PDA validation is needed, use [`with_state_pda_signer`].
pub fn with_state_pda_signer_from_bump(
Expand All @@ -146,7 +146,7 @@ pub fn with_state_pda_signer_from_bump(
/// Validate that `state_pda_account` is the canonical state PDA and run `f`
/// with a signer for it, in one step. Use [`with_state_pda_signer_from_bump`]
/// directly when the bump has already been derived (as settling does, via
/// [`require_solver`]) to avoid re-deriving the PDA.
/// [`check_state_pda`]) to avoid re-deriving the PDA.
pub fn with_state_pda_signer(
program_id: &Address,
state_pda_account: &AccountView,
Expand All @@ -155,22 +155,21 @@ pub fn with_state_pda_signer(
with_state_pda_signer_from_bump(check_state_pda(program_id, state_pda_account)?, f)
}

/// Confirm that the given account is a valid solver.
/// Confirm that `solver_account` signed the transaction and is in the solver
/// list held by `state_pda_account`.
///
/// Returns the state PDA's canonical bump, so the caller can build its signer via
/// [`with_state_pda_signer_from_bump`] without deriving the PDA a second time.
/// Confirming the state account sits at the canonical state PDA (and deriving
/// its bump for the signer) is left to the caller, via [`check_state_pda`].
#[must_use = "ignoring the result skips solver authentication"]
pub fn require_solver(
program_id: &Address,
state_pda_account: &AccountView,
solver_account: &AccountView,
) -> Result<u8, ProgramError> {
let state_bump = check_state_pda(program_id, state_pda_account)?;
) -> ProgramResult {
let state = StateAccount::attach(state_pda_account.try_borrow()?)?;
if !solver_account.is_signer() || !state.is_solver(solver_account.address()) {
return Err(SettlementError::UnauthorizedSolver.into());
}
Ok(state_bump)
Ok(())
}

pub fn is_cpi_call() -> bool {
Expand Down
9 changes: 5 additions & 4 deletions programs/settlement/src/settle/begin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ use pinocchio::{
};
use pinocchio_token::{instructions::Transfer, state::Account as TokenAccount};

use crate::processor::{is_cpi_call, require_solver, with_state_pda_signer_from_bump};
use crate::processor::{
check_state_pda, is_cpi_call, require_solver, with_state_pda_signer_from_bump,
};

use super::{validate_counterpart, validate_token_program_account};

Expand All @@ -44,9 +46,8 @@ pub fn process_begin_settle(

let input = BeginSettleInput::parse(instruction_data, accounts)?;

// Only an approved solver may settle. Reuse the bump this derives so the
// signer below doesn't re-derive the state PDA.
let state_bump = require_solver(program_id, input.state_pda_account, input.solver_account)?;
let state_bump = check_state_pda(program_id, input.state_pda_account)?;
require_solver(input.state_pda_account, input.solver_account)?;

// We use `instructions_sysvar_account` from the input but this could be
// any address since parsing doesn't validate the input. We rely on the
Expand Down