-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(trezor): add segwit support for withdraw with trezor #1984
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Only minor comments!
I reviewed the main code changes, will check the ported emulator code and the tests in the next and last iteration :)
@@ -0,0 +1,160 @@ | |||
/// This source file was borrowed from Trezor repo and modified to integrate into this project | |||
/// Adds udp transport to interact with trezor emulator | |||
/// To build emulator use this repo: https://github.com/trezor/trezor-firmware, build with build-docker.sh for the desired branch (tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea in the future to build and run the trezor emulator in CI to have trezor dockerized tests, please add this to the checklist here #964 (comment) or create a new checklist in a new comment on the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just create an issue?
(I am just not sure how to find that checklist as it appears buried inside another issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just create an issue?
Sure, please create an issue.
mm2src/trezor/src/transport/udp.rs
Outdated
@@ -0,0 +1,160 @@ | |||
/// This source file was borrowed from Trezor repo and modified to integrate into this project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ported code, this guidelines #1861 (review) #1861 (comment) are generally a good idea so we can track the changes in the commit history. If it's not easy to do that now, no problem but please remember this for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to change commits to add the origin ported file to the history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, before merging you should squash other commits except the ported code commit, then I should merge to dev without squashing so we would have 2 commits only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please clarify, 2 or 3 commits?
in the guidelines above it is suggested to have 3 commits: initial ported code, changes to the ported code and the rest of the work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, 3 commits is the best way :)
I thought 2 is not a big difference since the other commit will have the changes too, but 3 is better to have a seperate commit related to changes to ported the code only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you for the fixes! Next review iteration where it's all also minor stuff to make the code better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
All unresolved comments are non-blockers, so you can work on them while testing for this feature is underway.
@dimxy I don't think we need to document anything for @KomodoPlatform/qa since this works the same as it does for non-segwit UTXO coins. The only thing needs mentioning is that we need to change the segwit coins derivation path, e.g. here https://github.com/KomodoPlatform/coins/blob/1194a05e76c416437c33658b8eacdf235216d23a/coins#L2074 since the purpose for segwit is |
I agree that we should fix the purpose field for segwit coins to make it correct according to the BIP84 standard. |
rebased on the latest dev |
Can you please include some working method examples? I'm only getting errors here at the moment.
|
I have a couple of samples in the code. They are marked 'ignored' as require trezor connected or emulator running:
they both create and print a signed transaction on BTC testnet. the path used is m/44'/1'/0'/0/0 and m/84'/1'/0'/0/0, you'll need some value on that account. |
I think pin is not supported yet (I tried my samples with no pin set on trezor)
this apparently relates to improper derivation path in the withdraw params |
added a small fix for the trezor withdraw test (removed an unused object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Some change notes from my side:
@@ -20,6 +20,7 @@ run-docker-tests = [] | |||
# TODO | |||
enable-solana = [] | |||
default = [] | |||
trezor-udp = ["crypto/trezor-udp"] # use for tests to connect to trezor emulator over udp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use for tests to connect to trezor emulator over udp
If we enable this by default here, wouldn't it be enabled for release binaries as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dimxy Is this fixed? I see that it's not enabled by default now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed this.
I tried to mark the code as #[cfg(all(test, feature = "trezor-udp"))]
but in this case the udp support is not included when I run tests using this feature. I guess, this is because the tests are in a different crate.
#[cfg(feature = "trezor-udp")] | ||
// try also to connect to emulator over UDP | ||
if let Some(trezor) = try_to_connect::<trezor::transport::udp::UdpAvailableDevice>().await? { | ||
return Ok(trezor); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be enough to check whether if mm2 running on debug mode or not? Adding a feature for just this piece of code seems an overkill to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea for adding udp as a feature was that normally we would use those tests for trezor with a physical device (that is why I marked them 'ignored' so you need to have a device to run them) and only who wishes to build and use emulator would enable this feature.
(Later we will add ci tests which include emulator auto build and start)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Tool to run withdraw directly with trezor device or emulator (no rpc version, added for easier debugging)
/// run cargo test with '--ignored' option
But we have many other tests marked as ignored too, so this test will end up with lots of other tests running and most of them probably will fail. Here we should actually use the feature flag e.g., cargo test --features enable-device-tests
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thank you for this idea, I'll add this feature for device test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that run-device-tests
feature is added, please confirm that this is fixed @dimxy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I added a feature "run-device-tests" (to invoke trezor tests, if needed)
@@ -22,10 +22,14 @@ serde_derive = "1.0" | |||
|
|||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | |||
bip32 = { version = "0.2.2", default-features = false, features = ["alloc", "secp256k1-ffi"] } | |||
async-std = { version = "1.5" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
secure code reviewed async-std
…s, fixed doc comments
… emulator support (via udp), add test config helpers, add layer to connect to Trezor or emulator over usb and udp
…me, better naming and constraints, thanks to shamardy)
…ared for extended use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
* dev: (24 commits) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) fix(config): accept a string as rpcport value (KomodoPlatform#2026) feat(nft): move db lock, add tx fee and confirmations (KomodoPlatform#1989) chore(network): update seednodes for netid 8762 (KomodoPlatform#2024) chore(network): add todo on peer storage behaviour (KomodoPlatform#2025) chore(network): exclude `168.119.236.249` from the seednode list (KomodoPlatform#2021) feat(network): deprecate 7777 network (KomodoPlatform#2020) chore(release): bump mm2 version to 2.0.0-beta (KomodoPlatform#2018) feat(UTXO swaps): kmd burn plan impl (KomodoPlatform#2006) chore(docs): fix the link to simple market maker in README.md (KomodoPlatform#2011) ...
* evm-hd-wallet: (27 commits) Fix todo comments Fix HDAddressOps::Address trait bounds fix(indexeddb): fix IDB cursor.continue_() call after drop (KomodoPlatform#2028) security bump for `h2` (KomodoPlatform#2062) fix(makerbot): allow more than one prices url in makerbot (KomodoPlatform#2027) fix(wasm worker env): refactor direct usage of `window` (KomodoPlatform#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (KomodoPlatform#2039) refactor(utxo): refactor utxo output script creation (KomodoPlatform#1960) feat(ETH): balance event streaming for ETH (KomodoPlatform#2041) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) ...
* dev: feat(zcoin): ARRR WASM implementation (KomodoPlatform#1957) feat(trading-proto-upgrade): locked amounts, kmd burn and other impl (KomodoPlatform#2046) fix(indexeddb): set stop on success cursor condition (KomodoPlatform#2067) feat(config): add `max_concurrent_connections` to mm2 config (KomodoPlatform#2063) feat(stats_swaps): add gui/mm_version in stats db (KomodoPlatform#2061) fix(indexeddb): fix IDB cursor.continue_() call after drop (KomodoPlatform#2028) security bump for `h2` (KomodoPlatform#2062) fix(makerbot): allow more than one prices url in makerbot (KomodoPlatform#2027) fix(wasm worker env): refactor direct usage of `window` (KomodoPlatform#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (KomodoPlatform#2039) refactor(utxo): refactor utxo output script creation (KomodoPlatform#1960) feat(ETH): balance event streaming for ETH (KomodoPlatform#2041) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984)
Add support for witness inputs and outputs for withdraw tx to sign it with trezor device
Add test tool to sign withdraw tx with witness inputs/outputs with trezor and emulator
Closes #1685