Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lydia/bugs in InternalFunctionCall4 (formerly named InternalFunctionCall2) #267

Merged
merged 24 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2d60350
Bugs in InternalFunctionCallTest
lydiagarms May 13, 2024
89498ae
fix: bug for internal function calls where non-secret parameters that…
lydiagarms May 13, 2024
70ea52c
fix: zappify bug in git testing
lydiagarms May 14, 2024
b6f4ba8
fix: create error message when a function calls internal functions th…
lydiagarms May 14, 2024
0900e2e
fix: zappify errors
lydiagarms May 14, 2024
53d8faa
fix: zappify errors for InternalFunctionCalls
lydiagarms May 14, 2024
e430c46
fix: bugs relating to internal function calls that use the same secre…
lydiagarms May 17, 2024
79093b4
fix: bug in orchestration due to multiple internal function calls mod…
lydiagarms May 17, 2024
c40cd6e
fix: error in circuits for internal function calls the wrong paramete…
lydiagarms May 17, 2024
da3d167
fix: errors in contract when mutliple internal function calls uses th…
lydiagarms May 17, 2024
2485ccd
fix: circuit compilation error because the nullifier is input to the …
lydiagarms May 20, 2024
6e94ae2
fix: zappify error due to null entries being created in statements list
lydiagarms May 20, 2024
5c5db4d
fix: logic for circuit imports due to Internal Function calls
lydiagarms May 22, 2024
cc9af07
fix: zappify bug and compilation error due to postStatements in the w…
lydiagarms May 23, 2024
f7bad6c
fix: order of statements in orchestration and declaration of non-acce…
lydiagarms May 23, 2024
7c4d2d9
fix: ordering of statements in circuits for internal function calls w…
lydiagarms May 23, 2024
d0353f5
fix: bug meaning that function names were not appearing in contract b…
lydiagarms May 24, 2024
0415c4c
fix: error in contract due to internal function calls that interact w…
lydiagarms May 24, 2024
838924d
fix: in the circuit when internal functions are not imported the impo…
lydiagarms May 24, 2024
6c5a61a
fix issue due to root appearing twice in mjs file
lydiagarms May 28, 2024
2d65562
fix: issue due to nullifier root and commitment root in wrong order i…
lydiagarms May 28, 2024
bf5e2ef
fix: error introduced in for-InternalFunctionCall due to double varia…
lydiagarms May 29, 2024
458744e
finalise test contracts and add comments
lydiagarms May 29, 2024
a29fa6d
comment
lydiagarms May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -219,7 +221,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 @@ -814,16 +820,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
Loading