Skip to content

Commit

Permalink
fixe comments and correct contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
kKahina committed Sep 2, 2024
1 parent 631d017 commit 009fe48
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ export const generateProofBoilerplate = (node: any) => {
!output.join().includes(`${para}.integer`) && !output.join().includes('msgValue')),
)



?.forEach((param: string) => {
if (param == 'msgSender') {
parameters.unshift(`\t${param}.integer,`);
Expand Down
7 changes: 1 addition & 6 deletions src/codeGenerators/orchestration/nodejs/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export default function codeGenerator(node: any, options: any = {}): any {
if (!node.incrementsSecretState && (node.interactsWithSecret || node.expression?.internalFunctionInteractsWithSecret)){
return `\n${codeGenerator(node.expression)};`;
}

if (node.incrementsSecretState && (node.interactsWithSecret ||node.containsPublic || node.expression?.internalFunctionInteractsWithSecret)){
let privateStateName = node.privateStateName.replace(/\./g, '_');
let increments;
Expand Down Expand Up @@ -174,17 +173,13 @@ export default function codeGenerator(node: any, options: any = {}): any {

if (!node.isInitializationAssignment && node.rightHandSide.subType !== 'generalNumber'){
if (['+=', '-=', '*='].includes(node.operator)) {

return `${codeGenerator(node.leftHandSide, {
lhs: true,
})} = generalise(${codeGenerator(node.leftHandSide)} ${node.operator.charAt(
0,
)} ${codeGenerator(node.rightHandSide)})`;

}


return `${codeGenerator(node.leftHandSide, { lhs: true })} ${
return `${codeGenerator(node.leftHandSide, { lhs: true })} ${
node.operator
} generalise(${codeGenerator(node.rightHandSide)})`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const markIndicatorSubtreeInteractsWithSecret = (thisPath: any, thisState: any)
indicator.addSecretInteractingPath(thisState.secretPath);
};

const interactwithPublicSecret = (thisPath: any, thisState: any) => {
const interactwithInferSecret = (thisPath: any, thisState: any) => {
const { node, scope } = thisPath;
if (node.nodeType === 'ExpressionStatement') {
const leftHandSideIndicator = scope.getReferencedIndicator(node.expression.leftHandSide, true);
Expand Down Expand Up @@ -76,7 +76,7 @@ export default {

FunctionDefinition: {
exit(path: NodePath) {
path.traversePathsFast(interactwithPublicSecret, {
path.traversePathsFast(interactwithInferSecret, {
publicPath: path,
});
},
Expand Down
1 change: 0 additions & 1 deletion src/transformers/visitors/toContractVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => {
) {
thisState.customInputs ??= [];
const type = binding.node.typeName.nodeType === 'Mapping' ? binding.node.typeName.valueType.name : binding.node.typeName.name;

const isConstantArray = thisPath.isConstantArray();
const arrayLength = isConstantArray && thisPath.node.typeName?.length ? thisPath.node.typeName.length.value : false;

Expand Down
16 changes: 3 additions & 13 deletions src/transformers/visitors/toOrchestrationVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ const addPublicInput = (path: NodePath, state: any, IDnode: any) => {
const { node } = path;

let { name } = path.scope.getReferencedIndicator(node, true) || path.node;
// if (name.includes('[') && name.includes(']')) {
// name = name.replace(/\[|\]/g, '_');
// }
name = name.replace(/\[([^\]]+)\]/g, '_$1');

name = name.replace(/\[([^\]]+)\]/g, '_$1');

// Ensure there is no trailing underscore
if (name.endsWith('_')) {
Expand Down Expand Up @@ -172,9 +170,7 @@ if (name.endsWith('_')) {
isAccessed: true,
isSecret: false,
})
}

else {
} else {
innerNode = buildNode('VariableDeclaration', {
name,
isAccessed: true,
Expand Down Expand Up @@ -331,7 +327,6 @@ if (name.endsWith('_')) {
}
});


//We ensure here that the public variable used has the correct name, e.g index_2 instead of index.
if(IDnode) {
if (num_modifiers != 0) {
Expand All @@ -343,8 +338,6 @@ if (name.endsWith('_')) {
}
}



// After the non-secret variables have been modified we need to reset the original variable name to its initial value.
// e.g. index = index_init.

Expand Down Expand Up @@ -987,23 +980,20 @@ const visitor = {
}

// this adds other values we need in the circuit

for (const param of node._newASTPointer.parameters.parameters) {
let oldParam : any ;
for(const para of node.parameters.parameters) {
if ( para?.name === param?.name )
oldParam = para ;
break;
}

if (param.isPrivate || param.isSecret || param.interactsWithSecret || scope.getReferencedIndicator(oldParam)?.interactsWithSecret) {
if (param.typeName.isStruct) {
param.typeName.properties.forEach((prop: any) => {
newNodes.generateProofNode.parameters.push(`${param.name}.${prop.name}${param.typeName.isConstantArray ? '.all' : ''}`);
});
} else newNodes.generateProofNode.parameters.push(`${param.name}${param.typeName.isConstantArray ? '.all' : ''}`);
}

}
if (state.publicInputs) {
state.publicInputs.forEach((input: any) => {
Expand Down
3 changes: 0 additions & 3 deletions src/traverse/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ export class Scope {
: indicator;
}


//if (path.isConstantArray(referencingNode) && referencingNode.nodeType === 'variableDeclaration') return null;
if ((path.isConstantArray(referencingNode) || referencingNode.memberName === 'length') && !NodePath.getPath(referencingNode).getAncestorOfType('IndexAccess')) return indicator;

// getMappingKeyName requires an indexAccessNode - referencingNode may be a baseExpression or indexExpression contained Identifier
Expand All @@ -445,7 +443,6 @@ export class Scope {
: indicator;
}


/**
* @returns {Node || null} - the node (VariableDeclaration) being referred-to by the input referencingNode.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Arrays-input.zol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
contract Assign {

secret uint256 private a;
uint256[6] public b;
uint256[5] public b;


function add(secret uint256[5] calldata value, uint256[5] calldata publicValue) public {
Expand Down
39 changes: 0 additions & 39 deletions test/contracts/Boolean-public.zol

This file was deleted.

8 changes: 8 additions & 0 deletions test/contracts/Non-Secret-Array.zol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ uint256 public index;
uint256[3] public c;


function add( uint256 value) public {
c[index] += value;
}

function add1( uint256 value) public {
c[index] += value;
known a += c[index];
}

function add2( uint256 value) public {
c[index] += value;
known a += value;
}

}

0 comments on commit 009fe48

Please sign in to comment.