mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-24 07:30:30 +00:00
Address coding style comments (#6966)
This commit is contained in:
@@ -289,7 +289,7 @@ verifyRevealedAmount(
|
||||
* @param hasAuditor Whether the issuance has an auditor configured.
|
||||
* @return The number of recipients (3 or 4).
|
||||
*/
|
||||
constexpr std::size_t
|
||||
constexpr uint8_t
|
||||
getConfidentialRecipientCount(bool hasAuditor)
|
||||
{
|
||||
return hasAuditor ? 4 : 3;
|
||||
|
||||
@@ -101,11 +101,7 @@ makeEcPair(Slice const& buffer)
|
||||
return std::nullopt; // LCOV_EXCL_LINE
|
||||
|
||||
auto parsePubKey = [](Slice const& slice, secp256k1_pubkey& out) {
|
||||
return secp256k1_ec_pubkey_parse(
|
||||
secp256k1Context(),
|
||||
&out,
|
||||
reinterpret_cast<unsigned char const*>(slice.data()),
|
||||
slice.length());
|
||||
return secp256k1_ec_pubkey_parse(secp256k1Context(), &out, slice.data(), slice.length());
|
||||
};
|
||||
|
||||
Slice const s1{buffer.data(), ecGamalEncryptedLength};
|
||||
@@ -123,13 +119,13 @@ serializeEcPair(EcPair const& pair)
|
||||
{
|
||||
auto serializePubKey = [](secp256k1_pubkey const& pub, unsigned char* out) {
|
||||
size_t outLen = ecGamalEncryptedLength; // 33 bytes
|
||||
int const ret = secp256k1_ec_pubkey_serialize(
|
||||
auto const ret = secp256k1_ec_pubkey_serialize(
|
||||
secp256k1Context(), out, &outLen, &pub, SECP256K1_EC_COMPRESSED);
|
||||
return ret == 1 && outLen == ecGamalEncryptedLength;
|
||||
};
|
||||
|
||||
Buffer buffer(ecGamalEncryptedTotalLength);
|
||||
unsigned char* ptr = buffer.data();
|
||||
auto const ptr = buffer.data();
|
||||
bool const res1 = serializePubKey(pair.c1, ptr);
|
||||
bool const res2 = serializePubKey(pair.c2, ptr + ecGamalEncryptedLength);
|
||||
|
||||
@@ -195,7 +191,7 @@ homomorphicSubtract(Slice const& a, Slice const& b)
|
||||
return std::nullopt;
|
||||
|
||||
EcPair diff{};
|
||||
if (auto res = secp256k1_elgamal_subtract(
|
||||
if (auto const res = secp256k1_elgamal_subtract(
|
||||
secp256k1Context(), &diff.c1, &diff.c2, &pairA->c1, &pairA->c2, &pairB->c1, &pairB->c2);
|
||||
res != 1)
|
||||
{
|
||||
@@ -268,7 +264,9 @@ verifyRevealedAmount(
|
||||
holder.encryptedAmount.size() != ecGamalEncryptedTotalLength ||
|
||||
issuer.publicKey.size() != ecPubKeyLength ||
|
||||
issuer.encryptedAmount.size() != ecGamalEncryptedTotalLength)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
auto toParticipant = [](ConfidentialRecipient const& r) {
|
||||
mpt_confidential_participant p;
|
||||
@@ -285,14 +283,18 @@ verifyRevealedAmount(
|
||||
{
|
||||
if (auditor->publicKey.size() != ecPubKeyLength ||
|
||||
auditor->encryptedAmount.size() != ecGamalEncryptedTotalLength)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
auditorP = toParticipant(*auditor);
|
||||
auditorPtr = &auditorP;
|
||||
}
|
||||
|
||||
if (mpt_verify_revealed_amount(amount, blindingFactor.data(), &holderP, &issuerP, auditorPtr) !=
|
||||
0)
|
||||
{
|
||||
return tecBAD_PROOF;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
@@ -305,11 +307,15 @@ checkEncryptedAmountFormat(STObject const& object)
|
||||
// are present.
|
||||
if (!object.isFieldPresent(sfHolderEncryptedAmount) ||
|
||||
!object.isFieldPresent(sfIssuerEncryptedAmount))
|
||||
{
|
||||
return temMALFORMED; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
if (object[sfHolderEncryptedAmount].length() != ecGamalEncryptedTotalLength ||
|
||||
object[sfIssuerEncryptedAmount].length() != ecGamalEncryptedTotalLength)
|
||||
{
|
||||
return temBAD_CIPHERTEXT;
|
||||
}
|
||||
|
||||
bool const hasAuditor = object.isFieldPresent(sfAuditorEncryptedAmount);
|
||||
if (hasAuditor && object[sfAuditorEncryptedAmount].length() != ecGamalEncryptedTotalLength)
|
||||
@@ -317,7 +323,9 @@ checkEncryptedAmountFormat(STObject const& object)
|
||||
|
||||
if (!isValidCiphertext(object[sfHolderEncryptedAmount]) ||
|
||||
!isValidCiphertext(object[sfIssuerEncryptedAmount]))
|
||||
{
|
||||
return temBAD_CIPHERTEXT;
|
||||
}
|
||||
|
||||
if (hasAuditor && !isValidCiphertext(object[sfAuditorEncryptedAmount]))
|
||||
return temBAD_CIPHERTEXT;
|
||||
@@ -347,11 +355,15 @@ verifyClawbackProof(
|
||||
{
|
||||
if (ciphertext.size() != ecGamalEncryptedTotalLength || pubKeySlice.size() != ecPubKeyLength ||
|
||||
proof.size() != ecClawbackProofLength)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
if (mpt_verify_clawback_proof(
|
||||
proof.data(), amount, pubKeySlice.data(), ciphertext.data(), contextHash.data()) != 0)
|
||||
{
|
||||
return tecBAD_PROOF;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
@@ -378,7 +390,9 @@ verifySendProof(
|
||||
spendingBalance.size() != ecGamalEncryptedTotalLength ||
|
||||
amountCommitment.size() != ecPedersenCommitmentLength ||
|
||||
balanceCommitment.size() != ecPedersenCommitmentLength)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
auto makeParticipant = [](ConfidentialRecipient const& r) {
|
||||
mpt_confidential_participant p;
|
||||
@@ -395,19 +409,23 @@ verifySendProof(
|
||||
{
|
||||
if (auditor->publicKey.size() != ecPubKeyLength ||
|
||||
auditor->encryptedAmount.size() != ecGamalEncryptedTotalLength)
|
||||
return tecINTERNAL;
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
participants[3] = makeParticipant(*auditor);
|
||||
}
|
||||
|
||||
if (mpt_verify_send_proof(
|
||||
proof.data(),
|
||||
participants.data(),
|
||||
static_cast<uint8_t>(recipientCount),
|
||||
recipientCount,
|
||||
spendingBalance.data(),
|
||||
amountCommitment.data(),
|
||||
balanceCommitment.data(),
|
||||
contextHash.data()) != 0)
|
||||
{
|
||||
return tecBAD_PROOF;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
@@ -424,7 +442,9 @@ verifyConvertBackProof(
|
||||
if (proof.size() != ecConvertBackProofLength || pubKeySlice.size() != ecPubKeyLength ||
|
||||
spendingBalance.size() != ecGamalEncryptedTotalLength ||
|
||||
balanceCommitment.size() != ecPedersenCommitmentLength)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
if (mpt_verify_convert_back_proof(
|
||||
proof.data(),
|
||||
@@ -433,7 +453,9 @@ verifyConvertBackProof(
|
||||
balanceCommitment.data(),
|
||||
amount,
|
||||
contextHash.data()) != 0)
|
||||
{
|
||||
return tecBAD_PROOF;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ ConfidentialMPTClawback::doApply()
|
||||
|
||||
auto const clawAmount = ctx_.tx[sfMPTAmount];
|
||||
|
||||
Slice const holderPubKey = (*sleHolderMPToken)[sfHolderEncryptionKey];
|
||||
Slice const issuerPubKey = (*sleIssuance)[sfIssuerEncryptionKey];
|
||||
auto const holderPubKey = (*sleHolderMPToken)[sfHolderEncryptionKey];
|
||||
auto const issuerPubKey = (*sleIssuance)[sfIssuerEncryptionKey];
|
||||
|
||||
// After clawback, the balance should be encrypted zero.
|
||||
auto const encZeroForHolder = encryptCanonicalZeroAmount(holderPubKey, holder, mptIssuanceID);
|
||||
@@ -142,7 +142,7 @@ ConfidentialMPTClawback::doApply()
|
||||
if (!sleIssuance->isFieldPresent(sfAuditorEncryptionKey))
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
Slice const auditorPubKey = (*sleIssuance)[sfAuditorEncryptionKey];
|
||||
auto const auditorPubKey = (*sleIssuance)[sfAuditorEncryptionKey];
|
||||
|
||||
auto encZeroForAuditor = encryptCanonicalZeroAmount(auditorPubKey, holder, mptIssuanceID);
|
||||
|
||||
|
||||
@@ -67,7 +67,9 @@ ConfidentialMPTConvert::preclaim(PreclaimContext const& ctx)
|
||||
|
||||
if (!sleIssuance->isFlag(lsfMPTCanConfidentialAmount) ||
|
||||
!sleIssuance->isFieldPresent(sfIssuerEncryptionKey))
|
||||
{
|
||||
return tecNO_PERMISSION;
|
||||
}
|
||||
|
||||
// already checked in preflight, but should also check that issuer on the
|
||||
// issuance isn't the account either
|
||||
@@ -102,7 +104,7 @@ ConfidentialMPTConvert::preclaim(PreclaimContext const& ctx)
|
||||
if (auto const ter = requireAuth(ctx.view, mptIssue, account); !isTesSuccess(ter))
|
||||
return ter;
|
||||
|
||||
STAmount const mptAmount =
|
||||
auto const mptAmount =
|
||||
STAmount(MPTAmount{static_cast<MPTAmount::value_type>(amount)}, mptIssue);
|
||||
if (accountHolds(
|
||||
ctx.view,
|
||||
@@ -203,9 +205,8 @@ ConfidentialMPTConvert::doApply()
|
||||
(*sleMptoken)[sfMPTAmount] = amt - amtToConvert;
|
||||
(*sleIssuance)[sfConfidentialOutstandingAmount] = currentCOA + amtToConvert;
|
||||
|
||||
Slice const holderEc = ctx_.tx[sfHolderEncryptedAmount];
|
||||
Slice const issuerEc = ctx_.tx[sfIssuerEncryptedAmount];
|
||||
|
||||
auto const holderEc = ctx_.tx[sfHolderEncryptedAmount];
|
||||
auto const issuerEc = ctx_.tx[sfIssuerEncryptedAmount];
|
||||
auto const auditorEc = ctx_.tx[~sfAuditorEncryptedAmount];
|
||||
|
||||
// Two cases for Convert:
|
||||
|
||||
@@ -164,9 +164,7 @@ ConfidentialMPTConvertBack::preclaim(PreclaimContext const& ctx)
|
||||
// holder is trying to convert back, we know for sure this txn should
|
||||
// fail
|
||||
if ((*sleIssuance)[~sfConfidentialOutstandingAmount].value_or(0) < amount)
|
||||
{
|
||||
return tecINSUFFICIENT_FUNDS;
|
||||
}
|
||||
|
||||
// Check lock
|
||||
MPTIssue const mptIssue(mptIssuanceID);
|
||||
|
||||
@@ -46,7 +46,9 @@ ConfidentialMPTMergeInbox::preclaim(PreclaimContext const& ctx)
|
||||
if (!sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) ||
|
||||
!sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
|
||||
!sleMptoken->isFieldPresent(sfHolderEncryptionKey))
|
||||
{
|
||||
return tecNO_PERMISSION;
|
||||
}
|
||||
|
||||
// Check lock
|
||||
auto const account = ctx.tx[sfAccount];
|
||||
|
||||
@@ -33,7 +33,9 @@ ConfidentialMPTSend::preflight(PreflightContext const& ctx)
|
||||
if (ctx.tx[sfSenderEncryptedAmount].length() != ecGamalEncryptedTotalLength ||
|
||||
ctx.tx[sfDestinationEncryptedAmount].length() != ecGamalEncryptedTotalLength ||
|
||||
ctx.tx[sfIssuerEncryptedAmount].length() != ecGamalEncryptedTotalLength)
|
||||
{
|
||||
return temBAD_CIPHERTEXT;
|
||||
}
|
||||
|
||||
bool const hasAuditor = ctx.tx.isFieldPresent(sfAuditorEncryptedAmount);
|
||||
if (hasAuditor && ctx.tx[sfAuditorEncryptedAmount].length() != ecGamalEncryptedTotalLength)
|
||||
@@ -46,14 +48,18 @@ ConfidentialMPTSend::preflight(PreflightContext const& ctx)
|
||||
// Check the Pedersen commitments are valid
|
||||
if (!isValidCompressedECPoint(ctx.tx[sfBalanceCommitment]) ||
|
||||
!isValidCompressedECPoint(ctx.tx[sfAmountCommitment]))
|
||||
{
|
||||
return temMALFORMED;
|
||||
}
|
||||
|
||||
// Check the encrypted amount formats, this is more expensive so put it at
|
||||
// the end
|
||||
if (!isValidCiphertext(ctx.tx[sfSenderEncryptedAmount]) ||
|
||||
!isValidCiphertext(ctx.tx[sfDestinationEncryptedAmount]) ||
|
||||
!isValidCiphertext(ctx.tx[sfIssuerEncryptedAmount]))
|
||||
{
|
||||
return temBAD_CIPHERTEXT;
|
||||
}
|
||||
|
||||
if (hasAuditor && !isValidCiphertext(ctx.tx[sfAuditorEncryptedAmount]))
|
||||
return temBAD_CIPHERTEXT;
|
||||
@@ -154,7 +160,9 @@ ConfidentialMPTSend::preclaim(PreclaimContext const& ctx)
|
||||
if (!sleSenderMPToken->isFieldPresent(sfHolderEncryptionKey) ||
|
||||
!sleSenderMPToken->isFieldPresent(sfConfidentialBalanceSpending) ||
|
||||
!sleSenderMPToken->isFieldPresent(sfIssuerEncryptedBalance))
|
||||
{
|
||||
return tecNO_PERMISSION;
|
||||
}
|
||||
|
||||
// Check destination's MPToken existence
|
||||
auto const sleDestinationMPToken = ctx.view.read(keylet::mptoken(mptIssuanceID, destination));
|
||||
@@ -165,14 +173,18 @@ ConfidentialMPTSend::preclaim(PreclaimContext const& ctx)
|
||||
if (!sleDestinationMPToken->isFieldPresent(sfHolderEncryptionKey) ||
|
||||
!sleDestinationMPToken->isFieldPresent(sfConfidentialBalanceInbox) ||
|
||||
!sleDestinationMPToken->isFieldPresent(sfIssuerEncryptedBalance))
|
||||
{
|
||||
return tecNO_PERMISSION;
|
||||
}
|
||||
|
||||
// Sanity check: Both MPTokens' auditor fields must be present if auditing
|
||||
// is enabled
|
||||
if (requiresAuditor &&
|
||||
(!sleSenderMPToken->isFieldPresent(sfAuditorEncryptedBalance) ||
|
||||
!sleDestinationMPToken->isFieldPresent(sfAuditorEncryptedBalance)))
|
||||
{
|
||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// Check lock
|
||||
MPTIssue const mptIssue(mptIssuanceID);
|
||||
@@ -205,7 +217,7 @@ ConfidentialMPTSend::doApply()
|
||||
auto sleSenderMPToken = view().peek(keylet::mptoken(mptIssuanceID, account_));
|
||||
auto sleDestinationMPToken = view().peek(keylet::mptoken(mptIssuanceID, destination));
|
||||
|
||||
auto sleDestAcct = view().peek(keylet::account(destination));
|
||||
auto const sleDestAcct = view().peek(keylet::account(destination));
|
||||
|
||||
if (!sleSenderMPToken || !sleDestinationMPToken || !sleDestAcct)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -215,15 +227,15 @@ ConfidentialMPTSend::doApply()
|
||||
!isTesSuccess(err))
|
||||
return err;
|
||||
|
||||
Slice const senderEc = ctx_.tx[sfSenderEncryptedAmount];
|
||||
Slice const destEc = ctx_.tx[sfDestinationEncryptedAmount];
|
||||
Slice const issuerEc = ctx_.tx[sfIssuerEncryptedAmount];
|
||||
auto const senderEc = ctx_.tx[sfSenderEncryptedAmount];
|
||||
auto const destEc = ctx_.tx[sfDestinationEncryptedAmount];
|
||||
auto const issuerEc = ctx_.tx[sfIssuerEncryptedAmount];
|
||||
|
||||
auto const auditorEc = ctx_.tx[~sfAuditorEncryptedAmount];
|
||||
|
||||
// Subtract from sender's spending balance
|
||||
{
|
||||
Slice const curSpending = (*sleSenderMPToken)[sfConfidentialBalanceSpending];
|
||||
auto const curSpending = (*sleSenderMPToken)[sfConfidentialBalanceSpending];
|
||||
auto newSpending = homomorphicSubtract(curSpending, senderEc);
|
||||
if (!newSpending)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -233,7 +245,7 @@ ConfidentialMPTSend::doApply()
|
||||
|
||||
// Subtract from issuer's balance
|
||||
{
|
||||
Slice const curIssuerEnc = (*sleSenderMPToken)[sfIssuerEncryptedBalance];
|
||||
auto const curIssuerEnc = (*sleSenderMPToken)[sfIssuerEncryptedBalance];
|
||||
auto newIssuerEnc = homomorphicSubtract(curIssuerEnc, issuerEc);
|
||||
if (!newIssuerEnc)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -244,7 +256,7 @@ ConfidentialMPTSend::doApply()
|
||||
// Subtract from auditor's balance if present
|
||||
if (auditorEc)
|
||||
{
|
||||
Slice const curAuditorEnc = (*sleSenderMPToken)[sfAuditorEncryptedBalance];
|
||||
auto const curAuditorEnc = (*sleSenderMPToken)[sfAuditorEncryptedBalance];
|
||||
auto newAuditorEnc = homomorphicSubtract(curAuditorEnc, *auditorEc);
|
||||
if (!newAuditorEnc)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -254,7 +266,7 @@ ConfidentialMPTSend::doApply()
|
||||
|
||||
// Add to destination's inbox balance
|
||||
{
|
||||
Slice const curInbox = (*sleDestinationMPToken)[sfConfidentialBalanceInbox];
|
||||
auto const curInbox = (*sleDestinationMPToken)[sfConfidentialBalanceInbox];
|
||||
auto newInbox = homomorphicAdd(curInbox, destEc);
|
||||
if (!newInbox)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -264,7 +276,7 @@ ConfidentialMPTSend::doApply()
|
||||
|
||||
// Add to issuer's balance
|
||||
{
|
||||
Slice const curIssuerEnc = (*sleDestinationMPToken)[sfIssuerEncryptedBalance];
|
||||
auto const curIssuerEnc = (*sleDestinationMPToken)[sfIssuerEncryptedBalance];
|
||||
auto newIssuerEnc = homomorphicAdd(curIssuerEnc, issuerEc);
|
||||
if (!newIssuerEnc)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
@@ -275,7 +287,7 @@ ConfidentialMPTSend::doApply()
|
||||
// Add to auditor's balance if present
|
||||
if (auditorEc)
|
||||
{
|
||||
Slice const curAuditorEnc = (*sleDestinationMPToken)[sfAuditorEncryptedBalance];
|
||||
auto const curAuditorEnc = (*sleDestinationMPToken)[sfAuditorEncryptedBalance];
|
||||
auto newAuditorEnc = homomorphicAdd(curAuditorEnc, *auditorEc);
|
||||
if (!newAuditorEnc)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
@@ -3247,7 +3247,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
// Get the share MPTID from vault
|
||||
auto const vaultSle = env.le(vaultKeylet);
|
||||
BEAST_EXPECT(vaultSle != nullptr);
|
||||
MPTID share = vaultSle->at(sfShareMPTID);
|
||||
auto const share = vaultSle->at(sfShareMPTID);
|
||||
|
||||
// Depositor deposits into vault
|
||||
tx = vault.deposit(
|
||||
@@ -3272,7 +3272,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
view.rawReplace(issuance);
|
||||
|
||||
auto const k = keylet::mptoken(share, depositor.id());
|
||||
auto sle = std::const_pointer_cast<SLE>(view.read(k));
|
||||
auto const sle = std::const_pointer_cast<SLE>(view.read(k));
|
||||
if (!sle)
|
||||
return false;
|
||||
// Inject dummy confidential balance fields
|
||||
@@ -5368,11 +5368,13 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.err = expectedResult,
|
||||
});
|
||||
else
|
||||
{
|
||||
mptAlice.convert({
|
||||
.account = bob,
|
||||
.amt = amt,
|
||||
.err = expectedResult,
|
||||
});
|
||||
}
|
||||
|
||||
if (expectedResult == tesSUCCESS)
|
||||
{
|
||||
|
||||
@@ -577,6 +577,7 @@ MPTTester::checkDomainID(std::optional<uint256> expected) const
|
||||
});
|
||||
}
|
||||
|
||||
// todo: remove this function, which is only for debugging
|
||||
[[nodiscard]] bool
|
||||
MPTTester::printMPT(Account const& holder_) const
|
||||
{
|
||||
@@ -833,14 +834,11 @@ MPTTester::getConfidentialSendProof(
|
||||
std::uint64_t const amount,
|
||||
std::vector<ConfidentialRecipient> const& recipients,
|
||||
Slice const& blindingFactor,
|
||||
std::size_t const nRecipients,
|
||||
uint256 const& contextHash,
|
||||
PedersenProofParams const& amountParams,
|
||||
PedersenProofParams const& balanceParams) const
|
||||
{
|
||||
auto const pedersenBalanceParams = makePedersenParams(balanceParams);
|
||||
if (recipients.size() != nRecipients)
|
||||
return std::nullopt;
|
||||
|
||||
if (blindingFactor.size() != ecBlindingFactorLength)
|
||||
return std::nullopt;
|
||||
@@ -857,13 +855,15 @@ MPTTester::getConfidentialSendProof(
|
||||
return std::nullopt;
|
||||
|
||||
// Build mpt_confidential_participant array
|
||||
std::vector<mpt_confidential_participant> participants(nRecipients);
|
||||
for (size_t i = 0; i < nRecipients; ++i)
|
||||
std::vector<mpt_confidential_participant> participants(recipients.size());
|
||||
for (size_t i = 0; i < recipients.size(); ++i)
|
||||
{
|
||||
auto const& r = recipients[i];
|
||||
if (r.encryptedAmount.size() != ecGamalEncryptedTotalLength ||
|
||||
r.publicKey.size() != ecPubKeyLength)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
std::memcpy(participants[i].pubkey, r.publicKey.data(), kMPT_PUBKEY_SIZE);
|
||||
std::memcpy(participants[i].ciphertext, r.encryptedAmount.data(), kMPT_ELGAMAL_TOTAL_SIZE);
|
||||
}
|
||||
@@ -876,7 +876,7 @@ MPTTester::getConfidentialSendProof(
|
||||
senderPubKey->data(),
|
||||
amount,
|
||||
participants.data(),
|
||||
nRecipients,
|
||||
recipients.size(),
|
||||
blindingFactor.data(),
|
||||
contextHash.data(),
|
||||
amountParams.pedersenCommitment.data(),
|
||||
@@ -1353,7 +1353,6 @@ MPTTester::send(MPTConfidentialSend const& arg)
|
||||
auto const ctxHash =
|
||||
getSendContextHash(arg.account->id(), *id_, seq, arg.dest->id(), version);
|
||||
|
||||
auto const nRecipients = getConfidentialRecipientCount(auditorAmt.has_value());
|
||||
std::vector<ConfidentialRecipient> recipients;
|
||||
|
||||
auto const senderPubKey = getPubKey(*arg.account);
|
||||
@@ -1361,8 +1360,7 @@ MPTTester::send(MPTConfidentialSend const& arg)
|
||||
auto const issuerPubKey = getPubKey(issuer_);
|
||||
|
||||
// If a key is missing, we skip adding the recipient. This intentionally
|
||||
// causes proof generation to fail (due to recipient count mismatch),
|
||||
// triggering the dummy proof fallback.
|
||||
// causes proof generation to fail, triggering the dummy proof fallback.
|
||||
if (senderPubKey)
|
||||
recipients.push_back({Slice(*senderPubKey), senderAmt});
|
||||
if (destPubKey)
|
||||
@@ -1397,7 +1395,6 @@ MPTTester::send(MPTConfidentialSend const& arg)
|
||||
*arg.amt,
|
||||
recipients,
|
||||
blindingFactor,
|
||||
nRecipients,
|
||||
ctxHash,
|
||||
{amountCommitment, *arg.amt, senderAmt, blindingFactor},
|
||||
{balanceCommitment,
|
||||
@@ -1611,7 +1608,6 @@ MPTTester::sendJV(
|
||||
auto const ctxHash =
|
||||
getSendContextHash(arg.account->id(), *id_, seq, arg.dest->id(), version);
|
||||
|
||||
auto const nRecipients = getConfidentialRecipientCount(auditorAmt.has_value());
|
||||
std::vector<ConfidentialRecipient> recipients;
|
||||
|
||||
auto const senderPubKey = getPubKey(*arg.account);
|
||||
@@ -1645,7 +1641,6 @@ MPTTester::sendJV(
|
||||
*arg.amt,
|
||||
recipients,
|
||||
blindingFactor,
|
||||
nRecipients,
|
||||
ctxHash,
|
||||
{amountCommitment, *arg.amt, senderAmt, blindingFactor},
|
||||
{balanceCommitment,
|
||||
@@ -1808,7 +1803,9 @@ MPTTester::generateKeyPair(Account const& account)
|
||||
if (secp256k1_ec_pubkey_serialize(
|
||||
secp256k1Context(), compressedPubKey, &outLen, &pubKey, SECP256K1_EC_COMPRESSED) != 1 ||
|
||||
outLen != ecPubKeyLength)
|
||||
{
|
||||
Throw<std::runtime_error>("failed to serialize public key");
|
||||
}
|
||||
|
||||
pubKeys.insert({account.id(), Buffer{compressedPubKey, ecPubKeyLength}});
|
||||
privKeys.insert({account.id(), Buffer{privKey, ecPrivKeyLength}});
|
||||
@@ -1817,11 +1814,8 @@ MPTTester::generateKeyPair(Account const& account)
|
||||
std::optional<Buffer>
|
||||
MPTTester::getPubKey(Account const& account) const
|
||||
{
|
||||
auto it = pubKeys.find(account.id());
|
||||
if (it != pubKeys.end())
|
||||
{
|
||||
if (auto const it = pubKeys.find(account.id()); it != pubKeys.end())
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -1829,11 +1823,8 @@ MPTTester::getPubKey(Account const& account) const
|
||||
std::optional<Buffer>
|
||||
MPTTester::getPrivKey(Account const& account) const
|
||||
{
|
||||
auto it = privKeys.find(account.id());
|
||||
if (it != privKeys.end())
|
||||
{
|
||||
if (auto const it = privKeys.find(account.id()); it != privKeys.end())
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -1879,9 +1870,8 @@ MPTTester::decryptAmount(Account const& account, Buffer const& amt) const
|
||||
|
||||
std::optional<uint64_t>
|
||||
MPTTester::getDecryptedBalance(Account const& account, EncryptedBalanceType balanceType) const
|
||||
|
||||
{
|
||||
auto encryptedAmt = getEncryptedBalance(account, balanceType);
|
||||
auto const encryptedAmt = getEncryptedBalance(account, balanceType);
|
||||
|
||||
// Return zero to test cases like Feature Disabled, where the ledger object
|
||||
// does not exist.
|
||||
@@ -2058,8 +2048,7 @@ MPTTester::convertBack(MPTConvertBack const& arg)
|
||||
// if the caller generated ciphertexts themselves, they should also
|
||||
// generate the proof themselves from the blinding factor
|
||||
auto const seq = arg.ticketSeq.value_or(env_.seq(*arg.account));
|
||||
uint256 const contextHash =
|
||||
getConvertBackContextHash(arg.account->id(), *id_, seq, version);
|
||||
auto const contextHash = getConvertBackContextHash(arg.account->id(), *id_, seq, version);
|
||||
auto const prevEncryptedSpendingBalance =
|
||||
getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING);
|
||||
|
||||
@@ -2194,8 +2183,7 @@ MPTTester::convertBackJV(MPTConvertBack const& arg, std::uint32_t seq)
|
||||
{
|
||||
auto const version = getMPTokenVersion(*arg.account);
|
||||
auto const prevEncSpending = getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING);
|
||||
uint256 const contextHash =
|
||||
getConvertBackContextHash(arg.account->id(), *id_, seq, version);
|
||||
auto const contextHash = getConvertBackContextHash(arg.account->id(), *id_, seq, version);
|
||||
|
||||
Buffer proof;
|
||||
if (!prevEncSpending)
|
||||
|
||||
@@ -567,7 +567,6 @@ public:
|
||||
std::uint64_t const amount,
|
||||
std::vector<ConfidentialRecipient> const& recipients,
|
||||
Slice const& blindingFactor,
|
||||
std::size_t const nRecipients,
|
||||
uint256 const& contextHash,
|
||||
PedersenProofParams const& amountParams,
|
||||
PedersenProofParams const& balanceParams) const;
|
||||
|
||||
Reference in New Issue
Block a user