Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Comment thread
jtcoolen marked this conversation as resolved.
Outdated
);
}
}`;
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}',
Expand All @@ -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}',
Expand All @@ -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:
Expand All @@ -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}',
Expand All @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions src/codeGenerators/orchestration/files/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand Down
Loading