Skip to content

Commit

Permalink
Merge pull request #267 from EYBlockchain/lydia/bugIFCT2
Browse files Browse the repository at this point in the history
Lydia/bugs in InternalFunctionCall4 (formerly named InternalFunctionCall2)
  • Loading branch information
SwatiEY authored Jun 10, 2024
2 parents 17f8e50 + a29fa6d commit 5ae4310
Show file tree
Hide file tree
Showing 20 changed files with 813 additions and 235 deletions.
6 changes: 3 additions & 3 deletions src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class BoilerplateGenerator {
if(isAccessed && !isNullified)
lines = [
`
// Create the Nullifier for ${x} and no need to nnullify it as its accessed only:
// Create the Nullifier for ${x} and no need to nullify it as its accessed only:
field ${x}_oldCommitment_nullifier = poseidon([\\
field ${x}_oldCommitment_nullifier_check_field = poseidon([\\
${x}_stateVarId_field,\\
${x}_oldCommitment_owner_secretKey,\\
${x}_oldCommitment_salt\\
Expand All @@ -137,7 +137,7 @@ class BoilerplateGenerator {
assert(\\
nullifierRoot == checkproof(\\
${x}_nullifier_nonmembershipWitness_siblingPath,\\
${x}_oldCommitment_nullifier\\
${x}_oldCommitment_nullifier_check_field\\
)\
)
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class ContractBoilerplateGenerator {
scope : Scope;
constructor(scope: Scope) {
if (bpCache.has(scope)) return bpCache.get(scope);

this.scope = scope;

bpCache.set(scope, this);
}

Expand Down Expand Up @@ -80,7 +78,7 @@ class ContractBoilerplateGenerator {
indicators: { nullifiersRequired, oldCommitmentAccessRequired, newCommitmentsRequired, containsAccessedOnlyState, encryptionRequired },
} = scope;
const fnDefBindings = scope.filterBindings(
(b: any) => b.kind === 'FunctionDefinition' && b.path.containsSecret,
(b: any) => b.kind === 'FunctionDefinition' && (b.path.containsSecret || b.path.scope.indicators.internalFunctionInteractsWithSecret),
);
let functionNames = Object.values(fnDefBindings).map((b: any) => b.path.getUniqueFunctionName());
if (isjoinSplitCommitmentsFunction.includes('true')) {
Expand Down Expand Up @@ -130,9 +128,11 @@ class ContractBoilerplateGenerator {
params?.forEach(circuitParamNode => {
switch (circuitParamNode.bpType) {
case 'nullification':
if (!newList.includes('nullifierRoot'))
newList.push('nullifierRoot');
if (circuitParamNode.isNullified) {
if (!newList.includes('nullifierRoot'))
newList.push('nullifierRoot')
if (!newList.includes('newNullifierRoot'))
newList.push('newNullifierRoot');
newList.push('nullifier');

}
Expand Down Expand Up @@ -177,7 +177,7 @@ class ContractBoilerplateGenerator {
}
circuitParams[ functionName ] = parameterList;
}
const constructorContainsSecret = Object.values(this.scope.bindings).some((binding: any) => binding.node.kind === 'constructor')
const constructorContainsSecret = Object.values(this.scope.bindings).some((binding: any) => binding.node.kind === 'constructor');
return { nullifiersRequired, oldCommitmentAccessRequired, newCommitmentsRequired, containsAccessedOnlyState, encryptionRequired, constructorContainsSecret, circuitParams, isjoinSplitCommitmentsFunction};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class ContractBoilerplateGenerator {
switch (input) {
case 'nullifierRoot':
verifyInput.push( `
inputs[k++] = _inputs.nullifierRoot;`);
inputs[k++] = _inputs.nullifierRoot;`);
break;
case 'newNullifierRoot':
verifyInput.push( `
inputs[k++] = _inputs.latestNullifierRoot;`);
break;
Expand Down Expand Up @@ -220,7 +222,6 @@ class ContractBoilerplateGenerator {
newCommitments: 0,
encryption: 0,
};

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class BoilerplateGenerator {
burnedOnly,
accessedOnly,
nullifierRootRequired,
newNullifierRootRequired,
initialisationRequired,
encryptionRequired,
rootRequired,
Expand Down Expand Up @@ -466,7 +467,7 @@ class BoilerplateGenerator {
\tsecretKey.integer,
\tsecretKey.integer,
${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``}
${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
${newNullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
\t${stateName}_0_nullifier.integer,
\t${stateName}_0_nullifier_path.integer,
\t${stateName}_0_nullifier_updatedpath.integer,
Expand Down Expand Up @@ -501,7 +502,7 @@ class BoilerplateGenerator {
${parameters.join('\n')}${stateVarIds.join('\n')}
\tsecretKey.integer,
${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``}
${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
${newNullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
\t${stateName}_nullifier.integer,
\t${stateName}_nullifier_path.integer,
\t${stateName}_nullifier_updatedpath.integer,
Expand Down Expand Up @@ -529,7 +530,7 @@ class BoilerplateGenerator {
${parameters.join('\n')}${stateVarIds.join('\n')}
\t${stateName}_commitmentExists ? secretKey.integer: generalise(0).integer,
${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``}
${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
${newNullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``}
\t${stateName}_nullifier.integer,
\t${stateName}_nullifier_path.integer,
\t${stateName}_nullifier_updatedpath.integer,
Expand Down
34 changes: 19 additions & 15 deletions src/boilerplate/orchestration/javascript/raw/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ export const sendTransactionBoilerplate = (node: any) => {
break;
case false:
default:
// whole
// whole
if (!stateNode.reinitialisedOnly)
output[2].push(`${privateStateName}_root.integer`);
if (!stateNode.accessedOnly && !stateNode.reinitialisedOnly) {
output[1].push(`${privateStateName}_nullifier.integer`);
output[0].push(`${privateStateName}_nullifierRoot.integer`,`${privateStateName}_newNullifierRoot.integer`);
}
if (!stateNode.accessedOnly && !stateNode.burnedOnly)
output[3].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
}
if (!stateNode.accessedOnly && !stateNode.reinitialisedOnly) {
output[1].push(`${privateStateName}_nullifier.integer`);
output[0].push(`${privateStateName}_nullifierRoot.integer`,`${privateStateName}_newNullifierRoot.integer`);
}
if (!stateNode.accessedOnly && !stateNode.burnedOnly)
output[3].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
}

break;
}
Expand All @@ -117,6 +117,7 @@ export const generateProofBoilerplate = (node: any) => {
const cipherTextLength: number[] = [];
let containsRoot = false;
let containsNullifierRoot = false;
let containsNewNullifierRoot = false;
const privateStateNames = Object.keys(node.privateStates);
let stateName: string;
let stateNode: any;
Expand Down Expand Up @@ -181,13 +182,15 @@ export const generateProofBoilerplate = (node: any) => {
burnedOnly: stateNode.burnedOnly,
accessedOnly: stateNode.accessedOnly,
nullifierRootRequired: !containsNullifierRoot,
newNullifierRootRequired: !containsNewNullifierRoot,
initialisationRequired: stateNode.initialisationRequired,
encryptionRequired: stateNode.encryptionRequired,
rootRequired: !containsRoot,
parameters,
})
);
if(stateNode.nullifierRequired) containsNullifierRoot = true;
if(stateNode.nullifierRequired || stateNode.accessedOnly) containsNullifierRoot = true;
if(stateNode.nullifierRequired) containsNewNullifierRoot = true;
if (!stateNode.reinitialisedOnly) containsRoot = true;
break;

Expand Down Expand Up @@ -216,6 +219,7 @@ export const generateProofBoilerplate = (node: any) => {
reinitialisedOnly: false,
burnedOnly: false,
nullifierRootRequired: !containsNullifierRoot,
newNullifierRootRequired: !containsNewNullifierRoot,
initialisationRequired: false,
encryptionRequired: stateNode.encryptionRequired,
rootRequired: !containsRoot,
Expand All @@ -224,6 +228,7 @@ export const generateProofBoilerplate = (node: any) => {
})
);
containsNullifierRoot = true;
containsNewNullifierRoot = true;
containsRoot = true;
break;
case false:
Expand All @@ -247,6 +252,7 @@ export const generateProofBoilerplate = (node: any) => {
reinitialisedOnly: false,
burnedOnly: false,
nullifierRootRequired: false,
newNullifierRootRequired: false,
initialisationRequired: false,
encryptionRequired: stateNode.encryptionRequired,
rootRequired: false,
Expand Down Expand Up @@ -817,16 +823,14 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
// params[1] = arr of commitment root(s)
// params[2] = arr of nullifiers
// params[3] = arr of commitments


if (params[0][0][0]) params[0][0] = `${params[0][0][0]},${params[0][0][1]},`; // nullifierRoot - array
if (params[0][0][0]) params[0][0] = `${params[0][0][0]},${params[0][0][1]},`; // nullifierRoot - array
if (params[0][2][0]) params[0][2] = `${params[0][2][0]},`; // commitmentRoot - array
if (params[0][1][0]) params[0][1] = `[${params[0][1]}],`; // nullifiers - array
if (params[0][3][0]) params[0][3] = `[${params[0][3]}],`; // commitments - array
if (params[0][4][0]) params[0][4] = `[${params[0][4]}],`; // cipherText - array of arrays
if (params[0][5][0]) params[0][5] = `[${params[0][5]}],`; // cipherText - array of arrays


if (node.functionName === 'cnstrctr') return {
statements: [
`\n\n// Save transaction for the constructor:
Expand Down
6 changes: 4 additions & 2 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export default function codeGenerator(node: any, options: any = {}): any {
return `${getAccessedValue(node.declarations[0].name)}`;
}

if (
if (!node.initialValue && !node.declarations[0].isAccessed) return `\nlet ${codeGenerator(node.declarations[0])};`;
if (node.initialValue &&
node.initialValue.operator &&
!node.initialValue.operator.includes('=')
)
Expand All @@ -117,8 +118,9 @@ export default function codeGenerator(node: any, options: any = {}): any {
}

case 'ExpressionStatement':
if (!node.incrementsSecretState && node.interactsWithSecret)
if (!node.incrementsSecretState && (node.interactsWithSecret || node.expression?.internalFunctionInteractsWithSecret)){
return `\n${codeGenerator(node.expression)};`;
}
if (!node.interactsWithSecret)
return `\n// non-secret line would go here but has been filtered out`;
return `\n// increment would go here but has been filtered out`;
Expand Down
Loading

0 comments on commit 5ae4310

Please sign in to comment.