Sitelet https://web.archive.org/web/20201229201527/https://github.com/ethereum/solidity/issues/10443
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialized checked exponentation when exponent is a literal #10443

Open
hrkrshnn opened this issue Nov 30, 2020 · 2 comments
Open

Specialized checked exponentation when exponent is a literal #10443

hrkrshnn opened this issue Nov 30, 2020 · 2 comments

Comments

@hrkrshnn
Copy link
Member

@hrkrshnn hrkrshnn commented Nov 30, 2020

We already have a specialized checked exponentiation when the base is a literal and exponent can only be known at compile time.

Implement the case where exponent is a literal and base is only known at compile time. Vyper already has this: vyperlang/vyper#2072

@axic
Copy link
Member

@axic axic commented Nov 30, 2020

Don't we have a rulelist entry for this in libevmasm?

@hrkrshnn
Copy link
Member Author

@hrkrshnn hrkrshnn commented Nov 30, 2020 •

What I mean is the following.

A code of the form x**literal should generate yul similar to this: x**literal < 2**256 iff x < e**(256 . ln(x) / ln(literal)) (you compute the upper bound using binary-search)

    if gt(x, upper-limit) {
       panic(Overflow)
    }
    ret :=  exp(x, literal)

Currently, the above code will undergo checked exponentiation by squaring.

We can have some rule list entries for special cases (such as exp(x, 2) into mul(x, x)), but that's not what this is about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.