mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 17:35:51 +00:00
add ciphertext check for ConfidentialSend (#5964)
This commit is contained in:
@@ -936,6 +936,42 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.issuerEncryptedAmt = Buffer(10),
|
||||
.err = temMALFORMED});
|
||||
|
||||
auto const ciphertextHex = generatePlaceholderCiphertext();
|
||||
|
||||
// sender encrypted amount malformed
|
||||
mptAlice.send(
|
||||
{.account = bob,
|
||||
.dest = carol,
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.senderEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.destEncryptedAmt = ciphertextHex,
|
||||
.issuerEncryptedAmt = ciphertextHex,
|
||||
.err = temBAD_CIPHERTEXT});
|
||||
// dest encrypted amount malformed
|
||||
mptAlice.send(
|
||||
{.account = bob,
|
||||
.dest = carol,
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.senderEncryptedAmt = ciphertextHex,
|
||||
.destEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.issuerEncryptedAmt = ciphertextHex,
|
||||
.err = temBAD_CIPHERTEXT});
|
||||
// issuer encrypted amount malformed
|
||||
mptAlice.send(
|
||||
{.account = bob,
|
||||
.dest = carol,
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.senderEncryptedAmt = ciphertextHex,
|
||||
.destEncryptedAmt = ciphertextHex,
|
||||
.issuerEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.err = temBAD_CIPHERTEXT});
|
||||
|
||||
// todo: proof length check
|
||||
}
|
||||
}
|
||||
@@ -1006,6 +1042,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
// env.close();
|
||||
// }
|
||||
|
||||
auto const ciphertextHex = generatePlaceholderCiphertext();
|
||||
|
||||
// destination does not exist
|
||||
{
|
||||
Account const unknown("unknown");
|
||||
@@ -1014,10 +1052,8 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.dest = unknown,
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.issuerEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.destEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.issuerEncryptedAmt = ciphertextHex,
|
||||
.destEncryptedAmt = ciphertextHex,
|
||||
.err = tecNO_TARGET});
|
||||
}
|
||||
|
||||
@@ -1044,8 +1080,7 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.dest = eve,
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.destEncryptedAmt =
|
||||
Buffer(ripple::ecGamalEncryptedTotalLength),
|
||||
.destEncryptedAmt = ciphertextHex,
|
||||
.err = tecOBJECT_NOT_FOUND});
|
||||
}
|
||||
|
||||
@@ -1058,12 +1093,12 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.err = tecLOCKED});
|
||||
mptAlice.set(
|
||||
{.account = alice, .flags = tfMPTUnlock}); // unlock issuance
|
||||
}
|
||||
|
||||
// sender is locked
|
||||
{
|
||||
mptAlice.set(
|
||||
{.account = alice, .flags = tfMPTUnlock}); // unlock issuance
|
||||
mptAlice.set({.account = alice, .holder = bob, .flags = tfMPTLock});
|
||||
mptAlice.send(
|
||||
{.account = bob,
|
||||
@@ -1071,14 +1106,14 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.err = tecLOCKED});
|
||||
}
|
||||
|
||||
// destination is locked
|
||||
{
|
||||
mptAlice.set(
|
||||
{.account = alice,
|
||||
.holder = bob,
|
||||
.flags = tfMPTUnlock}); // unlock bob
|
||||
}
|
||||
|
||||
// destination is locked
|
||||
{
|
||||
mptAlice.set(
|
||||
{.account = alice, .holder = carol, .flags = tfMPTLock});
|
||||
mptAlice.send(
|
||||
@@ -1087,6 +1122,10 @@ class ConfidentialTransfer_test : public beast::unit_test::suite
|
||||
.amt = 10,
|
||||
.proof = "123",
|
||||
.err = tecLOCKED});
|
||||
mptAlice.set(
|
||||
{.account = alice,
|
||||
.holder = carol,
|
||||
.flags = tfMPTUnlock}); // unlock carol
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,20 @@ namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
ripple::Buffer
|
||||
generatePlaceholderCiphertext()
|
||||
{
|
||||
Buffer buf(ecGamalEncryptedTotalLength);
|
||||
|
||||
buf.data()[0] = 0x02;
|
||||
buf.data()[ecGamalEncryptedLength] = 0x02;
|
||||
|
||||
buf.data()[ecGamalEncryptedLength - 1] = 0x01;
|
||||
buf.data()[ecGamalEncryptedTotalLength - 1] = 0x01;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
mptflags::operator()(Env& env) const
|
||||
{
|
||||
|
||||
@@ -35,6 +35,10 @@ namespace jtx {
|
||||
|
||||
class MPTTester;
|
||||
|
||||
// Generates a syntactically valid placeholder ciphertext
|
||||
ripple::Buffer
|
||||
generatePlaceholderCiphertext();
|
||||
|
||||
// Check flags settings on MPT create
|
||||
class mptflags
|
||||
{
|
||||
|
||||
@@ -55,6 +55,11 @@ ConfidentialSend::preflight(PreflightContext const& ctx)
|
||||
ctx.tx[sfIssuerEncryptedAmount].length() != ecGamalEncryptedTotalLength)
|
||||
return temMALFORMED;
|
||||
|
||||
if (!isValidCiphertext(ctx.tx[sfSenderEncryptedAmount]) ||
|
||||
!isValidCiphertext(ctx.tx[sfDestinationEncryptedAmount]) ||
|
||||
!isValidCiphertext(ctx.tx[sfIssuerEncryptedAmount]))
|
||||
return temBAD_CIPHERTEXT;
|
||||
|
||||
// if (ctx.tx[sfZKProof].length() != ecEqualityProofLength)
|
||||
// return temMALFORMED;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user