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

Added a fix for stack-too deep error #226

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,6 @@ class FunctionBoilerplateGenerator {
customInputs = customInputs?.flat(Infinity).filter(p => p.inCircuit);

return [
`
Inputs memory inputs;`,

...(customInputs?.length ?
[`
inputs.customInputs = new uint[](${customInputs.flat(Infinity).length});
${customInputs.flat(Infinity).map((input: any, i: number) => {
if (input.type === 'address') return `inputs.customInputs[${i}] = uint256(uint160(address(${input.name})));`;
if (input.type === 'bool' && !['0', '1'].includes(input.name)) return `inputs.customInputs[${i}] = ${input.name} == false ? 0 : 1;`;
return `inputs.customInputs[${i}] = ${input.name};`;
}).join('\n')}`]
: []),

...(newNullifiers ? [`
inputs.nullifierRoot = nullifierRoot; `] : []),

...(newNullifiers ? [`
inputs.latestNullifierRoot = latestNullifierRoot; `] : []),


...(newNullifiers ? [`
inputs.newNullifiers = newNullifiers;
`] : []),

...(commitmentRoot ? [`
inputs.commitmentRoot = commitmentRoot;`] : []),

...(newCommitments ? [`
inputs.newCommitments = newCommitments;`] : []),

...(encryptionRequired ? [`
inputs.cipherText = cipherText;`] : []),

...(encryptionRequired ? [`
inputs.encKeys = ephPubKeys;`] : []),
`
${msgSigCheck.join('\n')}`,
`
verify(proof, uint(FunctionNames.${functionName}), inputs);`,

Expand Down
21 changes: 10 additions & 11 deletions src/boilerplate/orchestration/javascript/raw/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,11 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
if (node.publicInputs[0]) {
node.publicInputs.forEach((input: any) => {
if (input.properties) {
lines.push(`[${input.properties.map(p => `${input.name}${input.isConstantArray ? '.all' : ''}.${p}.integer`).join(',')}]`)
lines.push(`customInputs: [${input.properties.map(p => `${input.name}${input.isConstantArray ? '.all' : ''}.${p}.integer`).join(',')}]`)
} else if (input.isConstantArray) {
lines.push(`${input.name}.all.integer`);
lines.push(`customInputs: ${input.name}.all.integer`);
} else {
lines.push(`${input}.integer`);
lines.push(`customInputs: ${input}.integer`);
}
});
lines[lines.length - 1] += `, `;
Expand All @@ -806,12 +806,12 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
// 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][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 (params[0][0][0]) params[0][0] = `nullifierRoot: ${params[0][0][0]},latestNullifierRoot:${params[0][0][1]},`; // nullifierRoot - array
if (params[0][2][0]) params[0][2] = `commitmentRoot: ${params[0][2][0]},`; // commitmentRoot - array
if (params[0][1][0]) params[0][1] = `newNullifiers: [${params[0][1]}],`; // nullifiers - array
if (params[0][3][0]) params[0][3] = `newCommitments: [${params[0][3]}],`; // commitments - array
if (params[0][4][0]) params[0][4] = `cipherText: [${params[0][4]}],`; // cipherText - array of arrays
if (params[0][5][0]) params[0][5] = `encKeys: [${params[0][5]}],`; // cipherText - array of arrays


if (node.functionName === 'cnstrctr') return {
Expand All @@ -820,12 +820,11 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
\nconst tx = { proofInput: [${params[0][0]}${params[0][1]} ${params[0][2]} ${params[0][3]} proof], ${node.publicInputs?.map(input => `${input}: ${input}.integer,`)}};`
]
}

return {
statements: [
`\n\n// Send transaction to the blockchain:
\nconst txData = await instance.methods
.${node.functionName}(${lines}${params[0][0]} ${params[0][1]} ${params[0][2]} ${params[0][3]} ${params[0][4]} ${params[0][5]} proof).encodeABI();
.${node.functionName}({${lines} ${params[0][0]}${params[0][1]}${params[0][2]}${params[0][3]}${params[0][4]}${params[0][5]}}, proof).encodeABI();
\n let txParams = {
from: config.web3.options.defaultAccount,
to: contractAddr,
Expand Down
6 changes: 3 additions & 3 deletions src/codeGenerators/contract/solidity/toContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function codeGenerator(node: any) {

}

const functionSignature = `${functionType} (${codeGenerator(node.parameters)}) ${node.visibility} ${node.stateMutability} {`;
const functionSignature = `${functionType} (Inputs calldata inputs, uint256[] calldata proof) ${node.visibility} ${node.stateMutability} {`;
let body = codeGenerator(node.body);
let msgSigCheck = body.slice(body.indexOf('bytes4 sig'), body.indexOf('verify') )
if(!node.msgSigRequired)
Expand Down Expand Up @@ -197,8 +197,8 @@ function codeGenerator(node: any) {
case 'InternalFunctionCall' :{
if(node.parameters ){
if(node.internalFunctionInteractsWithSecret)
return `\t \t \t \t ${node.name} (${node.parameters});`
return `\t \t \t \t ${node.name} (${node.parameters.map(codeGenerator)});`
return `\t \t \t \t ${node.name} (inputs, proof);`
return `\t \t \t \t ${node.name} (inputs, proof);`
} else {
const args = node.arguments.map(codeGenerator);
return `\t \t \t \t${node.name} (${args.join(', ')});`
Expand Down
Loading