diff --git a/src/codeGenerators/contract/solidity/toContract.ts b/src/codeGenerators/contract/solidity/toContract.ts index 472ddb08..4bbb6f56 100644 --- a/src/codeGenerators/contract/solidity/toContract.ts +++ b/src/codeGenerators/contract/solidity/toContract.ts @@ -119,7 +119,7 @@ function codeGenerator(node: any) { if (!node.declarationType && !!node._newASTPointer?.declarationType) node.declarationType = node._newASTPointer.declarationType; // we crop 'struct ContractName.structname' to just 'structname' - if (typeString.includes('struct ')) typeString = typeString.substring(typeString.indexOf(".") + 1); + if (typeString.includes('struct ')) typeString = typeString.replace(/struct\s+\w+\./, ''); typeString = typeString.replace('contract ', ''); // pesky userdefined type 'contract' keword needs to be removed in some cases. const constant = node.constant ? ' constant' : ''; const visibility = node.visibility ? ` ${node.visibility}` : ''; @@ -202,6 +202,7 @@ function codeGenerator(node: any) { if (node.operator === '!'){ return `${node.operator}${codeGenerator(node.subExpression)}`; } + if (node.prefix === true) return `${node.operator}${codeGenerator(node.subExpression)};`; return `${codeGenerator(node.subExpression)} ${node.operator};`; case 'EmitStatement': diff --git a/src/transformers/visitors/toContractVisitor.ts b/src/transformers/visitors/toContractVisitor.ts index 460ee2b3..5ce67ad8 100644 --- a/src/transformers/visitors/toContractVisitor.ts +++ b/src/transformers/visitors/toContractVisitor.ts @@ -305,7 +305,6 @@ export default { if (!path.containsSecret && !path.scope.indicators.internalFunctionInteractsWithSecret) return; const file = state.circuitAST.files.find((n: any) => n.fileId === node.id); const circuitParams = file.nodes.find((n: any) => n.nodeType === node.nodeType).parameters.parameters; - state.circuitParams ??= {}; state.circuitParams[path.getUniqueFunctionName()] ??= {}; state.circuitParams[path.getUniqueFunctionName()].parameters = circuitParams; diff --git a/test/contracts/publicMappingtoStruct.zol b/test/contracts/publicMappingtoStruct.zol new file mode 100644 index 00000000..cf99e72c --- /dev/null +++ b/test/contracts/publicMappingtoStruct.zol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: CC0 + +pragma solidity ^0.8.0; + +contract Receipt { + + mapping (address => Rct) private total; + secret uint256 a; + + struct Rct { + uint256 amount; + uint256 tax; + } + + + function add(Rct memory myrct, address user) public { + total[user].amount += myrct.amount; + total[user].tax += myrct.tax; + } + + function addSecret(secret uint256 param) public { + a += param; + } + + +}