-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
VIP: Forbid implicit conversion in arithmetic and comparison #775
Comments
@jacqueswww Just for a note about the gas cost that may require a (good-to-have) optimization. Let Essentially, if we have a decimal being multiplied/divided by an integer (with the explicit conversion to a decimal), then we can save the gas by optimizing (dropping the redundant) the multiplication of |
@daejunpark I'm not sure that is fully correct, it would be only two of these scenarios because decimal assignment would not perform the division by
|
@fubuloubu Let me clarify. Let Then the decimal multiplication is defined as follows: For example,
Similarly, the decimal division is: |
Ah yes, I see it now. Thanks! |
@yzhang90 Is there still something outstanding on the implementation of this VIP? It looks to me to be resolved (using version |
Yes I believe these got implemented, issue was just never closed. Closing now. |
Preamble
Simple Summary
We should forbid the implicit conversion in arithmetic and comparison and require the developers to explicitly do the conversion by themselves.
Abstract
Implicit conversion between integer types (
int128
,uint256
,decimal
) in arithmetic and comparison can be confusing and harm the auditability of smart contracts. We should forbid the implicit conversion in arithmetic and comparison.Motivation
Implicit conversion between integer types (
int128
,uint256
,decimal
) in arithmetic and comparison can cause harm the auditability of smart contracts, increase the complexity of the compiler and make it very hard to optimize gas cost ( See #issue716, #issue717 and #issue737). Thus, we should forbid the implicit conversion in arithmetic and comparison and require the developers to explicitly do the conversion.Specification
General principle is that the parameters of arithmetic op (
+
,-
,*
,/
) and comparison (<
,<=
,>
,>=
,!=
) should be of the same type. Arithmetic will return the same type and comparison will returnbool
.Specifically, for arithmetic:
The developers should use
convert
orfloor
to do the conversion by themselves.Backwards Compatibility
This change is NOT backward compatible.
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: