Skip to content

Stack to deep error when setting optimizer = true in foundry.toml #77

@johnwhitton

Description

@johnwhitton

Overview

When adding the following to foundry.toml

via_ir = true
optimizer = true

You get the error

uniswapfoundation/v4-template - (main)$ forge test
[⠊] Compiling...
[⠘] Compiling 87 files with Solc 0.8.28
[⠃] Solc 0.8.28 finished in 4.94s
Error: Compiler run failed:
Error: Yul exception:Variable expr_mpos_2 is 1 too deep in the stack [ var_amount0Max RET _2 expr_mpos_2 expr_mpos_1 _1 expr_mpos var_deadline var_posm_address _2 var_recipient var_poolKey_mpos var_tickUpper var_tickLower var_hookData_mpos var_recipient var_amount1Max var_amount0Max expr expr_1 ]
No memoryguard was present. Consider using memory-safe assembly only and annotating it via 'assembly ("memory-safe") { ... }'.
uniswapfoundation/v4-template - (main)$

Removing them tests succesfully

Additional Information

Note that I tested the included .gitmodules (hookmate and uniswap-hooks) individually, and they could compile optimized code. Also if you remove all the tests it will compile succesfully with optimizer = true.

Therefore, it appears that the tests use of the gitmodules are causing the error, likely due to the' create2' functionality.
I'll look more into this as time permits.

Workaround - Hack

Currently I have added a release profile into foundry.toml as follows

[profile.release]
solc_version = "0.8.30"
evm_version = "prague"

ffi = true
fs_permissions = [{access = "read-write", path = ".forge-snapshots/"}]

via_ir = true
optimizer = true

and when building for a release will specify the profile and the file I wish to compile.

Let me know if there is a better approach for this.

🙏 💙 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions