Skip to content

Commit 53885f1

Browse files
committed
account for lookup tables
1 parent 83d3b8a commit 53885f1

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

auction-server/src/auction/service/verification.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -249,54 +249,50 @@ impl Service {
249249
}
250250
}
251251

252-
fn validate_swap_transaction_instructions(
252+
async fn validate_swap_transaction_instructions(
253253
&self,
254254
tx: &VersionedTransaction,
255255
user_wallet: &Pubkey,
256256
) -> Result<(), RestError> {
257-
let accounts = tx.message.static_account_keys();
258-
tx.message
259-
.instructions()
260-
.iter()
261-
.enumerate()
262-
.try_for_each(|(index, ix)| {
263-
self.validate_swap_transaction_instruction(
264-
ix.program_id(tx.message.static_account_keys()),
265-
ix,
266-
user_wallet,
267-
accounts,
268-
)
269-
.map_err(|e| RestError::InvalidInstruction(Some(index), e))
270-
})?;
271-
257+
for (index, ix) in tx.message.instructions().iter().enumerate() {
258+
self.validate_swap_transaction_instruction(
259+
ix.program_id(tx.message.static_account_keys()),
260+
ix,
261+
tx,
262+
user_wallet,
263+
index,
264+
)
265+
.await?;
266+
}
272267
Ok(())
273268
}
274269

275270
/// Checks if the instruction provided meets the criteria for validity.
276271
/// Instruction must either be an approved program instruction or not contain the user wallet in its accounts.
277-
fn validate_swap_transaction_instruction(
272+
async fn validate_swap_transaction_instruction(
278273
&self,
279274
program_id: &Pubkey,
280275
ix: &CompiledInstruction,
276+
tx: &VersionedTransaction,
281277
user_wallet: &Pubkey,
282-
accounts: &[Pubkey],
283-
) -> Result<(), InstructionError> {
278+
ix_index: usize,
279+
) -> Result<(), RestError> {
284280
if self
285281
.check_approved_program_instruction(program_id, ix)
286282
.is_ok()
287283
{
288284
Ok(())
289285
} else {
290-
ix.accounts.iter().try_for_each(|i| {
291-
if accounts
292-
.get(*i as usize)
293-
.expect("account index out of bounds")
294-
== user_wallet
295-
{
296-
return Err(InstructionError::UnsupportedInvocationOfUserWallet);
286+
// TODO: this loop will be slow and invoke many rpc calls if there are many lookup accounts. either parallelize this extraction or limit number of lookup accounts
287+
for i in 0..ix.accounts.len() {
288+
let account_key = self.extract_account(tx, ix, i).await?;
289+
if account_key == *user_wallet {
290+
return Err(RestError::InvalidInstruction(
291+
Some(ix_index),
292+
InstructionError::UnsupportedInvocationOfUserWallet,
293+
));
297294
}
298-
Ok(())
299-
})?;
295+
}
300296

301297
Ok(())
302298
}
@@ -1097,7 +1093,8 @@ impl Service {
10971093
self.validate_swap_transaction_instructions(
10981094
bid_chain_data_create_svm.get_transaction(),
10991095
&user_wallet,
1100-
)?;
1096+
)
1097+
.await?;
11011098
let quote_tokens = get_swap_quote_tokens(&opp);
11021099
let opportunity_swap_data = get_opportunity_swap_data(&opp);
11031100
self.check_svm_swap_bid_fields(bid_data, opportunity_swap_data, &quote_tokens)

0 commit comments

Comments
 (0)