📢 This HIP is in the last call for review stage. The authors wish to finalize the HIP and appreciate feedback.

HIP-564: Zero unit token operations in smart contracts Source

AuthorMatthew DeLorenzo, Vae Vecturne
Discussions-Tohttps://github.com/hashgraph/hedera-improvement-proposal/discussions/563
StatusLast Call
Needs Council ApprovalYes
Review period endsWed, 21 Sep 2022 07:00:00 +0000
TypeStandards Track
CategoryService
Created2022-09-01
Updated2022-09-07

Abstract

Integer rounding will naturally lead to DeFi contracts sometimes minting or transferring 0 units of a token. But the network rejects 0 units in these operations, forcing contract developers to include special cases that would not be necessary on most networks.

Motivation

Currently, whenever a zero value parameter passes through a mint, burn or transfer transaction, the network rejects it immediately. Frequently this happens with integer rounding calculations in smart contracts. To get around it, contract developers must check for a non-zero value to submit mint, burn or transfer transactions, which is inconsistent with most other networks. This hip will eliminate if statements checking for zero before mint, burn or transfer transactions in smart contracts making them easier to use and be in alignment with most other networks.

Rationale

DeFi contracts using ERC20 standard may mint, burn, and transfer zero tokens.

When we deprecate farms in our farm contracts by giving them a weighting of 0, the network rejects 0 units in these operations, forcing contract developers to include special cases that would not be necessary on most networks. Currently, all ‘SafeHederaTokenService’ calls (meaning they require HederaResponseCode.SUCCESS) must be qualified with a statement if(amount > 0), as a 0 amount would result in HederaResponseCode.INVALID_TOKEN_MINT_AMOUNT or similar.

Importantly, ERC20 token standard allows for 0 amount mint, burn, transfer, etc.

User stories

As a solidity developer, I would like to send 0 tokens in my smart contracts.

Specification

The response code for token mint, burn, and transfer returns SUCCESS = 22

Backwards Compatibility

This would be backward compatible.

Security Implications

N/A

How to Teach This

N/A

Reference Implementation

Example :

Example of a mint transaction that should be allowed if a 0 amount is passed.

function mint(uint amount) external {
        balanceOf[msg.sender] += amount;
        totalSupply += amount;
        emit Transfer(address(0), msg.sender, amount);
 }

Rejected Ideas

Open Issues

References

Copyright/license

This document is licensed under the Apache License, Version 2.0 – see LICENSE or (https://www.apache.org/licenses/LICENSE-2.0)

Citation

Please cite this document as: