diff --git a/bench-report.json b/bench-report.json index df7ad9f..738f6ee 100644 --- a/bench-report.json +++ b/bench-report.json @@ -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 diff --git a/programs/settlement/src/processor.rs b/programs/settlement/src/processor.rs index 7f3246c..76e1cc7 100644 --- a/programs/settlement/src/processor.rs +++ b/programs/settlement/src/processor.rs @@ -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( @@ -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, @@ -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 { - 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 { diff --git a/programs/settlement/src/settle/begin.rs b/programs/settlement/src/settle/begin.rs index 498adff..9fa067d 100644 --- a/programs/settlement/src/settle/begin.rs +++ b/programs/settlement/src/settle/begin.rs @@ -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}; @@ -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