From 03516a14da35a49bcb97de5db0521a7ad96cebb3 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 7 Nov 2015 12:18:30 -0800 Subject: [PATCH] Defer checking whether master key was used for signing --- src/ripple/app/tx/impl/SetAccount.cpp | 19 +++++++++++++++-- src/ripple/app/tx/impl/Transactor.cpp | 30 --------------------------- src/ripple/app/tx/impl/Transactor.h | 3 --- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/ripple/app/tx/impl/SetAccount.cpp b/src/ripple/app/tx/impl/SetAccount.cpp index fab6cc10a..aab888b92 100644 --- a/src/ripple/app/tx/impl/SetAccount.cpp +++ b/src/ripple/app/tx/impl/SetAccount.cpp @@ -176,6 +176,21 @@ SetAccount::doApply () bool bSetDisallowXRP = (uTxFlags & tfDisallowXRP) || (uSetFlag == asfDisallowXRP); bool bClearDisallowXRP = (uTxFlags & tfAllowXRP) || (uClearFlag == asfDisallowXRP); + bool sigWithMaster = false; + + { + auto const blob = ctx_.tx.getSigningPubKey(); + + if (!blob.empty ()) + { + auto const signingPubKey = + RippleAddress::createAccountPublic(blob); + + if (calcAccountID(signingPubKey) == account_) + sigWithMaster = true; + } + } + // // RequireAuth // @@ -226,7 +241,7 @@ SetAccount::doApply () // if ((uSetFlag == asfDisableMaster) && !(uFlagsIn & lsfDisableMaster)) { - if (!mSigMaster) + if (!sigWithMaster) { j_.trace << "Must use master key to disable master key."; return tecNEED_MASTER_KEY; @@ -273,7 +288,7 @@ SetAccount::doApply () // if (uSetFlag == asfNoFreeze) { - if (!mSigMaster && !(uFlagsIn & lsfDisableMaster)) + if (!sigWithMaster && !(uFlagsIn & lsfDisableMaster)) { j_.trace << "Can't use regular key to set NoFreeze."; return tecNEED_MASTER_KEY; diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index 5bc3594a0..a983f6556 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -79,15 +79,6 @@ preflight1 (PreflightContext const& ctx) TER preflight2 (PreflightContext const& ctx) { - // Extract signing key - // Transactions contain a signing key. This allows us to trivially verify a - // transaction has at least been properly signed without going to disk. - // Each transaction also notes a source account id. This is used to verify - // that the signing key is associated with the account. - // XXX This could be a lot cleaner to prevent unnecessary copying. - auto const pk = RippleAddress::createAccountPublic( - ctx.tx.getSigningPubKey()); - if(!( ctx.flags & tapNO_CHECK_SIGN) && checkValidity(ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config(), @@ -128,7 +119,6 @@ Transactor::Transactor( ApplyContext& ctx) : ctx_ (ctx) , j_ (ctx.journal) - , mSigMaster (false) { } @@ -285,9 +275,6 @@ void Transactor::preCompute () { account_ = ctx_.tx.getAccountID(sfAccount); assert(account_ != zero); - mSigningPubKey = - RippleAddress::createAccountPublic( - ctx_.tx.getSigningPubKey()); } TER Transactor::apply () @@ -316,8 +303,6 @@ TER Transactor::apply () if (terResult != tesSUCCESS) return terResult; - checkMasterSign (); - view().update (sle); } @@ -344,21 +329,6 @@ Transactor::checkSign (PreclaimContext const& ctx) return checkSingleSign (ctx); } -void -Transactor::checkMasterSign () -{ - if ((view().flags() & tapENABLE_TESTING) || - (view().rules().enabled(featureMultiSign, - ctx_.app.config().features))) - { - if (mSigningPubKey.getAccountPublic().empty()) - // Multisign obviously doesn't use the master key - return; - } - - mSigMaster = calcAccountID(mSigningPubKey) == account_; -} - TER Transactor::checkSingleSign (PreclaimContext const& ctx) { diff --git a/src/ripple/app/tx/impl/Transactor.h b/src/ripple/app/tx/impl/Transactor.h index 2743fa610..e482d45b9 100644 --- a/src/ripple/app/tx/impl/Transactor.h +++ b/src/ripple/app/tx/impl/Transactor.h @@ -79,8 +79,6 @@ protected: XRPAmount mFeeDue; XRPAmount mPriorBalance; // Balance before fees. XRPAmount mSourceBalance; // Balance after fees. - bool mSigMaster; - RippleAddress mSigningPubKey; public: /** Process the transaction. */ @@ -151,7 +149,6 @@ protected: private: void setSeq (); TER payFee (); - void checkMasterSign (); static TER checkSingleSign (PreclaimContext const& ctx); static TER checkMultiSign (PreclaimContext const& ctx); };