As described in the documentation, int
and uint
are aliases for int256
and uint256
respectively.
This project contains tests that prove that, any combination of declarations and uses of these types will generate the same bytecode. Thus Prettier can enforce the use of Explicit types across the project.
Before v0.8.0
, byte
was an alias for bytes1
but it has been removed.
Playing around with Prettier JS, I noticed that the expression a / b * c
would be printed as (a / b) * c
.
This change has no repercussion in the output, but there are benefits for the developer as seeing it can uncover missing bits in case of working with integers.
However, I wouldn't attempt proposing this change in prettier-solidity without, making sure that the cost in gas is untouched.
To my surprise, as long as the Order of Precedence of Operators is followed (which is the whole idea behind this PoC), the bytecode will be the same.
Since v0.8.0
Solidity is parsing a ** b ** c;
as a ** (b ** c);
previous versions would parse it as (a ** b) ** c;
.
I've kept all of the tests made before coming up with just comparing the bytecode.
To run the tests, juts type:
npm test
Here is a list of all the combinations and their changes:
No Parentheses | Prettier Parentheses |
---|---|
a + b + c; |
a + b + c; |
a + b - c; |
a + b - c; |
a + b * c; |
a + b * c; |
a + b / c; |
a + b / c; |
a + b % c; |
a + (b % c); |
a + b ** c; |
a + b ** c; |
a + b << c; |
(a + b) << c; |
a + b >> c; |
(a + b) >> c; |
a + b & c; |
(a + b) & c; |
a + b | c; |
(a + b) | c; |
a + b ^ c; |
(a + b) ^ c; |
a - b + c; |
a - b + c; |
a - b - c; |
a - b - c; |
a - b * c; |
a - b * c; |
a - b / c; |
a - b / c; |
a - b % c; |
a - (b % c); |
a - b ** c; |
a - b ** c; |
a - b << c; |
(a - b) << c; |
a - b >> c; |
(a - b) >> c; |
a - b & c; |
(a - b) & c; |
a - b | c; |
(a - b) | c; |
a - b ^ c; |
(a - b) ^ c; |
a * b + c; |
a * b + c; |
a * b - c; |
a * b - c; |
a * b * c; |
a * b * c; |
a * b / c; |
(a * b) / c; |
a * b % c; |
(a * b) % c; |
a * b ** c; |
a * b ** c; |
a * b << c; |
(a * b) << c; |
a * b >> c; |
(a * b) >> c; |
a * b & c; |
(a * b) & c; |
a * b | c; |
(a * b) | c; |
a * b ^ c; |
(a * b) ^ c; |
a / b + c; |
a / b + c; |
a / b - c; |
a / b - c; |
a / b * c; |
(a / b) * c; |
a / b / c; |
a / b / c; |
a / b % c; |
(a / b) % c; |
a / b ** c; |
a / b ** c; |
a / b << c; |
(a / b) << c; |
a / b >> c; |
(a / b) >> c; |
a / b & c; |
(a / b) & c; |
a / b | c; |
(a / b) | c; |
a / b ^ c; |
(a / b) ^ c; |
a % b + c; |
(a % b) + c; |
a % b - c; |
(a % b) - c; |
a % b * c; |
(a % b) * c; |
a % b / c; |
(a % b) / c; |
a % b % c; |
(a % b) % c; |
a % b ** c; |
a % b ** c; |
a % b << c; |
a % b << c; |
a % b >> c; |
a % b >> c; |
a % b & c; |
a % b & c; |
a % b | c; |
a % b | c; |
a % b ^ c; |
a % b ^ c; |
a ** b + c; |
a ** b + c; |
a ** b - c; |
a ** b - c; |
a ** b * c; |
a ** b * c; |
a ** b / c; |
a ** b / c; |
a ** b % c; |
a ** b % c; |
a ** b ** c; |
a ** (b ** c); |
a ** b << c; |
(a ** b) << c; |
a ** b >> c; |
(a ** b) >> c; |
a ** b & c; |
(a ** b) & c; |
a ** b | c; |
(a ** b) | c; |
a ** b ^ c; |
(a ** b) ^ c; |
a << b + c; |
a << (b + c); |
a << b - c; |
a << (b - c); |
a << b * c; |
a << (b * c); |
a << b / c; |
a << (b / c); |
a << b % c; |
a << b % c; |
a << b ** c; |
a << (b ** c); |
a << b << c; |
(a << b) << c; |
a << b >> c; |
(a << b) >> c; |
a << b & c; |
(a << b) & c; |
a << b | c; |
(a << b) | c; |
a << b ^ c; |
(a << b) ^ c; |
a >> b + c; |
a >> (b + c); |
a >> b - c; |
a >> (b - c); |
a >> b * c; |
a >> (b * c); |
a >> b / c; |
a >> (b / c); |
a >> b % c; |
a >> b % c; |
a >> b ** c; |
a >> (b ** c); |
a >> b << c; |
(a >> b) << c; |
a >> b >> c; |
(a >> b) >> c; |
a >> b & c; |
(a >> b) & c; |
a >> b | c; |
(a >> b) | c; |
a >> b ^ c; |
(a >> b) ^ c; |
a & b + c; |
a & (b + c); |
a & b - c; |
a & (b - c); |
a & b * c; |
a & (b * c); |
a & b / c; |
a & (b / c); |
a & b % c; |
a & b % c; |
a & b ** c; |
a & (b ** c); |
a & b << c; |
a & (b << c); |
a & b >> c; |
a & (b >> c); |
a & b & c; |
a & b & c; |
a & b | c; |
(a & b) | c; |
a & b ^ c; |
(a & b) ^ c; |
a | b + c; |
a | (b + c); |
a | b - c; |
a | (b - c); |
a | b * c; |
a | (b * c); |
a | b / c; |
a | (b / c); |
a | b % c; |
a | b % c; |
a | b ** c; |
a | (b ** c); |
a | b << c; |
a | (b << c); |
a | b >> c; |
a | (b >> c); |
a | b & c; |
a | (b & c); |
a | b | c; |
a | b | c; |
a | b ^ c; |
a | (b ^ c); |
a ^ b + c; |
a ^ (b + c); |
a ^ b - c; |
a ^ (b - c); |
a ^ b * c; |
a ^ (b * c); |
a ^ b / c; |
a ^ (b / c); |
a ^ b % c; |
a ^ b % c; |
a ^ b ** c; |
a ^ (b ** c); |
a ^ b << c; |
a ^ (b << c); |
a ^ b >> c; |
a ^ (b >> c); |
a ^ b & c; |
a ^ (b & c); |
a ^ b | c; |
(a ^ b) | c; |
a ^ b ^ c; |
a ^ b ^ c; |
a || b || c; |
a || b || c; |
a || b && c; |
a || (b && c); |
a && b || c; |
(a && b) || c; |
a && b && c; |
a && b && c; |