Skip to content

Commit bfd859c

Browse files
eldarikclaude
andcommitted
feat(clients/js): add confidential mint/burn instruction plan helpers
Token-2022's /confidential subpath ships InstructionPlan helpers for transfer, withdraw and configure, but nothing for confidential mint/burn — downstream consumers had to re-derive the three-proof orchestration themselves. Add helpers so that logic lives upstream. - getConfidentialMintInstructionPlan / getConfidentialBurnInstructionPlan: build the equality, batched grouped-3-handles validity and U128 range proofs, verify them via context-state accounts, and assemble the token instruction — reusing the existing transfer/withdraw plumbing. - getUpdateConfidentialMintBurnDecryptableSupplyInstructionFromSupply: re-encrypt the decryptable supply under the supply AES key (u64-guarded). - addWithLoHiCiphertexts: the one missing arithmetic primitive, mirroring subtractWithLoHiCiphertexts, for homomorphically adding the minted amount to the encrypted supply. - test setup: createConfidentialMintBurnMint, initializing a mint with both the ConfidentialTransferMint and ConfidentialMintBurn extensions. The helpers reuse the primitives introduced by #1253 rather than adding their own: getRequiredMintExtension for the ConfidentialMintBurn lookup and assertU64Amount for the supply guards. getAuditorElGamalPubkey is widened to a structural input so transfer, transfer-with-fee, mint and burn all resolve the auditor key through one function, and main's now-redundant getRequiredConfidentialTransferMintExtension folds into the generic lookup. Covered by a new offline arithmetic test and a validator e2e that exercises mint -> apply -> burn -> apply-pending-burn -> update-supply against the on-chain ZK verifiers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent ead789a commit bfd859c

5 files changed

Lines changed: 733 additions & 18 deletions

File tree

clients/js/src/confidentialTransferArithmetic.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export function extractCiphertextFromGroupedBytes(groupedCiphertext: ReadonlyUin
5151
return ciphertext;
5252
}
5353

54+
function addCiphertexts(left: ReadonlyUint8Array, right: ReadonlyUint8Array) {
55+
const leftPoints = ciphertextToPoints(left);
56+
const rightPoints = ciphertextToPoints(right);
57+
return pointsToCiphertext(
58+
leftPoints.commitment.add(rightPoints.commitment),
59+
leftPoints.handle.add(rightPoints.handle),
60+
);
61+
}
62+
5463
function subtractCiphertexts(left: ReadonlyUint8Array, right: ReadonlyUint8Array) {
5564
const leftPoints = ciphertextToPoints(left);
5665
const rightPoints = ciphertextToPoints(right);
@@ -70,6 +79,20 @@ function combineLoHiCiphertexts(ciphertextLo: ReadonlyUint8Array, ciphertextHi:
7079
);
7180
}
7281

82+
/**
83+
* Combines lo/hi ciphertext halves (hi << bitLength + lo) and adds the result
84+
* to `left`. Used to compute the new encrypted supply ciphertext after a
85+
* confidential mint.
86+
*/
87+
export function addWithLoHiCiphertexts(
88+
left: ReadonlyUint8Array,
89+
ciphertextLo: ReadonlyUint8Array,
90+
ciphertextHi: ReadonlyUint8Array,
91+
bitLength: bigint,
92+
) {
93+
return addCiphertexts(left, combineLoHiCiphertexts(ciphertextLo, ciphertextHi, bitLength));
94+
}
95+
7396
/**
7497
* Combines lo/hi ciphertext halves (hi << bitLength + lo) and subtracts the
7598
* result from `left`. Used to compute the new available-balance ciphertext

0 commit comments

Comments
 (0)