Skip to content

fix: widen memory cost square to 64-bit in grow_memory - #1

Open
hatemosphere wants to merge 1 commit into
erigontech:release/airbenderfrom
hatemosphere:fix/grow-memory-2mb-uint32-overflow
Open

fix: widen memory cost square to 64-bit in grow_memory#1
hatemosphere wants to merge 1 commit into
erigontech:release/airbenderfrom
hatemosphere:fix/grow-memory-2mb-uint32-overflow

Conversation

@hatemosphere

Copy link
Copy Markdown

grow_memory computes new_words * new_words in uint32. At exactly 65536 memory words (2 MiB) the square is 2^32 and wraps, so the expansion cost delta underflows to ~4.3e9 gas and any frame growing memory past 2 MiB OOGs instantly. 65535 words still fits in 32 bits, so everything below 2 MiB is unaffected.

Hit on mainnet by zilkworm preflight (kWrongBlockGas) on blocks 25723470, 25728210 and 25737170 - Resupply liquidation txs that abi-encode >2 MiB call buffers in a loop. With this fix all three validate byte-exact against canonical gas, and 20 recent healthy blocks pass as regression.

The widened square is still a single mul/mulhu pair on rv32im.

Note: includes a regression test crossing the 2 MiB boundary, written to upstream evmone conventions. This branch's unittest suite does not currently build standalone (test/state drift vs lib, e.g. TransactionReceipt::logs_bloom_filter), so the test is syntax-checked against branch headers only.

grow_memory computed new_words * new_words in uint32; at 65536 words
(2 MiB) the square is exactly 2^32 and wraps, turning the expansion
cost delta into ~4.3e9 gas and OOG-ing any frame that grows memory
past 2 MiB. 65535 words still fits, so smaller memory is unaffected.

Found via zilkworm preflight kWrongBlockGas on mainnet blocks
25723470, 25728210, 25737170 (>2 MiB abi-encode buffers); all three
validate byte-exact against canonical gas with the fix.
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.

2 participants