Skip to content

Commit

Permalink
allow for mappings to structs in BackupDataRetriever
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Nov 20, 2024
1 parent 5b77f9c commit 2bfac5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ encryptBackupPreimage = {
} else{
plainText = `[BigInt(${saltName}.hex(32)), BigInt(${stateName}_stateVarId),
${valueName}]`;
if (structProperties) varName += ` s`;
}
if (structProperties) varName += ` s`;
if (stateType === 'increment') varName += ` u`;
return[`\n\n// Encrypt pre-image for state variable ${stateName} as a backup: \n
let ${stateName}_ephSecretKey = generalise(utils.randomHex(31)); \n
Expand Down
52 changes: 33 additions & 19 deletions src/codeGenerators/orchestration/files/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ const prepareBackupDataRetriever = (node: any) => {
console.log("Decrypted pre-image of commitment for variable name: " + name + ": ");
let salt = generalise(plainText[0]);
console.log(\`\\tSalt: \${salt.integer}\`);
let count;
if (isArray){
console.log(\`\\tState variable StateVarId: \${plainText[2]}\`);
mappingKey = generalise(plainText[1]);
Expand All @@ -824,31 +825,44 @@ const prepareBackupDataRetriever = (node: any) => {
);
stateVarId = reGenStateVarId;
console.log(\`Regenerated StateVarId: \${reGenStateVarId.bigInt}\`);
value = generalise(plainText[3]);
console.log(\`\\tValue: \${value.integer}\`);
count = 3;
} else {
stateVarId = generalise(plainText[1]);
console.log(\`\\tStateVarId: \${plainText[1]}\`);
if (isStruct){
value = {};`;
count = 2;
}
if (isStruct){
value = {};`;

node.privateStates.forEach((stateVar: any) => {
if (stateVar.structProperties){
let propCount = 2;
node.privateStates.forEach((stateVar: any) => {
if (stateVar.structProperties){
let propCount = 2;
if (stateVar.mappingKey){
propCount++;
let reGenStateVarId =
genericApiServiceFile += `\nif (stateVarId.integer ===
generalise(utils.mimcHash(
[
${stateVar.stateVarId[0]},
generalise(${stateVar.mappingKey}).bigInt,
],
"ALT_BN_254"
)).integer) {`
} else{
genericApiServiceFile += `\nif (stateVarId.integer === '${stateVar.stateVarId}') {`
stateVar.structProperties.forEach((prop: any) => {
genericApiServiceFile += `value.${prop} = plainText[${propCount}];\n`;
propCount++;
});
genericApiServiceFile += `}\n`;
}
});

genericApiServiceFile += `console.log(\`\\tValue: \${value}\`);
} else {
value = generalise(plainText[2]);
console.log(\`\\tValue: \${value.integer}\`);
}
stateVar.structProperties.forEach((prop: any) => {
genericApiServiceFile += `value.${prop} = plainText[${propCount}];\n`;
propCount++;
});
genericApiServiceFile += `}\n`;
}
});

genericApiServiceFile += `console.log(\`\\tValue: \${value}\`);
} else {
value = generalise(plainText[count]);
console.log(\`\\tValue: \${value.integer}\`);
}
let newCommitment;
if (isStruct){
Expand Down

0 comments on commit 2bfac5c

Please sign in to comment.