Skip to content

Commit

Permalink
expression left and right containsSecret
Browse files Browse the repository at this point in the history
  • Loading branch information
kKahina committed Jul 11, 2024
1 parent 4f12b8e commit 7a31ec7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/transformers/visitors/toCircuitVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ let childOfSecret = path.getAncestorOfType('ForStatement')?.containsSecret;
if(path.getAncestorOfType('ForStatement') && expression.containsPublic ){
childOfSecret = false;
}

const thisState = { interactsWithSecretInScope: false };

path.traverseNodesFast(n => {
Expand All @@ -780,10 +781,29 @@ let childOfSecret = path.getAncestorOfType('ForStatement')?.containsSecret;
}

}, thisState);

const leftHandSideInteracts = expression.leftHandSide && scope.getReferencedIndicator(expression.leftHandSide)?.interactsWithSecret;
const rightHandSideInteracts = expression.rightHandSide && scope.getReferencedIndicator(expression.rightHandSide)?.interactsWithSecret;

expression.leftHandSide.containsSecret = false;
expression.rightHandSide.containsSecret = false;

// Mark leftHandSide and rightHandSide if they interact with a secret
if (leftHandSideInteracts) {
expression.leftHandSide.containsSecret = true;
}
if (rightHandSideInteracts) {
expression.rightHandSide.containsSecret = true;
}

if (!node.containsSecret && !childOfSecret && !thisState.interactsWithSecretInScope) {
state.skipSubNodes = true;
return;
// if (!expression.leftHandSide.containsSecret && !expression.rightHandSide.containsSecret && !thisState.interactsWithSecretInScope) {
// state.skipSubNodes = true;
// return;
}

const { isIncremented, isDecremented } = expression;
let newNode: any;

Expand Down
16 changes: 16 additions & 0 deletions test/contracts/Circuit-interactSecret
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: CC0
pragma solidity ^0.8.0;

contract Assign {
secret uint256 private a;
uint256 public c;

function addC(uint256 value) public {

c += a * value;
}

function setA(uint256 newValue) public {
a = newValue;
}
}

0 comments on commit 7a31ec7

Please sign in to comment.