fix(solana): verify accounts in sysvar slots
What changed, and why it matters
This update fixes a security issue in how Trezor handles Solana transactions. Some Solana programs use special 'sysvar' accounts in fixed slots. A malicious transaction could put a different account into one of those slots, causing the device to interpret the remaining accounts incorrectly and approve a transaction that looks safe on screen but does something else on the blockchain. The fix makes the device reject any transaction where a sysvar slot does not contain the exact expected sysvar account.
Apply the patch and ensure generated instructions.py is rebuilt from the updated .mako template. Run the new TestSolanaSysvarAccounts tests and the corrected staking transaction fixtures. Consider auditing other program parsers that rely on positional account semantics for similar slot-validation gaps.
Security signals we found
UI-to-blockchain account role mismatch
Missing validation of expected sysvar account public keys
Version-0 address lookup table references bypass static verification
Changelog explicitly labels change as security-relevant
Fixtures previously contained an incorrect sysvar account
Evidence from the diff
The Solana Stake program v5 made sysvar accounts optional and chooses the account layout by checking whether a sysvar slot actually holds the sysvar. Because Trezor previously did not verify the sysvar slot contents, an attacker could substitute another account in that slot, shifting subsequent accounts into different semantic roles than those displayed to the user. The patch adds a SYSVAR_ACCOUNTS map and validates that any reference named *_sysvar resolves to the expected base58 sysvar public key; it also rejects address-table references in those slots because they cannot be verified. Fixtures were corrected to supply the real StakeHistory sysvar instead of ComputeBudget.
Changed components
core/src/apps/solana/transaction/instruction.pycore/src/apps/solana/transaction/instructions.pycore/src/apps/solana/transaction/instructions.py.makocommon/defs/solana/programs.jsoncore/tests/test_apps.solana.transaction.pyInspect captured patch +116 / −15
### common/defs/solana/programs.json
@@ -2586,6 +2586,12 @@
]
}
],
+ "sysvars": {
+ "clock_sysvar": "SysvarC1ock11111111111111111111111111111111",
+ "rent_sysvar": "SysvarRent111111111111111111111111111111111",
+ "stake_history_sysvar": "SysvarStakeHistory1111111111111111111111111",
+ "recent_blockhashes_sysvar": "SysvarRecentB1ockHashes11111111111111111111"
+ },
"types": {
"u8": {
"parse": "parse_byte",
### common/tests/fixtures/solana/sign_tx.staking_transactions.json
@@ -383,14 +383,15 @@
"header": {
"signers": 1,
"readonly_signers": 0,
- "readonly_non_signers": 3
+ "readonly_non_signers": 4
},
"accounts": [
"14CCvQzQzHCVgZM3j9soPnXuJXh1RmCfwLVUcdfbZVBS",
"ATFXMD5cYiw9yHkvexgx3nf9LNSouEViB5BZBsgwunAv",
"Stake11111111111111111111111111111111111111",
"SysvarC1ock11111111111111111111111111111111",
- "ComputeBudget111111111111111111111111111111"
+ "ComputeBudget111111111111111111111111111111",
+ "SysvarStakeHistory1111111111111111111111111"
],
"blockhash": "2p4rYZAaFfV5Uk5ugdG5KPNty9Uda9B3b4gWB8qnNqak",
"instructions": [
@@ -408,7 +409,7 @@
"stake_account": 1,
"recipient_account": 0,
"clock_sysvar": 3,
- "stake_history_sysvar": 4,
+ "stake_history_sysvar": 5,
"withdrawal_authority": 0,
"lockup_authority": 0
},
@@ -422,7 +423,7 @@
}
},
"result": {
- "expected_signature": "4edf71d1b4d075c6717617ef43cd896a80153f418dbe4cca5e66ee9f27bd5652bec67d30ee9a14e3bd7062dd72ed619cf238e6f5538b150dae34d24bee650303"
+ "expected_signature": "31f428aa2e363b07bdb920438502a723ccfebfcc252b60022cf9f41c661d5b1f107380f6c151a851383d2347698ff51d0cff06aba78872480be7c1273b022c05"
}
},
{
@@ -434,15 +435,16 @@
"header": {
"signers": 1,
"readonly_signers": 0,
- "readonly_non_signers": 3
+ "readonly_non_signers": 4
},
"accounts": [
"14CCvQzQzHCVgZM3j9soPnXuJXh1RmCfwLVUcdfbZVBS",
"ATFXMD5cYiw9yHkvexgx3nf9LNSouEViB5BZBsgwunAv",
"Stake11111111111111111111111111111111111111",
"SysvarC1ock11111111111111111111111111111111",
"ComputeBudget111111111111111111111111111111",
- "AeDJ1BqA7ruBbd6mEcS1QNxFbT8FQbiBVuN9NqK94Taq"
+ "AeDJ1BqA7ruBbd6mEcS1QNxFbT8FQbiBVuN9NqK94Taq",
+ "SysvarStakeHistory1111111111111111111111111"
],
"blockhash": "2p4rYZAaFfV5Uk5ugdG5KPNty9Uda9B3b4gWB8qnNqak",
"instructions": [
@@ -460,7 +462,7 @@
"stake_account": 1,
"recipient_account": 0,
"clock_sysvar": 3,
- "stake_history_sysvar": 4,
+ "stake_history_sysvar": 6,
"withdrawal_authority": 0,
"lockup_authority": 0
},
@@ -475,7 +477,7 @@
"stake_account": 5,
"recipient_account": 0,
"clock_sysvar": 3,
- "stake_history_sysvar": 4,
+ "stake_history_sysvar": 6,
"withdrawal_authority": 0,
"lockup_authority": 0
},
@@ -489,7 +491,7 @@
}
},
"result": {
- "expected_signature": "87a376794de2e69b6bd46b2f48081aa915d97139706a1fa9aef9d5efd95615bb1f71c8bc64155b2d602cb259a2ac5d3a91a0cc6d95afc0d573bcf17f2bbc2e09"
+ "expected_signature": "8e9cfeea62b1cb7b17a5bfbc0630a9cc16f3f31d6387ee1383cc1801431c3cd681ea262266ce57653e8de94cc7935f80698fd9826696ede02040b06088b52b08"
}
},
{
@@ -501,15 +503,16 @@
"header": {
"signers": 1,
"readonly_signers": 0,
- "readonly_non_signers": 3
+ "readonly_non_signers": 4
},
"accounts": [
"14CCvQzQzHCVgZM3j9soPnXuJXh1RmCfwLVUcdfbZVBS",
"ATFXMD5cYiw9yHkvexgx3nf9LNSouEViB5BZBsgwunAv",
"Stake11111111111111111111111111111111111111",
"SysvarC1ock11111111111111111111111111111111",
"ComputeBudget111111111111111111111111111111",
- "AeDJ1BqA7ruBbd6mEcS1QNxFbT8FQbiBVuN9NqK94Taq"
+ "AeDJ1BqA7ruBbd6mEcS1QNxFbT8FQbiBVuN9NqK94Taq",
+ "SysvarStakeHistory1111111111111111111111111"
],
"blockhash": "2p4rYZAaFfV5Uk5ugdG5KPNty9Uda9B3b4gWB8qnNqak",
"instructions": [
@@ -527,7 +530,7 @@
"stake_account": 1,
"recipient_account": 5,
"clock_sysvar": 3,
- "stake_history_sysvar": 4,
+ "stake_history_sysvar": 6,
"withdrawal_authority": 0,
"lockup_authority": 0
},
@@ -541,7 +544,7 @@
}
},
"result": {
- "expected_signature": "53e953033988f8ce3cca4f7d1f94da41d8f3d1467724785f5cd9c4d16250198429a5d27bc474a66d4c1bf4a936c680f51973d54a3b16a2b73e62ecbb1f062104"
+ "expected_signature": "9964ba4386e8245a34c3e808344958b96560c8628eb4145e2e9bcd4c7765cdad35b2c5febaf423b491d2ee3178e91e9cd3ebb80ee33754ed72306d6151bb1f0b"
}
}
]
### core/.changelog.d/+solana_sysvar_accounts.security
@@ -0,0 +1 @@
+Solana: Reject instructions whose sysvar account slot holds a different account or a lookup-table reference.
### core/src/apps/solana/README.md
@@ -207,13 +207,14 @@ The `programs.json` file serves as a structured configuration file in the Solana
- `type`: The data type of the parameter, such as `u64` for 64-bit unsigned integers.
- `optional`: Indicates whether the parameter is optional.
- `args`: An optional dict of arguments for the formatter, see explanation below.
- - `references`: An array of account names that are used by the instruction.
+ - `references`: An array of account names that are used by the instruction. A reference named `*_sysvar` must hold the account listed under `sysvars`, otherwise the transaction is rejected.
- `references_required`: The number of references required by the instruction. If more `references` are specified than required, the extra ones are optional, and may or may not be present in the transaction.
- `ui_properties`: Contains user interface-related information for this instruction.
- `account`: Reference to one account in the references list identified by its `name`
- `parameter`: Reference to one parameter in the parameters list identified by its `name`
- `display_name`: A human-readable label for the parameter or account, suitable for user interfaces.
- `default_value_to_hide`: Optional. If this value is found in the account / parameter, the UI property will not be shown for confirmation. This is useful when the default value is considered safe. Two special words are recognized: if `"signer"` is used and the value of the property is a public key, the UI property will be hidden if the public key matches the Trezor's account; if `"none"` is used, the UI property will be hidden if its value is `None` (an absent optional parameter, which is otherwise displayed as `None`). An absent optional account reference is always hidden, regardless of `default_value_to_hide`.
+- `sysvars`: Maps every `*_sysvar` reference name to the base58 encoded sysvar account it must hold.
Certain types of parameters, specified in `types` dict of the `programs.json` file, have special formatting capabilities.
In particular, the type `token_amount` is a regular `u64` type, but the formatter function accepts additional parameters:
### core/src/apps/solana/transaction/instruction.py
@@ -65,14 +65,23 @@ def parse_instruction_accounts(
accounts_required: int,
account_templates: tuple[str, ...],
) -> dict[str, Account]:
+ from ..types import is_address_reference
+ from .instructions import SYSVAR_ACCOUNTS
+
parsed_accounts = {}
if len(accounts) < accounts_required:
raise ValueError # "Account is missing
for i, account_name in enumerate(account_templates):
if i >= len(accounts):
break
- parsed_accounts[account_name] = accounts[i]
+ account = accounts[i]
+ sysvar = SYSVAR_ACCOUNTS.get(account_name)
+ if sysvar is not None and (
+ is_address_reference(account) or account[0] != sysvar
+ ):
+ raise ValueError # Sysvar slot does not hold the expected sysvar
+ parsed_accounts[account_name] = account
return parsed_accounts
def __init__(
### core/src/apps/solana/transaction/instructions.py
@@ -40,6 +40,15 @@
_MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
_MEMO_LEGACY_PROGRAM_ID = "Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"
+
+# Accounts that the `*_sysvar` references must hold.
+SYSVAR_ACCOUNTS: dict[str, bytes] = {
+ "clock_sysvar": b"\x06\xa7\xd5\x17\x18\xc7t\xc9(Vc\x98i\x1d^\xb6\x8b^\xb8\xa3\x9bKm\\sU[!\x00\x00\x00\x00",
+ "rent_sysvar": b"\x06\xa7\xd5\x17\x19,\\Q!\x8c\xc9L=J\xf1\x7fX\xda\xee\x08\x9b\xa1\xfdD\xe3\xdb\xd9\x8a\x00\x00\x00\x00",
+ "stake_history_sysvar": b"\x06\xa7\xd5\x17\x195\x84\xd0\xfe\xed\x9b\xb3C\x1d\x13 k\xe5D(\x1bW\xb8Vl\xc57_\xf4\x00\x00\x00",
+ "recent_blockhashes_sysvar": b"\x06\xa7\xd5\x17\x19,V\x8e\xe0\x8a\x84_s\xd2\x97\x88\xcf\x03\\1E\xb2\x1a\xb3D\xd8\x06.\xa9@\x00\x00",
+}
+
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT = const(0)
_SYSTEM_PROGRAM_ID_INS_ASSIGN = const(1)
_SYSTEM_PROGRAM_ID_INS_TRANSFER = const(2)
### core/src/apps/solana/transaction/instructions.py.mako
@@ -69,6 +69,29 @@ if TYPE_CHECKING:
${getProgramId(program)} = "${program["id"]}"
% endfor
+<%
+ from trezorlib.tools import b58decode
+
+ # Make sure that every `*_sysvar` reference has a known account to check against.
+ sysvars = programs["sysvars"]
+ for name, sysvar in sysvars.items():
+ if not name.endswith("_sysvar"):
+ raise Exception(f"Sysvar \"{name}\" must be named \"*_sysvar\".")
+ if len(b58decode(sysvar)) != 32:
+ raise Exception(f"Sysvar \"{name}\" has an invalid account \"{sysvar}\".")
+ for program in programs["programs"]:
+ for instruction in program["instructions"]:
+ for reference in instruction["references"]:
+ if reference.endswith("_sysvar") and reference not in sysvars:
+ raise Exception(f"Instruction \"{instruction['name']}\" references an unknown sysvar \"{reference}\".")
+%>
+# Accounts that the `*_sysvar` references must hold.
+SYSVAR_ACCOUNTS: dict[str, bytes] = {
+% for name, sysvar in sysvars.items():
+ "${name}": ${repr(b58decode(sysvar))},
+% endfor
+}
+
% for program in programs["programs"]:
% for instruction in program["instructions"]:
% if isinstance(instruction["id"], int):
### core/tests/test_apps.solana.transaction.py
@@ -410,6 +410,55 @@ def test_v0_missing_alts(self):
Transaction(b"\x80" + legacy_tx)
+STAKE_PROGRAM = base58.decode("Stake11111111111111111111111111111111111111")
+CLOCK_SYSVAR = base58.decode("SysvarC1ock11111111111111111111111111111111")
+STAKE_ACCOUNT = b"a" * 32
+# Deactivate (instruction 5) the stake account at index 1, with the Clock sysvar
+# at index 3 and the signer as the stake authority.
+DEACTIVATE_INSTRUCTION: RawInstruction = (2, (1, 3, 0), (5).to_bytes(4, "little"))
+
+
+@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
+class TestSolanaSysvarAccounts(unittest.TestCase):
+ def test_sysvar(self):
+ transaction = Transaction(
+ build_tx(
+ (1, 0, 2),
+ (SIGNER, STAKE_ACCOUNT, STAKE_PROGRAM, CLOCK_SYSVAR),
+ [DEACTIVATE_INSTRUCTION],
+ )
+ )
+ (deactivate,) = transaction.instructions
+ self.assertEqual(
+ deactivate.clock_sysvar, (CLOCK_SYSVAR, AddressType.AddressReadOnly)
+ )
+ self.assertEqual(deactivate.stake_authority, (SIGNER, AddressType.AddressSig))
+
+ def test_other_account(self):
+ with self.assertRaises(ValueError):
+ Transaction(
+ build_tx(
+ (1, 0, 2),
+ (SIGNER, STAKE_ACCOUNT, STAKE_PROGRAM, b"x" * 32),
+ [DEACTIVATE_INSTRUCTION],
+ )
+ )
+
+ def test_alt_reference(self):
+ # The Clock slot refers to index 3, i.e. the first address loaded from
+ # the table right after the static accounts, which can't be verified.
+ with self.assertRaises(ValueError):
+ Transaction(
+ build_tx(
+ (1, 0, 1),
+ (SIGNER, STAKE_ACCOUNT, STAKE_PROGRAM),
+ [DEACTIVATE_INSTRUCTION],
+ version=0,
+ alts=[(b"t" * 32, (), (7,))],
+ )
+ )
+
+
def raw_instructions(transaction: Transaction) -> list[tuple]:
# Instruction data are memoryviews, which can't be compared directly.
return [Why this scored 76/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.