-
Notifications
You must be signed in to change notification settings - Fork 979
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
Add support for top level using for directive #1352
Comments
Files with Error also manifests as Contract taken from Solidity docs: // SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.3;
struct Data { mapping(uint => bool) flags; }
using {insert, remove, contains} for Data; // problem line
function insert(Data storage self, uint value)
returns (bool)
{
if (self.flags[value])
return false; // already there
self.flags[value] = true;
return true;
}
function remove(Data storage self, uint value)
returns (bool)
{
if (!self.flags[value])
return false; // not there
self.flags[value] = false;
return true;
}
function contains(Data storage self, uint value)
view
returns (bool)
{
return self.flags[value];
}
contract C {
Data knownValues;
function register(uint value) public {
// Here, all variables of type Data have
// corresponding member functions.
// The following function call is identical to
// `Set.insert(knownValues, value)`
require(knownValues.insert(value));
}
} crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Error: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function definition.
--> using_for.sol:12:1:
|
12 | using {insert, remove, contains} for Data;
| ^^^^^ |
Oh, that's right, the project does have one top-level Should I open an issue in |
using ... for
is used outside of a contract
This solidity feature hasn't been added to slither yet, so this is the correct place to have opened an issue. |
using ... for
is used outside of a contract
I've tried running Slither using branch
I have no idea what this exception means. Is it another issue or is the fix incomplete? The most similar exception to this one is in #1295, but it's hard to tell if it's the same problem. |
Hi @CodeSandwich, i can't understand from only this exception if it's related to the fix or not. Could you share the codebase? |
Thank you for looking into this! The codebase is here: https://github.com/radicle-dev/drips-contracts |
I've found the root issue. It turns out that Slither has a problem with the Foundry's test utils. Even the exception says that the problem was found in FOUNDRY_TEST=nonexisten slither . It's clearly a separate issue, so I've opened a new one: #1422. |
I've just wanted to use Slither for the first time in a while, and I bumped into this immediately as soon as I run it. My math library PRBMath makes extensive use of user-defined value types and top-level using for directives - so all of the library users will bump into the same issue. Is there any ETA for when this will be implemented in Slither? We would love to be able to run the static analysis at least once before going to production. |
Hi @PaulRBerg . We actually worked on the support this week (#1378, #1563). We encountered a couple of edge cases that slowed us down, but we are aiming for a release at the beginning of next week. We will try slither on your repo to make sure it passes before the release |
Great news, thanks very much, @montyly! |
Thanks for implementing this feature, guys! Unfortunately, we might have to re-open this issue. Slither doesn't work with chained function calls on value types: pragma solidity >=0.8.17;
import { UD60x18 } from "prb-math/UD60x18.sol";
contract Foo {
function tryUnwrap(UD60x18 a, UD60x18 b) external pure returns (uint256 c, uint256 d) {
// This is ok
c = a.unwrap();
// This triggers a bug
d = a.mul(b).unwrap();
}
} Defining
I can attach the full stack trace but you should be able to replicate this by spinning up a Foundry project and installing PRBMath (the latest commit from |
@PaulRBerg I've opened an issue, and we'll get this fixed soon. Thanks for taking the time to report the bug and provide an example as it helps a ton! |
Describe the issue:
I'm trying to run
slither .
on a project and I'm getting the error:The project uses Forge (yesterday version) and Solidity 0.8.15. This is the first Slither run ever, all I did before was running
pip3 install slither-analyzer
. I haven't installedsolc
manually, Slither seems to be using Forge and whatever compiler it has inside. (If that's the case, congratulations on that integration, I love it!). I'm running Manjaro Linux. Bothpython --version
andpython3 --version
yieldPython 3.10.5
.Code example to reproduce the issue:
https://github.com/radicle-dev/drips-contracts
Version:
0.8.3
Relevant log output:
I don't know where can I find the logs, if you tell me, I'll add them
The text was updated successfully, but these errors were encountered: