-
Notifications
You must be signed in to change notification settings - Fork 632
[CBR-288] Review wallet peripheral utilities #3128
[CBR-288] Review wallet peripheral utilities #3128
Conversation
…hecksum-fix [CO-298] Apply fix from haskoin on mnemonic checksum calculation
See haskoin@f00f09d392ca38bb4b68a65c8515ed70f8986841
* [CBR-298] Remove integration test script * [CBR-298] Add info about how to run integration test to README
- Note that the old implementations have been kept for now in wallet/test/Test/Pos/Util. They are compared side-by-side with the current refactoring to make sure I don't mess up with something and preserve the old behavior. That's rather crucial since this part is at the core of Wallet restoration. - Also started a surface refactor, introducing newtypes instead of type aliases and simplifying some functions (moving logic around instead of having it split across 14,546 packages)
They're actually very close... one 'serialize' away! This commit also adds side-by-side testing of the function getting the AESKey from the mnemonic to make sure that the new implementation matches the old one
- The revision removes a lot of the heavy bits manipulation that were really unclear and hard to grasp. - It heavily relies on smart-constructor to define some invariant and allow conversion functions later on to become pure and not failable basically eliminating possible errors by design.
The implementation has been slightly reviewed to avoid duplication there and also to increase type-safety. The from and to bits functions are now tested with QuickCheck.
This has the advantage to represent each mnemonic phrase by a different type for thiner guaranties in the implementation. It makes it explicit at first glance what type of Mnemonic is used
It appeared that we've doing double work on that. Instead of having two separated implementations of the same stuff, I've remodeled cardano-sl implementation to leverage the work done in cardano-crypto. This leaves us with a small and simple façade used across cardano-sl
The previous implementation wrapped the backup phrases in a singleton object with a 'bpToList' property. This is now preserved
This is a textbook side channel timing measurement. not a very straightforward/useful one, but this could be used to determine some information about the mnemonics.
…cardano-crypto The legacy-compatibility were there during the refactoring to ensure behavior with the old code was preserved; now that the refactor is done, it doesn't make much sense to keep them, nor is the old code. Instead, we now have a few golden tests to make sure that new modification won't introduce any regression since we now that the current refactor behaves as the old one.
…emonic-implementation [CBR-289] Review mnemonic implementation
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
tools/src/dbgen/Lib.hs
Outdated
-- | Generates a new 'Mnemonic'. | ||
newRandomMnemonic :: WalletWebMode (Mnemonic 12) | ||
newRandomMnemonic = | ||
liftIO $ (entropyToMnemonic <$> genEntropy) |
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.
extra parens
|
||
-- | A backup-phrase in the form of a non-empty of Mnemonic words | ||
-- Constructor isn't exposed. | ||
data Mnemonic (mw :: Nat) = Mnemonic |
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.
<3
\e -> (mnemonicToEntropy @12 . entropyToMnemonic @12 @(EntropySize 12)) e == e | ||
|
||
prop "(9) parseJSON . toJSON == pure" $ | ||
\(mw :: Mnemonic 9) -> (Aeson.decode . Aeson.encode) mw === pure mw |
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 might be able to move this to aeson roundtrip tests prop (the same way how we test other aeson roundtrips).
Aeson.decode bytes `shouldBe` (pure mnemonic) | ||
|
||
it "CBackupPhrase to JSON" $ forM_ testVectors $ \(bytes, _, mnemonic, _, _) -> | ||
Aeson.encode (CBackupPhrase mnemonic) `shouldBe` (jsonV0Compat bytes) |
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.
👍
Aeson.encode (CBackupPhrase mnemonic) `shouldBe` (jsonV0Compat bytes) | ||
|
||
it "CBackupPhrase from JSON" $ forM_ testVectors $ \(bytes, _, mnemonic, _, _) -> | ||
Aeson.decode (jsonV0Compat bytes) `shouldBe` (pure $ CBackupPhrase mnemonic) |
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.
👍
mkEntropy' = | ||
maybe (Left MnemonicErrFailedToCreate) Right . toEntropy @128 @4 @ByteString | ||
|
||
-- | V0 Mnemonics are wrapped in a singleton object with a `bpToList` prop |
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.
👍
3d4abce
to
6a36e02
Compare
Description
Linked issue
Type of change
Developer checklist
Testing checklist
QA Steps
Screenshots (if available)