Repository navigation
feat(node): accept a TronLink signature (TIP-191 signMessageV2) on a transaction - #24
Merged
Merged
Conversation
…transaction
TronLink will not sign a bare hash either. It signs a text with signMessageV2
(TIP-191). That is personal_sign with the prefix "\x19TRON Signed Message:\n"
in place of the Ethereum one. The key, the curve, the Keccak-256 and the 20
address bytes are the same as for an Ethereum key, so a TronLink account is a
Clutch account already. TRON only writes the address in base58.
Transaction::verify_signature now accepts a third scheme, next to the
hash-string signature and the personal_sign one:
Keccak256("\x19TRON Signed Message:\n" + len + "clutch-tx:{chain_id}:{hash}")
Each scheme has its own digest, so one cannot pass for another, and the text
names the chain. The wire format and the hash do not change.
This is a consensus change. A node without it rejects a block that carries a
TronLink transaction, so every validator must run this build first.
Tests: the layout of tron_sign_bytes; a signature made by TronWeb 6.5.1 itself
(the library TronLink wraps) verifies, and does not verify under the other
prefix; the transaction cases for chain, key, transaction and an unknown
prefix; two whole-path tests (pool, block, balance) in
tests/wallet_signature.rs.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The node now accepts a third signature on a transaction: the one TronLink makes. This is a consensus change.
TronLink will not sign a bare hash. It signs a text with
signMessageV2(TIP-191). That ispersonal_signwith the prefix\x19TRON Signed Message:\nin place of\x19Ethereum Signed Message:\n. A TRON account is the same kind of key as an Ethereum key: the same curve, the same Keccak-256 and the same 20 address bytes. TRON only writes the address in base58 with a0x41prefix. So a TronLink account is already a valid Clutch account, and only the digest is new.Keccak256(hash string)(unchanged)Keccak256("\x19Ethereum Signed Message:\n" + len + "clutch-tx:{chain_id}:{hash}")(unchanged)Keccak256("\x19TRON Signed Message:\n" + len + "clutch-tx:{chain_id}:{hash}")Each scheme has its own digest, so one cannot pass for another. The text names the chain, and
verify_hashties the hash tochain_id, so a signature cannot move to another chain or another transaction. The wire format and the hash do not change. Block, authority and mint-cosignature checks are untouched.Rollout rule: a node without this build rejects a block that carries a TronLink transaction, so every validator must run it before the first TronLink transaction. Nothing sends one until the Hub API, SDK and demo app release that follows this PR.
Tests (by name in CI)
tron_sign_bytes_has_the_tip191_layout,the_tron_and_ethereum_digests_of_one_text_differa_signature_tronweb_made_verifies: the signature comes from TronWeb 6.5.1 itself (trx.signMessageV2, the library TronLink wraps), not from this code. I also checked the digest layout with a second library (@noble) before I wrote the Rust.verify_signature_accepts_a_tronlink_signature,…_the_sign_tron_helper,…_the_signature_tronweb_made…_rejects_a_tronlink_signature_for_another_chain,…_from_another_key,…_for_another_transaction, andverify_signature_accepts_each_prefix_and_no_other(a prefix the node does not know is refused)a_tronlink_signed_transfer_is_accepted_and_applied,a_tronlink_signature_made_for_another_chain_is_refusedNot in this PR
The Hub API login, the SDK signer and the demo app. They follow in clutch-hub, after this build is live on stage.
🤖 Generated with Claude Code