Skip to content

Commit

Permalink
add proof test for large amount withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Dec 9, 2024
1 parent 25b4001 commit 96bd178
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/api/veiledCoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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();
});
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/veiled/veiledProofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 96bd178

Please sign in to comment.