Skip to content

Commit

Permalink
Simplify BE verification for compute unit limit
Browse files Browse the repository at this point in the history
  • Loading branch information
abhidtu2014 committed Mar 28, 2024
1 parent bcb99cd commit 008ea6d
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions backend/src/utils/fund-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import config from '../config'

const SET_COMPUTE_UNIT_LIMIT_DISCRIMINANT = 2
const SET_COMPUTE_UNIT_PRICE_DISCRIMINANT = 3

const MAX_COMPUTE_UNIT_PRICE = BigInt(1_000_000)

export function deserializeTransactions(
Expand Down Expand Up @@ -77,26 +79,11 @@ export function checkSetComputeBudgetInstructionsAreSetComputeUnitLimit(
ComputeBudgetProgram.programId
)
) {
/*
Below is a hack that was added to extract the instructionType from the transaction
ComputeBudgetInstruction.decodeInstructionType requires legacTransactionInstruction not
MessageCompiledInstruction
*/
const programId = ComputeBudgetProgram.programId
const legacTransactionInstruction = new TransactionInstruction({
keys: [],
programId,
data: Buffer.from(ix.data)
})

const instructonType = ComputeBudgetInstruction.decodeInstructionType(
legacTransactionInstruction
)
// Note: We continue processing tx data because setComputeUnitPrice is mandatory to be set
if (ix.data[0] === SET_COMPUTE_UNIT_PRICE_DISCRIMINANT) continue;

// Note: We check that instruction is not SetComputeUnitPrice because we want to make sure that
// that the instruction is SetComputeUnitLimit when we compare against the discriminant
if (
instructonType !== 'SetComputeUnitPrice' &&
ix.data[0] !== SET_COMPUTE_UNIT_LIMIT_DISCRIMINANT
) {
console.error('Compute unit limit discriminant does not match')
Expand Down

0 comments on commit 008ea6d

Please sign in to comment.