Remove finney and szabo denominations.

This commit is contained in:
Daniel Kirchner 2020-07-08 19:45:30 +02:00 committed by Leonardo Alt
parent cf189a3285
commit 38c6ecbbe2
17 changed files with 43 additions and 76 deletions

View File

@ -15,6 +15,7 @@ Breaking changes:
* ``using A for B`` only affects the contract it is mentioned in and not all derived contracts * ``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: 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``. * 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: Language Features:
* Yul: Disallow EVM instruction `pc()`. * Yul: Disallow EVM instruction `pc()`.

View File

@ -361,11 +361,12 @@ assemblyType
subAssembly subAssembly
: 'assembly' identifier assemblyBlock ; : 'assembly' identifier assemblyBlock ;
// 'finney' and 'szabo' are no longer supported as denominations by latest Solidity.
numberLiteral numberLiteral
: (DecimalNumber | HexNumber) (NumberUnit | Gwei)?; : (DecimalNumber | HexNumber) (NumberUnit | Gwei | Finney | Szabo)?;
identifier identifier
: (Gwei | 'from' | 'calldata' | 'address' | Identifier) ; : (Gwei | Finney | Szabo | 'from' | 'calldata' | 'address' | Identifier) ;
BooleanLiteral BooleanLiteral
: 'true' | 'false' ; : 'true' | 'false' ;
@ -385,10 +386,12 @@ HexDigits
: HexCharacter ( '_'? HexCharacter )* ; : HexCharacter ( '_'? HexCharacter )* ;
NumberUnit NumberUnit
: 'wei' | 'szabo' | 'finney' | 'ether' : 'wei' | 'ether'
| 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years' ; | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years' ;
Gwei: 'gwei' ; Gwei: 'gwei' ;
Szabo: 'szabo' ;
Finney: 'finney' ;
HexLiteralFragment HexLiteralFragment
: 'hex' (('"' HexDigits? '"') | ('\'' HexDigits? '\'')) ; : 'hex' (('"' HexDigits? '"') | ('\'' HexDigits? '\'')) ;

View File

@ -2,23 +2,23 @@
Units and Globally Available Variables Units and Globally Available Variables
************************************** **************************************
.. index:: wei, finney, szabo, ether .. index:: wei, finney, szabo, gwei, ether
Ether Units 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 wei == 1);
assert(1 gwei == 1e9); assert(1 gwei == 1e9);
assert(1 szabo == 1e12);
assert(1 finney == 1e15);
assert(1 ether == 1e18); assert(1 ether == 1e18);
The only effect of the subdenomination suffix is a multiplication by a power of ten. 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 .. index:: time, seconds, minutes, hours, days, weeks, years

View File

@ -196,8 +196,6 @@ namespace solidity::langutil
\ \
/* Ether subdenominations */ \ /* Ether subdenominations */ \
K(SubWei, "wei", 0) \ K(SubWei, "wei", 0) \
K(SubSzabo, "szabo", 0) \
K(SubFinney, "finney", 0) \
K(SubEther, "ether", 0) \ K(SubEther, "ether", 0) \
K(SubSecond, "seconds", 0) \ K(SubSecond, "seconds", 0) \
K(SubMinute, "minutes", 0) \ K(SubMinute, "minutes", 0) \
@ -313,7 +311,7 @@ namespace TokenTraits
|| op == Token::Pure || op == Token::View || op == Token::Payable; || 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 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); } constexpr bool isReservedKeyword(Token op) { return (Token::After <= op && op <= Token::Unchecked); }

View File

@ -2086,8 +2086,6 @@ public:
None = static_cast<int>(Token::Illegal), None = static_cast<int>(Token::Illegal),
Wei = static_cast<int>(Token::SubWei), Wei = static_cast<int>(Token::SubWei),
Gwei = static_cast<int>(Token::SubGwei), Gwei = static_cast<int>(Token::SubGwei),
Szabo = static_cast<int>(Token::SubSzabo),
Finney = static_cast<int>(Token::SubFinney),
Ether = static_cast<int>(Token::SubEther), Ether = static_cast<int>(Token::SubEther),
Second = static_cast<int>(Token::SubSecond), Second = static_cast<int>(Token::SubSecond),
Minute = static_cast<int>(Token::SubMinute), Minute = static_cast<int>(Token::SubMinute),

View File

