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.

Make 0-valued transfers valid semantics (fire the event and return true)

See original GitHub issue

EDIT: Replace “revert” with “returned false” in this issue; I realized StandardToken does not throw on error but then realized the issue is practically the same and still just as harmful

Reverting on 0-valued transfer and approval is an anti-pattern that pops up repeatedly in code reviews. I realized it’s because many people are copying your StandardToken.

These two lines should have && _value > 0 removed:

        if (balances[msg.sender] >= _value && _value > 0) {
        if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {

0-valued transfers and approvals should be valid and behave almost like no-ops, without reverting state. This is so that consumer contracts do not have to take care to work around this edge case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
simondlrcommented, May 10, 2017

Great points and well put @mbrock. Agreed.

Thanks for the comments/discussions.

Will change/fix soon.

3reactions
mbrockcommented, May 5, 2017

I also agree that it’s more parsimonious to have 0-valued transfers be harmless no-ops rather than failures.

It’s kind of like how append(x, []) is a harmless no-op rather than something which causes an EmptyAppendException.

From an algebraic perspective, zero being the identity for additive operations is an ancient and fundamental meme; returning an error on “addition by zero” is surprising and unusual.

We don’t yet know which contract will be the first to be surprised by this behavior. We’ve already seen some possible examples by @nmushegian.

For example a system that interacts with any number of external tokens and imposes some kind of configurable fees denominated in tokens. That fee is changed to 0 for some reason, which causes the contract to attempt to transfer 0 * x, which then fails unexpectedly, and now some user’s funds are locked.

That kind of problem seems much more serious than the risk of accidentally wasting a user’s gas because of a glitchy frontend. Such gas costs are a very limited risk, whereas the 0 fee example is an unbounded risk.

Someone could ask “why are you writing code that appends an empty string?”, and maybe the examples I came up with would sound contrived – but I still don’t want the string library to fail in such cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listener (Infinispan Distribution 7.0.3.Final API)
Class-level annotation used to annotate an object as being a valid cache listener. Used with the Listenable.addListener(Object) and related APIs.
Read more >
FSMDirector
Return true if the model errors are handled. boolean, implementsStrictActorSemantics(). Return true if all state refinements have directors that implement the ...
Read more >
#GTMtips: Create A Generic Event Tag | Simo Ahava's blog
How to create a generic event tag using Google Tag Manager. ... and making sure that the Tag fires whenever the GAEvent value...
Read more >
Design for ECSL-DP - Institute for Software Integrated Systems
Title: Compositional Specification of Behavioral Semantics ... while the execution of a guard only returns a Boolean value for the true or false...
Read more >
Database Engine events and errors - SQL Server
ls' used with WAITFOR is not a valid value. ... Additional messages in the SQL Server error log and system event log may...
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