From 80915e920ebc1a1a54666befdd94b0124d08b7b9 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Mon, 25 Sep 2023 16:08:00 -0400 Subject: [PATCH] code cleanup --- contracts/contracts/FundingRound.sol | 8 +++---- contracts/tests/round.ts | 4 ++-- contracts/utils/maci.ts | 31 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/contracts/contracts/FundingRound.sol b/contracts/contracts/FundingRound.sol index 88864c2df..927530ccc 100644 --- a/contracts/contracts/FundingRound.sol +++ b/contracts/contracts/FundingRound.sol @@ -640,8 +640,8 @@ contract FundingRound is Ownable, SignUpGatekeeper, InitialVoiceCreditProxy, Dom uint256[] calldata _voteOptionIndices, uint256[] calldata _tallyResults, uint256[][][] calldata _tallyResultProofs, - uint256[] calldata _spentVoiceCreditsHashes, - uint256[] calldata _perVOSpentVoiceCreditsHashes, + uint256 _spentVoiceCreditsHashes, + uint256 _perVOSpentVoiceCreditsHashes, uint256 _tallyCommitment ) external @@ -660,8 +660,8 @@ contract FundingRound is Ownable, SignUpGatekeeper, InitialVoiceCreditProxy, Dom _voteOptionIndices[i], _tallyResults[i], _tallyResultProofs[i], - _spentVoiceCreditsHashes[i], - _perVOSpentVoiceCreditsHashes[i], + _spentVoiceCreditsHashes, + _perVOSpentVoiceCreditsHashes, _tallyCommitment ); } diff --git a/contracts/tests/round.ts b/contracts/tests/round.ts index e6c1fedf1..3d489525b 100644 --- a/contracts/tests/round.ts +++ b/contracts/tests/round.ts @@ -1560,7 +1560,7 @@ describe('Funding Round', () => { smallTallyTestData, batchSize ) - expect(data).to.have.lengthOf(7) + expect(data).to.have.lengthOf(3) expect(data[1]).to.have.lengthOf(5) }) } @@ -1571,7 +1571,7 @@ describe('Funding Round', () => { smallTallyTestData, batchSize ) - expect(data).to.have.lengthOf(7) + expect(data).to.have.lengthOf(3) expect(data[1]).to.have.lengthOf(1) }) it(`should fail with startIndex ${total}`, () => { diff --git a/contracts/utils/maci.ts b/contracts/utils/maci.ts index 73a147e21..054917347 100644 --- a/contracts/utils/maci.ts +++ b/contracts/utils/maci.ts @@ -166,7 +166,7 @@ export function getRecipientTallyResult( recipientIndex: number, recipientTreeDepth: number, tally: any -): any[] { +): { recipientIndex: number; result: string; proof: any[] } { // Create proof for tally result const result = tally.results.tally[recipientIndex] const resultTree = new IncrementalQuinTree( @@ -179,12 +179,11 @@ export function getRecipientTallyResult( resultTree.insert(leaf) } const resultProof = resultTree.genMerklePath(recipientIndex) - return [ - recipientTreeDepth, + return { recipientIndex, result, - resultProof.pathElements.map((x) => x.map((y) => y.toString())), - ] + proof: resultProof.pathElements.map((x) => x.map((y) => y.toString())), + } } export function getRecipientTallyResultsBatch( @@ -208,10 +207,9 @@ export function getRecipientTallyResultsBatch( } return [ - recipientTreeDepth, - tallyData.map((item) => item[1]), - tallyData.map((item) => item[2]), - tallyData.map((item) => item[3]), + tallyData.map((item) => item.recipientIndex), + tallyData.map((item) => item.result), + tallyData.map((item) => item.proof), ] } @@ -242,11 +240,13 @@ export async function addTallyResultsBatch( BigInt(tallyData.results.salt), recipientTreeDepth ) - const newTallyCommitment = hash3( + + const newTallyCommitment = hash3([ newResultCommitment, spentVoiceCreditsHash, - perVOSpentVoiceCreditsHash - ) + perVOSpentVoiceCreditsHash, + ]) + if ('0x' + newTallyCommitment.toString(16) === tallyData.newTallyCommitment) { console.log('OK') } else { @@ -262,10 +262,11 @@ export async function addTallyResultsBatch( ) const tx = await fundingRound.addTallyResultsBatch( + recipientTreeDepth, ...data, - '0x' + BigInt(spentVoiceCreditsHash).toString(16), - '0x' + BigInt(perVOSpentVoiceCreditsHash).toString(16), - tally.newTallyCommitment + BigInt(spentVoiceCreditsHash).toString(), + BigInt(perVOSpentVoiceCreditsHash).toString(), + tallyData.newTallyCommitment ) const receipt = await tx.wait() if (callback) {