Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Sep 25, 2023
1 parent 2b83328 commit 80915e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions contracts/contracts/FundingRound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -660,8 +660,8 @@ contract FundingRound is Ownable, SignUpGatekeeper, InitialVoiceCreditProxy, Dom
_voteOptionIndices[i],
_tallyResults[i],
_tallyResultProofs[i],
_spentVoiceCreditsHashes[i],
_perVOSpentVoiceCreditsHashes[i],
_spentVoiceCreditsHashes,
_perVOSpentVoiceCreditsHashes,
_tallyCommitment
);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/tests/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand All @@ -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}`, () => {
Expand Down
31 changes: 16 additions & 15 deletions contracts/utils/maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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),
]
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 80915e9

Please sign in to comment.