Skip to content

Commit

Permalink
fix: in orchestration nullifierRoot is sent as a newNullifierRoot in …
Browse files Browse the repository at this point in the history
…SendTransaction
  • Loading branch information
lydiagarms committed Jul 31, 2024
1 parent 301261b commit 4bcae06
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions src/boilerplate/orchestration/javascript/raw/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ const stateVariableIds = (node: any) => {
const Orchestrationbp = new OrchestrationBP();
export const sendTransactionBoilerplate = (node: any) => {
const { privateStates } = node;
const output: string[][] = [[],[],[],[],[],[]];
const output: string[][] = [[],[],[],[],[],[],[]];
// output[0] = nullifier root(s)
// output[1] = arr of nullifiers
// output[2] = commitments root(s)
// output[3] = arr of commitments
// output[4] = arr of cipherText
// output[5] = arr of enc keys
// output[1] = nullifier root(s)
// output[2] = arr of nullifiers
// output[3] = commitments root(s)
// output[4] = arr of commitments
// output[5] = arr of cipherText
// output[6] = arr of enc keys
let privateStateName: string;
let stateNode: any;
for ([privateStateName, stateNode] of Object.entries(privateStates)) {
Expand All @@ -71,20 +72,21 @@ export const sendTransactionBoilerplate = (node: any) => {
switch (stateNode.nullifierRequired) {
case true:
// decrement
output[2].push(`${privateStateName}_root.integer`);
output[0].push(`${privateStateName}_nullifierRoot.integer`, `${privateStateName}_newNullifierRoot.integer`);
output[1].push(
output[3].push(`${privateStateName}_root.integer`);
output[0].push(`${privateStateName}_nullifierRoot.integer`);
output[1].push(`${privateStateName}_newNullifierRoot.integer`);
output[2].push(
`${privateStateName}_0_nullifier.integer, ${privateStateName}_1_nullifier.integer`,
);
output[3].push(`${privateStateName}_2_newCommitment.integer`);
output[4].push(`${privateStateName}_2_newCommitment.integer`);
break;
case false:
default:
// increment
output[3].push(`${privateStateName}_newCommitment.integer`);
output[4].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
output[5].push(`${privateStateName}_cipherText`);
output[6].push(`${privateStateName}_encKey`);
}
break;
}
Expand All @@ -93,19 +95,19 @@ export const sendTransactionBoilerplate = (node: any) => {
default:
// whole
if (!stateNode.reinitialisedOnly)
output[2].push(`${privateStateName}_root.integer`);
output[3].push(`${privateStateName}_root.integer`);
if (!stateNode.reinitialisedOnly) {
output[0].push(`${privateStateName}_nullifierRoot.integer`)
if (!stateNode.accessedOnly) {
output[1].push(`${privateStateName}_nullifier.integer`);
output[0].push(`${privateStateName}_newNullifierRoot.integer`);
output[2].push(`${privateStateName}_nullifier.integer`);
output[1].push(`${privateStateName}_newNullifierRoot.integer`);
}
}
if (!stateNode.accessedOnly && !stateNode.burnedOnly)
output[3].push(`${privateStateName}_newCommitment.integer`);
output[4].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
output[5].push(`${privateStateName}_cipherText`);
output[6].push(`${privateStateName}_encKey`);
}

break;
Expand Down Expand Up @@ -924,27 +926,26 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
}

params[0] = sendTransactionBoilerplate(node);
if(!node.returnInputs[0] && !params[0][4][0]) returnInputs.push(`1`); // If there are no return, circuit's default return is true
if(!node.returnInputs[0] && !params[0][5][0]) returnInputs.push(`1`); // If there are no return, circuit's default return is true
// params[0] = arr of nullifier root(s)
// params[1] = arr of commitment root(s)
// params[2] = arr of nullifiers
// params[3] = arr of commitments
(params[0][0][0]) ? params[0][0][0] = ` ${params[0][0][0]}, ` : params[0][0][0] = ` 0 , ` ; // nullifierRoot - array // Default value for the struct
(params[0][0][1]) ? params[0][0][1] = ` ${params[0][0][1]}, ` : params[0][0][1] = ` 0, `;
(params[0][2][0]) ? params[0][2] = ` ${params[0][2][0]},` : params[0][2] = ` 0 , ` ; // commitmentRoot - array
(params[0][1][0]) ? params[0][1] = ` [${params[0][1]}],` : params[0][1] = ` [], `; // nullifiers - array
(params[0][3][0]) ? params[0][3] = `[${params[0][3]}],` : params[0][3] = ` [], `; // commitments - array
(params[0][4][0]) ? params[0][4] = `[${params[0][4]}],` : params[0][4] = ` [], `; // cipherText - array of arrays
(params[0][5][0]) ? params[0][5] = `[${params[0][5]}],`: params[0][5] = ` [], `;// cipherText - array of arrays

(params[0][0][0]) ? params[0][0] = ` ${params[0][0][0]}, ` : params[0][0] = ` 0 , ` ; // nullifierRoot - array // Default value for the struct
(params[0][1][0]) ? params[0][1] = ` ${params[0][1][0]}, ` : params[0][1] = ` 0, `;
(params[0][3][0]) ? params[0][3] = ` ${params[0][3][0]},` : params[0][3] = ` 0 , ` ; // commitmentRoot - array
(params[0][2][0]) ? params[0][2] = ` [${params[0][2]}],` : params[0][2] = ` [], `; // nullifiers - array
(params[0][4][0]) ? params[0][4] = `[${params[0][4]}],` : params[0][4] = ` [], `; // commitments - array
(params[0][5][0]) ? params[0][5] = `[${params[0][5]}],` : params[0][5] = ` [], `; // cipherText - array of arrays
(params[0][6][0]) ? params[0][6] = `[${params[0][6]}],`: params[0][6] = ` [], `;// cipherText - array of arrays

if (node.functionName === 'cnstrctr') return {
statements: [
`\n\n// Save transaction for the constructor:
\nBackupData.forEach((element) => {
element.cipherText = element.cipherText.map(ct => generalise(ct).hex(32));
});
\nconst tx = { proofInput: [{customInputs: [${returnInputs}], nullifierRoot: ${params[0][0][0]} latestNullifierRoot:${params[0][0][1]} newNullifiers: ${params[0][1]} commitmentRoot:${params[0][2]} newCommitments: ${params[0][3]}}, proof, BackupData], nullifiers: ${params[0][1]} isNullfiersAdded: false, ${node.publicInputs?.map(input => `${input}: ${input}.integer,`)}};`
\nconst tx = { proofInput: [{customInputs: [${returnInputs}], nullifierRoot: ${params[0][0]} latestNullifierRoot:${params[0][1]} newNullifiers: ${params[0][2]} commitmentRoot:${params[0][3]} newCommitments: ${params[0][4]}}, proof, BackupData], nullifiers: ${params[0][2]} isNullfiersAdded: false, ${node.publicInputs?.map(input => `${input}: ${input}.integer,`)}};`
]
}

Expand All @@ -954,7 +955,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
statements: [
`\n\n// Send transaction to the blockchain:
\nconst txData = await instance.methods
.${node.functionName}(${lines.length > 0 ? `${lines},`: ``} {customInputs: [${returnInputs}], nullifierRoot: ${params[0][0][0]} latestNullifierRoot:${params[0][0][1]} newNullifiers: ${params[0][1]} commitmentRoot:${params[0][2]} newCommitments: ${params[0][3]} cipherText:${params[0][4]} encKeys: ${params[0][5]}}, proof, BackupData).encodeABI();
.${node.functionName}(${lines.length > 0 ? `${lines},`: ``} {customInputs: [${returnInputs}], nullifierRoot: ${params[0][0]} latestNullifierRoot:${params[0][1]} newNullifiers: ${params[0][2]} commitmentRoot:${params[0][3]} newCommitments: ${params[0][4]} cipherText:${params[0][5]} encKeys: ${params[0][6]}}, proof, BackupData).encodeABI();
\n let txParams = {
from: config.web3.options.defaultAccount,
to: contractAddr,
Expand Down

0 comments on commit 4bcae06

Please sign in to comment.