From dc8a3b27c425c57ba6de49c9657074a906586277 Mon Sep 17 00:00:00 2001 From: msinkec Date: Fri, 27 Oct 2023 20:35:18 +0200 Subject: [PATCH] Update elgamal syntax. --- src/contracts/elGamalHE.ts | 7 ++++--- tests/elGamalHE.test.ts | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/contracts/elGamalHE.ts b/src/contracts/elGamalHE.ts index 0d819da0..543baa39 100644 --- a/src/contracts/elGamalHE.ts +++ b/src/contracts/elGamalHE.ts @@ -8,17 +8,17 @@ export type CT = { export class ElGamalHE extends SmartContract { @prop(true) - salarySum: CT + expenseSum: CT constructor(salarySum: CT) { super(...arguments) - this.salarySum = salarySum + this.expenseSum = salarySum } @method() public add(toAdd: CT) { // Add encrypted value to the total sum. - this.salarySum = ElGamalHE.addCT(this.salarySum, toAdd) + this.expenseSum = ElGamalHE.addCT(this.expenseSum, toAdd) const outputs = this.buildStateOutput(this.ctx.utxo.value) + @@ -26,6 +26,7 @@ export class ElGamalHE extends SmartContract { assert(hash256(outputs) == this.ctx.hashOutputs, 'hashOutputs mismatch') } + // Add homomorphicly. @method() static addCT(ct0: CT, ct1: CT): CT { const res: CT = { diff --git a/tests/elGamalHE.test.ts b/tests/elGamalHE.test.ts index 504499d9..a646e6e0 100644 --- a/tests/elGamalHE.test.ts +++ b/tests/elGamalHE.test.ts @@ -50,10 +50,10 @@ describe('Heavy: Test SmartContract `ElGamalHE`', () => { const Q = SECP256K1.pubKey2Point(PubKey(pub.toByteString())) // Encrypt initial value of 0. - const [salarySum] = encryptNumber(0n, Q) + const [expenseSum] = encryptNumber(0n, Q) // Instantiate and deploy contract. - const instance = new ElGamalHE(salarySum) + const instance = new ElGamalHE(expenseSum) await instance.connect(getDefaultSigner()) await instance.deploy(1) @@ -66,8 +66,8 @@ describe('Heavy: Test SmartContract `ElGamalHE`', () => { // Add encrypted amount (100) to the total sum of the contract. const [toAdd] = encryptNumber(100n, Q) - nextInstance.salarySum = ElGamalHE.addCT( - currentInstance.salarySum, + nextInstance.expenseSum = ElGamalHE.addCT( + currentInstance.expenseSum, toAdd ) @@ -85,7 +85,7 @@ describe('Heavy: Test SmartContract `ElGamalHE`', () => { } // Decrypt and check end result. - const mG = decrypt(currentInstance.salarySum, k) + const mG = decrypt(currentInstance.expenseSum, k) const _mG = SECP256K1.mulByScalar(SECP256K1.G, 500n) expect(mG.x === _mG.x && mG.y === _mG.y).to.be.true