Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CBR-288] Review wallet peripheral utilities #3128

Merged
merged 24 commits into from
Jun 26, 2018

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Jun 25, 2018

Description

Linked issue

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

QA Steps

  • /!\ CRITICAL /!\ Make sure wallets that were created before this story can still be restored after this story.

Screenshots (if available)

KtorZ and others added 23 commits June 25, 2018 15:22
…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
Copy link
Contributor

@akegalj akegalj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

-- | Generates a new 'Mnemonic'.
newRandomMnemonic :: WalletWebMode (Mnemonic 12)
newRandomMnemonic =
liftIO $ (entropyToMnemonic <$> genEntropy)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@KtorZ KtorZ force-pushed the Squad1/CBR-288/review-wallet-peripheral-utilities branch from 3d4abce to 6a36e02 Compare June 25, 2018 15:46
@KtorZ KtorZ merged commit 7a7c74d into develop Jun 26, 2018
@KtorZ KtorZ deleted the Squad1/CBR-288/review-wallet-peripheral-utilities branch June 26, 2018 07:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants