Frontier's modexp precompile is slow for even modulus
High severity
GitHub Reviewed
Published
Mar 20, 2023
in
polkadot-evm/frontier
•
Updated Oct 24, 2024
Description
Published to the GitHub Advisory Database
Mar 21, 2023
Reviewed
Mar 21, 2023
Published by the National Vulnerability Database
Mar 22, 2023
Last updated
Oct 24, 2024
Impact
Frontier's
modexpprecompile usesnum-bigintcrate under the hood. In the implementation, the cases for modulus being even and modulus being odd are treated separately. Odd modulus uses the fast Montgomery multiplication, and even modulus uses the slow plain power algorithm. This gas cost discrepancy was not accounted for in themodexpprecompile, leading to possible denial of service attacks.Patches
No fixes for
num-bigintis currently available, and thus this advisory will be first fixed in the short term by raising the gas costs for even modulus, and in the long term fixing it innum-bigintor switching to another modexp implementation.The short-term fix for Frontier is deployed at PR 1017.
The recommendations are as follows:
Workarounds
None.
References
A similar issue was presented in Geth's implementation and the fix can be found here.
References