diff --git a/Changelog.md b/Changelog.md index ec24544ab..e45646c91 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ Breaking changes: * Constructors should not have visibility. * Deprecated dot syntax for `value` and `gas`. * Deprecated the identifier `now`. + * Disallow `gwei` as identifier. * JSON AST: Removes members with ``null`` value from JSON output. * Parser: NatSpec comments on variables are only allowed for public state variables. * Type Checker: Disallow shifts by signed types. @@ -15,6 +16,7 @@ Breaking changes: * ``using A for B`` only affects the contract it is mentioned in and not all derived contracts * Inline Assembly: Disallow `.` in user-defined function and variable names. * Inline Assembly: Slot and offset of storage pointer variable ``x`` are accessed via ``x.slot`` and ``x.offset`` instead of ``x_slot`` and ``x_offset``. + * Remove the finney and szabo denominations. Language Features: * Yul: Disallow EVM instruction `pc()`. diff --git a/docs/Solidity.g4 b/docs/Solidity.g4 index d4e86c523..f86d95fc4 100644 --- a/docs/Solidity.g4 +++ b/docs/Solidity.g4 @@ -361,11 +361,12 @@ assemblyType subAssembly : 'assembly' identifier assemblyBlock ; +// 'finney' and 'szabo' are no longer supported as denominations by latest Solidity. numberLiteral - : (DecimalNumber | HexNumber) (NumberUnit | Gwei)?; + : (DecimalNumber | HexNumber) (NumberUnit | Gwei | Finney | Szabo)?; identifier - : (Gwei | 'from' | 'calldata' | 'address' | Identifier) ; + : (Gwei | Finney | Szabo | 'from' | 'calldata' | 'address' | Identifier) ; BooleanLiteral : 'true' | 'false' ; @@ -385,10 +386,12 @@ HexDigits : HexCharacter ( '_'? HexCharacter )* ; NumberUnit - : 'wei' | 'szabo' | 'finney' | 'ether' + : 'wei' | 'ether' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years' ; Gwei: 'gwei' ; +Szabo: 'szabo' ; +Finney: 'finney' ; HexLiteralFragment : 'hex' (('"' HexDigits? '"') | ('\'' HexDigits? '\'')) ; diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 28232f6a9..a32900a50 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -2,23 +2,23 @@ Units and Globally Available Variables ************************************** -.. index:: wei, finney, szabo, ether +.. index:: wei, finney, szabo, gwei, ether Ether Units =========== -A literal number can take a suffix of ``wei``, ``gwei``, ``finney``, ``szabo`` or ``ether`` to specify a subdenomination of Ether, where Ether numbers without a postfix are assumed to be Wei. +A literal number can take a suffix of ``wei``, ``gwei`` or ``ether`` to specify a subdenomination of Ether, where Ether numbers without a postfix are assumed to be Wei. :: assert(1 wei == 1); assert(1 gwei == 1e9); - assert(1 szabo == 1e12); - assert(1 finney == 1e15); assert(1 ether == 1e18); The only effect of the subdenomination suffix is a multiplication by a power of ten. +.. note:: + The denominations ``finney`` and ``szabo`` have been removed in version 0.7.0. .. index:: time, seconds, minutes, hours, days, weeks, years diff --git a/liblangutil/Token.h b/liblangutil/Token.h index 916f71c75..cea102f0f 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -196,8 +196,7 @@ namespace solidity::langutil \ /* Ether subdenominations */ \ K(SubWei, "wei", 0) \ - K(SubSzabo, "szabo", 0) \ - K(SubFinney, "finney", 0) \ + K(SubGwei, "gwei", 0) \ K(SubEther, "ether", 0) \ K(SubSecond, "seconds", 0) \ K(SubMinute, "minutes", 0) \ @@ -232,7 +231,6 @@ namespace solidity::langutil \ /* Identifiers (not keywords or future reserved words). */ \ T(Identifier, nullptr, 0) \ - T(SubGwei, "gwei", 0) \ \ /* Keywords reserved for future use. */ \ K(After, "after", 0) \ @@ -313,7 +311,7 @@ namespace TokenTraits || op == Token::Pure || op == Token::View || op == Token::Payable; } - constexpr bool isEtherSubdenomination(Token op) { return op == Token::SubWei || op == Token::SubSzabo || op == Token::SubFinney || op == Token::SubEther; } + constexpr bool isEtherSubdenomination(Token op) { return op >= Token::SubWei && op <= Token::SubEther; } constexpr bool isTimeSubdenomination(Token op) { return op == Token::SubSecond || op == Token::SubMinute || op == Token::SubHour || op == Token::SubDay || op == Token::SubWeek || op == Token::SubYear; } constexpr bool isReservedKeyword(Token op) { return (Token::After <= op && op <= Token::Unchecked); } diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 9fcbe2926..ec37044a4 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -2086,8 +2086,6 @@ public: None = static_cast(Token::Illegal), Wei = static_cast(Token::SubWei), Gwei = static_cast(Token::SubGwei), - Szabo = static_cast(Token::SubSzabo), - Finney = static_cast(Token::SubFinney), Ether = static_cast(Token::SubEther), Second = static_cast(Token::SubSecond), Minute = static_cast(Token::SubMinute), diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index 1d9f77ad1..dfce6cb41 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -1004,10 +1004,6 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no return Literal::SubDenomination::Wei; else if (subDenStr == "gwei") return Literal::SubDenomination::Gwei; - else if (subDenStr == "szabo") - return Literal::SubDenomination::Szabo; - else if (subDenStr == "finney") - return Literal::SubDenomination::Finney; else if (subDenStr == "ether") return Literal::SubDenomination::Ether; else if (subDenStr == "seconds") diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index e50c4b617..a3521adbd 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -988,12 +988,6 @@ tuple RationalNumberType::isValidLiteral(Literal const& _literal case Literal::SubDenomination::Gwei: value *= bigint("1000000000"); break; - case Literal::SubDenomination::Szabo: - value *= bigint("1000000000000"); - break; - case Literal::SubDenomination::Finney: - value *= bigint("1000000000000000"); - break; case Literal::SubDenomination::Ether: value *= bigint("1000000000000000000"); break; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 819d18a79..ab8180dc7 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1825,16 +1825,11 @@ ASTPointer Parser::parsePrimaryExpression() expression = nodeFactory.createNode(token, getLiteralAndAdvance()); break; case Token::Number: - if ( - (m_scanner->peekNextToken() == Token::Identifier && m_scanner->peekLiteral() == "gwei") || - TokenTraits::isEtherSubdenomination(m_scanner->peekNextToken()) - ) + if (TokenTraits::isEtherSubdenomination(m_scanner->peekNextToken())) { ASTPointer literal = getLiteralAndAdvance(); nodeFactory.markEndPosition(); - Token actualToken = m_scanner->currentToken() == Token::Identifier ? Token::SubGwei : m_scanner->currentToken(); - - Literal::SubDenomination subdenomination = static_cast(actualToken); + Literal::SubDenomination subdenomination = static_cast(m_scanner->currentToken()); m_scanner->next(); expression = nodeFactory.createNode(token, literal, subdenomination); } diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index 6fea5310a..5e660c805 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -45,13 +45,9 @@ using rational = boost::rational; /// @NOTE This is not endian-specific; it's just a bunch of bytes. using Address = util::h160; -// The various denominations; here for ease of use where needed within code. -static const u256 wei = 1; -static const u256 shannon = u256("1000000000"); -static const u256 gwei = shannon; -static const u256 szabo = shannon * 1000; -static const u256 finney = szabo * 1000; -static const u256 ether = finney * 1000; +// The ether and gwei denominations; here for ease of use where needed within code. +static const u256 gwei = u256(1) << 9; +static const u256 ether = u256(1) << 18; class ExecutionFramework { @@ -287,7 +283,7 @@ protected: bool m_transactionSuccessful = true; Address m_sender = account(0); Address m_contractAddress; - u256 const m_gasPrice = 100 * szabo; + u256 const m_gasPrice = 10 * gwei; u256 const m_gas = 100000000; bytes m_output; u256 m_gasUsed; diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index 10083b827..5885bc616 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -236,37 +236,6 @@ BOOST_AUTO_TEST_CASE(int_with_gwei_ether_subdenomination) BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } -BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination) -{ - char const* sourceCode = R"( - contract test { - function test () { - uint x = 1 szabo; - } - } - )"; - bytes code = compileFirstExpression(sourceCode); - - bytes expectation({uint8_t(Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00}); - BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); -} - -BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination) -{ - char const* sourceCode = R"( - contract test { - constructor() - { - uint x = 1 finney; - } - } - )"; - bytes code = compileFirstExpression(sourceCode); - - bytes expectation({uint8_t(Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00}); - BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); -} - BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index b02a910a5..5b83778ba 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -428,11 +428,9 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence) BOOST_AUTO_TEST_CASE(ether_subdenominations) { - Scanner scanner(CharStream("wei gwei szabo finney ether", "")); + Scanner scanner(CharStream("wei gwei ether", "")); BOOST_CHECK_EQUAL(scanner.currentToken(), Token::SubWei); - BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); - BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo); - BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney); + BOOST_CHECK_EQUAL(scanner.next(), Token::SubGwei); BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther); } diff --git a/test/libsolidity/semanticTests/literals/denominations.sol b/test/libsolidity/semanticTests/literals/denominations.sol new file mode 100644 index 000000000..256525cb9 --- /dev/null +++ b/test/libsolidity/semanticTests/literals/denominations.sol @@ -0,0 +1,9 @@ +contract C { + uint constant x = 1 ether + 1 gwei + 1 wei; + + function f() public view returns(uint) { return x; } +} +// ==== +// compileViaYul: also +// ---- +// f() -> 1000000001000000001 diff --git a/test/libsolidity/semanticTests/literals/ether.sol b/test/libsolidity/semanticTests/literals/ether.sol new file mode 100644 index 000000000..f03171796 --- /dev/null +++ b/test/libsolidity/semanticTests/literals/ether.sol @@ -0,0 +1,9 @@ +contract C { + uint constant x = 1 ether; + + function f() public view returns(uint) { return x; } +} +// ==== +// compileViaYul: also +// ---- +// f() -> 1000000000000000000 diff --git a/test/libsolidity/semanticTests/literals/gwei.sol b/test/libsolidity/semanticTests/literals/gwei.sol index 7762021dc..54870040f 100644 --- a/test/libsolidity/semanticTests/literals/gwei.sol +++ b/test/libsolidity/semanticTests/literals/gwei.sol @@ -1,7 +1,7 @@ contract C { - uint constant gwei = 1 gwei; + uint constant x = 1 gwei; - function f() public view returns(uint) { return gwei; } + function f() public view returns(uint) { return x; } } // ==== // compileViaYul: also diff --git a/test/libsolidity/semanticTests/literals/wei.sol b/test/libsolidity/semanticTests/literals/wei.sol new file mode 100644 index 000000000..59af2a3d7 --- /dev/null +++ b/test/libsolidity/semanticTests/literals/wei.sol @@ -0,0 +1,9 @@ +contract C { + uint constant x = 1 wei; + + function f() public view returns(uint) { return x; } +} +// ==== +// compileViaYul: also +// ---- +// f() -> 1 diff --git a/test/libsolidity/syntaxTests/denominations/denominations.sol b/test/libsolidity/syntaxTests/denominations/denominations.sol index a34c03de0..3c1c305cf 100644 --- a/test/libsolidity/syntaxTests/denominations/denominations.sol +++ b/test/libsolidity/syntaxTests/denominations/denominations.sol @@ -1,7 +1,7 @@ contract C { - uint constant a = 1 wei + 2 szabo + 3 finney + 4 ether; + uint constant a = 1 wei + 4 ether; uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks; - uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours; - uint constant d = 2 gwei / 1 seconds + 3 finney * 3 hours; + uint constant c = 2 ether / 1 seconds + 3 gwei * 3 hours; + uint constant d = 2 gwei / 1 seconds + 3 minutes * 3 hours; } // ---- diff --git a/test/libsolidity/syntaxTests/denominations/finney_invalid.sol b/test/libsolidity/syntaxTests/denominations/finney_invalid.sol new file mode 100644 index 000000000..b7bae7fa7 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/finney_invalid.sol @@ -0,0 +1,7 @@ +contract C { + function f() { + uint x = 1 finney; + } +} +// ---- +// ParserError 2314: (45-51): Expected ';' but got identifier diff --git a/test/libsolidity/syntaxTests/denominations/gwei.sol b/test/libsolidity/syntaxTests/denominations/gwei.sol deleted file mode 100644 index 5bc5edb3d..000000000 --- a/test/libsolidity/syntaxTests/denominations/gwei.sol +++ /dev/null @@ -1,3 +0,0 @@ -contract C { - uint constant gwei = 1 gwei; -} diff --git a/test/libsolidity/syntaxTests/denominations/gwei_as_identifier.sol b/test/libsolidity/syntaxTests/denominations/gwei_as_identifier.sol new file mode 100644 index 000000000..43fde5ed7 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/gwei_as_identifier.sol @@ -0,0 +1,5 @@ +contract C { + uint constant gwei = 1; +} +// ---- +// ParserError 2314: (28-32): Expected identifier but got 'gwei' diff --git a/test/libsolidity/syntaxTests/denominations/szabo_finney_identifiers.sol b/test/libsolidity/syntaxTests/denominations/szabo_finney_identifiers.sol new file mode 100644 index 000000000..8facd62d4 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/szabo_finney_identifiers.sol @@ -0,0 +1,6 @@ +contract C { + function f(uint finney) public pure returns (uint szabo) { + // These used to be denominations. + szabo = finney; + } +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/denominations/szabo_invalid.sol b/test/libsolidity/syntaxTests/denominations/szabo_invalid.sol new file mode 100644 index 000000000..d206830d5 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/szabo_invalid.sol @@ -0,0 +1,7 @@ +contract C { + function f() { + uint x = 1 szabo; + } +} +// ---- +// ParserError 2314: (45-50): Expected ';' but got identifier diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol index 51ce8b4d5..6b3ccc7c0 100644 --- a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol @@ -2,15 +2,11 @@ contract C { function f() public { a = 1 wei; - b = 2 szabo; - c = 3 finney; - d = 4 ether; - e = 5 gwei; + b = 2 ether; + c = 3 gwei; } uint256 a; uint256 b; uint256 c; - uint256 d; - uint256 e; } // ---- diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol index efe2d2670..537320737 100644 --- a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol @@ -1,7 +1,7 @@ contract c { constructor() { - a = 1 wei * 100 wei + 7 szabo - 3; + a = 1 wei * 100 wei + 7 gwei - 3; } uint256 a; } diff --git a/test/tools/ossfuzz/config/solidity.dict b/test/tools/ossfuzz/config/solidity.dict index f788d49c2..f80fab989 100644 --- a/test/tools/ossfuzz/config/solidity.dict +++ b/test/tools/ossfuzz/config/solidity.dict @@ -6,7 +6,6 @@ " block.timestamp " " days " " ether " -" finney " " gasleft() " " gwei " " hours " @@ -18,7 +17,6 @@ " msg.value " " now " " seconds " -" szabo " " tx.gasprice " " tx.origin " " weeks "