Skip to content

Commit

Permalink
chore: added code for node
Browse files Browse the repository at this point in the history
  • Loading branch information
SwatiEY committed Sep 13, 2024
1 parent ccdccea commit 2e01f09
Showing 1 changed file with 66 additions and 73 deletions.
139 changes: 66 additions & 73 deletions src/boilerplate/orchestration/javascript/raw/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ const Orchestrationbp = new OrchestrationBP();
export const sendTransactionBoilerplate = (node: any) => {
const { privateStates } = node;
const output: string[][] = [[],[],[],[],[],[],[]];
// output[0] = nullifier root(s)
// 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
// output[0] = arr of nullifiers
// output[1] = commitments root(s)
// output[2] = arr of commitments
// output[3] = arr of nullifiers to check, not add (for accessed states)
// output[4] = arr of cipherText
// output[5] = arr of enc keys
let privateStateName: string;
let stateNode: any;
for ([privateStateName, stateNode] of Object.entries(privateStates)) {
Expand All @@ -72,21 +71,19 @@ export const sendTransactionBoilerplate = (node: any) => {
switch (stateNode.nullifierRequired) {
case true:
// decrement
output[3].push(`${privateStateName}_root.integer`);
output[0].push(`${privateStateName}_nullifierRoot.integer`);
output[1].push(`${privateStateName}_newNullifierRoot.integer`);
output[2].push(
output[1].push(`${privateStateName}_root.integer`);
output[0].push(
`${privateStateName}_0_nullifier.integer, ${privateStateName}_1_nullifier.integer`,
);
output[4].push(`${privateStateName}_2_newCommitment.integer`);
output[2].push(`${privateStateName}_2_newCommitment.integer`);
break;
case false:
default:
// increment
output[4].push(`${privateStateName}_newCommitment.integer`);
output[2].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[5].push(`${privateStateName}_cipherText`);
output[6].push(`${privateStateName}_encKey`);
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
}
break;
}
Expand All @@ -95,19 +92,19 @@ export const sendTransactionBoilerplate = (node: any) => {
default:
// whole
if (!stateNode.reinitialisedOnly)
output[3].push(`${privateStateName}_root.integer`);
if (!stateNode.reinitialisedOnly) {
output[0].push(`${privateStateName}_nullifierRoot.integer`)
if (!stateNode.accessedOnly) {
output[2].push(`${privateStateName}_nullifier.integer`);
output[1].push(`${privateStateName}_newNullifierRoot.integer`);
}
output[1].push(`${privateStateName}_root.integer`);
if (stateNode.accessedOnly) {
output[3].push(`${privateStateName}_nullifier.integer`);
} else {
if (!stateNode.reinitialisedOnly) {
output[0].push(`${privateStateName}_nullifier.integer`);
}
}
if (!stateNode.accessedOnly && !stateNode.burnedOnly)
output[4].push(`${privateStateName}_newCommitment.integer`);
if (!stateNode.burnedOnly)
output[2].push(`${privateStateName}_newCommitment.integer`);
if (stateNode.encryptionRequired) {
output[5].push(`${privateStateName}_cipherText`);
output[6].push(`${privateStateName}_encKey`);
output[4].push(`${privateStateName}_cipherText`);
output[5].push(`${privateStateName}_encKey`);
}
break;
}
Expand Down Expand Up @@ -197,8 +194,6 @@ export const generateProofBoilerplate = (node: any) => {
parameters,
})
);
if(stateNode.nullifierRequired || stateNode.accessedOnly) containsNullifierRoot = true;
if(stateNode.nullifierRequired) containsNewNullifierRoot = true;
if (!stateNode.reinitialisedOnly) containsRoot = true;
break;

Expand Down Expand Up @@ -759,41 +754,41 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
}));
}
}
for ([stateName, stateNode] of Object.entries(node.privateStates)) {
if (stateNode.isPartitioned) {
lines.push(
Orchestrationbp.temporaryUpdatedNullifier.postStatements({
stateName,
accessedOnly: stateNode.accessedOnly,
stateType: 'partitioned',
}));
} else {
lines.push(
Orchestrationbp.temporaryUpdatedNullifier.postStatements({
stateName,
accessedOnly: stateNode.accessedOnly,
stateType: 'whole',
}));
}
}
for ([stateName, stateNode] of Object.entries(node.privateStates)) {
if (stateNode.isPartitioned) {
lines.push(
Orchestrationbp.calculateUpdateNullifierPath.postStatements({
stateName,
accessedOnly: stateNode.accessedOnly,
stateType: 'partitioned',
}));
// for ([stateName, stateNode] of Object.entries(node.privateStates)) {
// if (stateNode.isPartitioned) {
// lines.push(
// Orchestrationbp.temporaryUpdatedNullifier.postStatements({
// stateName,
// accessedOnly: stateNode.accessedOnly,
// stateType: 'partitioned',
// }));
// } else {
// lines.push(
// Orchestrationbp.temporaryUpdatedNullifier.postStatements({
// stateName,
// accessedOnly: stateNode.accessedOnly,
// stateType: 'whole',
// }));
// }
// }
// for ([stateName, stateNode] of Object.entries(node.privateStates)) {
// if (stateNode.isPartitioned) {
// lines.push(
// Orchestrationbp.calculateUpdateNullifierPath.postStatements({
// stateName,
// accessedOnly: stateNode.accessedOnly,
// stateType: 'partitioned',
// }));

} else {
lines.push(
Orchestrationbp.calculateUpdateNullifierPath.postStatements({
stateName,
accessedOnly: stateNode.accessedOnly,
stateType: 'whole',
}));
}
}
// } else {
// lines.push(
// Orchestrationbp.calculateUpdateNullifierPath.postStatements({
// stateName,
// accessedOnly: stateNode.accessedOnly,
// stateType: 'whole',
// }));
// }
// }
return {
statements: [`\n// Calculate nullifier(s): \n`, ...lines],
};
Expand Down Expand Up @@ -909,33 +904,31 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {

params[0] = sendTransactionBoilerplate(node);
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[0] = arr of nullifier
// params[1] = arr of commitment root(s)
// params[2] = arr of nullifiers
// params[3] = arr of commitments
(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
(params[0][0][0]) ? params[0][0] = ` [${params[0][0]}],` : params[0][0] = ` [], `; // nullifiers - array
(params[0][1][0]) ? params[0][1] = ` ${params[0][1][0]}, ` : params[0][1] = ` 0, `; // commitmentRoot
(params[0][2][0]) ? params[0][2] = ` [${params[0][2][0]}],` : params[0][2] = ` [] , ` ; // commitment -array
(params[0][3][0]) ? params[0][3] = `[${params[0][3]}],` : params[0][3] = ` [], `; // accessed nullifiers -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

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]} 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,`)}};`
\nconst tx = { proofInput: [{customInputs: [${returnInputs}], newNullifiers: ${params[0][0]} commitmentRoot:${params[0][1]} checkNullifiers: ${params[0][3]} newCommitments: ${params[0][2]}}, proof, BackupData], nullifiers: ${params[0][1]} isNullfiersAdded: false, ${node.publicInputs?.map(input => `${input}: ${input}.integer,`)}};`
]
}

return {
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]} 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();
.${node.functionName}(${lines.length > 0 ? `${lines},`: ``} {customInputs: [${returnInputs}], newNullifiers: ${params[0][0]} commitmentRoot:${params[0][1]} checkNullifiers: ${params[0][3]} newCommitments: ${params[0][2]} cipherText:${params[0][4]} encKeys: ${params[0][5]}}, proof, BackupData).encodeABI();
\n let txParams = {
from: config.web3.options.defaultAccount,
to: contractAddr,
Expand Down

0 comments on commit 2e01f09

Please sign in to comment.