Skip to content

Conversation

@mekkanik
Copy link
Contributor

Fix for issue with very large exponent values causing CPU blowout. Exponent values now restricted to max of 1232 ( rational(1) << 4096, approximated.) It should also be noted that values above E78 are causing casting errors:

biginttest.sol:6:11: Error: Type int_const 1000000000000000000000000000000000000000000000000000000000000000000000000000000 is not implicitly convertible to expected type uint256. c=1E78;

bigint exp = bigint(string(expPoint + 1, _literal.value().end()));

if (exp > numeric_limits<int32_t>::max() || exp < numeric_limits<int32_t>::min())
// SOL-008: Huge values for exponent are causing a crash. Limiting maximum to rational(1) << 4096
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could shorten this to something like `disallow gigantic exponents to limit memory consumption'.

// SOL-008: Huge values for exponent are causing a crash. Limiting maximum to rational(1) << 4096
// 1<<1024 = 1.7977^308. Extrapolating for 1<<4096, the exponent value will approximately be 1232.
// However, it does appear that values in excess of E77 will still cause casting errors.
if (exp > 1232 || exp < -1232)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, this still depends on the mantissa. We could be conservative with the exponent, i.e. allow anything where abs(exp) < 1250 and then re-check once we have the actual value. We should re-check this anyway at the end of the function because you can also do things like

x = (1e20 * 1e20)** 500.

The only reason we need a more intricate check at any point where boost::multiprecision::pow is used is that this operation itself could already exhaust memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going by the following error message:

biginttest.sol:6:11: Error: Type int_const 1000000000000000000000000000000000000000000000000000000000000000000000000000000 is not implicitly convertible to expected type uint256. c=1E78;

It appears that we are running into the hard limit of uint256 (2^256 = 1.157920892×10⁷⁷.) Exponent 77. This being the case, why not just set the upper limit to 77? We are not going to be able to support anything bigger unless we start using a different data type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to allow intermediate values that are larger, as long as the final value of a computation fits into 256 bits.

@chriseth
Copy link
Contributor

Do you want to handle things like 10**1000000 in a second pull request?

@chriseth
Copy link
Contributor

Oh and please add a test for this change.

@chriseth
Copy link
Contributor

Oh I'm sorry, I forget something: Could you also add a line into the Changelog.md file at the topmost section under 'bugfixes'? Something like Type Checker: Limit the size of the exponent in scientific notation of number literals.

@chriseth
Copy link
Contributor

chriseth commented Jan 4, 2018

Could you please rebase this? There is a conflict in the changelog.

@axic
Copy link
Contributor

axic commented Jan 5, 2018

Also can you please squash some of these commits? There appears to be a couple of them with the same commit log.

@mekkanik
Copy link
Contributor Author

mekkanik commented Jan 5, 2018

Done. Sorry had some difficulties getting used to remote branch :)

@chriseth
Copy link
Contributor

chriseth commented Jan 9, 2018

Please remove the merge commits by rebasing.

@mekkanik
Copy link
Contributor Author

@chriseth @axic Requires re-review. I tried to squash the changes before committing. Somehow unable to resolve conflicts in the browser. Will try that again tomorrow.

@mekkanik
Copy link
Contributor Author

This has gotten completely out of hand. my fault. I'll submit a fresh request with the proper fix.

@mekkanik mekkanik closed this Jan 15, 2018
@mekkanik mekkanik deleted the mekkanik_fixes branch January 15, 2018 17:00
@mekkanik
Copy link
Contributor Author

I thought I closed this out... ah well. closing this out for a cleaner PR.

@axic axic mentioned this pull request Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants