-
Notifications
You must be signed in to change notification settings - Fork 224
Byron wallet restoration from xprv endpoint integration test #1476
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
Byron wallet restoration from xprv endpoint integration test #1476
Conversation
b8220c7
to
9aa7e4a
Compare
@paweljakubas, @KtorZ If that'e the case there is some data from the script produced while testing that could be used for testing the endpoint (input-output-hk/cardano-sl#4278 (comment) or input-output-hk/cardano-sl#4278 (comment)). However trying this (input-output-hk/cardano-sl#4278 (comment)) data on testnet is not successful. Mostly results in:
but also errors about invalid Json or name (more details below), which is unexpected because I was able to create this data using cardano-wallet on cardano-sl and then exported it using Details of the request/response using this data:
👇
👇
👇
👇
👇
|
9aa7e4a
to
0c3ccb4
Compare
@piotr-iohk I was aware of this restriction (hence this PR). When designing this U/S we were thinking that 64-byte passphrase hash is requirement. But it turn out to be wrong. Which is corrected in 0c3ccb4 |
Correct ✔️
Damn. I didn't thought about the length of the name... I just checked, in -sl, there's no actual upper limit, so names could in practice be of any arbitrary length... We can't possibly accept that on the new implementation. But I am not sure that rejecting restoration would help. Truncating the name down to 255 characters could make sense, don't you think @piotr-iohk @paweljakubas ? It's quite an edge-case and, what we do really want is users to be able to identify their wallets. Also, to be checked with Daedalus but, there's maybe a limit on the frontend, so all Daedalus users should actually do quite okay and not run into the issue at all. So maybe rejecting is fine after all and truncating isn't needed. |
there is limitation on wallet name in daedalus : https://github.com/input-output-hk/daedalus/blob/318e5ec583ed3c0220b2f801cbf3b6f88713464c/source/renderer/app/utils/validations.js#L6 |
bors try |
tryBuild failed |
bors try |
tryBuild failed |
two times failing because of :
|
c3a07e7
to
325ff5d
Compare
\597a425834515177666475467578436b4d485569733d7c78324d646738\ | ||
\49554a3232507235676531393575445a76583646552b7757395a6a6a2f\ | ||
\51303054356c654751794279732f7662753367526d726c316c657a7150\ | ||
\43676d364e6758476d4d2f4b6438343265304b4945773d3d" |
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.
Where does this hash come from 😶 ?
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 added tests for "cardano-wallet" here : https://github.com/input-output-hk/cardano-wallet/pull/1476/files#diff-131f348ed80ae192131796acae9042efR273
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.
moved to DSL with proper comment : c8e89ed
@@ -270,15 +270,13 @@ x-walletPassphrase: &walletPassphrase | |||
|
|||
x-walletPassphraseHash: &walletPassphraseHash | |||
description: | | |||
A hash of master passphrase. The hash should be a 64-byte output of a Scrypt function with the following parameters: | |||
A hash of master passphrase. The hash should be an output of a Scrypt function with the following parameters: |
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.
We do know the size however right, it's actually a 100 bytes? So 200 hex-encoded. Isn't it.
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.
when looking at https://github.com/input-output-hk/cardano-wallet/pull/1476/files#diff-131f348ed80ae192131796acae9042efR247-R280
I see that the hex-encoded strings are the same in length, but the one added by you ("patate") is different. I used this to have it :
let p = Passphrase @"raw" $ BA.convert $ T.encodeUtf8 PASSWD
hp <- encryptPasswordWithScrypt p
TR.trace ("hp:"<>show (hex hp))
("Byron Wallet", rootXPrv, passwHash) | ||
rd2 <- request | ||
@ApiByronWallet ctx (Link.deleteWallet @'Byron w2) Default Empty | ||
expectResponseCode @IO HTTP.status204 rd2 |
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.
What's the difference between this scenario and the one in "BYRON_RESTORE_01 - one recipient". To me, it sounds like the latter makes this one redundant (as it includes it already, but has more steps)
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, BYRON_RESTORE_01 is more powerful and check everything what is here, and even more
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.
addressed in c8e89ed
@@ -685,7 +684,14 @@ instance ToText (ApiT XPrv) where | |||
. getApiT | |||
|
|||
instance FromText (ApiT (Hash "encryption")) where | |||
fromText = fmap ApiT . hashFromText 64 |
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.
Why not hashFromText 100
🤔 Can the Scrypt output actually be of different sizes ?
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.
if i is 100
then we should have hashFromText 100
but I have this comment : #1476 (comment)
Hash . Scrypt.getEncryptedPass <$> | ||
Scrypt.encryptPassIO Scrypt.defaultParams (Scrypt.Pass $ BA.convert passwd) | ||
where | ||
(Passphrase passwd) = preparePassphrase EncryptWithScrypt p |
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.
side note, Passphrase
has an instance of ByteArrayAccess
, to BA.convert
can be called on it directly, no need to pattern match on this output 👍
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.
Passphrase
is BA.ScrubbedBytes
inside and Scrypt.Pass
requires B8.ByteString
- hence I used BA.convert
here
p /= p' ==> monadicIO $ liftIO $ do | ||
hp <- encryptPasswordWithScrypt p | ||
checkPassphrase EncryptWithScrypt p' hp | ||
`shouldBe` Left ErrWrongPassphrase |
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.
👍
-> Property | ||
prop_passphraseFromScryptRoundtrip p = monadicIO $ liftIO $ do | ||
hp <- encryptPasswordWithScrypt p | ||
checkPassphrase EncryptWithScrypt p hp `shouldBe` Right () |
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.
👍
One thing that would be worth testing as well is, what happens if we submit an "invalid" passphrase hash? Something that wasn't generated from Scrypt. The behavior should be that we basically fail to use this wallet because we'll never possibly get the passphrase. It'll be good to make sure that the scrypt function doesn't throw when presented an illed-formed passphrase :s |
lib/byron/test/integration/Test/Integration/Byron/Scenario/API/Transactions.hs
Show resolved
Hide resolved
e3a3d5e
to
30ea64d
Compare
@piotr-iohk @KtorZ I added integration test with corrupt passphrase hash, but correct rootXPrv and it restored in a sense that available balance is like faucet wallet, but was expecting different :
The test was added here : 359c914 BUT it seems to be ok, because restoration is basing on master key as specified here : https://github.com/input-output-hk/cardano-wallet/blob/master/lib/core/src/Cardano/Wallet/Api/Server.hs#L910 Is this as expected? |
re: #1476 (comment)
I wonder if we should allow restoring in case of corrupt passphrase... it makes the wallet useless I suppose, cause the passphrase is ... unavailable, isn't it. |
@paweljakubas @piotr-iohk that's a feature of Random wallets in the Byron era indeed. Good to know:
Thus @paweljakubas , this is indeed expected. You do not need the passphrase to actually restore the wallet. So, the passphrase hash can be complete garbage, one would still be able to restore the wallet with only the a. From @paweljakubas' tests, it seems that the Scrypt b. In theory, you can only really know whether the passphrase is correct when you actually get your hand on the passphrase (i.e., when submitting a transaction) 🙃 |
@KtorZ thanks for confirmation and comment. It would be good then to add test restoring wallet with wrong passphrase hash and show that making tx is not possible with it. |
359c914
to
f457078
Compare
correct property tests
compilation correction
correct expectation plus nix patch
f457078
to
e721b26
Compare
bors try |
tryBuild succeeded |
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
Issue Number
#1436
Overview
Comments