From 992007ecbc5dec7f16ed98a17cd6d1ed7fe65606 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Wed, 19 Aug 2020 14:25:49 +0800 Subject: [PATCH] Move esk derivation check to beginning of plaintext_checks_without_height() --- src/zcash/Note.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index f2b4cf11e..dbfca1edc 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -369,6 +369,14 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit const uint256 &cmu ) { + if (plaintext.get_leadbyte() != 0x01) { + // ZIP 212: Additionally check that the esk provided to this function + // is consistent with the esk we can derive + if (esk != plaintext.generate_or_derive_esk()) { + return boost::none; + } + } + // ZIP 212: The recipient MUST derive esk and check that epk is consistent with it. // https://zips.z.cash/zip-0212#changes-to-the-process-of-receiving-sapling-notes uint256 expected_epk; @@ -396,14 +404,6 @@ boost::optional SaplingNotePlaintext::plaintext_checks_wit return boost::none; } - if (plaintext.get_leadbyte() != 0x01) { - // ZIP 212: Additionally check that the esk provided to this function - // is consistent with the esk we can derive - if (esk != plaintext.generate_or_derive_esk()) { - return boost::none; - } - } - return plaintext; }