From ec9c8855bc71d1eebb3e822fb50c8b01e748de0d Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Wed, 7 May 2025 10:52:09 +0100 Subject: [PATCH 1/5] fixes several bugs in Encrypt.zol --- .../raw/FunctionBoilerplateGenerator.ts | 13 ++++++++++-- .../javascript/raw/boilerplate-generator.ts | 20 +++++++++++++++---- .../orchestration/files/toOrchestration.ts | 11 +++++----- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts index 6631abb6e..20ae59645 100644 --- a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts @@ -64,10 +64,20 @@ class FunctionBoilerplateGenerator { encryptionRequired }): string[] { // prettier-ignore + let inputs_sig = `${[ + `(`, + ...(newNullifiers ? [`uint256[],`] : []), + ...(checkNullifiers ? [`uint256[],`] : []), + ...(commitmentRoot ? [`uint256,`] : []), + ...(newCommitments? [`uint256[],`] : []), + ...(encryptionRequired ? [`uint256[][],`] : []), + ...(encryptionRequired ? [`uint256[2][],`] : []), + `uint256[])`, // TODO: consider whether we need to identify when / when not to include this. + ].join('')}`; let parameter = [ ...(customInputs ? customInputs.filter(input => !input.dummy && input.isParam) .map(input => input.structName ? `(${input.properties.map(p => p.type)})` : input.isConstantArray ? `${input.type}[${input.isConstantArray}]` : input.type) : []), // TODO arrays of structs/ structs of arrays - `(uint256[],uint256,uint256[],uint256[])`, + inputs_sig, `uint256[]`, `(string,uint256[],uint256)[]`, ].filter(para => para !== undefined); // Added for return parameter @@ -86,7 +96,6 @@ class FunctionBoilerplateGenerator { } if (input.structName) customInputs[i] = input.properties; }); - let msgSigCheck = ([...(isConstructor ? [] : [`bytes4 sig = bytes4(keccak256("${functionName}(${parameter})")) ; \n \t \t \t if (sig == msg.sig)`])]); customInputs = customInputs?.flat(Infinity).filter(p => (p.inCircuit || p.isReturn)); diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index 702dbdfad..89ed6ae72 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -629,10 +629,20 @@ sendTransaction = { isConstructor }): string[] { let value; + const errorCatch = `\n console.log("Added commitment", newCommitment.hex(32)); + } catch (e) { + if (e.toString().includes("E11000 duplicate key")) { + console.log( + "encrypted-data-listener -", + "receiving EncryptedData event with balances.", + "This b already exists. Ignore it." + ); + } + }`; switch (stateType) { case 'increment': value = structProperties ? `{ ${structProperties.map((p, i) => `${p}: ${stateName}_newCommitmentValue.integer[${i}]`)} }` : `${stateName}_newCommitmentValue`; - return [` + return [`try { \nawait storeCommitment({ hash: ${stateName}_newCommitment, name: '${mappingName}', @@ -645,12 +655,13 @@ sendTransaction = { }, secretKey: ${stateName}_newOwnerPublicKey.integer === ${isSharedSecret ? `sharedPublicKey.integer` : `publicKey.integer`} ? ${isSharedSecret ? `sharedSecretKey` : `secretKey`}: null, isNullified: false, - });`]; + });` + errorCatch]; case 'decrement': value = structProperties ? `{ ${structProperties.map((p, i) => `${p}: ${stateName}_change.integer[${i}]`)} }` : `${stateName}_change`; return [` \nawait markNullified(generalise(${stateName}_0_oldCommitment._id), secretKey.hex(32)); \nawait markNullified(generalise(${stateName}_1_oldCommitment._id), secretKey.hex(32)); + \n try { \nawait storeCommitment({ hash: ${stateName}_2_newCommitment, name: '${mappingName}', @@ -663,7 +674,7 @@ sendTransaction = { }, secretKey: ${stateName}_newOwnerPublicKey.integer === ${isSharedSecret ? `sharedPublicKey.integer` : `publicKey.integer`} ? ${isSharedSecret ? `sharedSecretKey` : `secretKey`}: null, isNullified: false, - });`]; + });`+ errorCatch]; case 'whole': switch (burnedOnly) { case true: @@ -674,6 +685,7 @@ sendTransaction = { return [` \n${reinitialisedOnly ? ' ': `if (${stateName}_commitmentExists) await markNullified(${stateName}_currentCommitment, secretKey.hex(32)); `} + \n \try { \nawait storeCommitment({ hash: ${stateName}_newCommitment, name: '${mappingName}', @@ -686,7 +698,7 @@ sendTransaction = { }, secretKey: ${stateName}_newOwnerPublicKey.integer === ${isSharedSecret ? `sharedPublicKey.integer` : `publicKey.integer`} ? ${isSharedSecret ? `sharedSecretKey` : `secretKey`}: null, isNullified: false, - });`]; + });` + errorCatch]; } default: throw new TypeError(stateType); diff --git a/src/codeGenerators/orchestration/files/toOrchestration.ts b/src/codeGenerators/orchestration/files/toOrchestration.ts index 600d5873f..6a7b7b135 100644 --- a/src/codeGenerators/orchestration/files/toOrchestration.ts +++ b/src/codeGenerators/orchestration/files/toOrchestration.ts @@ -265,8 +265,9 @@ node.stateVariables?.forEach( const ${structProp} = generalise(decrypted[${index+1}]);` }) : ''; if(variable.isStruct) { + encryptedCommitmentCode += ` - if (stateVarId.integer === ${variable.name}_stateVarId.integer) { + if (stateVarId.integer === generalise(${variable.id}).integer) { ${encryptedValue}; newCommitment = poseidonHash([ BigInt(stateVarId.hex(32)), @@ -276,7 +277,7 @@ node.stateVariables?.forEach( ]); }` encryptedCode += ` - if (stateVarId.integer === ${variable.name}_stateVarId.integer) { + if (stateVarId.integer === generalise(${variable.id}).integer) { ${encryptedValue}; const newCommitment = poseidonHash([ BigInt(stateVarId.hex(32)), @@ -315,8 +316,7 @@ node.stateVariables?.forEach( } else { encryptedCommitmentCode += ` - - if (stateVarId.integer === ${variable.name}_stateVarId.integer) { + if (stateVarId.integer === generalise(${variable.id}).integer) { const value = generalise(decrypted[1]); newCommitment = poseidonHash([ @@ -327,8 +327,7 @@ node.stateVariables?.forEach( ]); }` encryptedCode += ` - - if (stateVarId.integer === ${variable.name}_stateVarId.integer) { + if (stateVarId.integer === generalise(${variable.id}).integer) { const value = generalise(decrypted[1]); const newCommitment = poseidonHash([ From 12470598379004962922e0ddf714b9edb315ab59 Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Wed, 7 May 2025 11:02:21 +0100 Subject: [PATCH 2/5] move Encrypt.zol into user friendly tests --- test/contracts/{action-tests => user-friendly-tests}/Encrypt.zol | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/contracts/{action-tests => user-friendly-tests}/Encrypt.zol (100%) diff --git a/test/contracts/action-tests/Encrypt.zol b/test/contracts/user-friendly-tests/Encrypt.zol similarity index 100% rename from test/contracts/action-tests/Encrypt.zol rename to test/contracts/user-friendly-tests/Encrypt.zol From 93abc5736bbbeb145fe2d309dd9fd99a2ee8bb25 Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Wed, 7 May 2025 12:20:37 +0100 Subject: [PATCH 3/5] remove slash --- .../orchestration/javascript/raw/boilerplate-generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index 89ed6ae72..b314788d5 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -685,7 +685,7 @@ sendTransaction = { return [` \n${reinitialisedOnly ? ' ': `if (${stateName}_commitmentExists) await markNullified(${stateName}_currentCommitment, secretKey.hex(32)); `} - \n \try { + \n try { \nawait storeCommitment({ hash: ${stateName}_newCommitment, name: '${mappingName}', From fd103f06ee81389c979cb6e18269cca9af4db6d9 Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Thu, 15 May 2025 16:54:13 +0100 Subject: [PATCH 4/5] set variable name in error message --- .../orchestration/javascript/raw/boilerplate-generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index b314788d5..7f23aa751 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -635,7 +635,7 @@ sendTransaction = { console.log( "encrypted-data-listener -", "receiving EncryptedData event with balances.", - "This b already exists. Ignore it." + 'This ${stateName} already exists. Ignore it.', ); } }`; From f03c26ae1feaa4048a07c154c57bd78c6c95e49f Mon Sep 17 00:00:00 2001 From: Lydia Garms Date: Fri, 16 May 2025 11:45:45 +0100 Subject: [PATCH 5/5] fix error message --- .../orchestration/javascript/raw/boilerplate-generator.ts | 2 +- src/codeGenerators/orchestration/files/toOrchestration.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index 7f23aa751..1b4f7b5ea 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -635,7 +635,7 @@ sendTransaction = { console.log( "encrypted-data-listener -", "receiving EncryptedData event with balances.", - 'This ${stateName} already exists. Ignore it.', + 'This commitment for ${stateName} already exists. Ignore it.', ); } }`; diff --git a/src/codeGenerators/orchestration/files/toOrchestration.ts b/src/codeGenerators/orchestration/files/toOrchestration.ts index 6a7b7b135..09a15676d 100644 --- a/src/codeGenerators/orchestration/files/toOrchestration.ts +++ b/src/codeGenerators/orchestration/files/toOrchestration.ts @@ -308,7 +308,7 @@ node.stateVariables?.forEach( console.log( 'encrypted-data-listener -', 'receiving EncryptedData event with balances.', - 'This ${variable.name} already exists. Ignore it.', + 'This commitment for ${variable.name} already exists. Ignore it.', ); } } @@ -357,7 +357,7 @@ node.stateVariables?.forEach( console.log( 'encrypted-data-listener -', 'receiving EncryptedData event with balances.', - 'This ${variable.name} already exists. Ignore it.', + 'This commitment for ${variable.name} already exists. Ignore it.', ); } }