Skip to content
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

Rules Wishlist #44

Open
4 of 9 tasks
federicobond opened this issue Nov 1, 2016 · 16 comments
Open
4 of 9 tasks

Rules Wishlist #44

federicobond opened this issue Nov 1, 2016 · 16 comments

Comments

@federicobond
Copy link
Contributor

federicobond commented Nov 1, 2016

This is my wishlist for additional rules. Let me know if you are against any of them getting implemented in the core. I will work on some of them but anything else is up for grabs.

  • Suggest send instead of dangerous call.value() (WIP @federicobond)
  • Suggest avoiding block.timestamp as it can be manipulated by miners (only in functions) (WIP @federicobond)
  • Ensure any function that uses msg.value has payable modifier (WIP @federicobond)
  • Ensure fallback function has payable modifier (WIP @federicobond)
  • Ensure send return value is checked.
  • Extract magic number to constant
  • Suggest using selfdestruct instead of deprecated suicide (WIP @federicobond)
  • Suggest better storage packing (see Warning here)
  • Find duplicate code (this one is hard, perhaps we can write a generic implementation and then integrate it into solium)
@maraoz
Copy link

maraoz commented Nov 1, 2016

Ensure fallback function has payable modifier

Not always desirable. See for example: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/Rejector.sol

@federicobond
Copy link
Contributor Author

Updated. Thanks @maraoz!

@duaraghav8
Copy link
Owner

duaraghav8 commented Nov 2, 2016

Agreed with @maroz and no issues with the rest.

My plan was to separate the linter into 2 layers - the base would only ensure compliance with the Solidity Style Guide.

The 2nd layer contains all the additional rules (like you've stated above) coming from the community. But this layer is optional and therefore can be enabled / disabled by the user at any time.

Until now, I've only been working with the Base. I think we should follow the 2-layer approach.
What do you think

@federicobond
Copy link
Contributor Author

Eslint has some notion of rulesets. See here. Perhaps we can do something similar with Solium rules, where you can choose to enable the base or core ruleset or something more complete.

I must confess I am not a big fan of the current --sync implementation. I believe that most users will forget to do that and lose out on newly developed rules. It's better to allow users to define a base ruleset and add/remove rules as overrides to the base ruleset(s).

@duaraghav8
Copy link
Owner

You're right, we should deprecate --sync and have a configuration file system instead.
Something similar to ESLint's.

I'll blog the final plan before I start implementing it but let me know if you have ideas of your own.

@duaraghav8
Copy link
Owner

duaraghav8 commented Nov 3, 2016

Also Rule proposal:

@federicobond
Copy link
Contributor Author

Rule:

  • Insecure instantiation of array or mapping

See: https://ethereum.karalabe.com/talks/2016-hackethon.html#10

P.S. Is there a secure case for this construct? Or are all its uses insecure?

@federicobond
Copy link
Contributor Author

  • Contract uses send or call.value but has no payable functions or constructor

@federicobond
Copy link
Contributor Author

federicobond commented Dec 21, 2016

  • Warn when using tx.origin instead of msg.sender

@federicobond
Copy link
Contributor Author

  • Warn about using a =+ b or a =- b. See here.

As a general rule, a linter for smart contracts should be very strict with spacing around all keywords, operators, etc. to avoid these problems.

@federicobond
Copy link
Contributor Author

  • Find similar identifiers that could be confused

@Sjors
Copy link

Sjors commented Aug 19, 2017

  • require explicit public, private, external or internal

See ConsenSys best practices. Or is there any situation where this is not possible?

@Sjors
Copy link

Sjors commented Aug 19, 2017

  • a function with returns should actually return for each code path, and should return the correct type
  • a function without returns should not have any return statement

@duaraghav8
Copy link
Owner

All security-related rules finalized in this thread are being implemented at https://github.com/duaraghav8/solium-plugin-security

@mushketyk
Copy link
Contributor

Ensure send return value is checked

I was thinking about implementing this rule, and it seems that to avoid false positives we should keep track of all variables of type address and then check if method send is called on any of them. But if we are processing a contract that inherits from other contracts we would first have to get all variables of type address in all parent contracts. To do this, we need to ensure that a rule is processing parent contracts first, collect a set of addresses in parent contracts, and then check if send is called on any of addresses.

Do you think Solium should support something like this?
Am I overthinking this?

@duaraghav8
Copy link
Owner

duaraghav8 commented Apr 7, 2018

@mushketyk you're not overthinking. There are several rules which are on pause because of this problem of Solium only being file-aware instead of project-aware, ie, at any given time, a rule only has context of 1 file whereas it should have context of the entire project so any external elements can also be considered. This problem is well documented in #83

Let's keep this rule on hold for now, because making solium project-aware is a major design change so it will take time. I'll work on it in near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants