Openzeppelin-solidity requires do not have string "reason" messages


#1

I’m curious, why is it that require statements inside the OZ-solidity contracts don’t have a string “reason” message? In practice, this seems to make it so that things can be confusing to debug


#2

I think I can give you an answer for this. The problem is that those messages (let’s call them reason strings in require statements are very expensive in terms of bytecode usage. Every reason string takes at least 32 bytes so make sure your string fits in 32 bytes or it will become more expensive


#3

That makes a lot of sense @madjarevicn. Thanks for responding!

It makes sense that OZ, being a library of low-level base contracts, would want to hyper-optimize for gas usage. However these reason messages would be super handy. It’d be awesome if there were some mechanism to have require “reasons”, but strip them out out as a separate step before shipping to a real chain.


#4

To be honest we have wanted this for some time but just haven’t got around to it. Performance is a concern, yes, but it was more a matter of having the time to do it.


#5

@zachlysobey we’ve long postponed this, but plan on tackling it as part of v2.3 (which should be coming out in about a month): see the corresponding GitHub issue here.

I share @madjarevicn’s concern regarding gas usage though - it’d be great if we could strip all require reasons before production deployment, but keep them while testing (similar to how other languages/build systems have Debug and Release settings). I think eventually we’ll have to introduce some sort of code-autogeneration into OpenZeppelin, but I’d like to postpone that moment as much as possible. An option I hadn’t considered until today is having Solidity itself be able to remove these strings: I’ve opened an issue in their repo to discuss this.


#6

Before moving forward with actually adding the revert reasons throughout the project, a pending task is defining the format and tone they will have. This was what initially blocked us.

What do you guys think about the style used by 0x?


#7

I like that style quite a bit; it makes the reasons easy to map to an enum in a web3 application hooking into the contracts.


#8

Hi, I’m glad to see this is being addressed. I need all the require() error messages for a project I’m working on now, but can’t wait for OZ 2.3 to come out. Assuming that the work has been done but just hasn’t been integrated yet… to avoid duplicating work, is there a repository with only these changes that I could make use of right now?
Thanks!

  • DJ

#9

About tone and style, I would simply consider the audience who would be viewing the error, as the error only really needs to guide the user as to what they need to do to resolve the problem. For example, if a math underflow were to happen during transfer(), an error saying “Insufficient funds.” I think would be good enough. Certainly way better than having no message at all!
Thanks,

  • DJ

#10

Speaking of this, where can I find information about the timing of the OZ 3.2 release?


#11

It hasn’t :frowning: I intend for this to be one of the first things we work on for the upcoming release, but for now we still have to settle on a message format. Contributions are more than welcome :slight_smile: That said, I’d usually advice against copying code from the repo directly, and suggest only working with published versions.

An issue to consider is that an error may happen way down the call stack, so a message saying ‘integer overflow’ may not be very useful when e.g. participating on a crowdsale. I don’t think we’ll be able to address this though with just these messages.

Our release cycle post has the information you’re looking for. In the case of v2.3, it is scheduled to come out on April 20th.


#12

Hi! I also like the format used by 0x. I think you are doing a great job in Zeppelin and it would be a pleasure for me to help and contribute to this issue. Of course when the decision on the message format will be made.