@ -1004,10 +1004,6 @@ Literal::SubDenomination ASTJsonImporter::subdenomination(Json::Value const& _no
return Literal::SubDenomination::Wei; return Literal::SubDenomination::Wei;
else if (subDenStr == "gwei") else if (subDenStr == "gwei")
return Literal::SubDenomination::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") else if (subDenStr == "ether")
return Literal::SubDenomination::Ether; return Literal::SubDenomination::Ether;
else if (subDenStr == "seconds") else if (subDenStr == "seconds")

View File

@ -988,12 +988,6 @@ tuple<bool, rational> RationalNumberType::isValidLiteral(Literal const& _literal
case Literal::SubDenomination::Gwei: case Literal::SubDenomination::Gwei:
value *= bigint("1000000000"); value *= bigint("1000000000");
break; break;
case Literal::SubDenomination::Szabo:
value *= bigint("1000000000000");
break;
case Literal::SubDenomination::Finney:
value *= bigint("1000000000000000");
break;
case Literal::SubDenomination::Ether: case Literal::SubDenomination::Ether:
value *= bigint("1000000000000000000"); value *= bigint("1000000000000000000");
break; break;

View File

@ -45,13 +45,9 @@ using rational = boost::rational<bigint>;
/// @NOTE This is not endian-specific; it's just a bunch of bytes. /// @NOTE This is not endian-specific; it's just a bunch of bytes.
using Address = util::h160; using Address = util::h160;
// The various denominations; here for ease of use where needed within code. // The ether and gwei denominations; here for ease of use where needed within code.
static const u256 wei = 1; static const u256 gwei = u256(1) << 9;
static const u256 shannon = u256("1000000000"); static const u256 ether = u256(1) << 18;
static const u256 gwei = shannon;
static const u256 szabo = shannon * 1000;
static const u256 finney = szabo * 1000;
static const u256 ether = finney * 1000;
class ExecutionFramework class ExecutionFramework
{ {
@ -287,7 +283,7 @@ protected:
bool m_transactionSuccessful = true; bool m_transactionSuccessful = true;
Address m_sender = account(0); Address m_sender = account(0);
Address m_contractAddress; Address m_contractAddress;
u256 const m_gasPrice = 100 * szabo; u256 const m_gasPrice = 10 * gwei;
u256 const m_gas = 100000000; u256 const m_gas = 100000000;
bytes m_output; bytes m_output;
u256 m_gasUsed; u256 m_gasUsed;

View File

@ -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_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) BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(

View File

@ -428,11 +428,9 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
BOOST_AUTO_TEST_CASE(ether_subdenominations) 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.currentToken(), Token::SubWei);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); 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::SubEther); BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
} }

View File

@ -1,7 +1,7 @@
contract C { 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 b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks;
uint constant c = 2 szabo / 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 finney * 3 hours; uint constant d = 2 gwei / 1 seconds + 3 minutes * 3 hours;
} }
// ---- // ----

View File

@ -0,0 +1,7 @@
contract C {
function f() {
uint x = 1 finney;
}
}
// ----
// ParserError 2314: (45-51): Expected ';' but got identifier

View File

@ -0,0 +1,6 @@
contract C {
function f(uint finney) public pure returns (uint szabo) {
// These used to be denominations.
szabo = finney;
}
}

View File

@ -0,0 +1,7 @@
contract C {
function f() {
uint x = 1 szabo;
}
}
// ----
// ParserError 2314: (45-50): Expected ';' but got identifier

View File

@ -2,15 +2,11 @@ contract C {
function f() public function f() public
{ {
a = 1 wei; a = 1 wei;
b = 2 szabo; b = 2 ether;
c = 3 finney; c = 3 gwei;
d = 4 ether;
e = 5 gwei;
} }
uint256 a; uint256 a;
uint256 b; uint256 b;
uint256 c; uint256 c;
uint256 d;
uint256 e;
} }
// ---- // ----

View File

@ -1,7 +1,7 @@
contract c { contract c {
constructor() constructor()
{ {
a = 1 wei * 100 wei + 7 szabo - 3; a = 1 wei * 100 wei + 7 gwei - 3;
} }
uint256 a; uint256 a;
} }

View File

@ -6,7 +6,6 @@
" block.timestamp " " block.timestamp "
" days " " days "
" ether " " ether "
" finney "
" gasleft() " " gasleft() "
" gwei " " gwei "
" hours " " hours "
@ -18,7 +17,6 @@
" msg.value " " msg.value "
" now " " now "
" seconds " " seconds "
" szabo "
" tx.gasprice " " tx.gasprice "
" tx.origin " " tx.origin "
" weeks " " weeks "