Skip to content

Commit deae97a

Browse files
authored
Merge pull request #462 from EYBlockchain/lyd/burnError
This PR fixes several errors: An error when it is detected that a variable is set to zero i.e. burned. Previously, it was checking that the owner binding was set to zero, which wasn't always giving the correct result. An error for a function where there are no new nullifiers but we do use checkNullifiers, i.e. we access secret variables and so need to make sure we are using the most up to date commitment by a nullifier doesn't exist in the nullifier list. The length of the inputs during proof verification in the Shield Contract were wrong in this case. In orchestration, we do a check to make sure the new leaves have been successfully added on chain at the end. However, if there are no new commitments, we should not include this check or an error will be returned incorrectly. Previously things were being marked as not burned only, i.e. the check included, even when there were no new commitments.
2 parents afdd6b9 + e884c86 commit deae97a

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,18 @@ class ContractBoilerplateGenerator {
218218
'customInputs.length',
219219
...(newNullifiers ? ['newNullifiers.length'] : []),
220220
...(checkNullifiers ? ['checkNullifiers.length']: []),
221-
...(commitmentRoot ? ['(newNullifiers.length > 0 ? 1 : 0)'] : []),
221+
...(() => {
222+
if (commitmentRoot){
223+
if (checkNullifiers && newNullifiers) {
224+
return ['((newNullifiers.length + checkNullifiers.length) > 0 ? 1 : 0)'];
225+
}
226+
if (checkNullifiers) {
227+
return ['((checkNullifiers.length) > 0 ? 1 : 0)'];
228+
}
229+
return ['(newNullifiers.length > 0 ? 1 : 0)'];
230+
}
231+
return [];
232+
})(),
222233
...(newCommitments ? ['newCommitments.length'] : []),
223234
...(encryptionRequired ? ['encInputsLen'] : []),
224235
].join(' + ')});`,

src/boilerplate/orchestration/javascript/raw/toOrchestration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => {
10521052
\n if (!tx) {
10531053
throw new Error( 'Tx failed - the commitment was not accepted on-chain, or the contract is not deployed.');
10541054
} \n`;
1055-
if (!node.newCommitmentsRequired){
1055+
if (!node.newCommitmentsRequired) {
10561056
checkLeaves = '';
10571057
}
10581058
return {

src/traverse/Binding.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,17 +601,7 @@ export class VariableBinding extends Binding {
601601
}
602602
}
603603
}
604-
// mapping[key] = msg.sender is owned by msg.sender => look for mapping[key] = 0
605-
// OR owner is some value (admin = address) => look for admin = 0
606-
if (
607-
ownerNode.name === 'msg' &&
608-
ownerNode.mappingOwnershipType === 'value'
609-
) {
610-
// the owner is represented by the mapping value - we look through the modifyingPaths for 0
611-
this.searchModifyingPathsForZero();
612-
} else if (ownerBinding && ownerBinding instanceof VariableBinding) {
613-
ownerBinding.searchModifyingPathsForZero();
614-
}
604+
this.searchModifyingPathsForZero();
615605
if (this.reinitialisable && !this.isBurned)
616606
throw new SyntaxUsageError(
617607
`The state ${this.name} has been marked as reinitialisable but we can't find anywhere to burn a commitment ready for reinitialisation.`,

src/traverse/Indicator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ export class FunctionDefinitionIndicator extends ContractDefinitionIndicator {
142142
let burnedOnly = true;
143143
for (const [, stateVarIndicator] of Object.entries(this)) {
144144
if (!(stateVarIndicator instanceof StateVariableIndicator)) continue; // eslint-disable-line no-continue, no-use-before-define
145-
// if we have a indicator which is NOT burned, then we do need new commitments
145+
// if we have a indicator which is NOT burned and requires new commitments, then we do need new commitments
146146
if (
147147
stateVarIndicator.isSecret &&
148-
(!stateVarIndicator.isBurned || stateVarIndicator.newCommitmentsRequired)
148+
!stateVarIndicator.isBurned &&
149+
stateVarIndicator.newCommitmentsRequired
149150
) {
150151
burnedOnly = false;
151152
break;

0 commit comments

Comments
 (0)