mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Limits rational numbers to 4096 bits.
This commit is contained in:
committed by
Daniel Kirchner
parent
2001cc6bdc
commit
33fbf88707
@@ -102,6 +102,29 @@ BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
|
||||
ABI_CHECK(callContractFunction("f()", bytes()), toBigEndian(u256(-8)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exp_zero)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f(uint a) returns(uint d) { return a ** 0; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
testContractAgainstCppOnRange("f(uint256)", [](u256 const&) -> u256 { return u256(1); }, 0, 16);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(exp_zero_literal)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns(uint d) { return 0 ** 0; }
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("f()", bytes()), toBigEndian(u256(1)));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(conditional_expression_true_literal)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
contract c {
|
||||
uint[2**253] data;
|
||||
}
|
||||
// ----
|
||||
// Warning: (17-34): Variable covers a large part of storage and thus makes collisions likely. Either use mappings or dynamic arrays and allow their size to be increased only in small quantities per transaction.
|
||||
@@ -0,0 +1,13 @@
|
||||
contract c {
|
||||
function f() public pure {
|
||||
int a;
|
||||
a = 1 << 4095; // shift is fine, but result too large
|
||||
a = 1 << 4096; // too large
|
||||
a = (1E1233) << 2; // too large
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-80): Type int_const 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (133-142): Operator << not compatible with types int_const 1 and int_const 4096
|
||||
// TypeError: (169-182): Operator << not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2
|
||||
// TypeError: (169-182): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
function f() public pure {
|
||||
int a;
|
||||
a = 1/(2<<4094)/(2<<4094);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-92): Operator / not compatible with types rational_const 1 / 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168
|
||||
// TypeError: (71-92): Type rational_const 1 / 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256. Try converting to type ufixed8x80 or use an explicit conversion.
|
||||
@@ -0,0 +1,50 @@
|
||||
contract c {
|
||||
function f() public pure {
|
||||
int a;
|
||||
a = 4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4;
|
||||
a = -4 ** 4 ** 2 ** 4 ** 4 ** 4 ** 4 ** 4;
|
||||
a = 4 ** (-(2 ** 4 ** 4 ** 4 ** 4 ** 4));
|
||||
a = 0 ** 1E1233; // fine
|
||||
a = 1 ** 1E1233; // fine
|
||||
a = -1 ** 1E1233; // fine
|
||||
a = 2 ** 1E1233;
|
||||
a = -2 ** 1E1233;
|
||||
a = 2 ** -1E1233;
|
||||
a = -2 ** -1E1233;
|
||||
a = 1E1233 ** 2;
|
||||
a = -1E1233 ** 2;
|
||||
a = 1E1233 ** -2;
|
||||
a = -1E1233 ** -2;
|
||||
a = 1E1233 ** 1E1233;
|
||||
a = 1E1233 ** -1E1233;
|
||||
a = -1E1233 ** 1E1233;
|
||||
a = -1E1233 ** -1E1233;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-102): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
|
||||
// TypeError: (71-102): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (116-148): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
|
||||
// TypeError: (116-153): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4
|
||||
// TypeError: (116-153): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (167-203): Operator ** not compatible with types int_const 4 and int_const -179...(302 digits omitted)...7216
|
||||
// TypeError: (317-328): Operator ** not compatible with types int_const 2 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (342-354): Operator ** not compatible with types int_const -2 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (368-380): Operator ** not compatible with types int_const 2 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (394-407): Operator ** not compatible with types int_const -2 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (421-432): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2
|
||||
// TypeError: (421-432): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (446-458): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2
|
||||
// TypeError: (446-458): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (472-484): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2
|
||||
// TypeError: (472-484): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (498-511): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2
|
||||
// TypeError: (498-511): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (525-541): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (525-541): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (555-572): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (555-572): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (586-603): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (586-603): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (617-635): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (617-635): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
function bignum() public {
|
||||
uint256 a;
|
||||
a = 1e1233 / 1e1233; // 1e1233 is still fine
|
||||
a = 1e1234; // 1e1234 is too big
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (128-134): Invalid literal value.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
function bignum() public {
|
||||
uint a;
|
||||
a = 134562324532464234452335168163516E1200 / 134562324532464234452335168163516E1200; // still fine
|
||||
a = 1345623245324642344523351681635168E1200; // too large
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (179-218): Invalid literal value.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
function bignum() public {
|
||||
uint a;
|
||||
a = 134562324532464.234452335168163517E1200 / 134562324532464.234452335168163517E1200; // still fine
|
||||
a = 134562324532464.2344523351681635177E1200; // too large
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (181-221): Invalid literal value.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
function f() public pure {
|
||||
int a;
|
||||
a = (1<<4095)*(1<<4095);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-90): Operator * not compatible with types int_const 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168
|
||||
// TypeError: (71-90): Type int_const 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256.
|
||||
Reference in New Issue
Block a user