question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reason strings for all require statements

See original GitHub issue

Supersedes #888.

This is way overdue, but a big push during these last couple weeks for it took it to the point where we’re now comfortable to include it in the library.

There was some discussion about formatting in our forum, which culminated in this post, which has some rough guidelines (pasting at the end of this message for reference).

I also did some testing and verified that we can safely add revert reasons to all of OpenZeppelin’s contracts, without them going over the gas limit for a block. The situation may differ for setups with particularly large contracts, but most users should be unaffected. Nonetheless, I opened an issue on the Solidity repo suggesting they provide a way to remove these strings, so that they can be stripped for production builds, if desired.

Our goal is to have all require statements also include a human-readable revert reason, unique across all of OpenZeppelin. Contributions are welcome! Please also update the tests with the shouldFail.reverting.withMessage test helper, so that we can both be sure of the actual revert reason, and prevent regression errors by having these messages change.

Rough guidelines:

I think there’s a fine line between machine-like messages and having bits of Shakespeare embedded in a smart contract. Some of 0x’s messages are quite terse, but then again, in some cases the revert will take place deep down the stack (e.g. you’ll get a SafeMath: subtraction overflow instead of ERC20: insufficient balance for transfer, or even LimitedCrowdsale: all tokens have been sold), and it’ll be up to the developer to figure out how the call got there. As long as each message is unique in their contract, and they are descriptive enough so that one can get an idea of what the revert means (in the context of that contract) without looking at the code, we should be fine.

Here are some examples I think are aligned with this guideline:

  • SafeMath: multiplication overflow
  • SafeMath: division by zero
  • ERC20: null transfer recipient
  • ERC165: invalid interface id
  • MinterRole: caller doesn't have the Minter role
  • ConditionalEscrow: withdrawal disallowed
  • RefundEscrow: can only close when active
  • RefundEscrow: can only withdraw when closed
  • PaymentSplitter: caller has no shares
  • PaymentSplitter: empty payment

Note that some are a bit different (like the RefundEscrow ones) since they originate from a statement such as require(_state == State.Closed), in which the message cannot describe why the performed call is wrong since the state cannot be returned (e.g. cannot withdraw while active), so we must resort to simply reporting the conditions for a successful call.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
frangiocommented, Apr 9, 2019

What about just “zero” or “empty”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview - Reason
This is an overview of most language features in Reason. It does not explain them in detail, but should serve as a quick...
Read more >
Why fromClause in import statement expects string literal?
First, remember that import is not currently supported by any environment, including Node.js. So you will probably be using a transpiler, ...
Read more >
Everything you should know about 'module' & 'require' in Node.js
You might be wondering why is there a need to have multiple modules? You could have just written all the code in a...
Read more >
JavaScript Require vs. Import - Bits and Pieces
1. Require statements can be called anywhere in the code · 2. Require can be called conditionally · 3. Import statements are asynchronous...
Read more >
typeof - JavaScript - MDN Web Docs - Mozilla
typeof is generally always guaranteed to return a string for any operand it is supplied with. Even with undeclared identifiers, typeof will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found