Skip to content

Commit

Permalink
fix: errors in contract when mutliple internal function calls uses th…
Browse files Browse the repository at this point in the history
…e same secret state
  • Loading branch information
lydiagarms committed May 17, 2024
1 parent c40cd6e commit da3d167
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class ContractBoilerplateGenerator {
newCommitments: 0,
encryption: 0,
};

_inputs.map(i => verifyInputsMap(type, i, counter));


Expand Down
18 changes: 17 additions & 1 deletion src/transformers/visitors/toContractVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ export default {
state.circuitParams ??= {};
state.circuitParams[path.getUniqueFunctionName()] ??= {};
state.circuitParams[path.getUniqueFunctionName()].parameters = circuitParams;
// Delete repeated circuit parameters
let deletedIndexes = [];
state.circuitParams[path.getUniqueFunctionName()].parameters.forEach((circParam1, index1) => {
state.circuitParams[path.getUniqueFunctionName()].parameters.forEach((circParam2, index2) => {
if (circParam1.bpType === 'nullification' && circParam2.bpType === 'nullification' && circParam1.name === circParam2.name && index1 > index2) {
deletedIndexes.push(index1);
}
if (circParam1.bpType === 'newCommitment' && circParam2.bpType === 'newCommitment' && circParam1.name === circParam2.name && index1 > index2) {
deletedIndexes.push(index1);
}
});
});
deletedIndexes = [...new Set(deletedIndexes)];
deletedIndexes.sort((a, b) => b - a);
deletedIndexes.forEach(index => {
state.circuitParams[path.getUniqueFunctionName()].parameters.splice(index, 1);
});
},

exit(path: NodePath, state: any) {
Expand Down Expand Up @@ -901,7 +918,6 @@ DoWhileStatement: {
...(internalfnDefIndicators.nullifiersRequired? [`newNullifiers`] : []),
...(internalfnDefIndicators.oldCommitmentAccessRequired ? [`commitmentRoot`] : []),
...(internalfnDefIndicators.newCommitmentsRequired ? [`newCommitments`] : []),
...(internalfnDefIndicators.containsAccessedOnlyState ? [`checkNullifiers`] : []),
...(internalfnDefIndicators.encryptionRequired ? [`cipherText`] : []),
...(internalfnDefIndicators.encryptionRequired ? [`ephPubKeys`] : []),
`proof`,
Expand Down

0 comments on commit da3d167

Please sign in to comment.