1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-11 11:28:46 +00:00

fix(core/solana): avoid looking at not-exposed instruction ids

This commit is contained in:
matejcik 2025-04-25 16:18:32 +02:00 committed by matejcik
parent e4e6d60e64
commit dd5a3365a9
3 changed files with 51 additions and 24 deletions

View File

@ -309,39 +309,19 @@ class Transaction:
SOLANA_TOKEN_ACCOUNT_SIZE, SOLANA_TOKEN_ACCOUNT_SIZE,
) )
from ..transaction.instructions import ( from ..transaction.instructions import (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID, is_system_program_account_creation,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE, is_atap_account_creation,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
_SYSTEM_PROGRAM_ID,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
_TOKEN_2022_PROGRAM_ID, _TOKEN_2022_PROGRAM_ID,
_TOKEN_PROGRAM_ID, _TOKEN_PROGRAM_ID,
) )
allocation = 0 allocation = 0
for instruction in self.instructions: for instruction in self.instructions:
if instruction.program_id == _SYSTEM_PROGRAM_ID and ( if is_system_program_account_creation(instruction):
instruction.instruction_id
in (
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
)
):
allocation += ( allocation += (
instruction.parsed_data["space"] + SOLANA_ACCOUNT_OVERHEAD_SIZE instruction.parsed_data["space"] + SOLANA_ACCOUNT_OVERHEAD_SIZE
) )
elif instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID and ( elif is_atap_account_creation(instruction):
instruction.instruction_id
in (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
)
):
spl_token_account = self.get_account_address( spl_token_account = self.get_account_address(
instruction.parsed_accounts["spl_token"] instruction.parsed_accounts["spl_token"]
) )

View File

@ -117,6 +117,30 @@ COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = (
) )
def is_system_program_account_creation(instruction: Instruction) -> bool:
return (
instruction.program_id == _SYSTEM_PROGRAM_ID
and instruction.instruction_id
in (
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
)
)
def is_atap_account_creation(instruction: Instruction) -> bool:
return (
instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
and instruction.instruction_id
in (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
)
)
def __getattr__(name: str) -> Type[Instruction]: def __getattr__(name: str) -> Type[Instruction]:
def get_id(name: str) -> tuple[str, InstructionId]: def get_id(name: str) -> tuple[str, InstructionId]:
if name == "SystemProgramCreateAccountInstruction": if name == "SystemProgramCreateAccountInstruction":

View File

@ -83,6 +83,29 @@ COMPUTE_BUDGET_PROGRAM_ID = _COMPUTE_BUDGET_PROGRAM_ID
COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT
COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE
def is_system_program_account_creation(instruction: Instruction) -> bool:
return (
instruction.program_id == _SYSTEM_PROGRAM_ID
and instruction.instruction_id in (
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
)
)
def is_atap_account_creation(instruction: Instruction) -> bool:
return (
instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
and instruction.instruction_id in (
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
)
)
def __getattr__(name: str) -> Type[Instruction]: def __getattr__(name: str) -> Type[Instruction]:
def get_id(name: str) -> tuple[str, InstructionId]: def get_id(name: str) -> tuple[str, InstructionId]:
%for program in programs["programs"]: %for program in programs["programs"]: