From 2bfac5c45447e347165ee04fffef69da6b758796 Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Wed, 20 Nov 2024 12:28:26 +0000 Subject: [PATCH] allow for mappings to structs in BackupDataRetriever --- .../javascript/raw/boilerplate-generator.ts | 2 +- .../orchestration/files/toOrchestration.ts | 52 ++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index f7eba5be..e4eb6414 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -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 diff --git a/src/codeGenerators/orchestration/files/toOrchestration.ts b/src/codeGenerators/orchestration/files/toOrchestration.ts index b491ef57..64b9f08c 100644 --- a/src/codeGenerators/orchestration/files/toOrchestration.ts +++ b/src/codeGenerators/orchestration/files/toOrchestration.ts @@ -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]); @@ -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){