diff --git a/src/transformers/visitors/checks/accessedVisitor.ts b/src/transformers/visitors/checks/accessedVisitor.ts index 7153c59b..6c744ae2 100644 --- a/src/transformers/visitors/checks/accessedVisitor.ts +++ b/src/transformers/visitors/checks/accessedVisitor.ts @@ -91,6 +91,7 @@ export default { if (indicator instanceof StateVariableIndicator) indicator.updateAccessed(path); return; } + // if this state is on the rhs AND isn't incremented OR is in an incrementation, but its not being incremented: if ( rightAncestor && @@ -153,10 +154,13 @@ export default { } // We need to ouput an error if a partitioned state is being accessed. //This seems difficult to support because we need the sum of the value of every commitment, how do we enforce that the prover inputs every commitment to the circuit? - else if (rightAncestor){ + else if (rightAncestor && + referencedBinding.isPartitioned + && (lhsNode.name !== node.name || !state.inIncrementation) + ){ const indicator = scope.getReferencedIndicator(node); if (indicator instanceof StateVariableIndicator) throw new TODOError( - `A partitioned state variable cannot be accessed. Only incrementations/ decrementations of form +=, -= are allowed.`, + `A partitioned state variable cannot be accessed. Only incrementations/ decrementations such as +=, -= are allowed.`, node, ); } diff --git a/src/transformers/visitors/checks/incrementedVisitor.ts b/src/transformers/visitors/checks/incrementedVisitor.ts index e4bba3ab..90c02dc1 100644 --- a/src/transformers/visitors/checks/incrementedVisitor.ts +++ b/src/transformers/visitors/checks/incrementedVisitor.ts @@ -435,9 +435,9 @@ export default { if ( nameMatch && precedingOperator[index + 1]?.includes('+') && // we have ... + a + ... - precedingOperator[index]?.includes('+') // otherwise we have a = b - a + (index ===0) + //precedingOperator[index]?.includes('+') // otherwise we have a = b - a ) { - discoveredLHS += 1; isIncremented = { incremented: true, decremented: false }; } @@ -445,17 +445,16 @@ export default { if ( nameMatch && precedingOperator[index + 1]?.includes('-') && // we have ... + a - ... - precedingOperator[index]?.includes('+') // otherwise we have a = b - a + (index ===0) + //precedingOperator[index]?.includes('+') // otherwise we have a = b - a ) { - discoveredLHS += 1; isIncremented = { incremented: true, decremented: true }; } - // a = something - a + if ( - nameMatch && - precedingOperator[index]?.includes('-') // we have a = b - a + nameMatch ) { - discoveredLHS -= 1; + discoveredLHS += 1; } // if none, go to the next operand if (operand.indexExpression?.expression?.name === 'msg') diff --git a/test/contracts/Assign-type-conversion.zol b/test/contracts/Assign-type-conversion.zol index 7c609e95..4ca3c539 100644 --- a/test/contracts/Assign-type-conversion.zol +++ b/test/contracts/Assign-type-conversion.zol @@ -13,6 +13,6 @@ contract Assign { } function remove(uint256 remval) public { - b -= uint(uint128(remval)); + b += uint(uint128(remval)); } } diff --git a/test/contracts/KnownUnknown.zol b/test/contracts/KnownUnknown.zol index 9cff8861..2998a513 100644 --- a/test/contracts/KnownUnknown.zol +++ b/test/contracts/KnownUnknown.zol @@ -13,8 +13,7 @@ contract Assign { function add( uint256 value ) public { - //unknown b = b + value +a; - unknown b += value +a; + unknown b = b + value +a; unknown x.prop1 += value + a; unknown x.prop2 += value; unknown b += value; @@ -24,9 +23,7 @@ contract Assign { } function remove( uint256 value ) public { - //unknown b = b - value +a; - unknown b -= value +a; - //unknown b = b - (value +a); + unknown b = b - (value +a); unknown x.prop1 -= value + a; unknown x.prop2 -= value; unknown b -= value;