Skip to content

Commit

Permalink
fix: generalise whole state after editing statements
Browse files Browse the repository at this point in the history
  • Loading branch information
MirandaWood committed Mar 16, 2022
1 parent 8782ac9 commit 688f2ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
lines[0] = preimageBoilerPlate(node);
for ([stateName, stateNode] of Object.entries(node.privateStates)) {
if (stateNode.accessedOnly) {
// if the state is only accessed, we need to initalise it here before statements
params.push(
`\nconst ${stateName} = generalise(${stateName}_preimage.${stateName});`,
);
} else if (stateNode.isWhole)
params.push(`\n${stateName} = generalise(${stateName});`);
}
}
return {
statements: [`${params.join('\n')}`, lines[0].join('\n')],
Expand Down
2 changes: 2 additions & 0 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export default function codeGenerator(node: any, options: any = {}): any {
return `parseInt(${node.name}.integer, 10)`;
case 'address':
return `${node.name}.integer`;
case 'generalNumber':
return `generalise(${node.name})`;
}

case 'Folder':
Expand Down
13 changes: 12 additions & 1 deletion src/transformers/visitors/toOrchestrationVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,17 @@ export default {
});
}
if (stateVarIndicator.isModified) {
if (stateVarIndicator.isWhole) {
// if we have a modified whole state, we must generalise it before postStatements
node._newASTPointer.body.statements.push(
buildNode('Assignment', {
leftHandSide: buildNode('Identifier', { name }),
operator: '=',
rightHandSide: buildNode('Identifier', { name, subType: 'generalNumber' })
}
)
);
}
newNodes.generateProofNode.privateStates[
name
] = buildPrivateStateNode('GenerateProof', {
Expand Down Expand Up @@ -489,7 +500,7 @@ export default {
accessedOnly: true,
});
}
const newFunctionDefinitionNode = node._newASTPointer;
const newFunctionDefinitionNode = node._newASTPointer;

// this adds other values we need in the circuit
for (const param of node._newASTPointer.parameters.parameters) {
Expand Down

0 comments on commit 688f2ae

Please sign in to comment.