From 86af28d91d1557c42f272e37a3aa8eaf6c87eda4 Mon Sep 17 00:00:00 2001 From: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> Date: Mon, 2 Feb 2026 11:15:39 -0500 Subject: [PATCH] Apply clang-format due to new column size (#6311) --- include/xrpl/protocol/ConfidentialTransfer.h | 37 +- src/libxrpl/ledger/View.cpp | 3 +- src/libxrpl/protocol/ConfidentialTransfer.cpp | 344 ++---- src/test/app/ConfidentialTransfer_test.cpp | 1051 +++++------------ src/test/app/MPToken_test.cpp | 3 +- src/test/jtx/impl/mpt.cpp | 541 +++------ src/test/jtx/mpt.h | 31 +- .../app/tx/detail/ConfidentialClawback.cpp | 15 +- .../app/tx/detail/ConfidentialConvert.cpp | 45 +- .../app/tx/detail/ConfidentialConvertBack.cpp | 49 +- .../app/tx/detail/ConfidentialMergeInbox.cpp | 17 +- src/xrpld/app/tx/detail/ConfidentialSend.cpp | 129 +- src/xrpld/app/tx/detail/MPTokenAuthorize.cpp | 7 +- .../app/tx/detail/MPTokenIssuanceCreate.cpp | 6 +- .../app/tx/detail/MPTokenIssuanceSet.cpp | 98 +- 15 files changed, 659 insertions(+), 1717 deletions(-) diff --git a/include/xrpl/protocol/ConfidentialTransfer.h b/include/xrpl/protocol/ConfidentialTransfer.h index 3ffefc104c..b2d6b93391 100644 --- a/include/xrpl/protocol/ConfidentialTransfer.h +++ b/include/xrpl/protocol/ConfidentialTransfer.h @@ -29,8 +29,7 @@ incrementConfidentialVersion(STObject& mptoken) // Retrieve current version and increment. // Unsigned integer overflow is defined behavior in C++ (wraps to 0), // which is acceptable here. - mptoken[sfConfidentialBalanceVersion] = - mptoken[~sfConfidentialBalanceVersion].value_or(0u) + 1u; + mptoken[sfConfidentialBalanceVersion] = mptoken[~sfConfidentialBalanceVersion].value_or(0u) + 1u; } void @@ -79,10 +78,7 @@ makeEcPair(Slice const& buffer, secp256k1_pubkey& out1, secp256k1_pubkey& out2); // serialize two secp256k1_pubkey components back into compressed 66-byte form bool -serializeEcPair( - secp256k1_pubkey const& in1, - secp256k1_pubkey const& in2, - Buffer& buffer); +serializeEcPair(secp256k1_pubkey const& in1, secp256k1_pubkey const& in2, Buffer& buffer); /** * @brief Verifies that a buffer contains two valid, parsable EC public keys. @@ -100,22 +96,13 @@ homomorphicSubtract(Slice const& a, Slice const& b, Buffer& out); // returns ciphertext and the blinding factor used std::optional -encryptAmount( - uint64_t const amt, - Slice const& pubKeySlice, - Slice const& blindingFactor); +encryptAmount(uint64_t const amt, Slice const& pubKeySlice, Slice const& blindingFactor); std::optional -encryptCanonicalZeroAmount( - Slice const& pubKeySlice, - AccountID const& account, - MPTID const& mptId); +encryptCanonicalZeroAmount(Slice const& pubKeySlice, AccountID const& account, MPTID const& mptId); TER -verifySchnorrProof( - Slice const& pubKeySlice, - Slice const& proofSlice, - uint256 const& contextHash); +verifySchnorrProof(Slice const& pubKeySlice, Slice const& proofSlice, uint256 const& contextHash); TER verifyElGamalEncryption( @@ -218,10 +205,7 @@ verifyBalancePcmLinkage( * @brief Generates a new secp256k1 key pair. */ SECP256K1_API int -secp256k1_elgamal_generate_keypair( - secp256k1_context const* ctx, - unsigned char* privkey, - secp256k1_pubkey* pubkey); +secp256k1_elgamal_generate_keypair(secp256k1_context const* ctx, unsigned char* privkey, secp256k1_pubkey* pubkey); /** * @brief Encrypts a 64-bit amount using ElGamal. @@ -302,19 +286,14 @@ generate_canonical_encrypted_zero( * @return 1 on success, 0 on failure. */ SECP256K1_API int -generate_random_scalar( - secp256k1_context const* ctx, - unsigned char* scalar_bytes); +generate_random_scalar(secp256k1_context const* ctx, unsigned char* scalar_bytes); /** * Computes the point M = amount * G. * IMPORTANT: This function MUST NOT be called with amount = 0. */ SECP256K1_API int -compute_amount_point( - secp256k1_context const* ctx, - secp256k1_pubkey* mG, - uint64_t amount); +compute_amount_point(secp256k1_context const* ctx, secp256k1_pubkey* mG, uint64_t amount); /** * Builds the challenge hash input for the NON-ZERO amount case. diff --git a/src/libxrpl/ledger/View.cpp b/src/libxrpl/ledger/View.cpp index 45ecaf4d68..e5f389af73 100644 --- a/src/libxrpl/ledger/View.cpp +++ b/src/libxrpl/ledger/View.cpp @@ -469,8 +469,7 @@ accountHolds( // Only if auth check is needed, as it needs to do an additional read // operation. Note featureSingleAssetVault will affect error codes. if (zeroIfUnauthorized == ahZERO_IF_UNAUTHORIZED && - (view.rules().enabled(featureSingleAssetVault) || - view.rules().enabled(featureConfidentialTransfer))) + (view.rules().enabled(featureSingleAssetVault) || view.rules().enabled(featureConfidentialTransfer))) { if (auto const err = requireAuth(view, mptIssue, account, AuthType::StrongAuth); !isTesSuccess(err)) amount.clear(mptIssue); diff --git a/src/libxrpl/protocol/ConfidentialTransfer.cpp b/src/libxrpl/protocol/ConfidentialTransfer.cpp index 3980513a03..19a2e7963d 100644 --- a/src/libxrpl/protocol/ConfidentialTransfer.cpp +++ b/src/libxrpl/protocol/ConfidentialTransfer.cpp @@ -45,8 +45,7 @@ getClawbackContextHash( AccountID const& holder) { Serializer s; - addCommonZKPFields( - s, ttCONFIDENTIAL_CLAWBACK, account, sequence, issuanceID); + addCommonZKPFields(s, ttCONFIDENTIAL_CLAWBACK, account, sequence, issuanceID); s.add64(amount); s.addBitString(holder); @@ -55,15 +54,10 @@ getClawbackContextHash( } uint256 -getConvertContextHash( - AccountID const& account, - std::uint32_t sequence, - uint192 const& issuanceID, - std::uint64_t amount) +getConvertContextHash(AccountID const& account, std::uint32_t sequence, uint192 const& issuanceID, std::uint64_t amount) { Serializer s; - addCommonZKPFields( - s, ttCONFIDENTIAL_CONVERT, account, sequence, issuanceID); + addCommonZKPFields(s, ttCONFIDENTIAL_CONVERT, account, sequence, issuanceID); s.add64(amount); @@ -79,8 +73,7 @@ getConvertBackContextHash( std::uint32_t version) { Serializer s; - addCommonZKPFields( - s, ttCONFIDENTIAL_CONVERT_BACK, account, sequence, issuanceID); + addCommonZKPFields(s, ttCONFIDENTIAL_CONVERT_BACK, account, sequence, issuanceID); s.add64(amount); s.addInteger(version); @@ -93,10 +86,7 @@ makeEcPair(Slice const& buffer, secp256k1_pubkey& out1, secp256k1_pubkey& out2) { auto parsePubKey = [](Slice const& slice, secp256k1_pubkey& out) { return secp256k1_ec_pubkey_parse( - secp256k1Context(), - &out, - reinterpret_cast(slice.data()), - slice.length()); + secp256k1Context(), &out, reinterpret_cast(slice.data()), slice.length()); }; Slice s1{buffer.data(), ecGamalEncryptedLength}; @@ -109,15 +99,11 @@ makeEcPair(Slice const& buffer, secp256k1_pubkey& out1, secp256k1_pubkey& out2) } bool -serializeEcPair( - secp256k1_pubkey const& in1, - secp256k1_pubkey const& in2, - Buffer& buffer) +serializeEcPair(secp256k1_pubkey const& in1, secp256k1_pubkey const& in2, Buffer& buffer) { auto serializePubKey = [](secp256k1_pubkey const& pub, unsigned char* out) { size_t outLen = ecGamalEncryptedLength; // 33 bytes - int const ret = secp256k1_ec_pubkey_serialize( - secp256k1Context(), out, &outLen, &pub, SECP256K1_EC_COMPRESSED); + int const ret = secp256k1_ec_pubkey_serialize(secp256k1Context(), out, &outLen, &pub, SECP256K1_EC_COMPRESSED); return ret == 1 && outLen == ecGamalEncryptedLength; }; @@ -143,8 +129,7 @@ isValidCiphertext(Slice const& buffer) TER homomorphicAdd(Slice const& a, Slice const& b, Buffer& out) { - if (a.length() != ecGamalEncryptedTotalLength || - b.length() != ecGamalEncryptedTotalLength) + if (a.length() != ecGamalEncryptedTotalLength || b.length() != ecGamalEncryptedTotalLength) return tecINTERNAL; secp256k1_pubkey aC1; @@ -158,8 +143,7 @@ homomorphicAdd(Slice const& a, Slice const& b, Buffer& out) secp256k1_pubkey sumC1; secp256k1_pubkey sumC2; - if (secp256k1_elgamal_add( - secp256k1Context(), &sumC1, &sumC2, &aC1, &aC2, &bC1, &bC2) != 1) + if (secp256k1_elgamal_add(secp256k1Context(), &sumC1, &sumC2, &aC1, &aC2, &bC1, &bC2) != 1) return tecINTERNAL; if (!serializeEcPair(sumC1, sumC2, out)) @@ -171,8 +155,7 @@ homomorphicAdd(Slice const& a, Slice const& b, Buffer& out) TER homomorphicSubtract(Slice const& a, Slice const& b, Buffer& out) { - if (a.length() != ecGamalEncryptedTotalLength || - b.length() != ecGamalEncryptedTotalLength) + if (a.length() != ecGamalEncryptedTotalLength || b.length() != ecGamalEncryptedTotalLength) return tecINTERNAL; secp256k1_pubkey aC1; @@ -186,8 +169,7 @@ homomorphicSubtract(Slice const& a, Slice const& b, Buffer& out) secp256k1_pubkey diffC1; secp256k1_pubkey diffC2; - if (secp256k1_elgamal_subtract( - secp256k1Context(), &diffC1, &diffC2, &aC1, &aC2, &bC1, &bC2) != 1) + if (secp256k1_elgamal_subtract(secp256k1Context(), &diffC1, &diffC2, &aC1, &aC2, &bC1, &bC2) != 1) return tecINTERNAL; if (!serializeEcPair(diffC1, diffC2, out)) @@ -209,10 +191,7 @@ generateBlindingFactor() } std::optional -encryptAmount( - uint64_t const amt, - Slice const& pubKeySlice, - Slice const& blindingFactor) +encryptAmount(uint64_t const amt, Slice const& pubKeySlice, Slice const& blindingFactor) { Buffer buf(ecGamalEncryptedTotalLength); @@ -226,8 +205,7 @@ encryptAmount( std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength); // Encrypt the amount - if (!secp256k1_elgamal_encrypt( - secp256k1Context(), &c1, &c2, &pubKey, amt, blindingFactor.data())) + if (!secp256k1_elgamal_encrypt(secp256k1Context(), &c1, &c2, &pubKey, amt, blindingFactor.data())) return std::nullopt; // Serialize the ciphertext pair into the buffer @@ -238,10 +216,7 @@ encryptAmount( } std::optional -encryptCanonicalZeroAmount( - Slice const& pubKeySlice, - AccountID const& account, - MPTID const& mptId) +encryptCanonicalZeroAmount(Slice const& pubKeySlice, AccountID const& account, MPTID const& mptId) { if (pubKeySlice.size() != ecPubKeyLength) return std::nullopt; // LCOV_EXCL_LINE @@ -252,13 +227,7 @@ encryptCanonicalZeroAmount( std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength); // Encrypt the amount - if (!generate_canonical_encrypted_zero( - secp256k1Context(), - &c1, - &c2, - &pubKey, - account.data(), - mptId.data())) + if (!generate_canonical_encrypted_zero(secp256k1Context(), &c1, &c2, &pubKey, account.data(), mptId.data())) return std::nullopt; Buffer buf(ecGamalEncryptedTotalLength); @@ -271,10 +240,7 @@ encryptCanonicalZeroAmount( } TER -verifySchnorrProof( - Slice const& pubKeySlice, - Slice const& proofSlice, - uint256 const& contextHash) +verifySchnorrProof(Slice const& pubKeySlice, Slice const& proofSlice, uint256 const& contextHash) { // sanity check proof length if (proofSlice.size() != ecSchnorrProofLength) @@ -287,8 +253,7 @@ verifySchnorrProof( secp256k1_pubkey pubKey; std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength); - int result = secp256k1_mpt_pok_sk_verify( - secp256k1Context(), proofSlice.data(), &pubKey, contextHash.data()); + int result = secp256k1_mpt_pok_sk_verify(secp256k1Context(), proofSlice.data(), &pubKey, contextHash.data()); if (result != 1) return tecBAD_PROOF; @@ -318,8 +283,8 @@ verifyElGamalEncryption( if (!makeEcPair(ciphertext, c1, c2)) return tecINTERNAL; // LCOV_EXCL_LINE - int result = secp256k1_elgamal_verify_encryption( - secp256k1Context(), &c1, &c2, &pubKey, amount, blindingFactor.data()); + int result = + secp256k1_elgamal_verify_encryption(secp256k1Context(), &c1, &c2, &pubKey, amount, blindingFactor.data()); if (result != 1) { @@ -337,15 +302,13 @@ verifyRevealedAmount( ConfidentialRecipient const& issuer, std::optional const& auditor) { - if (auto const res = verifyElGamalEncryption( - amount, blindingFactor, holder.publicKey, holder.encryptedAmount); + if (auto const res = verifyElGamalEncryption(amount, blindingFactor, holder.publicKey, holder.encryptedAmount); !isTesSuccess(res)) { return res; } - if (auto const res = verifyElGamalEncryption( - amount, blindingFactor, issuer.publicKey, issuer.encryptedAmount); + if (auto const res = verifyElGamalEncryption(amount, blindingFactor, issuer.publicKey, issuer.encryptedAmount); !isTesSuccess(res)) { return res; @@ -353,11 +316,8 @@ verifyRevealedAmount( if (auditor) { - if (auto const res = verifyElGamalEncryption( - amount, - blindingFactor, - auditor->publicKey, - auditor->encryptedAmount); + if (auto const res = + verifyElGamalEncryption(amount, blindingFactor, auditor->publicKey, auditor->encryptedAmount); !isTesSuccess(res)) { return res; @@ -409,14 +369,7 @@ verifyMultiCiphertextEqualityProof( } int const result = secp256k1_mpt_verify_same_plaintext_multi( - secp256k1Context(), - proof.data(), - proof.size(), - nRecipients, - r.data(), - s.data(), - pk.data(), - contextHash.data()); + secp256k1Context(), proof.data(), proof.size(), nRecipients, r.data(), s.data(), pk.data(), contextHash.data()); if (result != 1) return tecBAD_PROOF; @@ -440,13 +393,7 @@ verifyClawbackEqualityProof( std::memcpy(pubKey.data, pubKeySlice.data(), ecPubKeyLength); if (secp256k1_equality_plaintext_verify( - secp256k1Context(), - proof.data(), - &pubKey, - &c2, - &c1, - amount, - contextHash.data()) != 1) + secp256k1Context(), proof.data(), &pubKey, &c2, &c1, amount, contextHash.data()) != 1) { return tecBAD_PROOF; } @@ -457,19 +404,15 @@ verifyClawbackEqualityProof( NotTEC checkEncryptedAmountFormat(STObject const& object) { - if (object[sfHolderEncryptedAmount].length() != - ecGamalEncryptedTotalLength || + if (object[sfHolderEncryptedAmount].length() != ecGamalEncryptedTotalLength || object[sfIssuerEncryptedAmount].length() != ecGamalEncryptedTotalLength) return temBAD_CIPHERTEXT; bool const hasAuditor = object.isFieldPresent(sfAuditorEncryptedAmount); - if (hasAuditor && - object[sfAuditorEncryptedAmount].length() != - ecGamalEncryptedTotalLength) + if (hasAuditor && object[sfAuditorEncryptedAmount].length() != ecGamalEncryptedTotalLength) return temBAD_CIPHERTEXT; - if (!isValidCiphertext(object[sfHolderEncryptedAmount]) || - !isValidCiphertext(object[sfIssuerEncryptedAmount])) + if (!isValidCiphertext(object[sfHolderEncryptedAmount]) || !isValidCiphertext(object[sfIssuerEncryptedAmount])) return temBAD_CIPHERTEXT; if (hasAuditor && !isValidCiphertext(object[sfAuditorEncryptedAmount])) @@ -505,13 +448,7 @@ verifyAmountPcmLinkage( std::memcpy(pcm.data, pcmSlice.data(), ecPedersenCommitmentLength); if (secp256k1_elgamal_pedersen_link_verify( - secp256k1Context(), - proof.data(), - &c1, - &c2, - &pubKey, - &pcm, - contextHash.data()) != 1) + secp256k1Context(), proof.data(), &c1, &c2, &pubKey, &pcm, contextHash.data()) != 1) { return tecBAD_PROOF; } @@ -548,13 +485,7 @@ verifyBalancePcmLinkage( std::memcpy(pcm.data, pcmSlice.data(), ecPubKeyLength); if (secp256k1_elgamal_pedersen_link_verify( - secp256k1Context(), - proof.data(), - &pubKey, - &c2, - &c1, - &pcm, - contextHash.data()) != 1) + secp256k1Context(), proof.data(), &pubKey, &c2, &c1, &pcm, contextHash.data()) != 1) { return tecBAD_PROOF; } @@ -565,10 +496,7 @@ verifyBalancePcmLinkage( // The following functions belong to the mpt-crypto library, // they will be finally removed and we will use conan2 to manage the dependency. int -secp256k1_elgamal_generate_keypair( - secp256k1_context const* ctx, - unsigned char* privkey, - secp256k1_pubkey* pubkey) +secp256k1_elgamal_generate_keypair(secp256k1_context const* ctx, unsigned char* privkey, secp256k1_pubkey* pubkey) { // 1. Generate 32 random bytes for the private key do @@ -681,12 +609,10 @@ secp256k1_elgamal_decrypt( // 2. Check for amount = 0 by comparing serialized points len = sizeof(c2_bytes); - if (secp256k1_ec_pubkey_serialize( - ctx, c2_bytes, &len, c2, SECP256K1_EC_COMPRESSED) != 1) + if (secp256k1_ec_pubkey_serialize(ctx, c2_bytes, &len, c2, SECP256K1_EC_COMPRESSED) != 1) return 0; len = sizeof(s_bytes); - if (secp256k1_ec_pubkey_serialize( - ctx, s_bytes, &len, &S, SECP256K1_EC_COMPRESSED) != 1) + if (secp256k1_ec_pubkey_serialize(ctx, s_bytes, &len, &S, SECP256K1_EC_COMPRESSED) != 1) return 0; if (memcmp(c2_bytes, s_bytes, sizeof(c2_bytes)) == 0) { @@ -706,8 +632,7 @@ secp256k1_elgamal_decrypt( // 4. Serialize M once for comparison in the loop len = sizeof(m_bytes); - if (secp256k1_ec_pubkey_serialize( - ctx, m_bytes, &len, &M, SECP256K1_EC_COMPRESSED) != 1) + if (secp256k1_ec_pubkey_serialize(ctx, m_bytes, &len, &M, SECP256K1_EC_COMPRESSED) != 1) return 0; // 5. Brute-force search loop @@ -718,12 +643,7 @@ secp256k1_elgamal_decrypt( for (i = 1; i <= 1000000; ++i) { len = sizeof(current_m_bytes); - if (secp256k1_ec_pubkey_serialize( - ctx, - current_m_bytes, - &len, - ¤t_M, - SECP256K1_EC_COMPRESSED) != 1) + if (secp256k1_ec_pubkey_serialize(ctx, current_m_bytes, &len, ¤t_M, SECP256K1_EC_COMPRESSED) != 1) return 0; if (memcmp(m_bytes, current_m_bytes, sizeof(m_bytes)) == 0) { @@ -781,8 +701,7 @@ secp256k1_elgamal_subtract( secp256k1_pubkey neg_b_c2 = *b_c2; // Negate the copies - if (secp256k1_ec_pubkey_negate(ctx, &neg_b_c1) != 1 || - secp256k1_ec_pubkey_negate(ctx, &neg_b_c2) != 1) + if (secp256k1_ec_pubkey_negate(ctx, &neg_b_c1) != 1 || secp256k1_ec_pubkey_negate(ctx, &neg_b_c2) != 1) { return 0; // Negation failed } @@ -844,8 +763,7 @@ generate_canonical_encrypted_zero( unsigned char hash_input[51]; // Size calculated above /* 1. Create the input buffer for hashing */ - build_hash_input( - hash_input, sizeof(hash_input), account_id, mpt_issuance_id); + build_hash_input(hash_input, sizeof(hash_input), account_id, mpt_issuance_id); /* 2. Hash the buffer to create the deterministic scalar 'r' */ do @@ -869,9 +787,7 @@ generate_canonical_encrypted_zero( } int -generate_random_scalar( - secp256k1_context const* ctx, - unsigned char* scalar_bytes) +generate_random_scalar(secp256k1_context const* ctx, unsigned char* scalar_bytes) { do { @@ -884,10 +800,7 @@ generate_random_scalar( } int -compute_amount_point( - secp256k1_context const* ctx, - secp256k1_pubkey* mG, - uint64_t amount) +compute_amount_point(secp256k1_context const* ctx, secp256k1_pubkey* mG, uint64_t amount) { unsigned char amount_scalar[32] = {0}; /* This function assumes amount != 0 */ @@ -915,35 +828,28 @@ build_challenge_hash_input_nonzero( char const* domain_sep = "MPT_POK_PLAINTEXT_PROOF"; // 23 bytes size_t offset = 0; size_t len; - secp256k1_context* ser_ctx = - secp256k1_context_create(SECP256K1_CONTEXT_NONE); + secp256k1_context* ser_ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE); memcpy(hash_input + offset, domain_sep, strlen(domain_sep)); offset += strlen(domain_sep); len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, c1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, c1, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, c2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, c2, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, pk, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, pk, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, mG, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, mG, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, T1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, T1, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, T2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, T2, SECP256K1_EC_COMPRESSED); offset += len; memcpy(hash_input + offset, tx_context_id, 32); @@ -966,31 +872,25 @@ build_challenge_hash_input_zero( char const* domain_sep = "MPT_POK_PLAINTEXT_PROOF"; // 23 bytes size_t offset = 0; size_t len; - secp256k1_context* ser_ctx = - secp256k1_context_create(SECP256K1_CONTEXT_NONE); + secp256k1_context* ser_ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE); memcpy(hash_input + offset, domain_sep, strlen(domain_sep)); offset += strlen(domain_sep); len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, c1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, c1, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, c2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, c2, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, pk, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, pk, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, T1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, T1, SECP256K1_EC_COMPRESSED); offset += len; len = 33; - secp256k1_ec_pubkey_serialize( - ser_ctx, hash_input + offset, &len, T2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, hash_input + offset, &len, T2, SECP256K1_EC_COMPRESSED); offset += len; memcpy(hash_input + offset, tx_context_id, 32); @@ -1042,8 +942,7 @@ secp256k1_equality_plaintext_prove( if (amount == 0) { unsigned char hash_input[220]; - build_challenge_hash_input_zero( - hash_input, c1, c2, pk_recipient, &T1, &T2, tx_context_id); + build_challenge_hash_input_zero(hash_input, c1, c2, pk_recipient, &T1, &T2, tx_context_id); SHA256(hash_input, sizeof(hash_input), e_scalar); } else @@ -1055,8 +954,7 @@ secp256k1_equality_plaintext_prove( memset(t_scalar, 0, 32); return 0; } - build_challenge_hash_input_nonzero( - hash_input, c1, c2, pk_recipient, &mG, &T1, &T2, tx_context_id); + build_challenge_hash_input_nonzero(hash_input, c1, c2, pk_recipient, &mG, &T1, &T2, tx_context_id); SHA256(hash_input, sizeof(hash_input), e_scalar); } @@ -1083,11 +981,9 @@ secp256k1_equality_plaintext_prove( /* 5. Format the proof = T1(33) || T2(33) || s(32) */ len = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof, &len, &T1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof, &len, &T1, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof + 33, &len, &T2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof + 33, &len, &T2, SECP256K1_EC_COMPRESSED); memcpy(proof + 66, s_scalar, 32); /* 6. Clear secret data */ @@ -1133,8 +1029,7 @@ secp256k1_equality_plaintext_verify( if (amount == 0) { unsigned char hash_input[220]; - build_challenge_hash_input_zero( - hash_input, c1, c2, pk_recipient, &T1, &T2, tx_context_id); + build_challenge_hash_input_zero(hash_input, c1, c2, pk_recipient, &T1, &T2, tx_context_id); SHA256(hash_input, sizeof(hash_input), e_scalar); } else @@ -1143,8 +1038,7 @@ secp256k1_equality_plaintext_verify( unsigned char hash_input[253]; if (!compute_amount_point(ctx, &mG, amount)) return 0; - build_challenge_hash_input_nonzero( - hash_input, c1, c2, pk_recipient, &mG, &T1, &T2, tx_context_id); + build_challenge_hash_input_nonzero(hash_input, c1, c2, pk_recipient, &mG, &T1, &T2, tx_context_id); SHA256(hash_input, sizeof(hash_input), e_scalar); } if (!secp256k1_ec_seckey_verify(ctx, e_scalar)) @@ -1162,11 +1056,9 @@ secp256k1_equality_plaintext_verify( return 0; len = 33; - secp256k1_ec_pubkey_serialize( - ctx, lhs_bytes, &len, &lhs_eq1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, lhs_bytes, &len, &lhs_eq1, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, rhs_bytes, &len, &rhs_eq1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, rhs_bytes, &len, &rhs_eq1, SECP256K1_EC_COMPRESSED); if (memcmp(lhs_bytes, rhs_bytes, 33) != 0) return 0; // Eq 1 failed @@ -1189,8 +1081,7 @@ secp256k1_equality_plaintext_verify( return 0; points_to_add[0] = c2; points_to_add[1] = &mG; - if (!secp256k1_ec_pubkey_combine( - ctx, &rhs_eq2_term2_base, points_to_add, 2)) + if (!secp256k1_ec_pubkey_combine(ctx, &rhs_eq2_term2_base, points_to_add, 2)) return 0; // Y = C2 - mG } @@ -1205,11 +1096,9 @@ secp256k1_equality_plaintext_verify( /* 4e. Compare LHS == RHS */ len = 33; - secp256k1_ec_pubkey_serialize( - ctx, lhs_bytes, &len, &lhs_eq2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, lhs_bytes, &len, &lhs_eq2, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, rhs_bytes, &len, &rhs_eq2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, rhs_bytes, &len, &rhs_eq2, SECP256K1_EC_COMPRESSED); if (memcmp(lhs_bytes, rhs_bytes, 33) != 0) return 0; // Eq 2 failed @@ -1276,8 +1165,7 @@ secp256k1_mpt_pok_sk_prove( // 4. Serialize Proof: T (33 bytes) || s (32 bytes) size_t clen = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof, &clen, &T, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof, &clen, &T, SECP256K1_EC_COMPRESSED); memcpy(proof + 33, s, 32); return 1; @@ -1318,11 +1206,9 @@ secp256k1_mpt_pok_sk_verify( // 4. Compare serialized points unsigned char ser_lhs[33], ser_rhs[33]; size_t clen = 33; - secp256k1_ec_pubkey_serialize( - ctx, ser_lhs, &clen, &lhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, ser_lhs, &clen, &lhs, SECP256K1_EC_COMPRESSED); clen = 33; - secp256k1_ec_pubkey_serialize( - ctx, ser_rhs, &clen, &rhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, ser_rhs, &clen, &rhs, SECP256K1_EC_COMPRESSED); return memcmp(ser_lhs, ser_rhs, 33) == 0; } @@ -1348,8 +1234,7 @@ secp256k1_elgamal_verify_encryption( secp256k1_ec_pubkey_serialize(ctx, ser1, &len, c1, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, ser2, &len, &expected_c1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, ser2, &len, &expected_c1, SECP256K1_EC_COMPRESSED); if (memcmp(ser1, ser2, 33) != 0) return 0; @@ -1381,8 +1266,7 @@ secp256k1_elgamal_verify_encryption( len = 33; secp256k1_ec_pubkey_serialize(ctx, ser1, &len, c2, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, ser2, &len, &expected_c2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, ser2, &len, &expected_c2, SECP256K1_EC_COMPRESSED); if (memcmp(ser1, ser2, 33) != 0) return 0; @@ -1423,8 +1307,7 @@ build_link_challenge_hash( for (int i = 0; i < 7; i++) { len = 33; - secp256k1_ec_pubkey_serialize( - ctx, hash_input + offset, &len, points[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, hash_input + offset, &len, points[i], SECP256K1_EC_COMPRESSED); offset += 33; } memcpy(hash_input + offset, context_id, 32); @@ -1443,13 +1326,11 @@ secp256k1_elgamal_pedersen_link_prove( unsigned char const* rho, unsigned char const* context_id) { - unsigned char km[32], kr[32], krho[32], e[32], sm[32], sr[32], srho[32], - m_sc[32] = {0}; + unsigned char km[32], kr[32], krho[32], e[32], sm[32], sr[32], srho[32], m_sc[32] = {0}; secp256k1_pubkey T1, T2, T3, H, mG, rPk, rhoH; size_t len = 33; - if (!generate_random_scalar(ctx, km) || !generate_random_scalar(ctx, kr) || - !generate_random_scalar(ctx, krho)) + if (!generate_random_scalar(ctx, km) || !generate_random_scalar(ctx, kr) || !generate_random_scalar(ctx, krho)) return 0; if (!secp256k1_ec_pubkey_create(ctx, &T1, kr)) return 0; @@ -1470,8 +1351,7 @@ secp256k1_elgamal_pedersen_link_prove( return 0; unsigned char hash_input[290]; - build_link_challenge_hash( - ctx, hash_input, c1, c2, pk, pcm, &T1, &T2, &T3, context_id); + build_link_challenge_hash(ctx, hash_input, c1, c2, pk, pcm, &T1, &T2, &T3, context_id); SHA256(hash_input, 290, e); for (int i = 0; i < 8; i++) @@ -1494,14 +1374,11 @@ secp256k1_elgamal_pedersen_link_prove( return 0; len = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof, &len, &T1, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof, &len, &T1, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof + 33, &len, &T2, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof + 33, &len, &T2, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, proof + 66, &len, &T3, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof + 66, &len, &T3, SECP256K1_EC_COMPRESSED); memcpy(proof + 99, sm, 32); memcpy(proof + 131, sr, 32); memcpy(proof + 163, srho, 32); @@ -1543,8 +1420,7 @@ secp256k1_elgamal_pedersen_link_verify( if (secp256k1_ec_seckey_verify(ctx, srho) != 1) return 0; - build_link_challenge_hash( - ctx, hash_input, c1, c2, pk, pcm, &T1_p, &T2_p, &T3_p, context_id); + build_link_challenge_hash(ctx, hash_input, c1, c2, pk, pcm, &T1_p, &T2_p, &T3_p, context_id); SHA256(hash_input, sizeof(hash_input), e); if (secp256k1_ec_seckey_verify(ctx, e) != 1) return 0; @@ -1563,20 +1439,18 @@ secp256k1_elgamal_pedersen_link_verify( (out) = _sum; \ } while (0) -#define EQ_PUBKEY(A, B) \ - do \ - { \ - unsigned char _a[33], _b[33]; \ - size_t _l = 33; \ - if (!secp256k1_ec_pubkey_serialize( \ - ctx, _a, &_l, (A), SECP256K1_EC_COMPRESSED)) \ - return 0; \ - _l = 33; \ - if (!secp256k1_ec_pubkey_serialize( \ - ctx, _b, &_l, (B), SECP256K1_EC_COMPRESSED)) \ - return 0; \ - if (memcmp(_a, _b, 33) != 0) \ - return 0; \ +#define EQ_PUBKEY(A, B) \ + do \ + { \ + unsigned char _a[33], _b[33]; \ + size_t _l = 33; \ + if (!secp256k1_ec_pubkey_serialize(ctx, _a, &_l, (A), SECP256K1_EC_COMPRESSED)) \ + return 0; \ + _l = 33; \ + if (!secp256k1_ec_pubkey_serialize(ctx, _b, &_l, (B), SECP256K1_EC_COMPRESSED)) \ + return 0; \ + if (memcmp(_a, _b, 33) != 0) \ + return 0; \ } while (0) /* Eq 1 */ @@ -1677,8 +1551,7 @@ build_hash_input( unsigned char buf[33]; size_t len = 33; size_t i; - secp256k1_context* ser_ctx = - secp256k1_context_create(SECP256K1_CONTEXT_NONE); + secp256k1_context* ser_ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE); SHA256_Init(&sha_ctx); SHA256_Update(&sha_ctx, domain, strlen(domain)); @@ -1686,29 +1559,23 @@ build_hash_input( // Public Inputs (R, S, Pk for each ciphertext) for (i = 0; i < n; ++i) { - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, &R[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, &R[i], SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, &S[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, &S[i], SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, &Pk[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, &Pk[i], SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); } // Commitments - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, T_m, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, T_m, SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); for (i = 0; i < n; ++i) { - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, &T_rG[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, &T_rG[i], SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); - secp256k1_ec_pubkey_serialize( - ser_ctx, buf, &len, &T_rP[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ser_ctx, buf, &len, &T_rP[i], SECP256K1_EC_COMPRESSED); SHA256_Update(&sha_ctx, buf, 33); } @@ -1816,19 +1683,16 @@ secp256k1_mpt_prove_same_plaintext_multi( size_t len = 33; // Points - secp256k1_ec_pubkey_serialize( - ctx, proof_out + offset, &len, &T_m, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof_out + offset, &len, &T_m, SECP256K1_EC_COMPRESSED); offset += 33; for (i = 0; i < n; ++i) { - secp256k1_ec_pubkey_serialize( - ctx, proof_out + offset, &len, &T_rG[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof_out + offset, &len, &T_rG[i], SECP256K1_EC_COMPRESSED); offset += 33; } for (i = 0; i < n; ++i) { - secp256k1_ec_pubkey_serialize( - ctx, proof_out + offset, &len, &T_rP[i], SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, proof_out + offset, &len, &T_rP[i], SECP256K1_EC_COMPRESSED); offset += 33; } @@ -1920,11 +1784,9 @@ secp256k1_mpt_verify_same_plaintext_multi( return 0; len = 33; - secp256k1_ec_pubkey_serialize( - ctx, b1, &len, &lhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, b1, &len, &lhs, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, b2, &len, &rhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, b2, &len, &rhs, SECP256K1_EC_COMPRESSED); if (memcmp(b1, b2, 33) != 0) return 0; @@ -1949,11 +1811,9 @@ secp256k1_mpt_verify_same_plaintext_multi( return 0; len = 33; - secp256k1_ec_pubkey_serialize( - ctx, b1, &len, &lhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, b1, &len, &lhs, SECP256K1_EC_COMPRESSED); len = 33; - secp256k1_ec_pubkey_serialize( - ctx, b2, &len, &rhs, SECP256K1_EC_COMPRESSED); + secp256k1_ec_pubkey_serialize(ctx, b2, &len, &rhs, SECP256K1_EC_COMPRESSED); if (memcmp(b1, b2, 33) != 0) return 0; } diff --git a/src/test/app/ConfidentialTransfer_test.cpp b/src/test/app/ConfidentialTransfer_test.cpp index c2bbf8a8e1..3dddcb7acc 100644 --- a/src/test/app/ConfidentialTransfer_test.cpp +++ b/src/test/app/ConfidentialTransfer_test.cpp @@ -52,8 +52,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite getTrivialSendProofHex(size_t nRecipients) { static std::string const trivialProofHex = [nRecipients]() { - size_t const sizeEquality = - getMultiCiphertextEqualityProofSize(nRecipients); + size_t const sizeEquality = getMultiCiphertextEqualityProofSize(nRecipients); size_t const totalSize = sizeEquality + (2 * ecPedersenProofLength); Buffer buf(totalSize); @@ -83,17 +82,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -131,9 +127,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const auditor("auditor"); MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -177,15 +171,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const alice("alice"); MPTTester mptAlice(env, alice); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.generateKeyPair(alice); mptAlice.convert( - {.account = alice, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(alice), - .err = temMALFORMED}); + {.account = alice, .amt = 10, .holderPubKey = mptAlice.getPubKey(alice), .err = temMALFORMED}); } { @@ -194,8 +184,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -203,16 +192,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, - .issuerPubKey = mptAlice.getPubKey(alice), - .err = temDISABLED}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice), .err = temDISABLED}); - mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = temDISABLED}); + mptAlice.convert({.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = temDISABLED}); } { @@ -221,8 +203,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -231,10 +212,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = alice, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = temMALFORMED}); + {.account = alice, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = temMALFORMED}); // blinding factor length is invalid mptAlice.convert( @@ -301,11 +279,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .err = temBAD_CIPHERTEXT}); // Holder public key is invalid (empty buffer) - mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = Buffer{}, - .err = temMALFORMED}); + mptAlice.convert({.account = bob, .amt = 10, .holderPubKey = Buffer{}, .err = temMALFORMED}); } // when registering holder pub key, the transaction must include a @@ -316,9 +290,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -326,8 +298,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.convert( {.account = bob, @@ -360,9 +331,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -370,8 +339,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // this will register bob's pub key, // and convert 10 to confidential balance @@ -382,11 +350,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); // proof must not be provided after pub key was registered - mptAlice.convert( - {.account = bob, - .amt = 20, - .fillSchnorrProof = true, - .err = temMALFORMED}); + mptAlice.convert({.account = bob, .amt = 20, .fillSchnorrProof = true, .err = temMALFORMED}); } } @@ -402,8 +366,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -411,10 +374,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, - .issuerPubKey = mptAlice.getPubKey(alice), - .err = temDISABLED}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice), .err = temDISABLED}); } // pub key is invalid @@ -424,9 +384,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -435,10 +393,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); // Pub key is invalid - mptAlice.set( - {.account = alice, - .issuerPubKey = Buffer{}, - .err = temMALFORMED}); + mptAlice.set({.account = alice, .issuerPubKey = Buffer{}, .err = temMALFORMED}); // Auditor key is invalid length mptAlice.set( @@ -448,24 +403,15 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .err = temMALFORMED}); // Cannot set auditor key without issuer key - mptAlice.set( - {.account = alice, - .auditorPubKey = mptAlice.getPubKey(alice), - .err = temMALFORMED}); + mptAlice.set({.account = alice, .auditorPubKey = mptAlice.getPubKey(alice), .err = temMALFORMED}); // Cannot set Holder and issuer Keys in the same transaction mptAlice.set( - {.account = alice, - .holder = bob, - .issuerPubKey = mptAlice.getPubKey(alice), - .err = temMALFORMED}); + {.account = alice, .holder = bob, .issuerPubKey = mptAlice.getPubKey(alice), .err = temMALFORMED}); // Cannot set Holder and auditor Keys in the same transaction mptAlice.set( - {.account = alice, - .holder = bob, - .auditorPubKey = mptAlice.getPubKey(alice), - .err = temMALFORMED}); + {.account = alice, .holder = bob, .auditorPubKey = mptAlice.getPubKey(alice), .err = temMALFORMED}); } // issuance has disabled confidential transfer @@ -476,8 +422,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob}}); // no tfMPTCanPrivacy flag enabled - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -485,10 +430,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, - .issuerPubKey = mptAlice.getPubKey(alice), - .err = tecNO_PERMISSION}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice), .err = tecNO_PERMISSION}); } } @@ -505,8 +447,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -515,10 +456,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecNO_PERMISSION}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecNO_PERMISSION}); } // issuer has not uploaded their sfIssuerElGamalPublicKey @@ -528,9 +466,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -539,10 +475,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecNO_PERMISSION}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecNO_PERMISSION}); } // issuance does not exist @@ -552,24 +485,18 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.destroy(); mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecOBJECT_NOT_FOUND}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecOBJECT_NOT_FOUND}); } // bob has not created MPToken @@ -579,21 +506,15 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecOBJECT_NOT_FOUND}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecOBJECT_NOT_FOUND}); } // trying to convert more than what bob has @@ -603,25 +524,19 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = bob, - .amt = 200, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecINSUFFICIENT_FUNDS}); + {.account = bob, .amt = 200, .holderPubKey = mptAlice.getPubKey(bob), .err = tecINSUFFICIENT_FUNDS}); } // holder cannot upload pk again @@ -631,31 +546,21 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); - mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob)}); // cannot upload pk again - mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecDUPLICATE}); + mptAlice.convert({.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecDUPLICATE}); } // cannot convert if locked @@ -665,30 +570,23 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTLock}); mptAlice.generateKeyPair(bob); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecINSUFFICIENT_FUNDS}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecINSUFFICIENT_FUNDS}); - mptAlice.set( - {.account = alice, .holder = bob, .flags = tfMPTUnlock}); + mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTUnlock}); mptAlice.convert({ .account = bob, @@ -705,9 +603,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob}}); mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | - tfMPTCanPrivacy}); + {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = alice, .holder = bob}); @@ -715,20 +611,15 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); // Unauthorize bob - mptAlice.authorize( - {.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); + mptAlice.authorize({.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecINSUFFICIENT_FUNDS}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecINSUFFICIENT_FUNDS}); // auth bob mptAlice.authorize({ @@ -750,12 +641,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const alice("alice"); Account const bob("bob"); Account const auditor("auditor"); - MPTTester mptAlice( - env, alice, {.holders = {bob}, .auditor = auditor}); + MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -786,9 +674,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -797,8 +683,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); // there is no auditor key set - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.convert( {.account = bob, @@ -815,11 +700,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const alice("alice"); Account const bob("bob"); Account const auditor("auditor"); - MPTTester mptAlice( - env, alice, {.holders = {bob}, .auditor = auditor}); + MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor}); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -848,9 +731,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -858,8 +739,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.convert( {.account = bob, @@ -880,17 +760,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -915,17 +792,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -956,15 +830,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.destroy(); mptAlice.generateKeyPair(bob); @@ -979,8 +850,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -998,14 +868,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.mergeInbox({.account = bob, .err = tecOBJECT_NOT_FOUND}); } @@ -1017,17 +884,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1046,9 +910,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -1060,14 +922,10 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // Convert 60 out of 100 - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)}); // bob merge inbox mptAlice.mergeInbox({ @@ -1075,10 +933,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); // carol convert 20 to confidential - mptAlice.convert( - {.account = carol, - .amt = 20, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 20, .holderPubKey = mptAlice.getPubKey(carol)}); // carol merge inbox mptAlice.mergeInbox({ @@ -1121,12 +976,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); Account const carol("carol"); Account const auditor("auditor"); - MPTTester mptAlice( - env, alice, {.holders = {bob, carol}, .auditor = auditor}); + MPTTester mptAlice(env, alice, {.holders = {bob, carol}, .auditor = auditor}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -1145,20 +997,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .auditorPubKey = mptAlice.getPubKey(auditor)}); // Convert 60 out of 100 - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)}); // bob merge inbox mptAlice.mergeInbox({ .account = bob, }); - mptAlice.convert( - {.account = carol, - .amt = 20, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 20, .holderPubKey = mptAlice.getPubKey(carol)}); // carol merge inbox mptAlice.mergeInbox({ @@ -1215,16 +1061,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.pay(alice, bob, 100); mptAlice.pay(alice, carol, 50); @@ -1241,37 +1085,20 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); // issuer can not be the same as sender - mptAlice.send( - {.account = alice, - .dest = carol, - .amt = 10, - .err = temMALFORMED}); + mptAlice.send({.account = alice, .dest = carol, .amt = 10, .err = temMALFORMED}); // can not send to self - mptAlice.send( - {.account = bob, .dest = bob, .amt = 10, .err = temMALFORMED}); + mptAlice.send({.account = bob, .dest = bob, .amt = 10, .err = temMALFORMED}); // sender encrypted amount wrong length mptAlice.send( - {.account = bob, - .dest = carol, - .amt = 10, - .senderEncryptedAmt = Buffer(10), - .err = temBAD_CIPHERTEXT}); + {.account = bob, .dest = carol, .amt = 10, .senderEncryptedAmt = Buffer(10), .err = temBAD_CIPHERTEXT}); // dest encrypted amount wrong length mptAlice.send( - {.account = bob, - .dest = carol, - .amt = 10, - .destEncryptedAmt = Buffer(10), - .err = temBAD_CIPHERTEXT}); + {.account = bob, .dest = carol, .amt = 10, .destEncryptedAmt = Buffer(10), .err = temBAD_CIPHERTEXT}); // issuer encrypted amount wrong length mptAlice.send( - {.account = bob, - .dest = carol, - .amt = 10, - .issuerEncryptedAmt = Buffer(10), - .err = temBAD_CIPHERTEXT}); + {.account = bob, .dest = carol, .amt = 10, .issuerEncryptedAmt = Buffer(10), .err = temBAD_CIPHERTEXT}); // sender encrypted amount malformed mptAlice.send( @@ -1351,9 +1178,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave, eve}}); // authorize bob, carol, dave (not eve) - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | - tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = alice, .holder = bob}); mptAlice.authorize({.account = carol}); @@ -1369,20 +1194,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); mptAlice.generateKeyPair(dave); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // bob and carol convert some funds to confidential - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tesSUCCESS}); - mptAlice.convert( - {.account = carol, - .amt = 20, - .holderPubKey = mptAlice.getPubKey(carol), - .err = tesSUCCESS}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob), .err = tesSUCCESS}); + mptAlice.convert({.account = carol, .amt = 20, .holderPubKey = mptAlice.getPubKey(carol), .err = tesSUCCESS}); // bob and carol merge inbox mptAlice.mergeInbox({ @@ -1404,8 +1220,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // destroy the issuance mptAlice.destroy(); @@ -1419,8 +1234,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite jv[sfDestinationEncryptedAmount] = strHex(getTrivialCiphertext()); jv[sfIssuerEncryptedAmount] = strHex(getTrivialCiphertext()); jv[sfAmountCommitment] = strHex(Buffer(ecPedersenCommitmentLength)); - jv[sfBalanceCommitment] = - strHex(Buffer(ecPedersenCommitmentLength)); + jv[sfBalanceCommitment] = strHex(Buffer(ecPedersenCommitmentLength)); jv[sfZKProof] = getTrivialSendProofHex(3); env(jv, ter(tecOBJECT_NOT_FOUND)); @@ -1487,8 +1301,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite { // lock issuance mptAlice.set({.account = alice, .flags = tfMPTLock}); - mptAlice.send( - {.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); + mptAlice.send({.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); // unlock issuance mptAlice.set({.account = alice, .flags = tfMPTUnlock}); // now can send @@ -1499,11 +1312,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite { // lock bob mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTLock}); - mptAlice.send( - {.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); + mptAlice.send({.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); // unlock bob - mptAlice.set( - {.account = alice, .holder = bob, .flags = tfMPTUnlock}); + mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTUnlock}); // now can send mptAlice.send({.account = bob, .dest = carol, .amt = 2}); } @@ -1511,13 +1322,10 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // destination is locked { // lock carol - mptAlice.set( - {.account = alice, .holder = carol, .flags = tfMPTLock}); - mptAlice.send( - {.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); + mptAlice.set({.account = alice, .holder = carol, .flags = tfMPTLock}); + mptAlice.send({.account = bob, .dest = carol, .amt = 10, .err = tecLOCKED}); // unlock carol - mptAlice.set( - {.account = alice, .holder = carol, .flags = tfMPTUnlock}); + mptAlice.set({.account = alice, .holder = carol, .flags = tfMPTUnlock}); // now can send mptAlice.send({.account = bob, .dest = carol, .amt = 3}); } @@ -1525,10 +1333,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // sender not authorized { // unauthorize bob - mptAlice.authorize( - {.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); - mptAlice.send( - {.account = bob, .dest = carol, .amt = 10, .err = tecNO_AUTH}); + mptAlice.authorize({.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); + mptAlice.send({.account = bob, .dest = carol, .amt = 10, .err = tecNO_AUTH}); // authorize bob again mptAlice.authorize({ .account = alice, @@ -1541,10 +1347,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // destination not authorized { // unauthorize carol - mptAlice.authorize( - {.account = alice, .holder = carol, .flags = tfMPTUnauthorize}); - mptAlice.send( - {.account = bob, .dest = carol, .amt = 10, .err = tecNO_AUTH}); + mptAlice.authorize({.account = alice, .holder = carol, .flags = tfMPTUnauthorize}); + mptAlice.send({.account = bob, .dest = carol, .amt = 10, .err = tecNO_AUTH}); // authorize carol again mptAlice.authorize({ .account = alice, @@ -1562,8 +1366,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -1575,15 +1378,10 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // Convert 60 out of 100 - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tesSUCCESS}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob), .err = tesSUCCESS}); // bob merge inbox mptAlice.mergeInbox({ @@ -1591,10 +1389,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); mptAlice.convert( - {.account = carol, - .amt = 20, - .holderPubKey = mptAlice.getPubKey(carol), - .err = tesSUCCESS}); + {.account = carol, .amt = 20, .holderPubKey = mptAlice.getPubKey(carol), .err = tesSUCCESS}); // carol merge inbox mptAlice.mergeInbox({ @@ -1617,9 +1412,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanLock | tfMPTCanPrivacy | tfMPTCanTransfer}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanLock | tfMPTCanPrivacy | tfMPTCanTransfer}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -1631,35 +1424,23 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tesSUCCESS}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob), .err = tesSUCCESS}); mptAlice.mergeInbox({ .account = bob, }); mptAlice.convert( - {.account = carol, - .amt = 20, - .holderPubKey = mptAlice.getPubKey(carol), - .err = tesSUCCESS}); + {.account = carol, .amt = 20, .holderPubKey = mptAlice.getPubKey(carol), .err = tesSUCCESS}); mptAlice.mergeInbox({ .account = carol, }); mptAlice.send( - {.account = bob, - .dest = carol, - .amt = 10, - .proof = getTrivialSendProofHex(3), - .err = tecBAD_PROOF}); + {.account = bob, .dest = carol, .amt = 10, .proof = getTrivialSendProofHex(3), .err = tecBAD_PROOF}); } } @@ -1676,17 +1457,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1696,10 +1474,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .holderPubKey = mptAlice.getPubKey(bob), }); - mptAlice.authorize( - {.account = bob, - .flags = tfMPTUnauthorize, - .err = tecHAS_OBLIGATIONS}); + mptAlice.authorize({.account = bob, .flags = tfMPTUnauthorize, .err = tecHAS_OBLIGATIONS}); } // cannot delete mptoken where it has encrypted balance @@ -1710,9 +1485,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -1720,8 +1493,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); @@ -1739,10 +1511,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); // carol cannot delete even if he has encrypted zero amount - mptAlice.authorize( - {.account = carol, - .flags = tfMPTUnauthorize, - .err = tecHAS_OBLIGATIONS}); + mptAlice.authorize({.account = carol, .flags = tfMPTUnauthorize, .err = tecHAS_OBLIGATIONS}); } // can delete mptoken if outstanding confidential balance is zero @@ -1752,15 +1521,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1784,15 +1550,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1823,17 +1586,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1865,9 +1625,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const auditor("auditor"); MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -1910,8 +1668,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -1919,8 +1676,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.convertBack( - {.account = bob, .amt = 30, .err = temDISABLED}); + mptAlice.convertBack({.account = bob, .amt = 30, .err = temDISABLED}); } { @@ -1929,17 +1685,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -1953,59 +1706,30 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .account = bob, }); - mptAlice.convertBack( - {.account = alice, .amt = 30, .err = temMALFORMED}); + mptAlice.convertBack({.account = alice, .amt = 30, .err = temMALFORMED}); - mptAlice.convertBack( - {.account = bob, .amt = 0, .err = temBAD_AMOUNT}); + mptAlice.convertBack({.account = bob, .amt = 0, .err = temBAD_AMOUNT}); - mptAlice.convertBack( - {.account = bob, - .amt = maxMPTokenAmount + 1, - .err = temBAD_AMOUNT}); + mptAlice.convertBack({.account = bob, .amt = maxMPTokenAmount + 1, .err = temBAD_AMOUNT}); // invalid blinding factor length - mptAlice.convertBack( - {.account = alice, - .amt = 30, - .blindingFactor = Buffer{}, - .err = temMALFORMED}); + mptAlice.convertBack({.account = alice, .amt = 30, .blindingFactor = Buffer{}, .err = temMALFORMED}); + + mptAlice.convertBack({.account = bob, .amt = 30, .holderEncryptedAmt = Buffer{}, .err = temBAD_CIPHERTEXT}); + + mptAlice.convertBack({.account = bob, .amt = 30, .issuerEncryptedAmt = Buffer{}, .err = temBAD_CIPHERTEXT}); mptAlice.convertBack( - {.account = bob, - .amt = 30, - .holderEncryptedAmt = Buffer{}, - .err = temBAD_CIPHERTEXT}); + {.account = bob, .amt = 30, .holderEncryptedAmt = getBadCiphertext(), .err = temBAD_CIPHERTEXT}); mptAlice.convertBack( - {.account = bob, - .amt = 30, - .issuerEncryptedAmt = Buffer{}, - .err = temBAD_CIPHERTEXT}); + {.account = bob, .amt = 30, .issuerEncryptedAmt = getBadCiphertext(), .err = temBAD_CIPHERTEXT}); mptAlice.convertBack( - {.account = bob, - .amt = 30, - .holderEncryptedAmt = getBadCiphertext(), - .err = temBAD_CIPHERTEXT}); + {.account = bob, .amt = 30, .auditorEncryptedAmt = Buffer(10), .err = temBAD_CIPHERTEXT}); mptAlice.convertBack( - {.account = bob, - .amt = 30, - .issuerEncryptedAmt = getBadCiphertext(), - .err = temBAD_CIPHERTEXT}); - - mptAlice.convertBack( - {.account = bob, - .amt = 30, - .auditorEncryptedAmt = Buffer(10), - .err = temBAD_CIPHERTEXT}); - - mptAlice.convertBack( - {.account = bob, - .amt = 30, - .auditorEncryptedAmt = getBadCiphertext(), - .err = temBAD_CIPHERTEXT}); + {.account = bob, .amt = 30, .auditorEncryptedAmt = getBadCiphertext(), .err = temBAD_CIPHERTEXT}); } } @@ -2022,21 +1746,17 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.destroy(); mptAlice.generateKeyPair(bob); - mptAlice.convertBack( - {.account = bob, .amt = 30, .err = tecOBJECT_NOT_FOUND}); + mptAlice.convertBack({.account = bob, .amt = 30, .err = tecOBJECT_NOT_FOUND}); } // tfMPTCanPrivacy is not set on issuance @@ -2046,8 +1766,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -2055,8 +1774,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.convertBack( - {.account = bob, .amt = 30, .err = tecNO_PERMISSION}); + mptAlice.convertBack({.account = bob, .amt = 30, .err = tecNO_PERMISSION}); } // no mptoken @@ -2066,18 +1784,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); - mptAlice.convertBack( - {.account = bob, .amt = 30, .err = tecOBJECT_NOT_FOUND}); + mptAlice.convertBack({.account = bob, .amt = 30, .err = tecOBJECT_NOT_FOUND}); } // bob doesn't have encrypted balances @@ -2087,22 +1801,18 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); - mptAlice.convertBack( - {.account = bob, .amt = 30, .err = tecNO_PERMISSION}); + mptAlice.convertBack({.account = bob, .amt = 30, .err = tecNO_PERMISSION}); } // bob tries to convert back more than COA @@ -2113,9 +1823,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -2124,8 +1832,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); @@ -2146,8 +1853,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .holderPubKey = mptAlice.getPubKey(carol), }); - mptAlice.convertBack( - {.account = bob, .amt = 300, .err = tecINSUFFICIENT_FUNDS}); + mptAlice.convertBack({.account = bob, .amt = 300, .err = tecINSUFFICIENT_FUNDS}); } // cannot convert if locked or unauth @@ -2158,9 +1864,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob}}); mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | - tfMPTCanPrivacy}); + {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTRequireAuth | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = alice, .holder = bob}); @@ -2168,8 +1872,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -2183,19 +1886,16 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.convertBack({.account = bob, .amt = 10, .err = tecLOCKED}); - mptAlice.set( - {.account = alice, .holder = bob, .flags = tfMPTUnlock}); + mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTUnlock}); mptAlice.convertBack({ .account = bob, .amt = 10, }); - mptAlice.authorize( - {.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); + mptAlice.authorize({.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); - mptAlice.convertBack( - {.account = bob, .amt = 10, .err = tecNO_AUTH}); + mptAlice.convertBack({.account = bob, .amt = 10, .err = tecNO_AUTH}); mptAlice.authorize({ .account = alice, @@ -2216,23 +1916,17 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // Bob converts funds to confidential so he has something to convert // back - mptAlice.convert( - {.account = bob, - .amt = 50, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 50, .holderPubKey = mptAlice.getPubKey(bob)}); mptAlice.mergeInbox({.account = bob}); mptAlice.convertBack( @@ -2249,11 +1943,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const alice("alice"); Account const bob("bob"); Account const auditor("auditor"); - MPTTester mptAlice( - env, alice, {.holders = {bob}, .auditor = auditor}); + MPTTester mptAlice(env, alice, {.holders = {bob}, .auditor = auditor}); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); @@ -2283,11 +1975,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // ConvertBack where auditor ciphertext mathematically // correct, but contains invalid data (mismatching amount). - mptAlice.convertBack( - {.account = bob, - .amt = 10, - .auditorEncryptedAmt = getTrivialCiphertext(), - .err = tecBAD_PROOF}); + mptAlice.convertBack( + {.account = bob, .amt = 10, .auditorEncryptedAmt = getTrivialCiphertext(), .err = tecBAD_PROOF}); } } @@ -2310,9 +1999,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite char const credType[] = "abcde"; MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); @@ -2324,8 +2011,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // Bob require preauthorization env(fset(bob, asfDepositAuth)); @@ -2353,11 +2039,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite }); // carol sends 10 to bob, but not authorized - mptAlice.send( - {.account = carol, - .dest = bob, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.send({.account = carol, .dest = bob, .amt = 10, .err = tecNO_PERMISSION}); // Bob authorize alice env(deposit::auth(bob, carol)); @@ -2373,38 +2055,21 @@ class ConfidentialTransfer_test : public beast::unit_test::suite auto const jv = credentials::ledgerEntry(env, bob, dpIssuer, credType); std::string const credIdx = jv[jss::result][jss::index].asString(); - mptAlice.send( - {.account = carol, - .dest = bob, - .amt = 10, - .credentials = {{credIdx}}}); + mptAlice.send({.account = carol, .dest = bob, .amt = 10, .credentials = {{credIdx}}}); // Bob revoke authorization env(deposit::unauth(bob, carol)); env.close(); - mptAlice.send( - {.account = carol, - .dest = bob, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.send({.account = carol, .dest = bob, .amt = 10, .err = tecNO_PERMISSION}); - mptAlice.send( - {.account = carol, - .dest = bob, - .amt = 10, - .credentials = {{credIdx}}, - .err = tecNO_PERMISSION}); + mptAlice.send({.account = carol, .dest = bob, .amt = 10, .credentials = {{credIdx}}, .err = tecNO_PERMISSION}); // Bob authorize credentials env(deposit::authCredentials(bob, {{dpIssuer, credType}})); env.close(); - mptAlice.send( - {.account = carol, - .dest = bob, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.send({.account = carol, .dest = bob, .amt = 10, .err = tecNO_PERMISSION}); mptAlice.send({ .account = carol, @@ -2427,9 +2092,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const dave("dave"); MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave}}); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback | - tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.authorize({.account = carol}); @@ -2441,17 +2104,13 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); mptAlice.generateKeyPair(dave); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // setup bob. // after setup, bob's spending balance is 60, inbox balance is 0. { // bob converts 60 to confidential - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)}); // bob merge inbox mptAlice.mergeInbox({ @@ -2463,10 +2122,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // after setup, carol's spending balance is 120, inbox balance is 0. { // carol converts 120 to confidential - mptAlice.convert( - {.account = carol, - .amt = 120, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 120, .holderPubKey = mptAlice.getPubKey(carol)}); // carol merge inbox mptAlice.mergeInbox({ @@ -2477,10 +2133,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // setup dave. // dave will not merge inbox. // after setup, dave's inbox balance is 200, spending balance is 0. - mptAlice.convert( - {.account = dave, - .amt = 200, - .holderPubKey = mptAlice.getPubKey(dave)}); + mptAlice.convert({.account = dave, .amt = 200, .holderPubKey = mptAlice.getPubKey(dave)}); // setup: carol confidential send 50 to bob. // after send, bob's inbox balance is 50, spending balance @@ -2492,18 +2145,15 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // bob has balance in both inbox and spending. These balances should // become zero after clawback, which is verified in the // confidentialClaw function. - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 110}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 110}); // alice clawback all confidential balance from carol, which is 70. // carol only has balance in spending. - mptAlice.confidentialClaw( - {.account = alice, .holder = carol, .amt = 70}); + mptAlice.confidentialClaw({.account = alice, .holder = carol, .amt = 70}); // alice clawback all confidential balance from dave, which is 200. // dave only has balance in inbox. - mptAlice.confidentialClaw( - {.account = alice, .holder = dave, .amt = 200}); + mptAlice.confidentialClaw({.account = alice, .holder = dave, .amt = 200}); } void @@ -2518,12 +2168,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); Account const dave("dave"); Account const auditor("auditor"); - MPTTester mptAlice( - env, alice, {.holders = {bob, carol, dave}, .auditor = auditor}); + MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave}, .auditor = auditor}); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback | - tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanClawback | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.authorize({.account = carol}); @@ -2545,10 +2192,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // after setup, bob's spending balance is 60, inbox balance is 0. { // bob converts 60 to confidential - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)}); // bob merge inbox mptAlice.mergeInbox({ @@ -2560,10 +2204,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // after setup, carol's spending balance is 120, inbox balance is 0. { // carol converts 120 to confidential - mptAlice.convert( - {.account = carol, - .amt = 120, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 120, .holderPubKey = mptAlice.getPubKey(carol)}); // carol merge inbox mptAlice.mergeInbox({ @@ -2574,10 +2215,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // setup dave. // dave will not merge inbox. // after setup, dave's inbox balance is 200, spending balance is 0. - mptAlice.convert( - {.account = dave, - .amt = 200, - .holderPubKey = mptAlice.getPubKey(dave)}); + mptAlice.convert({.account = dave, .amt = 200, .holderPubKey = mptAlice.getPubKey(dave)}); // setup: carol confidential send 50 to bob. // after send, bob's inbox balance is 50, spending balance @@ -2589,18 +2227,15 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // bob has balance in both inbox and spending. These balances should // become zero after clawback, which is verified in the // confidentialClaw function. - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 110}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 110}); // alice clawback all confidential balance from carol, which is 70. // carol only has balance in spending. - mptAlice.confidentialClaw( - {.account = alice, .holder = carol, .amt = 70}); + mptAlice.confidentialClaw({.account = alice, .holder = carol, .amt = 70}); // alice clawback all confidential balance from dave, which is 200. // dave only has balance in inbox. - mptAlice.confidentialClaw( - {.account = alice, .holder = dave, .amt = 200}); + mptAlice.confidentialClaw({.account = alice, .holder = dave, .amt = 200}); } void @@ -2619,12 +2254,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.create(); mptAlice.authorize({.account = bob}); - mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 10, - .proof = "123", - .err = temDISABLED}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 10, .proof = "123", .err = temDISABLED}); } // test malformed @@ -2636,26 +2266,19 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const carol("carol"); MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = carol}); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.pay(alice, bob, 100); mptAlice.pay(alice, carol, 50); // only issuer can clawback - mptAlice.confidentialClaw( - {.account = carol, - .holder = bob, - .amt = 10, - .err = temMALFORMED}); + mptAlice.confidentialClaw({.account = carol, .holder = bob, .amt = 10, .err = temMALFORMED}); // invalid issuance ID, whose issuer is not alice { @@ -2667,33 +2290,20 @@ class ConfidentialTransfer_test : public beast::unit_test::suite jv[sfZKProof] = "123"; // wrong issuance ID - jv[sfMPTokenIssuanceID] = - "00000004AE123A8556F3CF91154711376AFB0F894F832B3E"; + jv[sfMPTokenIssuanceID] = "00000004AE123A8556F3CF91154711376AFB0F894F832B3E"; env(jv, ter(temMALFORMED)); } // issuer cannot clawback from self - mptAlice.confidentialClaw( - {.account = alice, - .holder = alice, - .amt = 10, - .err = temMALFORMED}); + mptAlice.confidentialClaw({.account = alice, .holder = alice, .amt = 10, .err = temMALFORMED}); // invalid amount - mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 0, - .err = temBAD_AMOUNT}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 0, .err = temBAD_AMOUNT}); // invalid proof length mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 10, - .proof = "123", - .err = temMALFORMED}); + {.account = alice, .holder = bob, .amt = 10, .proof = "123", .err = temMALFORMED}); } } @@ -2714,9 +2324,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const dave("dave"); MPTTester mptAlice(env, alice, {.holders = {bob, carol, dave}}); - mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanClawback | - tfMPTRequireAuth | tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTRequireAuth | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = alice, .holder = bob}); mptAlice.authorize({.account = carol}); @@ -2727,8 +2335,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); mptAlice.generateKeyPair(carol); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.convert({ .account = bob, @@ -2742,29 +2349,17 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // holder does not exist { Account const unknown("unknown"); - mptAlice.confidentialClaw( - {.account = alice, - .holder = unknown, - .amt = 10, - .err = tecNO_TARGET}); + mptAlice.confidentialClaw({.account = alice, .holder = unknown, .amt = 10, .err = tecNO_TARGET}); } // dave does not hold mpt at all, no MPT object { - mptAlice.confidentialClaw( - {.account = alice, - .holder = dave, - .amt = 10, - .err = tecOBJECT_NOT_FOUND}); + mptAlice.confidentialClaw({.account = alice, .holder = dave, .amt = 10, .err = tecOBJECT_NOT_FOUND}); } // carol has no confidential balance { - mptAlice.confidentialClaw( - {.account = alice, - .holder = carol, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.confidentialClaw({.account = alice, .holder = carol, .amt = 10, .err = tecNO_PERMISSION}); } } @@ -2778,14 +2373,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); - mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 10, .err = tecNO_PERMISSION}); } // no issuer key @@ -2798,11 +2388,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 10, - .err = tecNO_PERMISSION}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 10, .err = tecNO_PERMISSION}); } // issuance not found @@ -2814,8 +2400,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.create({.flags = tfMPTCanClawback | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // destroy the issuance mptAlice.destroy(); @@ -2834,25 +2419,18 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // helper function to set up accounts to test lock and unauthorize // cases. after set up, bob has confidential balance 60 in spending. - auto setupAccounts = [&](Env& env, - Account const& alice, - Account const& bob) -> MPTTester { + auto setupAccounts = [&](Env& env, Account const& alice, Account const& bob) -> MPTTester { MPTTester mptAlice(env, alice, {.holders = {bob}}); mptAlice.create( - {.flags = tfMPTCanTransfer | tfMPTCanClawback | - tfMPTRequireAuth | tfMPTCanLock | tfMPTCanPrivacy}); + {.flags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTRequireAuth | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.authorize({.account = alice, .holder = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); - mptAlice.convert( - {.account = bob, - .amt = 60, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.convert({.account = bob, .amt = 60, .holderPubKey = mptAlice.getPubKey(bob)}); mptAlice.mergeInbox({ .account = bob, }); @@ -2869,8 +2447,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTLock}); // clawback should still work - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 60}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 60}); } // lock globally @@ -2882,8 +2459,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite mptAlice.set({.account = alice, .flags = tfMPTLock}); // clawback should still work - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 60}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 60}); } // unauthorize should not block clawback @@ -2894,11 +2470,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice = setupAccounts(env, alice, bob); // unauthorize bob - mptAlice.authorize( - {.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); + mptAlice.authorize({.account = alice, .holder = bob, .flags = tfMPTUnauthorize}); // clawback should still work - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 60}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 60}); } // insufficient funds, clawback amount exceeding confidential @@ -2909,11 +2483,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice = setupAccounts(env, alice, bob); - mptAlice.confidentialClaw( - {.account = alice, - .holder = bob, - .amt = 10000, - .err = tecINSUFFICIENT_FUNDS}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 10000, .err = tecINSUFFICIENT_FUNDS}); } } @@ -2933,12 +2503,9 @@ class ConfidentialTransfer_test : public beast::unit_test::suite auto setupEnv = [&](Env& env) -> MPTTester { MPTTester mptAlice(env, alice, {.holders = {bob, carol}}); - mptAlice.create( - {.flags = - tfMPTCanTransfer | tfMPTCanClawback | tfMPTCanPrivacy}); + mptAlice.create({.flags = tfMPTCanTransfer | tfMPTCanClawback | tfMPTCanPrivacy}); - for (auto const& [acct, amt] : - {std::pair{bob, 1000}, {carol, 2000}}) + for (auto const& [acct, amt] : {std::pair{bob, 1000}, {carol, 2000}}) { mptAlice.authorize({.account = acct}); mptAlice.pay(alice, acct, amt); @@ -2946,24 +2513,17 @@ class ConfidentialTransfer_test : public beast::unit_test::suite } mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); return mptAlice; }; // lambda function to test a set of bad clawback amounts that should // return tecBAD_PROOF - auto checkBadProofs = [&](MPTTester& mpt, - Account const& holder, - std::initializer_list amts) { + auto checkBadProofs = [&](MPTTester& mpt, Account const& holder, std::initializer_list amts) { for (auto const badAmt : amts) { - mpt.confidentialClaw( - {.account = alice, - .holder = holder, - .amt = badAmt, - .err = tecBAD_PROOF}); + mpt.confidentialClaw({.account = alice, .holder = holder, .amt = badAmt, .err = tecBAD_PROOF}); } }; @@ -2976,33 +2536,23 @@ class ConfidentialTransfer_test : public beast::unit_test::suite auto mptAlice = setupEnv(env); // bob converts and merges - mptAlice.convert( - {.account = bob, - .amt = 500, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 500, .holderPubKey = mptAlice.getPubKey(bob)}); mptAlice.mergeInbox({ .account = bob, }); // carol converts without merge - mptAlice.convert( - {.account = carol, - .amt = 1000, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 1000, .holderPubKey = mptAlice.getPubKey(carol)}); // verify proof fails with invalid clawback amount // bob: 500 in Spending, 0 in Inbox - checkBadProofs( - mptAlice, bob, {1, 10, 70, 100, 110, 200, 499, 501, 600}); + checkBadProofs(mptAlice, bob, {1, 10, 70, 100, 110, 200, 499, 501, 600}); // carol: 1000 in Inbox, 0 in Spending - checkBadProofs( - mptAlice, carol, {1, 10, 50, 500, 777, 850, 999, 1001, 1200}); + checkBadProofs(mptAlice, carol, {1, 10, 50, 500, 777, 850, 999, 1001, 1200}); // clawback with correct amount that passes proof verification - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 500}); - mptAlice.confidentialClaw( - {.account = alice, .holder = carol, .amt = 1000}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 500}); + mptAlice.confidentialClaw({.account = alice, .holder = carol, .amt = 1000}); } // SCENARIO 2: clawback from mixed inbox and spending balances. @@ -3015,17 +2565,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Env env{*this, features}; auto mptAlice = setupEnv(env); - mptAlice.convert( - {.account = bob, - .amt = 300, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 300, .holderPubKey = mptAlice.getPubKey(bob)}); mptAlice.mergeInbox({ .account = bob, }); - mptAlice.convert( - {.account = carol, - .amt = 400, - .holderPubKey = mptAlice.getPubKey(carol)}); + mptAlice.convert({.account = carol, .amt = 400, .holderPubKey = mptAlice.getPubKey(carol)}); mptAlice.mergeInbox({ .account = carol, }); @@ -3038,14 +2582,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // proof failure for incorrect amount when clawbacking from // carol carol: 100 in inbox, 300 in spending - checkBadProofs( - mptAlice, carol, {1, 10, 50, 100, 300, 399, 401, 501}); + checkBadProofs(mptAlice, carol, {1, 10, 50, 100, 300, 399, 401, 501}); // clawback with correct amount that passes proof verification - mptAlice.confidentialClaw( - {.account = alice, .holder = bob, .amt = 300}); - mptAlice.confidentialClaw( - {.account = alice, .holder = carol, .amt = 400}); + mptAlice.confidentialClaw({.account = alice, .holder = bob, .amt = 300}); + mptAlice.confidentialClaw({.account = alice, .holder = carol, .amt = 400}); } } @@ -3063,10 +2604,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 0, - .mutableFlags = tmfMPTCannotMutatePrivacy, - .err = temDISABLED}); + mptAlice.create({.ownerCount = 0, .mutableFlags = tmfMPTCannotMutatePrivacy, .err = temDISABLED}); } // can not create mpt issuance with tmfMPTCannotMutatePrivacy when @@ -3077,10 +2615,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 0, - .mutableFlags = tmfMPTCannotMutatePrivacy, - .err = temDISABLED}); + mptAlice.create({.ownerCount = 0, .mutableFlags = tmfMPTCannotMutatePrivacy, .err = temDISABLED}); } // if lsmfMPTCannotMutatePrivacy is set, can not set/clear @@ -3091,20 +2626,11 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Account const bob("bob"); MPTTester mptAlice(env, alice, {.holders = {bob}}); - mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer, - .mutableFlags = tmfMPTCannotMutatePrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer, .mutableFlags = tmfMPTCannotMutatePrivacy}); - mptAlice.set( - {.account = alice, - .mutableFlags = tmfMPTSetPrivacy, - .err = tecNO_PERMISSION}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTSetPrivacy, .err = tecNO_PERMISSION}); - mptAlice.set( - {.account = alice, - .mutableFlags = tmfMPTClearPrivacy, - .err = tecNO_PERMISSION}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTClearPrivacy, .err = tecNO_PERMISSION}); } // Toggle lsfMPTCanPrivacy @@ -3115,26 +2641,20 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob}}); mptAlice.create( - {.ownerCount = 1, - .flags = tfMPTCanTransfer | tfMPTCanPrivacy, - .mutableFlags = tmfMPTCanMutateCanLock}); + {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanPrivacy, .mutableFlags = tmfMPTCanMutateCanLock}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); auto holderPubKeySet = false; auto verifyToggle = [&](TER expectedResult, uint64_t amt) { if (!holderPubKeySet) mptAlice.convert( - {.account = bob, - .amt = amt, - .holderPubKey = mptAlice.getPubKey(bob), - .err = expectedResult}); + {.account = bob, .amt = amt, .holderPubKey = mptAlice.getPubKey(bob), .err = expectedResult}); else mptAlice.convert({ .account = bob, @@ -3164,15 +2684,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite verifyToggle(tesSUCCESS, 10); // clear lsfMPTCanPrivacy - mptAlice.set( - {.account = alice, .mutableFlags = tmfMPTClearPrivacy}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTClearPrivacy}); verifyToggle(tecNO_PERMISSION, 10); // can clear lsfMPTCanPrivacy again but has no effect // for privacy settings - mptAlice.set( - {.account = alice, - .mutableFlags = tmfMPTClearPrivacy | tmfMPTSetCanLock}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTClearPrivacy | tmfMPTSetCanLock}); verifyToggle(tecNO_PERMISSION, 20); // set lsfMPTCanPrivacy again @@ -3190,33 +2707,22 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // lsmfMPTCannotMutatePrivacy is false by default, // so that lsfMPTCanPrivacy can be mutated - mptAlice.create( - {.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanPrivacy}); + mptAlice.create({.ownerCount = 1, .flags = tfMPTCanTransfer | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); mptAlice.generateKeyPair(bob); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); // bob convert 50 to confidential - mptAlice.convert( - {.account = bob, - .amt = 50, - .holderPubKey = mptAlice.getPubKey(bob)}); + mptAlice.convert({.account = bob, .amt = 50, .holderPubKey = mptAlice.getPubKey(bob)}); // set or clear lsfMPTCanPrivacy should fail because of // confidential outstanding balance - mptAlice.set( - {.account = alice, - .mutableFlags = tmfMPTSetPrivacy, - .err = tecNO_PERMISSION}); - mptAlice.set( - {.account = alice, - .mutableFlags = tmfMPTClearPrivacy, - .err = tecNO_PERMISSION}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTSetPrivacy, .err = tecNO_PERMISSION}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTClearPrivacy, .err = tecNO_PERMISSION}); // bob merge inbox mptAlice.mergeInbox({ @@ -3231,16 +2737,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite // now clear lsfMPTCanPrivacy should succeed, // because there's no confidential outstanding balance - mptAlice.set( - {.account = alice, .mutableFlags = tmfMPTClearPrivacy}); + mptAlice.set({.account = alice, .mutableFlags = tmfMPTClearPrivacy}); // bob can not convert because lsfMPTCanPrivacy was cleared // successfully mptAlice.convert( - {.account = bob, - .amt = 10, - .holderPubKey = mptAlice.getPubKey(bob), - .err = tecNO_PERMISSION}); + {.account = bob, .amt = 10, .holderPubKey = mptAlice.getPubKey(bob), .err = tecNO_PERMISSION}); // can set lsfMPTCanPrivacy again when there's no confidential // outstanding balance @@ -3264,17 +2766,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite MPTTester mptAlice(env, alice, {.holders = {bob}}); mptAlice.create( - {.ownerCount = 1, - .holderCount = 0, - .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); + {.ownerCount = 1, .holderCount = 0, .flags = tfMPTCanTransfer | tfMPTCanLock | tfMPTCanPrivacy}); mptAlice.authorize({.account = bob}); mptAlice.pay(alice, bob, 100); mptAlice.generateKeyPair(alice); - mptAlice.set( - {.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); + mptAlice.set({.account = alice, .issuerPubKey = mptAlice.getPubKey(alice)}); mptAlice.generateKeyPair(bob); @@ -3294,29 +2793,21 @@ class ConfidentialTransfer_test : public beast::unit_test::suite Buffer const blindingFactor = generateBlindingFactor(); Buffer const pcBlindingFactor = generateBlindingFactor(); - auto const spendingBalance = mptAlice.getDecryptedBalance( - bob, MPTTester::HOLDER_ENCRYPTED_SPENDING); + auto const spendingBalance = mptAlice.getDecryptedBalance(bob, MPTTester::HOLDER_ENCRYPTED_SPENDING); BEAST_EXPECT(spendingBalance.has_value()); - auto const encryptedSpendingBalance = mptAlice.getEncryptedBalance( - bob, MPTTester::HOLDER_ENCRYPTED_SPENDING); - BEAST_EXPECT( - encryptedSpendingBalance.has_value() && - !encryptedSpendingBalance->empty()); + auto const encryptedSpendingBalance = mptAlice.getEncryptedBalance(bob, MPTTester::HOLDER_ENCRYPTED_SPENDING); + BEAST_EXPECT(encryptedSpendingBalance.has_value() && !encryptedSpendingBalance->empty()); - Buffer const pedersenCommitment = - mptAlice.getPedersenCommitment(*spendingBalance, pcBlindingFactor); - Buffer const issuerCiphertext = - mptAlice.encryptAmount(alice, amt, blindingFactor); - Buffer const bobCiphertext = - mptAlice.encryptAmount(bob, amt, blindingFactor); + Buffer const pedersenCommitment = mptAlice.getPedersenCommitment(*spendingBalance, pcBlindingFactor); + Buffer const issuerCiphertext = mptAlice.encryptAmount(alice, amt, blindingFactor); + Buffer const bobCiphertext = mptAlice.encryptAmount(bob, amt, blindingFactor); auto const version = mptAlice.getMPTokenVersion(bob); // generate a proof using a pedersen commitment using the wrong value { - uint256 const contextHash = getConvertBackContextHash( - bob, env.seq(bob), mptAlice.issuanceID(), amt, version); - Buffer const badPedersenCommitment = - mptAlice.getPedersenCommitment(1, pcBlindingFactor); + uint256 const contextHash = + getConvertBackContextHash(bob, env.seq(bob), mptAlice.issuanceID(), amt, version); + Buffer const badPedersenCommitment = mptAlice.getPedersenCommitment(1, pcBlindingFactor); Buffer const proof = mptAlice.getConvertBackProof( bob, amt, @@ -3326,8 +2817,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite {}, blindingFactor, { - .pedersenCommitment = - badPedersenCommitment, // bad pedersen commitment + .pedersenCommitment = badPedersenCommitment, // bad pedersen commitment .amt = *spendingBalance, .encryptedAmt = *encryptedSpendingBalance, .blindingFactor = pcBlindingFactor, @@ -3349,11 +2839,10 @@ class ConfidentialTransfer_test : public beast::unit_test::suite { // generate the context hash again because bob's sequence // incremented from prev txn - uint256 const contextHash = getConvertBackContextHash( - bob, env.seq(bob), mptAlice.issuanceID(), amt, version); + uint256 const contextHash = + getConvertBackContextHash(bob, env.seq(bob), mptAlice.issuanceID(), amt, version); - Buffer const badPedersenCommitment = - mptAlice.getPedersenCommitment(1, pcBlindingFactor); + Buffer const badPedersenCommitment = mptAlice.getPedersenCommitment(1, pcBlindingFactor); Buffer const proof = mptAlice.getConvertBackProof( bob, amt, @@ -3376,8 +2865,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .holderEncryptedAmt = bobCiphertext, .issuerEncryptedAmt = issuerCiphertext, .blindingFactor = blindingFactor, - .pedersenCommitment = - badPedersenCommitment, // wrong pc used here + .pedersenCommitment = badPedersenCommitment, // wrong pc used here .err = tecBAD_PROOF}); } @@ -3386,8 +2874,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite { // generate the context hash again because bob's sequence // incremented from prev txn - uint256 const contextHash = getConvertBackContextHash( - bob, env.seq(bob), mptAlice.issuanceID(), amt, version); + uint256 const contextHash = + getConvertBackContextHash(bob, env.seq(bob), mptAlice.issuanceID(), amt, version); Buffer const proof = mptAlice.getConvertBackProof( bob, @@ -3401,8 +2889,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite .pedersenCommitment = pedersenCommitment, .amt = *spendingBalance, .encryptedAmt = *encryptedSpendingBalance, - .blindingFactor = - generateBlindingFactor(), // bad blinding factor + .blindingFactor = generateBlindingFactor(), // bad blinding factor }); mptAlice.convertBack( @@ -3420,8 +2907,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite { // generate the context hash again because bob's sequence // incremented from prev txn - uint256 const contextHash = getConvertBackContextHash( - bob, env.seq(bob), mptAlice.issuanceID(), amt, version); + uint256 const contextHash = + getConvertBackContextHash(bob, env.seq(bob), mptAlice.issuanceID(), amt, version); Buffer const proof = mptAlice.getConvertBackProof( bob, @@ -3500,5 +2987,5 @@ public: } }; -BEAST_DEFINE_TESTSUITE(ConfidentialTransfer, app, ripple); +BEAST_DEFINE_TESTSUITE(ConfidentialTransfer, app, xrpl); } // namespace xrpl diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 698453ab3b..3530f2a1db 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -507,8 +507,7 @@ class MPToken_test : public beast::unit_test::suite // (2) mptAlice.set({.account = alice, .flags = 0x00000008, .err = temINVALID_FLAG}); - if (!features[featureSingleAssetVault] && - !features[featureDynamicMPT] && + if (!features[featureSingleAssetVault] && !features[featureDynamicMPT] && !features[featureConfidentialTransfer]) { // test invalid flags - nothing is being changed diff --git a/src/test/jtx/impl/mpt.cpp b/src/test/jtx/impl/mpt.cpp index 9af6b5b852..a5bd0130b0 100644 --- a/src/test/jtx/impl/mpt.cpp +++ b/src/test/jtx/impl/mpt.cpp @@ -1,10 +1,10 @@ #include +#include #include #include #include -#include #include #include @@ -46,11 +46,7 @@ MPTTester::makeHolders(std::vector const& holders) } MPTTester::MPTTester(Env& env, Account const& issuer, MPTInit const& arg) - : env_(env) - , issuer_(issuer) - , holders_(makeHolders(arg.holders)) - , auditor_(arg.auditor) - , close_(arg.close) + : env_(env), issuer_(issuer), holders_(makeHolders(arg.holders)), auditor_(arg.auditor), close_(arg.close) { if (arg.fund) { @@ -372,8 +368,7 @@ MPTTester::set(MPTSet const& arg) { if ((arg.flags.value_or(0) || arg.mutableFlags)) { - auto require = [&](std::optional const& holder, - bool unchanged) { + auto require = [&](std::optional const& holder, bool unchanged) { auto flags = getFlags(holder); if (!unchanged) { @@ -427,9 +422,7 @@ MPTTester::set(MPTSet const& arg) }; if (arg.account) require(std::nullopt, arg.holder.has_value()); - if (auto const account = - (arg.holder ? std::get_if(&(*arg.holder)) - : nullptr)) + if (auto const account = (arg.holder ? std::get_if(&(*arg.holder)) : nullptr)) require(*account, false); } @@ -441,11 +434,9 @@ MPTTester::set(MPTSet const& arg) { auto const issuerPubKey = getPubKey(issuer_); if (!issuerPubKey) - Throw( - "MPTTester::set: issuer's pubkey is not set"); + Throw("MPTTester::set: issuer's pubkey is not set"); - return strHex((*sle)[sfIssuerElGamalPublicKey]) == - strHex(*issuerPubKey); + return strHex((*sle)[sfIssuerElGamalPublicKey]) == strHex(*issuerPubKey); } return false; }); @@ -459,16 +450,13 @@ MPTTester::set(MPTSet const& arg) if (sle) { if (!auditor_.has_value()) - Throw( - "MPTTester::set: auditor is not set"); + Throw("MPTTester::set: auditor is not set"); auto const auditorPubKey = getPubKey(*auditor_); if (!auditorPubKey) - Throw( - "MPTTester::set: auditor's pubkey is not set"); + Throw("MPTTester::set: auditor's pubkey is not set"); - return strHex((*sle)[sfAuditorElGamalPublicKey]) == - strHex(*auditorPubKey); + return strHex((*sle)[sfAuditorElGamalPublicKey]) == strHex(*auditorPubKey); } return false; }); @@ -510,9 +498,7 @@ MPTTester::printMPT(Account const& holder_) const } [[nodiscard]] bool -MPTTester::checkMPTokenAmount( - Account const& holder_, - std::int64_t expectedAmount) const +MPTTester::checkMPTokenAmount(Account const& holder_, std::int64_t expectedAmount) const { return forObject([&](SLEP const& sle) { return expectedAmount == (*sle)[sfMPTAmount]; }, holder_); } @@ -526,16 +512,12 @@ MPTTester::checkMPTokenOutstandingAmount(std::int64_t expectedAmount) const [[nodiscard]] bool MPTTester::checkIssuanceConfidentialBalance(std::int64_t expectedAmount) const { - return forObject([&](SLEP const& sle) { - return expectedAmount == - (*sle)[~sfConfidentialOutstandingAmount].value_or(0); - }); + return forObject( + [&](SLEP const& sle) { return expectedAmount == (*sle)[~sfConfidentialOutstandingAmount].value_or(0); }); } [[nodiscard]] bool -MPTTester::checkFlags( - uint32_t const expectedFlags, - std::optional const& holder) const +MPTTester::checkFlags(uint32_t const expectedFlags, std::optional const& holder) const { return expectedFlags == getFlags(holder); } @@ -706,17 +688,12 @@ MPTTester::getClawbackProof( secp256k1_pubkey c1, c2, pk; auto const ctx = secp256k1Context(); - if (!secp256k1_ec_pubkey_parse( - ctx, &c1, ciphertextBlob.data(), ecGamalEncryptedLength)) + if (!secp256k1_ec_pubkey_parse(ctx, &c1, ciphertextBlob.data(), ecGamalEncryptedLength)) { return std::nullopt; } - if (!secp256k1_ec_pubkey_parse( - ctx, - &c2, - ciphertextBlob.data() + ecGamalEncryptedLength, - ecGamalEncryptedLength)) + if (!secp256k1_ec_pubkey_parse(ctx, &c2, ciphertextBlob.data() + ecGamalEncryptedLength, ecGamalEncryptedLength)) { return std::nullopt; } @@ -725,14 +702,7 @@ MPTTester::getClawbackProof( Buffer proof(ecEqualityProofLength); if (secp256k1_equality_plaintext_prove( - ctx, - proof.data(), - &pk, - &c2, - &c1, - amount, - privateKey.data(), - contextHash.data()) != 1) + ctx, proof.data(), &pk, &c2, &c1, amount, privateKey.data(), contextHash.data()) != 1) { return std::nullopt; } @@ -756,12 +726,7 @@ MPTTester::getSchnorrProof(Account const& account, uint256 const& ctxHash) const Buffer proof(ecSchnorrProofLength); - if (secp256k1_mpt_pok_sk_prove( - secp256k1Context(), - proof.data(), - &pk, - privKey->data(), - ctxHash.data()) != 1) + if (secp256k1_mpt_pok_sk_prove(secp256k1Context(), proof.data(), &pk, privKey->data(), ctxHash.data()) != 1) { return std::nullopt; } @@ -810,31 +775,22 @@ MPTTester::getConfidentialSendProof( if (recipient.publicKey.size() != ecPubKeyLength) return std::nullopt; - if (!secp256k1_ec_pubkey_parse( - ctx, &r[i], ctData, ecGamalEncryptedLength)) + if (!secp256k1_ec_pubkey_parse(ctx, &r[i], ctData, ecGamalEncryptedLength)) { return std::nullopt; } - if (!secp256k1_ec_pubkey_parse( - ctx, - &s[i], - ctData + ecGamalEncryptedLength, - ecGamalEncryptedLength)) + if (!secp256k1_ec_pubkey_parse(ctx, &s[i], ctData + ecGamalEncryptedLength, ecGamalEncryptedLength)) { return std::nullopt; } std::memcpy(pk[i].data, recipient.publicKey.data(), ecPubKeyLength); - sr.insert( - sr.end(), - blindingFactor.data(), - blindingFactor.data() + ecBlindingFactorLength); + sr.insert(sr.end(), blindingFactor.data(), blindingFactor.data() + ecBlindingFactorLength); } - size_t sizeEquality = - secp256k1_mpt_prove_same_plaintext_multi_size(nRecipients); + size_t sizeEquality = secp256k1_mpt_prove_same_plaintext_multi_size(nRecipients); Buffer equalityProof(sizeEquality); // Get the multi-ciphertext equality proof @@ -854,19 +810,14 @@ MPTTester::getConfidentialSendProof( } auto const amountLinkageProof = getAmountLinkageProof( - *senderPubKey, - Buffer(blindingFactor.data(), ecBlindingFactorLength), - contextHash, - amountParams); + *senderPubKey, Buffer(blindingFactor.data(), ecBlindingFactorLength), contextHash, amountParams); - auto const balanceLinkageProof = getBalanceLinkageProof( - sender, contextHash, *senderPubKey, balanceParams); + auto const balanceLinkageProof = getBalanceLinkageProof(sender, contextHash, *senderPubKey, balanceParams); auto const sizeAmountLinkage = amountLinkageProof.size(); auto const sizeBalanceLinkage = balanceLinkageProof.size(); - size_t const proofSize = - sizeEquality + sizeAmountLinkage + sizeBalanceLinkage; + size_t const proofSize = sizeEquality + sizeAmountLinkage + sizeBalanceLinkage; Buffer proof(proofSize); auto ptr = proof.data(); @@ -882,9 +833,7 @@ MPTTester::getConfidentialSendProof( } Buffer -MPTTester::getPedersenCommitment( - std::uint64_t const amount, - Buffer const& pedersenBlindingFactor) +MPTTester::getPedersenCommitment(std::uint64_t const amount, Buffer const& pedersenBlindingFactor) { // Blinding factor (rho) must be a 32-byte scalar if (pedersenBlindingFactor.size() != ecBlindingFactorLength) @@ -898,8 +847,7 @@ MPTTester::getPedersenCommitment( auto const ctx = secp256k1Context(); // Compute PC = m*G + rho*H - if (secp256k1_mpt_pedersen_commit( - ctx, &commitment, amount, pedersenBlindingFactor.data()) != 1) + if (secp256k1_mpt_pedersen_commit(ctx, &commitment, amount, pedersenBlindingFactor.data()) != 1) { Throw("Pedersen commitment generation failed"); } @@ -919,15 +867,13 @@ MPTTester::getConvertBackProof( PedersenProofParams const& pcParams) const { auto const sleMptoken = env_.le(keylet::mptoken(*id_, holder.id())); - if (!sleMptoken || - !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending)) + if (!sleMptoken || !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending)) return Buffer{}; auto const holderPubKey = getPubKey(holder); if (holderPubKey) { - Buffer const pedersenProof = getBalanceLinkageProof( - holder, contextHash, *holderPubKey, pcParams); + Buffer const pedersenProof = getBalanceLinkageProof(holder, contextHash, *holderPubKey, pcParams); // todo: incoporate range proof return pedersenProof; @@ -937,35 +883,21 @@ MPTTester::getConvertBackProof( } std::optional -MPTTester::getEncryptedBalance( - Account const& account, - EncryptedBalanceType option) const +MPTTester::getEncryptedBalance(Account const& account, EncryptedBalanceType option) const { if (!id_) Throw("MPT has not been created"); if (auto const sle = env_.le(keylet::mptoken(*id_, account.id()))) { - if (option == HOLDER_ENCRYPTED_INBOX && - sle->isFieldPresent(sfConfidentialBalanceInbox)) - return Buffer( - (*sle)[sfConfidentialBalanceInbox].data(), - (*sle)[sfConfidentialBalanceInbox].size()); - if (option == HOLDER_ENCRYPTED_SPENDING && - sle->isFieldPresent(sfConfidentialBalanceSpending)) - return Buffer( - (*sle)[sfConfidentialBalanceSpending].data(), - (*sle)[sfConfidentialBalanceSpending].size()); - if (option == ISSUER_ENCRYPTED_BALANCE && - sle->isFieldPresent(sfIssuerEncryptedBalance)) - return Buffer( - (*sle)[sfIssuerEncryptedBalance].data(), - (*sle)[sfIssuerEncryptedBalance].size()); - if (option == AUDITOR_ENCRYPTED_BALANCE && - sle->isFieldPresent(sfAuditorEncryptedBalance)) - return Buffer( - (*sle)[sfAuditorEncryptedBalance].data(), - (*sle)[sfAuditorEncryptedBalance].size()); + if (option == HOLDER_ENCRYPTED_INBOX && sle->isFieldPresent(sfConfidentialBalanceInbox)) + return Buffer((*sle)[sfConfidentialBalanceInbox].data(), (*sle)[sfConfidentialBalanceInbox].size()); + if (option == HOLDER_ENCRYPTED_SPENDING && sle->isFieldPresent(sfConfidentialBalanceSpending)) + return Buffer((*sle)[sfConfidentialBalanceSpending].data(), (*sle)[sfConfidentialBalanceSpending].size()); + if (option == ISSUER_ENCRYPTED_BALANCE && sle->isFieldPresent(sfIssuerEncryptedBalance)) + return Buffer((*sle)[sfIssuerEncryptedBalance].data(), (*sle)[sfIssuerEncryptedBalance].size()); + if (option == AUDITOR_ENCRYPTED_BALANCE && sle->isFieldPresent(sfAuditorEncryptedBalance)) + return Buffer((*sle)[sfAuditorEncryptedBalance].data(), (*sle)[sfAuditorEncryptedBalance].size()); } return {}; @@ -1007,15 +939,13 @@ MPTTester::fillConversionCiphertexts( std::optional& auditorCiphertext, Buffer& blindingFactor) const { - blindingFactor = - arg.blindingFactor ? *arg.blindingFactor : generateBlindingFactor(); + blindingFactor = arg.blindingFactor ? *arg.blindingFactor : generateBlindingFactor(); // Handle Holder if (arg.holderEncryptedAmt) holderCiphertext = *arg.holderEncryptedAmt; else - holderCiphertext = - encryptAmount(*arg.account, *arg.amt, blindingFactor); + holderCiphertext = encryptAmount(*arg.account, *arg.amt, blindingFactor); jv[sfHolderEncryptedAmount.jsonName] = strHex(holderCiphertext); @@ -1067,13 +997,7 @@ MPTTester::convert(MPTConvert const& arg) std::optional auditorCiphertext; Buffer blindingFactor; - fillConversionCiphertexts( - arg, - jv, - holderCiphertext, - issuerCiphertext, - auditorCiphertext, - blindingFactor); + fillConversionCiphertexts(arg, jv, holderCiphertext, issuerCiphertext, auditorCiphertext, blindingFactor); jv[sfBlindingFactor.jsonName] = strHex(blindingFactor); if (arg.proof) @@ -1084,8 +1008,7 @@ MPTTester::convert(MPTConvert const& arg) // if fillSchnorrProof is explicitly set, follow its value; // otherwise, default to generating the proof only if holder pub key is // present. - auto const contextHash = getConvertContextHash( - arg.account->id(), env_.seq(*arg.account), *id_, *arg.amt); + auto const contextHash = getConvertContextHash(arg.account->id(), env_.seq(*arg.account), *id_, *arg.amt); auto const proof = getSchnorrProof(*arg.account, contextHash); if (proof) @@ -1097,12 +1020,9 @@ MPTTester::convert(MPTConvert const& arg) auto const holderAmt = getBalance(*arg.account); auto const prevConfidentialOutstanding = getIssuanceConfidentialBalance(); - auto const prevInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const prevSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const prevIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const prevInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const prevSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const prevIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance) Throw("Failed to get Pre-convert balance"); @@ -1110,66 +1030,48 @@ MPTTester::convert(MPTConvert const& arg) std::optional prevAuditorBalance; if (arg.auditorEncryptedAmt || auditor_) { - prevAuditorBalance = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + prevAuditorBalance = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); if (!prevAuditorBalance) Throw("Failed to get Pre-convert balance"); } if (submit(arg, jv) == tesSUCCESS) { - auto const postConfidentialOutstanding = - getIssuanceConfidentialBalance(); + auto const postConfidentialOutstanding = getIssuanceConfidentialBalance(); env_.require(mptbalance(*this, *arg.account, holderAmt - *arg.amt)); - env_.require(requireAny([&]() -> bool { - return prevConfidentialOutstanding + *arg.amt == - postConfidentialOutstanding; - })); + env_.require(requireAny( + [&]() -> bool { return prevConfidentialOutstanding + *arg.amt == postConfidentialOutstanding; })); - auto const postInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const postIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); - auto const postSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const postInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const postIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const postSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); if (!postInboxBalance || !postIssuerBalance || !postSpendingBalance) Throw("Failed to get post-convert balance"); if (arg.auditorEncryptedAmt || auditor_) { - auto const postAuditorBalance = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + auto const postAuditorBalance = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); if (!postAuditorBalance) Throw("Failed to get post-convert balance"); // auditor's encrypted balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevAuditorBalance + *arg.amt == *postAuditorBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevAuditorBalance + *arg.amt == *postAuditorBalance; })); } // spending balance should not change - env_.require(requireAny([&]() -> bool { - return *postSpendingBalance == *prevSpendingBalance; - })); + env_.require(requireAny([&]() -> bool { return *postSpendingBalance == *prevSpendingBalance; })); // issuer's encrypted balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevIssuerBalance + *arg.amt == *postIssuerBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevIssuerBalance + *arg.amt == *postIssuerBalance; })); // holder's inbox balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevInboxBalance + *arg.amt == *postInboxBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevInboxBalance + *arg.amt == *postInboxBalance; })); // sum of holder's inbox and spending balance should equal to issuer's // encrypted balance - env_.require(requireAny([&]() -> bool { - return *postInboxBalance + *postSpendingBalance == - *postIssuerBalance; - })); + env_.require( + requireAny([&]() -> bool { return *postInboxBalance + *postSpendingBalance == *postIssuerBalance; })); if (arg.holderPubKey) { @@ -1184,8 +1086,7 @@ MPTTester::convert(MPTConvert const& arg) "MPTTester::convert: holder's pubkey is " "not set"); - return strHex((*sle)[sfHolderElGamalPublicKey]) == - strHex(*holderPubKey); + return strHex((*sle)[sfHolderElGamalPublicKey]) == strHex(*holderPubKey); } return false; }, @@ -1223,19 +1124,15 @@ MPTTester::send(MPTConfidentialSend const& arg) jv[sfMPTokenIssuanceID] = to_string(*id_); } - Buffer const blindingFactor = - arg.blindingFactor ? *arg.blindingFactor : generateBlindingFactor(); + Buffer const blindingFactor = arg.blindingFactor ? *arg.blindingFactor : generateBlindingFactor(); // fill in the encrypted amounts if not provided - auto const senderAmt = arg.senderEncryptedAmt - ? *arg.senderEncryptedAmt - : encryptAmount(*arg.account, *arg.amt, blindingFactor); - auto const destAmt = arg.destEncryptedAmt - ? *arg.destEncryptedAmt - : encryptAmount(*arg.dest, *arg.amt, blindingFactor); - auto const issuerAmt = arg.issuerEncryptedAmt - ? *arg.issuerEncryptedAmt - : encryptAmount(issuer_, *arg.amt, blindingFactor); + auto const senderAmt = + arg.senderEncryptedAmt ? *arg.senderEncryptedAmt : encryptAmount(*arg.account, *arg.amt, blindingFactor); + auto const destAmt = + arg.destEncryptedAmt ? *arg.destEncryptedAmt : encryptAmount(*arg.dest, *arg.amt, blindingFactor); + auto const issuerAmt = + arg.issuerEncryptedAmt ? *arg.issuerEncryptedAmt : encryptAmount(issuer_, *arg.amt, blindingFactor); std::optional auditorAmt; if (arg.auditorEncryptedAmt) @@ -1257,39 +1154,31 @@ MPTTester::send(MPTConfidentialSend const& arg) } // Sender's previous confidential state - auto const prevSenderInbox = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const prevSenderSpending = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const prevSenderIssuer = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const prevSenderInbox = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const prevSenderSpending = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const prevSenderIssuer = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!prevSenderInbox || !prevSenderSpending || !prevSenderIssuer) Throw("Failed to get Pre-send balance"); std::optional prevSenderAuditor; if (arg.auditorEncryptedAmt || auditor_) { - prevSenderAuditor = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + prevSenderAuditor = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); if (!prevSenderAuditor) Throw("Failed to get Pre-send balance"); } // Destination's previous confidential state - auto const prevDestInbox = - getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_INBOX); - auto const prevDestSpending = - getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_SPENDING); - auto const prevDestIssuer = - getDecryptedBalance(*arg.dest, ISSUER_ENCRYPTED_BALANCE); + auto const prevDestInbox = getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_INBOX); + auto const prevDestSpending = getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_SPENDING); + auto const prevDestIssuer = getDecryptedBalance(*arg.dest, ISSUER_ENCRYPTED_BALANCE); if (!prevDestInbox || !prevDestSpending || !prevDestIssuer) Throw("Failed to get Pre-send balance"); std::optional prevDestAuditor; if (arg.auditorEncryptedAmt || auditor_) { - prevDestAuditor = - getDecryptedBalance(*arg.dest, AUDITOR_ENCRYPTED_BALANCE); + prevDestAuditor = getDecryptedBalance(*arg.dest, AUDITOR_ENCRYPTED_BALANCE); if (!prevDestAuditor) Throw("Failed to get Pre-send balance"); } @@ -1300,8 +1189,7 @@ MPTTester::send(MPTConfidentialSend const& arg) if (arg.amountCommitment) amountCommitment = *arg.amountCommitment; else - amountCommitment = - getPedersenCommitment(*arg.amt, amountBlindingFactor); + amountCommitment = getPedersenCommitment(*arg.amt, amountBlindingFactor); jv[sfAmountCommitment] = strHex(amountCommitment); @@ -1309,8 +1197,7 @@ MPTTester::send(MPTConfidentialSend const& arg) if (arg.balanceCommitment) balanceCommitment = *arg.balanceCommitment; else - balanceCommitment = - getPedersenCommitment(*prevSenderSpending, balanceBlindingFactor); + balanceCommitment = getPedersenCommitment(*prevSenderSpending, balanceBlindingFactor); jv[sfBalanceCommitment] = strHex(balanceCommitment); @@ -1320,15 +1207,10 @@ MPTTester::send(MPTConfidentialSend const& arg) else { auto const version = getMPTokenVersion(*arg.account); - auto const ctxHash = getSendContextHash( - arg.account->id(), - env_.seq(*arg.account), - *id_, - arg.dest->id(), - version); + auto const ctxHash = + getSendContextHash(arg.account->id(), env_.seq(*arg.account), *id_, arg.dest->id(), version); - auto const nRecipients = - getConfidentialRecipientCount(auditorAmt.has_value()); + auto const nRecipients = getConfidentialRecipientCount(auditorAmt.has_value()); std::vector recipients; auto const senderPubKey = getPubKey(*arg.account); @@ -1356,8 +1238,7 @@ MPTTester::send(MPTConfidentialSend const& arg) recipients.push_back({Slice(*auditorPubKey), *auditorAmt}); } - auto const prevEncryptedSenderSpending = - getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const prevEncryptedSenderSpending = getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); std::optional proof; @@ -1388,8 +1269,7 @@ MPTTester::send(MPTConfidentialSend const& arg) jv[sfZKProof.jsonName] = strHex(*proof); else { - size_t const dummySize = - secp256k1_mpt_prove_same_plaintext_multi_size(nRecipients); + size_t const dummySize = secp256k1_mpt_prove_same_plaintext_multi_size(nRecipients); jv[sfZKProof.jsonName] = strHex(Buffer(dummySize)); } @@ -1406,23 +1286,17 @@ MPTTester::send(MPTConfidentialSend const& arg) auto const postOA = getIssuanceOutstandingBalance(); // Sender's post confidential state - auto const postSenderInbox = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const postSenderSpending = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const postSenderIssuer = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const postSenderInbox = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const postSenderSpending = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const postSenderIssuer = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!postSenderInbox || !postSenderSpending || !postSenderIssuer) Throw("Failed to get Post-send balance"); // Destination's post confidential state - auto const postDestInbox = - getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_INBOX); - auto const postDestSpending = - getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_SPENDING); - auto const postDestIssuer = - getDecryptedBalance(*arg.dest, ISSUER_ENCRYPTED_BALANCE); + auto const postDestInbox = getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_INBOX); + auto const postDestSpending = getDecryptedBalance(*arg.dest, HOLDER_ENCRYPTED_SPENDING); + auto const postDestIssuer = getDecryptedBalance(*arg.dest, ISSUER_ENCRYPTED_BALANCE); if (!postDestInbox || !postDestSpending || !postDestIssuer) Throw("Failed to get Post-send balance"); @@ -1437,58 +1311,40 @@ MPTTester::send(MPTConfidentialSend const& arg) // Verify sender changes env_.require(requireAny([&]() -> bool { - return *prevSenderSpending >= *arg.amt && - *postSenderSpending == *prevSenderSpending - *arg.amt; + return *prevSenderSpending >= *arg.amt && *postSenderSpending == *prevSenderSpending - *arg.amt; })); - env_.require(requireAny( - [&]() -> bool { return postSenderInbox == prevSenderInbox; })); + env_.require(requireAny([&]() -> bool { return postSenderInbox == prevSenderInbox; })); env_.require(requireAny([&]() -> bool { - return *prevSenderIssuer >= *arg.amt && - *postSenderIssuer == *prevSenderIssuer - *arg.amt; + return *prevSenderIssuer >= *arg.amt && *postSenderIssuer == *prevSenderIssuer - *arg.amt; })); // Verify destination changes - env_.require(requireAny([&]() -> bool { - return *postDestInbox == *prevDestInbox + *arg.amt; - })); - env_.require(requireAny( - [&]() -> bool { return *postDestSpending == *prevDestSpending; })); - env_.require(requireAny([&]() -> bool { - return *postDestIssuer == *prevDestIssuer + *arg.amt; - })); + env_.require(requireAny([&]() -> bool { return *postDestInbox == *prevDestInbox + *arg.amt; })); + env_.require(requireAny([&]() -> bool { return *postDestSpending == *prevDestSpending; })); + env_.require(requireAny([&]() -> bool { return *postDestIssuer == *prevDestIssuer + *arg.amt; })); // Cross checks - env_.require(requireAny([&]() -> bool { - return *postSenderInbox + *postSenderSpending == *postSenderIssuer; - })); - env_.require(requireAny([&]() -> bool { - return *postDestInbox + *postDestSpending == *postDestIssuer; - })); + env_.require(requireAny([&]() -> bool { return *postSenderInbox + *postSenderSpending == *postSenderIssuer; })); + env_.require(requireAny([&]() -> bool { return *postDestInbox + *postDestSpending == *postDestIssuer; })); if (arg.auditorEncryptedAmt || auditor_) { - auto const postSenderAuditor = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); - auto const postDestAuditor = - getDecryptedBalance(*arg.dest, AUDITOR_ENCRYPTED_BALANCE); + auto const postSenderAuditor = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + auto const postDestAuditor = getDecryptedBalance(*arg.dest, AUDITOR_ENCRYPTED_BALANCE); if (!postSenderAuditor || !postDestAuditor) Throw("Failed to get Post-send balance"); env_.require(requireAny([&]() -> bool { - return *postSenderAuditor == *postSenderIssuer && - *postDestAuditor == *postDestIssuer; + return *postSenderAuditor == *postSenderIssuer && *postDestAuditor == *postDestIssuer; })); // verify sender env_.require(requireAny([&]() -> bool { - return prevSenderAuditor >= *arg.amt && - *postSenderAuditor == *prevSenderAuditor - *arg.amt; + return prevSenderAuditor >= *arg.amt && *postSenderAuditor == *prevSenderAuditor - *arg.amt; })); // verify dest - env_.require(requireAny([&]() -> bool { - return *postDestAuditor == *prevDestAuditor + *arg.amt; - })); + env_.require(requireAny([&]() -> bool { return *postDestAuditor == *prevDestAuditor + *arg.amt; })); } } } @@ -1521,15 +1377,13 @@ MPTTester::confidentialClaw(MPTConfidentialClawback const& arg) else { std::uint32_t const seq = env_.seq(account); - uint256 const contextHash = getClawbackContextHash( - account.id(), seq, *id_, *arg.amt, arg.holder->id()); + uint256 const contextHash = getClawbackContextHash(account.id(), seq, *id_, *arg.amt, arg.holder->id()); auto const privKey = getPrivKey(account); if (!privKey || privKey->size() != ecPrivKeyLength) Throw("Failed to get clawback private key"); - auto const proof = - getClawbackProof(*arg.holder, *arg.amt, *privKey, contextHash); + auto const proof = getClawbackProof(*arg.holder, *arg.amt, *privKey, contextHash); if (proof) jv[sfZKProof] = strHex(*proof); @@ -1550,30 +1404,18 @@ MPTTester::confidentialClaw(MPTConfidentialClawback const& arg) env_.require(mptbalance(*this, *arg.holder, holderPubAmt)); // Verify COA and OA are reduced correctly - env_.require(requireAny([&]() -> bool { - return prevCOA >= *arg.amt && postCOA == prevCOA - *arg.amt; - })); - env_.require(requireAny([&]() -> bool { - return prevOA >= *arg.amt && postOA == prevOA - *arg.amt; - })); + env_.require(requireAny([&]() -> bool { return prevCOA >= *arg.amt && postCOA == prevCOA - *arg.amt; })); + env_.require(requireAny([&]() -> bool { return prevOA >= *arg.amt && postOA == prevOA - *arg.amt; })); // Verify holder's confidential balances are zeroed out - env_.require(requireAny([&]() -> bool { - return getDecryptedBalance(*arg.holder, HOLDER_ENCRYPTED_INBOX) == - 0; - })); - env_.require(requireAny([&]() -> bool { - return getDecryptedBalance( - *arg.holder, HOLDER_ENCRYPTED_SPENDING) == 0; - })); - env_.require(requireAny([&]() -> bool { - return getDecryptedBalance(*arg.holder, ISSUER_ENCRYPTED_BALANCE) == - 0; - })); - env_.require(requireAny([&]() -> bool { - return getDecryptedBalance( - *arg.holder, AUDITOR_ENCRYPTED_BALANCE) == 0; - })); + env_.require( + requireAny([&]() -> bool { return getDecryptedBalance(*arg.holder, HOLDER_ENCRYPTED_INBOX) == 0; })); + env_.require( + requireAny([&]() -> bool { return getDecryptedBalance(*arg.holder, HOLDER_ENCRYPTED_SPENDING) == 0; })); + env_.require( + requireAny([&]() -> bool { return getDecryptedBalance(*arg.holder, ISSUER_ENCRYPTED_BALANCE) == 0; })); + env_.require( + requireAny([&]() -> bool { return getDecryptedBalance(*arg.holder, AUDITOR_ENCRYPTED_BALANCE) == 0; })); } } @@ -1582,8 +1424,7 @@ MPTTester::generateKeyPair(Account const& account) { unsigned char privKey[ecPrivKeyLength]; secp256k1_pubkey pubKey; - if (!secp256k1_elgamal_generate_keypair( - secp256k1Context(), privKey, &pubKey)) + if (!secp256k1_elgamal_generate_keypair(secp256k1Context(), privKey, &pubKey)) Throw("failed to generate key pair"); pubKeys.insert({account.id(), Buffer{pubKey.data, ecPubKeyLength}}); @@ -1615,15 +1456,11 @@ MPTTester::getPrivKey(Account const& account) const } Buffer -MPTTester::encryptAmount( - Account const& account, - uint64_t const amt, - Buffer const& blindingFactor) const +MPTTester::encryptAmount(Account const& account, uint64_t const amt, Buffer const& blindingFactor) const { if (auto const pubKey = getPubKey(account)) { - if (auto const result = - xrpl::encryptAmount(amt, *pubKey, blindingFactor)) + if (auto const result = xrpl::encryptAmount(amt, *pubKey, blindingFactor)) return *result; } @@ -1649,8 +1486,7 @@ MPTTester::decryptAmount(Account const& account, Buffer const& amt) const return std::nullopt; uint64_t decryptedAmt; - if (!secp256k1_elgamal_decrypt( - secp256k1Context(), &decryptedAmt, &c1, &c2, privKey->data())) + if (!secp256k1_elgamal_decrypt(secp256k1Context(), &decryptedAmt, &c1, &c2, privKey->data())) { return std::nullopt; } @@ -1659,9 +1495,7 @@ MPTTester::decryptAmount(Account const& account, Buffer const& amt) const } std::optional -MPTTester::getDecryptedBalance( - Account const& account, - EncryptedBalanceType balanceType) const +MPTTester::getDecryptedBalance(Account const& account, EncryptedBalanceType balanceType) const { auto encryptedAmt = getEncryptedBalance(account, balanceType); @@ -1703,42 +1537,30 @@ MPTTester::mergeInbox(MPTMergeInbox const& arg) } jv[sfTransactionType] = jss::ConfidentialMergeInbox; - auto const prevInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const prevSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const prevIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const prevInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const prevSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const prevIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance) Throw("Failed to get pre-mergeInbox balances"); if (submit(arg, jv) == tesSUCCESS) { - auto const postInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const postSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const postIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const postInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const postSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const postIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!postInboxBalance || !postSpendingBalance || !postIssuerBalance) Throw("Failed to get post-mergeInbox balances"); env_.require(requireAny([&]() -> bool { - return *postSpendingBalance == - *prevInboxBalance + *prevSpendingBalance && - *postInboxBalance == 0; + return *postSpendingBalance == *prevInboxBalance + *prevSpendingBalance && *postInboxBalance == 0; })); - env_.require(requireAny([&]() -> bool { - return *prevIssuerBalance == *postIssuerBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevIssuerBalance == *postIssuerBalance; })); - env_.require(requireAny([&]() -> bool { - return *postSpendingBalance + *postInboxBalance == - *postIssuerBalance; - })); + env_.require( + requireAny([&]() -> bool { return *postSpendingBalance + *postInboxBalance == *postIssuerBalance; })); } } @@ -1751,8 +1573,7 @@ MPTTester::getIssuanceOutstandingBalance() const auto const sle = env_.current()->read(keylet::mptIssuance(*id_)); if (!sle || !sle->isFieldPresent(sfOutstandingAmount)) - Throw( - "Issuance object does not contain outstanding amount"); + Throw("Issuance object does not contain outstanding amount"); return (*sle)[sfOutstandingAmount]; } @@ -1800,22 +1621,13 @@ MPTTester::convertBack(MPTConvertBack const& arg) std::optional auditorCiphertext; Buffer blindingFactor; - fillConversionCiphertexts( - arg, - jv, - holderCiphertext, - issuerCiphertext, - auditorCiphertext, - blindingFactor); + fillConversionCiphertexts(arg, jv, holderCiphertext, issuerCiphertext, auditorCiphertext, blindingFactor); jv[sfBlindingFactor] = strHex(blindingFactor); - auto const prevInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const prevSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); - auto const prevIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const prevInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const prevSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const prevIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); if (!prevInboxBalance || !prevSpendingBalance || !prevIssuerBalance) Throw("Failed to get Pre-convertBack balance"); @@ -1825,8 +1637,7 @@ MPTTester::convertBack(MPTConvertBack const& arg) if (arg.pedersenCommitment) pedersenCommitment = *arg.pedersenCommitment; else - pedersenCommitment = - getPedersenCommitment(*prevSpendingBalance, pcBlindingFactor); + pedersenCommitment = getPedersenCommitment(*prevSpendingBalance, pcBlindingFactor); jv[sfBalanceCommitment] = strHex(pedersenCommitment); @@ -1838,10 +1649,9 @@ MPTTester::convertBack(MPTConvertBack const& arg) // if the caller generated ciphertexts themselves, they should also // generate the proof themselves from the blinding factor - uint256 const contextHash = getConvertBackContextHash( - arg.account->id(), env_.seq(*arg.account), *id_, *arg.amt, version); - auto const prevEncryptedSpendingBalance = - getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + uint256 const contextHash = + getConvertBackContextHash(arg.account->id(), env_.seq(*arg.account), *id_, *arg.amt, version); + auto const prevEncryptedSpendingBalance = getEncryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); Buffer proof; // generate a dummy proof if no encrypted amount field, so that other @@ -1874,67 +1684,49 @@ MPTTester::convertBack(MPTConvertBack const& arg) std::optional prevAuditorBalance; if (arg.auditorEncryptedAmt || auditor_) { - prevAuditorBalance = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + prevAuditorBalance = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); if (!prevAuditorBalance) Throw("Failed to get Pre-convertBack balance"); } if (submit(arg, jv) == tesSUCCESS) { - auto const postConfidentialOutstanding = - getIssuanceConfidentialBalance(); + auto const postConfidentialOutstanding = getIssuanceConfidentialBalance(); env_.require(mptbalance(*this, *arg.account, holderAmt + *arg.amt)); - env_.require(requireAny([&]() -> bool { - return prevConfidentialOutstanding - *arg.amt == - postConfidentialOutstanding; - })); + env_.require(requireAny( + [&]() -> bool { return prevConfidentialOutstanding - *arg.amt == postConfidentialOutstanding; })); - auto const postInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - auto const postIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); - auto const postSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + auto const postInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + auto const postIssuerBalance = getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + auto const postSpendingBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); if (!postInboxBalance || !postIssuerBalance || !postSpendingBalance) Throw("Failed to get post-convertBack balance"); if (arg.auditorEncryptedAmt || auditor_) { - auto const postAuditorBalance = - getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); + auto const postAuditorBalance = getDecryptedBalance(*arg.account, AUDITOR_ENCRYPTED_BALANCE); if (!postAuditorBalance) - Throw( - "Failed to get post-convertBack balance"); + Throw("Failed to get post-convertBack balance"); // auditor's encrypted balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevAuditorBalance - *arg.amt == *postAuditorBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevAuditorBalance - *arg.amt == *postAuditorBalance; })); } // inbox balance should not change - env_.require(requireAny( - [&]() -> bool { return *postInboxBalance == *prevInboxBalance; })); + env_.require(requireAny([&]() -> bool { return *postInboxBalance == *prevInboxBalance; })); // issuer's encrypted balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevIssuerBalance - *arg.amt == *postIssuerBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevIssuerBalance - *arg.amt == *postIssuerBalance; })); // holder's spending balance is updated correctly - env_.require(requireAny([&]() -> bool { - return *prevSpendingBalance - *arg.amt == *postSpendingBalance; - })); + env_.require(requireAny([&]() -> bool { return *prevSpendingBalance - *arg.amt == *postSpendingBalance; })); // sum of holder's inbox and spending balance should equal to issuer's // encrypted balance - env_.require(requireAny([&]() -> bool { - return *postInboxBalance + *postSpendingBalance == - *postIssuerBalance; - })); + env_.require( + requireAny([&]() -> bool { return *postInboxBalance + *postSpendingBalance == *postIssuerBalance; })); } } @@ -1946,21 +1738,15 @@ MPTTester::getAmountLinkageProof( PedersenProofParams const& params) const { if (params.blindingFactor.size() != ecBlindingFactorLength || - params.pedersenCommitment.size() != ecPedersenCommitmentLength || - pubKey.size() != ecPubKeyLength || - params.encryptedAmt.size() != ecGamalEncryptedTotalLength || - blindingFactor.size() != ecBlindingFactorLength) + params.pedersenCommitment.size() != ecPedersenCommitmentLength || pubKey.size() != ecPubKeyLength || + params.encryptedAmt.size() != ecGamalEncryptedTotalLength || blindingFactor.size() != ecBlindingFactorLength) return Buffer(ecPedersenProofLength); secp256k1_pubkey c1, c2; auto const ctx = secp256k1Context(); - if (!secp256k1_ec_pubkey_parse( - ctx, &c1, params.encryptedAmt.data(), ecGamalEncryptedLength) || + if (!secp256k1_ec_pubkey_parse(ctx, &c1, params.encryptedAmt.data(), ecGamalEncryptedLength) || !secp256k1_ec_pubkey_parse( - ctx, - &c2, - params.encryptedAmt.data() + ecGamalEncryptedLength, - ecGamalEncryptedLength)) + ctx, &c2, params.encryptedAmt.data() + ecGamalEncryptedLength, ecGamalEncryptedLength)) { return Buffer(); } @@ -1969,8 +1755,7 @@ MPTTester::getAmountLinkageProof( std::memcpy(pk.data, pubKey.data(), ecPubKeyLength); secp256k1_pubkey pcm; - std::memcpy( - pcm.data, params.pedersenCommitment.data(), ecPedersenCommitmentLength); + std::memcpy(pcm.data, params.pedersenCommitment.data(), ecPedersenCommitmentLength); Buffer proof(ecPedersenProofLength); if (secp256k1_elgamal_pedersen_link_prove( @@ -1999,20 +1784,15 @@ MPTTester::getBalanceLinkageProof( PedersenProofParams const& params) const { if (params.blindingFactor.size() != ecBlindingFactorLength || - params.pedersenCommitment.size() != ecPedersenCommitmentLength || - pubKey.size() != ecPubKeyLength || + params.pedersenCommitment.size() != ecPedersenCommitmentLength || pubKey.size() != ecPubKeyLength || params.encryptedAmt.size() != ecGamalEncryptedTotalLength) return Buffer(ecPedersenProofLength); secp256k1_pubkey c1, c2; auto const ctx = secp256k1Context(); - if (!secp256k1_ec_pubkey_parse( - ctx, &c1, params.encryptedAmt.data(), ecGamalEncryptedLength) || + if (!secp256k1_ec_pubkey_parse(ctx, &c1, params.encryptedAmt.data(), ecGamalEncryptedLength) || !secp256k1_ec_pubkey_parse( - ctx, - &c2, - params.encryptedAmt.data() + ecGamalEncryptedLength, - ecGamalEncryptedLength)) + ctx, &c2, params.encryptedAmt.data() + ecGamalEncryptedLength, ecGamalEncryptedLength)) { return Buffer(); } @@ -2021,8 +1801,7 @@ MPTTester::getBalanceLinkageProof( std::memcpy(pk.data, pubKey.data(), ecPubKeyLength); secp256k1_pubkey pcm; - std::memcpy( - pcm.data, params.pedersenCommitment.data(), ecPedersenCommitmentLength); + std::memcpy(pcm.data, params.pedersenCommitment.data(), ecPedersenCommitmentLength); Buffer proof(ecPedersenProofLength); diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index 1650168f79..74a07357ff 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -332,8 +332,7 @@ public: convertBack(MPTConvertBack const& arg = MPTConvertBack{}); void - confidentialClaw( - MPTConfidentialClawback const& arg = MPTConfidentialClawback{}); + confidentialClaw(MPTConfidentialClawback const& arg = MPTConfidentialClawback{}); [[nodiscard]] bool checkDomainID(std::optional expected) const; @@ -348,9 +347,7 @@ public: checkIssuanceConfidentialBalance(std::int64_t expectedAmount) const; [[nodiscard]] bool - checkFlags( - uint32_t const expectedFlags, - std::optional const& holder = std::nullopt) const; + checkFlags(uint32_t const expectedFlags, std::optional const& holder = std::nullopt) const; [[nodiscard]] bool checkMetadata(std::string const& metadata) const; @@ -401,9 +398,7 @@ public: getIssuanceConfidentialBalance() const; std::optional - getEncryptedBalance( - Account const& account, - EncryptedBalanceType option = HOLDER_ENCRYPTED_INBOX) const; + getEncryptedBalance(Account const& account, EncryptedBalanceType option = HOLDER_ENCRYPTED_INBOX) const; MPT operator[](std::string const& name) const; @@ -426,28 +421,20 @@ public: getPrivKey(Account const& account) const; Buffer - encryptAmount( - Account const& account, - uint64_t const amt, - Buffer const& blindingFactor) const; + encryptAmount(Account const& account, uint64_t const amt, Buffer const& blindingFactor) const; std::optional decryptAmount(Account const& account, Buffer const& amt) const; std::optional - getDecryptedBalance( - Account const& account, - EncryptedBalanceType balanceType) const; + getDecryptedBalance(Account const& account, EncryptedBalanceType balanceType) const; std::int64_t getIssuanceOutstandingBalance() const; std::optional - getClawbackProof( - Account const& holder, - std::uint64_t amount, - Buffer const& privateKey, - uint256 const& txHash) const; + getClawbackProof(Account const& holder, std::uint64_t amount, Buffer const& privateKey, uint256 const& txHash) + const; std::optional getSchnorrProof(Account const& account, uint256 const& ctxHash) const; @@ -492,9 +479,7 @@ public: PedersenProofParams const& params) const; Buffer - getPedersenCommitment( - std::uint64_t const amount, - Buffer const& pedersenBlindingFactor); + getPedersenCommitment(std::uint64_t const amount, Buffer const& pedersenBlindingFactor); private: using SLEP = SLE::const_pointer; diff --git a/src/xrpld/app/tx/detail/ConfidentialClawback.cpp b/src/xrpld/app/tx/detail/ConfidentialClawback.cpp index 4b780d29b0..8adb74d078 100644 --- a/src/xrpld/app/tx/detail/ConfidentialClawback.cpp +++ b/src/xrpld/app/tx/detail/ConfidentialClawback.cpp @@ -70,8 +70,7 @@ ConfidentialClawback::preclaim(PreclaimContext const& ctx) return tecNO_PERMISSION; // Check holder's MPToken - auto const sleHolderMPToken = - ctx.view.read(keylet::mptoken(mptIssuanceID, holder)); + auto const sleHolderMPToken = ctx.view.read(keylet::mptoken(mptIssuanceID, holder)); if (!sleHolderMPToken) return tecOBJECT_NOT_FOUND; @@ -84,8 +83,7 @@ ConfidentialClawback::preclaim(PreclaimContext const& ctx) if (amount > (*sleIssuance)[~sfConfidentialOutstandingAmount].value_or(0)) return tecINSUFFICIENT_FUNDS; - auto const contextHash = getClawbackContextHash( - account, ctx.tx[sfSequence], mptIssuanceID, amount, holder); + auto const contextHash = getClawbackContextHash(account, ctx.tx[sfSequence], mptIssuanceID, amount, holder); // Verify the revealed confidential amount by the issuer matches the exact // confidential balance of the holder. @@ -115,13 +113,11 @@ ConfidentialClawback::doApply() Slice const issuerPubKey = (*sleIssuance)[sfIssuerElGamalPublicKey]; // After clawback, the balance should be encrypted zero. - auto const encZeroForHolder = - encryptCanonicalZeroAmount(holderPubKey, holder, mptIssuanceID); + auto const encZeroForHolder = encryptCanonicalZeroAmount(holderPubKey, holder, mptIssuanceID); if (!encZeroForHolder) return tecINTERNAL; // LCOV_EXCL_LINE - auto const encZeroForIssuer = - encryptCanonicalZeroAmount(issuerPubKey, holder, mptIssuanceID); + auto const encZeroForIssuer = encryptCanonicalZeroAmount(issuerPubKey, holder, mptIssuanceID); if (!encZeroForIssuer) return tecINTERNAL; // LCOV_EXCL_LINE @@ -140,8 +136,7 @@ ConfidentialClawback::doApply() Slice const auditorPubKey = (*sleIssuance)[sfAuditorElGamalPublicKey]; - auto const encZeroForAuditor = - encryptCanonicalZeroAmount(auditorPubKey, holder, mptIssuanceID); + auto const encZeroForAuditor = encryptCanonicalZeroAmount(auditorPubKey, holder, mptIssuanceID); if (!encZeroForAuditor) return tecINTERNAL; // LCOV_EXCL_LINE diff --git a/src/xrpld/app/tx/detail/ConfidentialConvert.cpp b/src/xrpld/app/tx/detail/ConfidentialConvert.cpp index 4319df14f7..a6d404b5f4 100644 --- a/src/xrpld/app/tx/detail/ConfidentialConvert.cpp +++ b/src/xrpld/app/tx/detail/ConfidentialConvert.cpp @@ -80,8 +80,7 @@ ConfidentialConvert::preclaim(PreclaimContext const& ctx) return tecNO_PERMISSION; bool const hasAuditor = ctx.tx.isFieldPresent(sfAuditorEncryptedAmount); - bool const requiresAuditor = - sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); + bool const requiresAuditor = sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); // tx must include auditor ciphertext if the issuance has enabled // auditing, and must not include it if auditing is not enabled @@ -93,8 +92,7 @@ ConfidentialConvert::preclaim(PreclaimContext const& ctx) return tecOBJECT_NOT_FOUND; auto const mptIssue = MPTIssue{issuanceID}; - STAmount const mptAmount = STAmount( - MPTAmount{static_cast(amount)}, mptIssue); + STAmount const mptAmount = STAmount(MPTAmount{static_cast(amount)}, mptIssue); if (accountHolds( ctx.view, account, @@ -106,10 +104,8 @@ ConfidentialConvert::preclaim(PreclaimContext const& ctx) return tecINSUFFICIENT_FUNDS; } - auto const hasHolderKeyOnLedger = - sleMptoken->isFieldPresent(sfHolderElGamalPublicKey); - auto const hasHolderKeyInTx = - ctx.tx.isFieldPresent(sfHolderElGamalPublicKey); + auto const hasHolderKeyOnLedger = sleMptoken->isFieldPresent(sfHolderElGamalPublicKey); + auto const hasHolderKeyInTx = ctx.tx.isFieldPresent(sfHolderElGamalPublicKey); // must have pk to convert if (!hasHolderKeyOnLedger && !hasHolderKeyInTx) @@ -124,12 +120,10 @@ ConfidentialConvert::preclaim(PreclaimContext const& ctx) { holderPubKey = ctx.tx[sfHolderElGamalPublicKey]; - auto const contextHash = getConvertContextHash( - account, ctx.tx[sfSequence], issuanceID, amount); + auto const contextHash = getConvertContextHash(account, ctx.tx[sfSequence], issuanceID, amount); // when register new pk, verify through schnorr proof - if (!isTesSuccess(verifySchnorrProof( - holderPubKey, ctx.tx[sfZKProof], contextHash))) + if (!isTesSuccess(verifySchnorrProof(holderPubKey, ctx.tx[sfZKProof], contextHash))) { return tecBAD_PROOF; } @@ -142,17 +136,15 @@ ConfidentialConvert::preclaim(PreclaimContext const& ctx) std::optional auditor; if (hasAuditor) { - auditor.emplace(ConfidentialRecipient{ - (*sleIssuance)[sfAuditorElGamalPublicKey], - ctx.tx[sfAuditorEncryptedAmount]}); + auditor.emplace( + ConfidentialRecipient{(*sleIssuance)[sfAuditorElGamalPublicKey], ctx.tx[sfAuditorEncryptedAmount]}); } return verifyRevealedAmount( amount, ctx.tx[sfBlindingFactor], {holderPubKey, ctx.tx[sfHolderEncryptedAmount]}, - {(*sleIssuance)[sfIssuerElGamalPublicKey], - ctx.tx[sfIssuerEncryptedAmount]}, + {(*sleIssuance)[sfIssuerElGamalPublicKey], ctx.tx[sfIssuerEncryptedAmount]}, auditor); } @@ -173,13 +165,11 @@ ConfidentialConvert::doApply() auto const amt = (*sleMptoken)[~sfMPTAmount].value_or(0); if (ctx_.tx.isFieldPresent(sfHolderElGamalPublicKey)) - (*sleMptoken)[sfHolderElGamalPublicKey] = - ctx_.tx[sfHolderElGamalPublicKey]; + (*sleMptoken)[sfHolderElGamalPublicKey] = ctx_.tx[sfHolderElGamalPublicKey]; (*sleMptoken)[sfMPTAmount] = amt - amtToConvert; (*sleIssuance)[sfConfidentialOutstandingAmount] = - (*sleIssuance)[~sfConfidentialOutstandingAmount].value_or(0) + - amtToConvert; + (*sleIssuance)[~sfConfidentialOutstandingAmount].value_or(0) + amtToConvert; Slice const holderEc = ctx_.tx[sfHolderEncryptedAmount]; Slice const issuerEc = ctx_.tx[sfIssuerEncryptedAmount]; @@ -195,8 +185,7 @@ ConfidentialConvert::doApply() // homomorphically add holder's encrypted balance { Buffer sum(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicAdd( - holderEc, (*sleMptoken)[sfConfidentialBalanceInbox], sum); + if (TER const ter = homomorphicAdd(holderEc, (*sleMptoken)[sfConfidentialBalanceInbox], sum); !isTesSuccess(ter)) return tecINTERNAL; @@ -206,8 +195,7 @@ ConfidentialConvert::doApply() // homomorphically add issuer's encrypted balance { Buffer sum(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicAdd( - issuerEc, (*sleMptoken)[sfIssuerEncryptedBalance], sum); + if (TER const ter = homomorphicAdd(issuerEc, (*sleMptoken)[sfIssuerEncryptedBalance], sum); !isTesSuccess(ter)) return tecINTERNAL; @@ -218,8 +206,7 @@ ConfidentialConvert::doApply() if (auditorEc) { Buffer sum(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicAdd( - *auditorEc, (*sleMptoken)[sfAuditorEncryptedBalance], sum); + if (TER const ter = homomorphicAdd(*auditorEc, (*sleMptoken)[sfAuditorEncryptedBalance], sum); !isTesSuccess(ter)) return tecINTERNAL; @@ -239,8 +226,8 @@ ConfidentialConvert::doApply() (*sleMptoken)[sfAuditorEncryptedBalance] = *auditorEc; // encrypt sfConfidentialBalanceSpending with zero balance - auto const zeroBalance = encryptCanonicalZeroAmount( - (*sleMptoken)[sfHolderElGamalPublicKey], account_, mptIssuanceID); + auto const zeroBalance = + encryptCanonicalZeroAmount((*sleMptoken)[sfHolderElGamalPublicKey], account_, mptIssuanceID); if (!zeroBalance) return tecINTERNAL; // LCOV_EXCL_LINE diff --git a/src/xrpld/app/tx/detail/ConfidentialConvertBack.cpp b/src/xrpld/app/tx/detail/ConfidentialConvertBack.cpp index d1f08676c0..e9d34b753b 100644 --- a/src/xrpld/app/tx/detail/ConfidentialConvertBack.cpp +++ b/src/xrpld/app/tx/detail/ConfidentialConvertBack.cpp @@ -40,10 +40,7 @@ ConfidentialConvertBack::preflight(PreflightContext const& ctx) } TER -verifyProofs( - STTx const& tx, - std::shared_ptr const& issuance, - std::shared_ptr const& mptoken) +verifyProofs(STTx const& tx, std::shared_ptr const& issuance, std::shared_ptr const& mptoken) { if (!mptoken->isFieldPresent(sfHolderElGamalPublicKey)) return tecINTERNAL; // LCOV_EXCL_LINE @@ -55,28 +52,21 @@ verifyProofs( auto const holderPubKey = (*mptoken)[sfHolderElGamalPublicKey]; auto const contextHash = getConvertBackContextHash( - account, - tx[sfSequence], - mptIssuanceID, - amount, - (*mptoken)[~sfConfidentialBalanceVersion].value_or(0)); + account, tx[sfSequence], mptIssuanceID, amount, (*mptoken)[~sfConfidentialBalanceVersion].value_or(0)); // Prepare Auditor Info std::optional auditor; bool const hasAuditor = issuance->isFieldPresent(sfAuditorElGamalPublicKey); if (hasAuditor) { - auditor.emplace(ConfidentialRecipient{ - (*issuance)[sfAuditorElGamalPublicKey], - tx[sfAuditorEncryptedAmount]}); + auditor.emplace(ConfidentialRecipient{(*issuance)[sfAuditorElGamalPublicKey], tx[sfAuditorEncryptedAmount]}); } if (auto const ter = verifyRevealedAmount( amount, blindingFactor, {holderPubKey, tx[sfHolderEncryptedAmount]}, - {(*issuance)[sfIssuerElGamalPublicKey], - tx[sfIssuerEncryptedAmount]}, + {(*issuance)[sfIssuerElGamalPublicKey], tx[sfIssuerEncryptedAmount]}, auditor); !isTesSuccess(ter)) { @@ -124,8 +114,7 @@ ConfidentialConvertBack::preclaim(PreclaimContext const& ctx) return tecNO_PERMISSION; bool const hasAuditor = ctx.tx.isFieldPresent(sfAuditorEncryptedAmount); - bool const requiresAuditor = - sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); + bool const requiresAuditor = sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); // tx must include auditor ciphertext if the issuance has enabled // auditing @@ -142,8 +131,7 @@ ConfidentialConvertBack::preclaim(PreclaimContext const& ctx) if (sleIssuance->getAccountID(sfIssuer) == account) return tefINTERNAL; // LCOV_EXCL_LINE - auto const sleMptoken = - ctx.view.read(keylet::mptoken(mptIssuanceID, account)); + auto const sleMptoken = ctx.view.read(keylet::mptoken(mptIssuanceID, account)); if (!sleMptoken) return tecOBJECT_NOT_FOUND; @@ -163,17 +151,14 @@ ConfidentialConvertBack::preclaim(PreclaimContext const& ctx) // Check lock MPTIssue const mptIssue(mptIssuanceID); - if (auto const ter = checkFrozen(ctx.view, account, mptIssue); - !isTesSuccess(ter)) + if (auto const ter = checkFrozen(ctx.view, account, mptIssue); !isTesSuccess(ter)) return ter; // Check auth - if (auto const ter = requireAuth(ctx.view, mptIssue, account); - !isTesSuccess(ter)) + if (auto const ter = requireAuth(ctx.view, mptIssue, account); !isTesSuccess(ter)) return ter; - if (TER const res = verifyProofs(ctx.tx, sleIssuance, sleMptoken); - !isTesSuccess(res)) + if (TER const res = verifyProofs(ctx.tx, sleIssuance, sleMptoken); !isTesSuccess(res)) return res; return tesSUCCESS; @@ -205,9 +190,7 @@ ConfidentialConvertBack::doApply() { Buffer res(ecGamalEncryptedTotalLength); if (TER const ter = homomorphicSubtract( - (*sleMptoken)[sfConfidentialBalanceSpending], - ctx_.tx[sfHolderEncryptedAmount], - res); + (*sleMptoken)[sfConfidentialBalanceSpending], ctx_.tx[sfHolderEncryptedAmount], res); !isTesSuccess(ter)) return tecINTERNAL; @@ -217,10 +200,8 @@ ConfidentialConvertBack::doApply() // homomorphically subtract issuer's encrypted balance { Buffer res(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicSubtract( - (*sleMptoken)[sfIssuerEncryptedBalance], - ctx_.tx[sfIssuerEncryptedAmount], - res); + if (TER const ter = + homomorphicSubtract((*sleMptoken)[sfIssuerEncryptedBalance], ctx_.tx[sfIssuerEncryptedAmount], res); !isTesSuccess(ter)) return tecINTERNAL; @@ -230,10 +211,8 @@ ConfidentialConvertBack::doApply() if (auditorEc) { Buffer res(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicSubtract( - (*sleMptoken)[sfAuditorEncryptedBalance], - ctx_.tx[sfAuditorEncryptedAmount], - res); + if (TER const ter = + homomorphicSubtract((*sleMptoken)[sfAuditorEncryptedBalance], ctx_.tx[sfAuditorEncryptedAmount], res); !isTesSuccess(ter)) return tecINTERNAL; diff --git a/src/xrpld/app/tx/detail/ConfidentialMergeInbox.cpp b/src/xrpld/app/tx/detail/ConfidentialMergeInbox.cpp index d8caec87cf..a8eebdd4d5 100644 --- a/src/xrpld/app/tx/detail/ConfidentialMergeInbox.cpp +++ b/src/xrpld/app/tx/detail/ConfidentialMergeInbox.cpp @@ -25,8 +25,7 @@ ConfidentialMergeInbox::preflight(PreflightContext const& ctx) TER ConfidentialMergeInbox::preclaim(PreclaimContext const& ctx) { - auto const sleIssuance = - ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID])); + auto const sleIssuance = ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID])); if (!sleIssuance) return tecOBJECT_NOT_FOUND; @@ -38,8 +37,7 @@ ConfidentialMergeInbox::preclaim(PreclaimContext const& ctx) if (sleIssuance->getAccountID(sfIssuer) == ctx.tx[sfAccount]) return tefINTERNAL; // LCOV_EXCL_LINE - auto const sleMptoken = ctx.view.read( - keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], ctx.tx[sfAccount])); + auto const sleMptoken = ctx.view.read(keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], ctx.tx[sfAccount])); if (!sleMptoken) return tecOBJECT_NOT_FOUND; @@ -70,16 +68,14 @@ ConfidentialMergeInbox::doApply() // homomorphically add holder's encrypted balance Buffer sum(ecGamalEncryptedTotalLength); if (TER const ter = homomorphicAdd( - (*sleMptoken)[sfConfidentialBalanceSpending], - (*sleMptoken)[sfConfidentialBalanceInbox], - sum); + (*sleMptoken)[sfConfidentialBalanceSpending], (*sleMptoken)[sfConfidentialBalanceInbox], sum); !isTesSuccess(ter)) return tecINTERNAL; (*sleMptoken)[sfConfidentialBalanceSpending] = sum; - auto const zeroEncryption = encryptCanonicalZeroAmount( - (*sleMptoken)[sfHolderElGamalPublicKey], account_, mptIssuanceID); + auto const zeroEncryption = + encryptCanonicalZeroAmount((*sleMptoken)[sfHolderElGamalPublicKey], account_, mptIssuanceID); if (!zeroEncryption) return tecINTERNAL; // LCOV_EXCL_LINE @@ -87,8 +83,7 @@ ConfidentialMergeInbox::doApply() (*sleMptoken)[sfConfidentialBalanceInbox] = *zeroEncryption; // it's fine if it reaches max uint32, it just resets to 0 - (*sleMptoken)[sfConfidentialBalanceVersion] = - (*sleMptoken)[~sfConfidentialBalanceVersion].value_or(0u) + 1u; + (*sleMptoken)[sfConfidentialBalanceVersion] = (*sleMptoken)[~sfConfidentialBalanceVersion].value_or(0u) + 1u; view().update(sleMptoken); return tesSUCCESS; diff --git a/src/xrpld/app/tx/detail/ConfidentialSend.cpp b/src/xrpld/app/tx/detail/ConfidentialSend.cpp index ba123ba1a1..3bc7eae1f9 100644 --- a/src/xrpld/app/tx/detail/ConfidentialSend.cpp +++ b/src/xrpld/app/tx/detail/ConfidentialSend.cpp @@ -30,23 +30,18 @@ ConfidentialSend::preflight(PreflightContext const& ctx) return temMALFORMED; // Check the length of the encrypted amounts - if (ctx.tx[sfSenderEncryptedAmount].length() != - ecGamalEncryptedTotalLength || - ctx.tx[sfDestinationEncryptedAmount].length() != - ecGamalEncryptedTotalLength || + 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) + if (hasAuditor && ctx.tx[sfAuditorEncryptedAmount].length() != ecGamalEncryptedTotalLength) return temBAD_CIPHERTEXT; // Check the length of the ZKProof auto const recipientCount = getConfidentialRecipientCount(hasAuditor); - auto const sizeEquality = - getMultiCiphertextEqualityProofSize(recipientCount); + auto const sizeEquality = getMultiCiphertextEqualityProofSize(recipientCount); auto const sizePedersenLinkage = 2 * ecPedersenProofLength; if (ctx.tx[sfZKProof].length() != sizeEquality + sizePedersenLinkage) @@ -60,8 +55,7 @@ ConfidentialSend::preflight(PreflightContext const& ctx) // 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])) + !isValidCiphertext(ctx.tx[sfDestinationEncryptedAmount]) || !isValidCiphertext(ctx.tx[sfIssuerEncryptedAmount])) return temBAD_CIPHERTEXT; if (hasAuditor && !isValidCiphertext(ctx.tx[sfAuditorEncryptedAmount])) @@ -88,8 +82,7 @@ verifySendProofs( size_t currentOffset = 0; // Extract equality proof - auto const sizeEquality = - getMultiCiphertextEqualityProofSize(recipientCount); + auto const sizeEquality = getMultiCiphertextEqualityProofSize(recipientCount); if (remainingLength < sizeEquality) return tecINTERNAL; // LCOV_EXCL_LINE @@ -101,8 +94,7 @@ verifySendProofs( if (remainingLength < ecPedersenProofLength) return tecINTERNAL; // LCOV_EXCL_LINE - auto const amountLinkageProof = - proof.substr(currentOffset, ecPedersenProofLength); + auto const amountLinkageProof = proof.substr(currentOffset, ecPedersenProofLength); currentOffset += ecPedersenProofLength; remainingLength -= ecPedersenProofLength; @@ -110,8 +102,7 @@ verifySendProofs( if (remainingLength < ecPedersenProofLength) return tecINTERNAL; // LCOV_EXCL_LINE - auto const balanceLinkageProof = - proof.substr(currentOffset, ecPedersenProofLength); + auto const balanceLinkageProof = proof.substr(currentOffset, ecPedersenProofLength); currentOffset += ecPedersenProofLength; remainingLength -= ecPedersenProofLength; @@ -123,23 +114,15 @@ verifySendProofs( std::vector recipients; recipients.reserve(recipientCount); - recipients.push_back( - {(*sleSenderMPToken)[sfHolderElGamalPublicKey], - ctx.tx[sfSenderEncryptedAmount]}); + recipients.push_back({(*sleSenderMPToken)[sfHolderElGamalPublicKey], ctx.tx[sfSenderEncryptedAmount]}); - recipients.push_back( - {(*sleDestinationMPToken)[sfHolderElGamalPublicKey], - ctx.tx[sfDestinationEncryptedAmount]}); + recipients.push_back({(*sleDestinationMPToken)[sfHolderElGamalPublicKey], ctx.tx[sfDestinationEncryptedAmount]}); - recipients.push_back( - {(*sleIssuance)[sfIssuerElGamalPublicKey], - ctx.tx[sfIssuerEncryptedAmount]}); + recipients.push_back({(*sleIssuance)[sfIssuerElGamalPublicKey], ctx.tx[sfIssuerEncryptedAmount]}); if (hasAuditor) { - recipients.push_back( - {(*sleIssuance)[sfAuditorElGamalPublicKey], - ctx.tx[sfAuditorEncryptedAmount]}); + recipients.push_back({(*sleIssuance)[sfAuditorElGamalPublicKey], ctx.tx[sfAuditorEncryptedAmount]}); } // Prepare the context hash @@ -151,8 +134,7 @@ verifySendProofs( (*sleSenderMPToken)[~sfConfidentialBalanceVersion].value_or(0)); // Verify the multi-ciphertext equality proof - if (auto const ter = verifyMultiCiphertextEqualityProof( - equalityProof, recipients, recipientCount, contextHash); + if (auto const ter = verifyMultiCiphertextEqualityProof(equalityProof, recipients, recipientCount, contextHash); !isTesSuccess(ter)) { JLOG(ctx.j.trace()) << "ConfidentialSend: Equality proof failed."; @@ -181,8 +163,7 @@ verifySendProofs( contextHash); !isTesSuccess(ter)) { - JLOG(ctx.j.trace()) - << "ConfidentialSend: Balance linkage proof failed."; + JLOG(ctx.j.trace()) << "ConfidentialSend: Balance linkage proof failed."; return ter; } @@ -221,8 +202,7 @@ ConfidentialSend::preclaim(PreclaimContext const& ctx) return tecNO_PERMISSION; bool const hasAuditor = ctx.tx.isFieldPresent(sfAuditorEncryptedAmount); - bool const requiresAuditor = - sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); + bool const requiresAuditor = sleIssuance->isFieldPresent(sfAuditorElGamalPublicKey); // Tx must include auditor ciphertext if the issuance has enabled // auditing, and must not include it if auditing is not enabled @@ -234,8 +214,7 @@ ConfidentialSend::preclaim(PreclaimContext const& ctx) return tefINTERNAL; // LCOV_EXCL_LINE // Check sender's MPToken existence - auto const sleSenderMPToken = - ctx.view.read(keylet::mptoken(mptIssuanceID, account)); + auto const sleSenderMPToken = ctx.view.read(keylet::mptoken(mptIssuanceID, account)); if (!sleSenderMPToken) return tecOBJECT_NOT_FOUND; @@ -247,13 +226,11 @@ ConfidentialSend::preclaim(PreclaimContext const& ctx) // Sanity check: MPToken's auditor field must be present if auditing is // enabled - if (requiresAuditor && - !sleSenderMPToken->isFieldPresent(sfAuditorEncryptedBalance)) + if (requiresAuditor && !sleSenderMPToken->isFieldPresent(sfAuditorEncryptedBalance)) return tefINTERNAL; // Check destination's MPToken existence - auto const sleDestinationMPToken = - ctx.view.read(keylet::mptoken(mptIssuanceID, destination)); + auto const sleDestinationMPToken = ctx.view.read(keylet::mptoken(mptIssuanceID, destination)); if (!sleDestinationMPToken) return tecOBJECT_NOT_FOUND; @@ -265,25 +242,20 @@ ConfidentialSend::preclaim(PreclaimContext const& ctx) // Check lock MPTIssue const mptIssue(mptIssuanceID); - if (auto const ter = checkFrozen(ctx.view, account, mptIssue); - !isTesSuccess(ter)) + if (auto const ter = checkFrozen(ctx.view, account, mptIssue); !isTesSuccess(ter)) return ter; - if (auto const ter = checkFrozen(ctx.view, destination, mptIssue); - !isTesSuccess(ter)) + if (auto const ter = checkFrozen(ctx.view, destination, mptIssue); !isTesSuccess(ter)) return ter; // Check auth - if (auto const ter = requireAuth(ctx.view, mptIssue, account); - !isTesSuccess(ter)) + if (auto const ter = requireAuth(ctx.view, mptIssue, account); !isTesSuccess(ter)) return ter; - if (auto const ter = requireAuth(ctx.view, mptIssue, destination); - !isTesSuccess(ter)) + if (auto const ter = requireAuth(ctx.view, mptIssue, destination); !isTesSuccess(ter)) return ter; - return verifySendProofs( - ctx, sleSenderMPToken, sleDestinationMPToken, sleIssuance); + return verifySendProofs(ctx, sleSenderMPToken, sleDestinationMPToken, sleIssuance); } TER @@ -292,23 +264,15 @@ ConfidentialSend::doApply() auto const mptIssuanceID = ctx_.tx[sfMPTokenIssuanceID]; auto const destination = ctx_.tx[sfDestination]; - auto sleSenderMPToken = - view().peek(keylet::mptoken(mptIssuanceID, account_)); - auto sleDestinationMPToken = - view().peek(keylet::mptoken(mptIssuanceID, destination)); + auto sleSenderMPToken = view().peek(keylet::mptoken(mptIssuanceID, account_)); + auto sleDestinationMPToken = view().peek(keylet::mptoken(mptIssuanceID, destination)); auto sleDestAcct = view().peek(keylet::account(destination)); if (!sleSenderMPToken || !sleDestinationMPToken || !sleDestAcct) return tecINTERNAL; - if (auto err = verifyDepositPreauth( - ctx_.tx, - ctx_.view(), - account_, - destination, - sleDestAcct, - ctx_.journal); + if (auto err = verifyDepositPreauth(ctx_.tx, ctx_.view(), account_, destination, sleDestAcct, ctx_.journal); !isTesSuccess(err)) return err; @@ -320,13 +284,10 @@ ConfidentialSend::doApply() // Subtract from sender's spending balance { - Slice const curSpending = - (*sleSenderMPToken)[sfConfidentialBalanceSpending]; + Slice const curSpending = (*sleSenderMPToken)[sfConfidentialBalanceSpending]; Buffer newSpending(ecGamalEncryptedTotalLength); - if (TER const ter = - homomorphicSubtract(curSpending, senderEc, newSpending); - !isTesSuccess(ter)) + if (TER const ter = homomorphicSubtract(curSpending, senderEc, newSpending); !isTesSuccess(ter)) return tecINTERNAL; (*sleSenderMPToken)[sfConfidentialBalanceSpending] = newSpending; @@ -334,13 +295,10 @@ ConfidentialSend::doApply() // Subtract from issuer's balance { - Slice const curIssuerEnc = - (*sleSenderMPToken)[sfIssuerEncryptedBalance]; + Slice const curIssuerEnc = (*sleSenderMPToken)[sfIssuerEncryptedBalance]; Buffer newIssuerEnc(ecGamalEncryptedTotalLength); - if (TER const ter = - homomorphicSubtract(curIssuerEnc, issuerEc, newIssuerEnc); - !isTesSuccess(ter)) + if (TER const ter = homomorphicSubtract(curIssuerEnc, issuerEc, newIssuerEnc); !isTesSuccess(ter)) return tecINTERNAL; (*sleSenderMPToken)[sfIssuerEncryptedBalance] = newIssuerEnc; @@ -349,13 +307,10 @@ ConfidentialSend::doApply() // Subtract from auditor's balance if present if (auditorEc) { - Slice const curAuditorEnc = - (*sleSenderMPToken)[sfAuditorEncryptedBalance]; + Slice const curAuditorEnc = (*sleSenderMPToken)[sfAuditorEncryptedBalance]; Buffer newAuditorEnc(ecGamalEncryptedTotalLength); - if (TER const ter = - homomorphicSubtract(curAuditorEnc, *auditorEc, newAuditorEnc); - !isTesSuccess(ter)) + if (TER const ter = homomorphicSubtract(curAuditorEnc, *auditorEc, newAuditorEnc); !isTesSuccess(ter)) return tecINTERNAL; (*sleSenderMPToken)[sfAuditorEncryptedBalance] = newAuditorEnc; @@ -363,12 +318,10 @@ ConfidentialSend::doApply() // Add to destination's inbox balance { - Slice const curInbox = - (*sleDestinationMPToken)[sfConfidentialBalanceInbox]; + Slice const curInbox = (*sleDestinationMPToken)[sfConfidentialBalanceInbox]; Buffer newInbox(ecGamalEncryptedTotalLength); - if (TER const ter = homomorphicAdd(curInbox, destEc, newInbox); - !isTesSuccess(ter)) + if (TER const ter = homomorphicAdd(curInbox, destEc, newInbox); !isTesSuccess(ter)) return tecINTERNAL; (*sleDestinationMPToken)[sfConfidentialBalanceInbox] = newInbox; @@ -376,13 +329,10 @@ ConfidentialSend::doApply() // Add to issuer's balance { - Slice const curIssuerEnc = - (*sleDestinationMPToken)[sfIssuerEncryptedBalance]; + Slice const curIssuerEnc = (*sleDestinationMPToken)[sfIssuerEncryptedBalance]; Buffer newIssuerEnc(ecGamalEncryptedTotalLength); - if (TER const ter = - homomorphicAdd(curIssuerEnc, issuerEc, newIssuerEnc); - !isTesSuccess(ter)) + if (TER const ter = homomorphicAdd(curIssuerEnc, issuerEc, newIssuerEnc); !isTesSuccess(ter)) return tecINTERNAL; (*sleDestinationMPToken)[sfIssuerEncryptedBalance] = newIssuerEnc; @@ -391,13 +341,10 @@ ConfidentialSend::doApply() // Add to auditor's balance if present if (auditorEc) { - Slice const curAuditorEnc = - (*sleDestinationMPToken)[sfAuditorEncryptedBalance]; + Slice const curAuditorEnc = (*sleDestinationMPToken)[sfAuditorEncryptedBalance]; Buffer newAuditorEnc(ecGamalEncryptedTotalLength); - if (TER const ter = - homomorphicAdd(curAuditorEnc, *auditorEc, newAuditorEnc); - !isTesSuccess(ter)) + if (TER const ter = homomorphicAdd(curAuditorEnc, *auditorEc, newAuditorEnc); !isTesSuccess(ter)) return tecINTERNAL; (*sleDestinationMPToken)[sfAuditorEncryptedBalance] = newAuditorEnc; diff --git a/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp b/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp index c64586d011..e22f13cb20 100644 --- a/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp +++ b/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp @@ -72,14 +72,11 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) if (ctx.view.rules().enabled(featureConfidentialTransfer)) { - auto const sleMptIssuance = ctx.view.read( - keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID])); + auto const sleMptIssuance = ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID])); // if there still existing encrypted balances of MPT in // circulation - if (sleMptIssuance && - (*sleMptIssuance)[~sfConfidentialOutstandingAmount] - .value_or(0) != 0) + if (sleMptIssuance && (*sleMptIssuance)[~sfConfidentialOutstandingAmount].value_or(0) != 0) { // this MPT still has encrypted balance, since we don't know // if it's non-zero or not, we won't allow deletion of diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp b/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp index 0226669e2f..f3f5d3f439 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp @@ -16,14 +16,12 @@ MPTokenIssuanceCreate::checkExtraFeatures(PreflightContext const& ctx) if (ctx.tx.isFieldPresent(sfMutableFlags) && !ctx.rules.enabled(featureDynamicMPT)) return false; - if (ctx.tx.isFlag(tfMPTCanPrivacy) && - !ctx.rules.enabled(featureConfidentialTransfer)) + if (ctx.tx.isFlag(tfMPTCanPrivacy) && !ctx.rules.enabled(featureConfidentialTransfer)) return false; // can not set tmfMPTCannotMutatePrivacy without featureConfidentialTransfer auto const mutableFlags = ctx.tx[~sfMutableFlags]; - if (mutableFlags && (*mutableFlags & tmfMPTCannotMutatePrivacy) && - !ctx.rules.enabled(featureConfidentialTransfer)) + if (mutableFlags && (*mutableFlags & tmfMPTCannotMutatePrivacy) && !ctx.rules.enabled(featureConfidentialTransfer)) return false; return true; diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp index 1c44c9a8c6..68d6e8597b 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp @@ -33,35 +33,13 @@ struct MPTMutabilityFlags }; static constexpr std::array mptMutabilityFlags = { - {{tmfMPTSetCanLock, - tmfMPTClearCanLock, - lsmfMPTCanMutateCanLock, - lsfMPTCanLock}, - {tmfMPTSetRequireAuth, - tmfMPTClearRequireAuth, - lsmfMPTCanMutateRequireAuth, - lsfMPTRequireAuth}, - {tmfMPTSetCanEscrow, - tmfMPTClearCanEscrow, - lsmfMPTCanMutateCanEscrow, - lsfMPTCanEscrow}, - {tmfMPTSetCanTrade, - tmfMPTClearCanTrade, - lsmfMPTCanMutateCanTrade, - lsfMPTCanTrade}, - {tmfMPTSetCanTransfer, - tmfMPTClearCanTransfer, - lsmfMPTCanMutateCanTransfer, - lsfMPTCanTransfer}, - {tmfMPTSetCanClawback, - tmfMPTClearCanClawback, - lsmfMPTCanMutateCanClawback, - lsfMPTCanClawback}, - {tmfMPTSetPrivacy, - tmfMPTClearPrivacy, - lsmfMPTCannotMutatePrivacy, - lsfMPTCanPrivacy, - true}}}; + {{tmfMPTSetCanLock, tmfMPTClearCanLock, lsmfMPTCanMutateCanLock, lsfMPTCanLock}, + {tmfMPTSetRequireAuth, tmfMPTClearRequireAuth, lsmfMPTCanMutateRequireAuth, lsfMPTRequireAuth}, + {tmfMPTSetCanEscrow, tmfMPTClearCanEscrow, lsmfMPTCanMutateCanEscrow, lsfMPTCanEscrow}, + {tmfMPTSetCanTrade, tmfMPTClearCanTrade, lsmfMPTCanMutateCanTrade, lsfMPTCanTrade}, + {tmfMPTSetCanTransfer, tmfMPTClearCanTransfer, lsmfMPTCanMutateCanTransfer, lsfMPTCanTransfer}, + {tmfMPTSetCanClawback, tmfMPTClearCanClawback, lsmfMPTCanMutateCanClawback, lsfMPTCanClawback}, + {tmfMPTSetPrivacy, tmfMPTClearPrivacy, lsmfMPTCannotMutatePrivacy, lsfMPTCanPrivacy, true}}}; NotTEC MPTokenIssuanceSet::preflight(PreflightContext const& ctx) @@ -70,14 +48,11 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) auto const metadata = ctx.tx[~sfMPTokenMetadata]; auto const transferFee = ctx.tx[~sfTransferFee]; auto const isMutate = mutableFlags || metadata || transferFee; - auto const hasIssuerElGamalKey = - ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey); - auto const hasAuditorElGamalKey = - ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey); + auto const hasIssuerElGamalKey = ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey); + auto const hasAuditorElGamalKey = ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey); auto const txFlags = ctx.tx.getFlags(); - auto const mutatePrivacy = mutableFlags && - ((*mutableFlags & (tmfMPTSetPrivacy | tmfMPTClearPrivacy))); + auto const mutatePrivacy = mutableFlags && ((*mutableFlags & (tmfMPTSetPrivacy | tmfMPTClearPrivacy))); auto const hasDomain = ctx.tx.isFieldPresent(sfDomainID); auto const hasHolder = ctx.tx.isFieldPresent(sfHolder); @@ -104,13 +79,11 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) if (holderID && accountID == holderID) return temMALFORMED; - if (ctx.rules.enabled(featureSingleAssetVault) || - ctx.rules.enabled(featureDynamicMPT) || + if (ctx.rules.enabled(featureSingleAssetVault) || ctx.rules.enabled(featureDynamicMPT) || ctx.rules.enabled(featureConfidentialTransfer)) { // Is this transaction actually changing anything ? - if (txFlags == 0 && !hasDomain && !hasIssuerElGamalKey && - !hasAuditorElGamalKey && !isMutate) + if (txFlags == 0 && !hasDomain && !hasIssuerElGamalKey && !hasAuditorElGamalKey && !isMutate) return temMALFORMED; } @@ -154,12 +127,10 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) if (hasAuditorElGamalKey && !hasIssuerElGamalKey) return temMALFORMED; - if (hasIssuerElGamalKey && - ctx.tx[sfIssuerElGamalPublicKey].length() != ecPubKeyLength) + if (hasIssuerElGamalKey && ctx.tx[sfIssuerElGamalPublicKey].length() != ecPubKeyLength) return temMALFORMED; - if (hasAuditorElGamalKey && - ctx.tx[sfAuditorElGamalPublicKey].length() != ecPubKeyLength) + if (hasAuditorElGamalKey && ctx.tx[sfAuditorElGamalPublicKey].length() != ecPubKeyLength) return temMALFORMED; return tesSUCCESS; @@ -255,22 +226,16 @@ MPTokenIssuanceSet::preclaim(PreclaimContext const& ctx) if (mutableFlags) { if (std::any_of( - mptMutabilityFlags.begin(), - mptMutabilityFlags.end(), - [mutableFlags, &isMutableFlag](auto const& f) { - bool const canMutate = f.isCannotMutate - ? isMutableFlag(f.mutabilityFlag) - : !isMutableFlag(f.mutabilityFlag); - return canMutate && - (*mutableFlags & (f.setFlag | f.clearFlag)); + mptMutabilityFlags.begin(), mptMutabilityFlags.end(), [mutableFlags, &isMutableFlag](auto const& f) { + bool const canMutate = + f.isCannotMutate ? isMutableFlag(f.mutabilityFlag) : !isMutableFlag(f.mutabilityFlag); + return canMutate && (*mutableFlags & (f.setFlag | f.clearFlag)); })) return tecNO_PERMISSION; - if ((*mutableFlags & tmfMPTSetPrivacy) || - (*mutableFlags & tmfMPTClearPrivacy)) + if ((*mutableFlags & tmfMPTSetPrivacy) || (*mutableFlags & tmfMPTClearPrivacy)) { - std::uint64_t const confidentialOA = - (*sleMptIssuance)[~sfConfidentialOutstandingAmount].value_or(0); + std::uint64_t const confidentialOA = (*sleMptIssuance)[~sfConfidentialOutstandingAmount].value_or(0); // If there's any confidential outstanding amount, disallow toggling // the lsfMPTCanPrivacy flag @@ -296,34 +261,29 @@ MPTokenIssuanceSet::preclaim(PreclaimContext const& ctx) } // cannot update issuer public key - if (ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) && - sleMptIssuance->isFieldPresent(sfIssuerElGamalPublicKey)) + if (ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) && sleMptIssuance->isFieldPresent(sfIssuerElGamalPublicKey)) { return tecNO_PERMISSION; } // cannot update auditor public key - if (ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey) && - sleMptIssuance->isFieldPresent(sfAuditorElGamalPublicKey)) + if (ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey) && sleMptIssuance->isFieldPresent(sfAuditorElGamalPublicKey)) { return tecNO_PERMISSION; // LCOV_EXCL_LINE } - if (ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) && - !sleMptIssuance->isFlag(lsfMPTCanPrivacy)) + if (ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) && !sleMptIssuance->isFlag(lsfMPTCanPrivacy)) { return tecNO_PERMISSION; } - if (ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey) && - !sleMptIssuance->isFlag(lsfMPTCanPrivacy)) + if (ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey) && !sleMptIssuance->isFlag(lsfMPTCanPrivacy)) { return tecNO_PERMISSION; } // cannot upload key if there's circulating supply of COA - if ((ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) || - ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey)) && + if ((ctx.tx.isFieldPresent(sfIssuerElGamalPublicKey) || ctx.tx.isFieldPresent(sfAuditorElGamalPublicKey)) && sleMptIssuance->isFieldPresent(sfConfidentialOutstandingAmount)) { return tecNO_PERMISSION; // LCOV_EXCL_LINE @@ -417,9 +377,7 @@ MPTokenIssuanceSet::doApply() if (auto const pubKey = ctx_.tx[~sfIssuerElGamalPublicKey]) { // This is enforced in preflight. - XRPL_ASSERT( - sle->getType() == ltMPTOKEN_ISSUANCE, - "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); + XRPL_ASSERT(sle->getType() == ltMPTOKEN_ISSUANCE, "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); sle->setFieldVL(sfIssuerElGamalPublicKey, *pubKey); } @@ -427,9 +385,7 @@ MPTokenIssuanceSet::doApply() if (auto const pubKey = ctx_.tx[~sfAuditorElGamalPublicKey]) { // This is enforced in preflight. - XRPL_ASSERT( - sle->getType() == ltMPTOKEN_ISSUANCE, - "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); + XRPL_ASSERT(sle->getType() == ltMPTOKEN_ISSUANCE, "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); sle->setFieldVL(sfAuditorElGamalPublicKey, *pubKey); }