Skip to content

EIP-7823: Set upper bounds for MODEXP #4070

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

am1r021
Copy link
Contributor

@am1r021 am1r021 commented May 6, 2025

This change implements EIP-7823, which is being considered for inclusion in Fusaka. With this EIP activated, the MODEXP precompile will reject any requests with any inputs of length greater than 1024 bytes, and will consume all gas in the process.

Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.41%. Comparing base (0303764) to head (e64c1c1).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 84.33% <ø> (ø)
blockchain 89.32% <ø> (ø)
client 67.55% <ø> (ø)
common 97.51% <100.00%> (+<0.01%) ⬆️
devp2p 86.71% <ø> (-0.08%) ⬇️
evm 73.13% <100.00%> (+0.02%) ⬆️
mpt 90.36% <ø> (+0.92%) ⬆️
statemanager 69.06% <ø> (ø)
static 99.11% <ø> (ø)
tx 89.89% <ø> (ø)
util 89.20% <100.00%> (+<0.01%) ⬆️
vm 55.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -150,6 +149,7 @@ export function precompile05(opts: PrecompileInput): ExecResult {
}
}

const maxSize = opts.common.isActivatedEIP(7823) ? BigInt(1024) : BigInt(2147483647) // @ethereumjs/util setLengthRight limitation
Copy link
Member

Choose a reason for hiding this comment

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

I think to be complicit with the EIP (or rather, before the EIP) a check should only be done if EIP 7823 is active (not hardcoding a "high" maxSize limit, this could fail specifically crafted tests which would not work in practice due to the high gas limit required to call this precompile with such large input data (due to quadratic memory gas costs))

/**
* Compute base^exp mod modulus for *arbitrarily* large BigInts
*/
function modPow(base: bigint, exp: bigint, modulus: bigint): bigint {
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be done directly with bigints?

it(`MODEXP should reject and consume all gas for inputs over 8192 bits in length - case ${maxInputLen} bytes`, async () => {
const result = await MODEXP({
data: input,
gasLimit: BigInt(0xffffffff),
Copy link
Member

Choose a reason for hiding this comment

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

I think there should be a sanity check to confirm that this gasLimit is enough to pay for the precompile, but that the precompile now rejects it due to the incode length limit

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

Successfully merging this pull request may close these issues.

2 participants