Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Ledger support #428

Closed
2 tasks done
distributedstatemachine opened this issue May 16, 2024 · 1 comment
Closed
2 tasks done

Integrate Ledger support #428

distributedstatemachine opened this issue May 16, 2024 · 1 comment
Assignees

Comments

@distributedstatemachine
Copy link
Collaborator

distributedstatemachine commented May 16, 2024

Ledger App support

Zondax et al. have developed a Ledger app to support generic substrate networks,1 meaning Bittensor will benefit from this app provided we integrate the required changes to our runtime, giving us Ledger support (and other hardware signers).

The changes required involve providing a verification of the chain metadata to consumers, e.g. hardware signers. This change allows hardware signer devices to verify their decoding of transactions, avoiding approvals of maliciously crafted transactions given some unverified metadata.

Background

TODO (from above guide)2:

  • Runtime integration

From the runtime side only the frame_metadata_hash_extension::CheckMetadataHash needs to be added to the list of signed extension[s]

Note:

Adding the signed extension changes the encoding of the transaction and adds one extra byte per transaction!

This signed extension will make sure to decode the requested mode and will add the metadata
hash to the signed data depending on the requested mode. The mode gives the user/wallet
control over deciding if the metadata hash should be verified or not. The metadata hash itself
is drawn from the RUNTIME_METADATA_HASH environment variable. If the environment variable is
not set, any transaction that requires the metadata hash is rejected with the error
CannotLookup. This is a security measurement to prevent including invalid transactions.

Warning

The extension does not work with the native runtime, because the
RUNTIME_METADATA_HASH environment variable is not set when building the
frame-metadata-hash-extension crate.

  • Enable metadata hash generation

The metadata hash generation needs to be enabled when building the wasm binary. The substrate-wasm-builder supports this out of the box

Note:

The metadata-hash feature needs to be enabled for the substrate-wasm-builder to enable the
code for being able to generate the metadata hash. It is also recommended to put the metadata
hash generation behind a feature in the runtime as shown above. The reason behind is that it
adds a lot of code which increases the compile time and the generation itself also increases
the compile time. Thus, it is recommended to enable the feature only when the metadata hash is
required (e.g. for an on-chain build).

The two parameters to enable_metadata_hash are the token symbol and the number of decimals of
the primary token of the chain. These information are included for the wallets to show token
related operations in a more user friendly way.

Footnotes

  1. https://zondax.ch/blog/the-generic-polkadot-ledger-app-proposal

  2. Guide for integration

@camfairchild
Copy link
Contributor

Also requires a change to client-code, notably https://github.com/opentensor/bittensor
See: opentensor/bittensor#2156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants