chore: use separate sc_constants for Tron
What changed, and why it matters
This commit is a routine code cleanup: it creates a Tron-specific copy of some smart-contract constants that were previously borrowed from the Ethereum app, and updates the Tron signing code to use its own copy. There is no functional change to how transactions are validated or signed, and no security bug is fixed or introduced.
No security action needed; treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors constant definitions for the Tron app. A new file core/src/apps/tron/sc_constants.py is added, duplicating constants (function signatures for Transfer/Approve/Stake/Unstake/Claim, argument sizes, etc.) that previously lived in core/src/apps/ethereum/sc_constants.py. sign_tx.py is updated to import from the local module, and the new qstr is registered in qstrdefsport.h. The values are identical to the Ethereum originals, so behavior is unchanged.
Changed components
core/src/apps/tron/sign_tx.pycore/src/apps/tron/sc_constants.pycore/embed/upymod/qstrdefsport.hInspect captured patch +20 / −1
diff --git a/core/embed/upymod/qstrdefsport.h b/core/embed/upymod/qstrdefsport.h
index 0ab382f7..86d248d5 100644
--- a/core/embed/upymod/qstrdefsport.h
+++ b/core/embed/upymod/qstrdefsport.h
@@ -659,6 +659,7 @@ Q(apps.tron.consts)
Q(apps.tron.get_address)
Q(apps.tron.helpers)
Q(apps.tron.layout)
+Q(apps.tron.sc_constants)
Q(apps.tron.sign_tx)
Q(apps.webauthn)
Q(apps.webauthn.add_resident_credential)
diff --git a/core/src/apps/tron/sc_constants.py b/core/src/apps/tron/sc_constants.py
new file mode 100644
index 00000000..746187cc
--- /dev/null
+++ b/core/src/apps/tron/sc_constants.py
@@ -0,0 +1,18 @@
+from micropython import const
+from ubinascii import unhexlify
+
+# smart contract 'data' field lengths in bytes
+SC_FUNC_SIG_BYTES = const(4)
+SC_ARGUMENT_BYTES = const(32)
+SC_ARGUMENT_ADDRESS_BYTES = const(20)
+SC_FUNC_APPROVE_REVOKE_AMOUNT = const(0)
+
+assert SC_ARGUMENT_ADDRESS_BYTES <= SC_ARGUMENT_BYTES
+
+# Known ERC-20 functions
+
+SC_FUNC_SIG_TRANSFER = unhexlify("a9059cbb")
+SC_FUNC_SIG_APPROVE = unhexlify("095ea7b3")
+SC_FUNC_SIG_STAKE = unhexlify("3a29dbae")
+SC_FUNC_SIG_UNSTAKE = unhexlify("76ec871c")
+SC_FUNC_SIG_CLAIM = unhexlify("33986ffa")
diff --git a/core/src/apps/tron/sign_tx.py b/core/src/apps/tron/sign_tx.py
index cc7e59b8..d2b9608a 100644
--- a/core/src/apps/tron/sign_tx.py
+++ b/core/src/apps/tron/sign_tx.py
@@ -130,7 +130,7 @@ async def process_known_trc20_contract(
"""Returns False when the contract is unrecoginsed. i.e. not (Transfer and known TRC-20)"""
from trezor.utils import BufferReader
- from ..ethereum.sc_constants import (
+ from .sc_constants import (
SC_ARGUMENT_ADDRESS_BYTES,
SC_ARGUMENT_BYTES,
SC_FUNC_SIG_BYTES,
Why this scored 15/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.