Skip to content

Commit

Permalink
fix: throw an error when key is used a variable name because this cau…
Browse files Browse the repository at this point in the history
…ses an error
  • Loading branch information
lydiagarms committed May 8, 2024
1 parent ddfb158 commit d279eda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/transformers/visitors/checks/unsupportedVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export default {
`Zokrates does not support variables that begin with an underscore such as as _value.`,
node
);
if (node.name === 'key'){
throw new ZKPError(
`Zokrates does not support variables with the name key, please choose a different name.`,
node
);
}
},
},
};
8 changes: 4 additions & 4 deletions test/contracts/increments.zol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ contract MyContract {
secret uint256 private a;
secret mapping(uint256 => uint256) private b;

function assign(secret uint256 param1, uint256 key, secret uint256 c) public {
function assign(secret uint256 param1, uint256 ky, secret uint256 c) public {
unknown a += param1;
unknown b[key] += c;
unknown b[ky] += c;
}

function decra(secret uint256 param2) public {
a -= param2;
}

function decrb(secret uint256 param2, uint256 key) public {
b[key] -= param2;
function decrb(secret uint256 param2, uint256 ky) public {
b[ky] -= param2;
}

function incra(secret uint256 param3) public {
Expand Down

0 comments on commit d279eda

Please sign in to comment.