From 96bd1784cdee2eca2a8acca37b3304fb9fc652fe Mon Sep 17 00:00:00 2001 From: lukachi Date: Mon, 9 Dec 2024 13:08:44 +0200 Subject: [PATCH] add proof test for large amount withdrawal --- tests/e2e/api/veiledCoin.test.ts | 4 +-- tests/unit/veiled/veiledProofs.test.ts | 36 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/e2e/api/veiledCoin.test.ts b/tests/e2e/api/veiledCoin.test.ts index 4227aea4..b7ee21bc 100644 --- a/tests/e2e/api/veiledCoin.test.ts +++ b/tests/e2e/api/veiledCoin.test.ts @@ -46,7 +46,7 @@ describe("Veiled balance api", () => { const addNewContentLineToFile = (filename: string, data: string) => { const filePath = path.resolve(rootDir, filename); - const content = `\n#TESTNET_DK=${data}\n`; + const content = `\n${data}\n`; fs.appendFileSync(filePath, content); }; @@ -442,7 +442,7 @@ describe("Veiled balance api", () => { console.log("\n\n\n"); /* eslint-enable */ - addNewContentLineToFile(".env.development", ALICE_NEW_VEILED_PRIVATE_KEY.toString()); + addNewContentLineToFile(".env.development", `#TESTNET_DK=${ALICE_NEW_VEILED_PRIVATE_KEY.toString()}`); expect(keyRotationAndUnfreezeTxResponse.success).toBeTruthy(); }); diff --git a/tests/unit/veiled/veiledProofs.test.ts b/tests/unit/veiled/veiledProofs.test.ts index 079d311a..c7b2c462 100644 --- a/tests/unit/veiled/veiledProofs.test.ts +++ b/tests/unit/veiled/veiledProofs.test.ts @@ -69,6 +69,42 @@ describe("Generate 'veiled coin' proofs", () => { expect(vbNew).toBeDefined(); }); + test("Should generate and verify veiled withdraw with large amounts", async () => { + const newAliceDecryptionKey = TwistedEd25519PrivateKey.generate(); + const newAliceBalance = VeiledAmount.fromAmount(2n ** 64n + 100n); + newAliceBalance.encrypt(newAliceDecryptionKey.publicKey()); + + const newWithdrawAmount = 2n ** 32n + 10n; + + const largeVeiledWithdrawal = await VeiledWithdraw.create({ + decryptionKey: newAliceDecryptionKey, + encryptedActualBalance: newAliceBalance.amountEncrypted!, + amountToWithdraw: newWithdrawAmount, + }); + + const [{ sigmaProof, rangeProof }, vbNew] = await largeVeiledWithdrawal.authorizeWithdrawal(); + + expect(sigmaProof).toBeDefined(); + expect(rangeProof).toBeDefined(); + expect(vbNew).toBeDefined(); + + const isSigmaProofValid = VeiledWithdraw.verifySigmaProof({ + publicKey: newAliceDecryptionKey.publicKey(), + encryptedActualBalance: largeVeiledWithdrawal.encryptedActualBalanceAmount, + encryptedActualBalanceAfterWithdraw: largeVeiledWithdrawal.veiledAmountAfterWithdraw!.amountEncrypted!, + amountToWithdraw: newWithdrawAmount, + sigmaProof, + }); + + const isRangeProofValid = VeiledWithdraw.verifyRangeProof({ + rangeProof, + encryptedActualBalanceAfterWithdraw: largeVeiledWithdrawal.veiledAmountAfterWithdraw!.amountEncrypted!, + }); + + expect(isSigmaProofValid).toBeTruthy(); + expect(isRangeProofValid).toBeTruthy(); + }); + const TRANSFER_AMOUNT = 10n; let veiledTransfer: VeiledTransfer; let veiledTransferSigmaProof: VeiledTransferSigmaProof;