-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Unchecked blocks are identified as checked #1187
Comments
However, node have their own scope: slither/slither/core/cfg/scope.py Line 9 in 8344524
And is_checked is set to False in this scope for unchecked block:
Which is used by the IR: slither/slither/slithir/operations/binary.py Lines 180 to 181 in 8344524
So this should definitely not return a checked operation, I am not sure why it happens |
The issue is that slither/slither/solc_parsing/declarations/function.py Lines 1048 to 1051 in 8344524
However when parsing a VariableDeclarationStatement the new scope is not taken in consideration and it uses the node.underlying_node.scope which is still the old scope.slither/slither/solc_parsing/declarations/function.py Lines 986 to 987 in 8344524
slither/slither/solc_parsing/declarations/function.py Lines 709 to 714 in 8344524
The same is true when parsing other statements. In the following example the operations after the unchecked block will also be unchecked. pragma solidity 0.8.3;
contract T {
function withdraw(address payable to, uint256 amount) public {
uint a;
uint counter;
unchecked {
uint b = amount - amount;
a = amount + b;
}
uint c = 5 + 7;
for(uint i = 0; i < 10; i++) {counter++;}
}
}
|
Thanks for identifying the functions.py file! I basically just added a Modified: Modified from: https://github.com/crytic/slither/blob/635649207d52feff049d92cd75ec5b19edbfc61e/slither/solc_parsing/declarations/function.py And here is a custom detector to test with.
|
Describe the issue:
The
is_checked
attribute does not return false for functions that have unchecked blocksCode example to reproduce the issue:
Version:
0.8.3
Relevant log output:
Contract Test Function Test.withdraw(address,uint256) (*) Expression: a = amount - amount IRs: TMP_0(uint256) = amount (c)- amount a(uint256) := TMP_0(uint256)
The text was updated successfully, but these errors were encountered: