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

Modular exponentiation precompile wrapper #1985

Closed
frangio opened this issue Nov 6, 2019 · 3 comments · Fixed by #3298
Closed

Modular exponentiation precompile wrapper #1985

frangio opened this issue Nov 6, 2019 · 3 comments · Fixed by #3298
Labels
Account Abstraction contracts Smart contract code. Cryptography feature New contracts, functions, or helpers.

Comments

@frangio
Copy link
Contributor

frangio commented Nov 6, 2019

EIP 198 introduced the modular exponentiation precompile, also known as "modexp".

It's a useful primitive for cryptographic operations, which we would like to wrap in a library so that developers can use it without having to write assembly.

One of the challenges is the fact that the precompile receives and returns bignums, i.e. numbers of arbitrary size. In order to provide a good interface, we might need to define a struct to represent bignum types.

@frangio frangio added contracts Smart contract code. feature New contracts, functions, or helpers. labels Nov 6, 2019
@mw2000
Copy link
Contributor

mw2000 commented Mar 26, 2022

Is anyone still working on this? If not I'd like to have a crack at this.

@mw2000
Copy link
Contributor

mw2000 commented Mar 26, 2022

I found this useful function on StackExchange that could be the solution to this:
https://ethereum.stackexchange.com/questions/71565/verifying-modular-exponentiation-operation-in-etherum

mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Dec 23, 2022
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Jun 9, 2023
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Jun 9, 2023
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Jun 11, 2023
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Jun 25, 2023
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Jun 25, 2023
mw2000 added a commit to mw2000/openzeppelin-contracts that referenced this issue Nov 8, 2023
@ernestognw
Copy link
Member

ernestognw commented Nov 8, 2023

I'm not sure if #3298 's implementation is actually useful in the majority of the cases. The main reason why I see developers using modexp is because they're working with RSA signatures (not sure if there are other use cases).

When working with RSA signatures, a private key consists of a modulus m and an exponent e. So for producing a signature, a signer should get a digest of the signed message and then do modexp(digest, e, m) in order to get a signature.

Similarly, for verifying it's needed to do modexp(signature, e, m).

Both operations don't fit in an uint256 since the values of both e and m are typically 3072 bits (for 128-bit security).

Although RSA signatures have never been popular on Ethereum, with the new Account Abstraction trend it can be used as an alternative authorization mechanism. So, I'm afraid that this implementation wouldn't solve that particular use case.
If there's another use case justifying this current implementation, we can consider merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Account Abstraction contracts Smart contract code. Cryptography feature New contracts, functions, or helpers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants