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

Bug: forge bind fails to compile on keyword enum (alloy) #5847

Closed
2 tasks done
0xJepsen opened this issue Sep 18, 2023 · 4 comments · Fixed by #9761
Closed
2 tasks done

Bug: forge bind fails to compile on keyword enum (alloy) #5847

0xJepsen opened this issue Sep 18, 2023 · 4 comments · Fixed by #9761
Assignees
Labels
C-forge Command: forge Cmd-forge-bind Command: forge bind P-low Priority: low T-bug Type: bug
Milestone

Comments

@0xJepsen
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (ecf9a10 2023-09-18T00:24:28.742120000Z)

What command(s) is the bug in?

forge bind

Operating System

macOS (Apple Silicon)

Describe the bug

To reproduce the bug run

forge init bug_repro
cd bug_repro
forge install ethereum-optimism/optimism@develop
cd lib/optimsim/packages/contracts-bedrock
forge bind

then in the project root run

cargo init --bin

and add foundry-contracts = { path = "lib/optimism/packages/contracts-bedrock/forge-artifacts/bindings" } to the cargo.toml

at this point the static analyzer will pick up the compile errors in the bindings. but you can verify by attempting to import them to the main file with use foundry_contracts::l2_output_oracle;

the bindings are mostly correct but generate duplicate struct definitions for the https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L1/L2OutputOracle.sol contract that then implicate the
https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L1/OptimismPortal.sol

From what i can tell the duplicate structs are in fact identical.

Desired functionality would be for forge bind to not produce codegen that doesn't compile.

@0xJepsen 0xJepsen added the T-bug Type: bug label Sep 18, 2023
@gakonst gakonst added this to Foundry Sep 18, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Sep 18, 2023
@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-bind Command: forge bind labels Jul 4, 2024
@zerosnacks
Copy link
Member

Able to reproduce with given instructions

forge bind (ethers) generates bindings with the duplicate struct definitions as reported.

Unfortunately forge bind --alloy fails to generate with:

Generating bindings for 394 contracts
Error: 
expected identifier, found keyword `enum`

cc @DaniPopes + @yash-atreya could be a good setup for stress testing Alloy's binding generation

Created a repo with instructions here to simplify reproduction: https://github.com/zerosnacks/foundry-bug-5847-repro

@zerosnacks zerosnacks changed the title Forge Bind generates duplicate structs that don't compile Bug: forge bind generates duplicate structs that don't compile (ethers) or fails to compile on keyword enum (alloy) Jul 4, 2024
@mattsse
Copy link
Member

mattsse commented Jul 4, 2024

closing since this is legacy ethers bind

reopen because alloy bind also fails -.-

@mattsse mattsse closed this as completed Jul 4, 2024
@mattsse mattsse reopened this Jul 4, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@zerosnacks
Copy link
Member

zerosnacks commented Nov 18, 2024

Confirming this is still an active issue with Alloy, keeping it in the milestone

Updating title to scope to Alloy only

Generating bindings for 525 contracts
Error: expected identifier, found keyword `enum`

cc @yash-atreya / @DaniPopes

@zerosnacks zerosnacks changed the title Bug: forge bind generates duplicate structs that don't compile (ethers) or fails to compile on keyword enum (alloy) Bug: forge bind fails to compile on keyword enum (alloy) Nov 18, 2024
@zerosnacks zerosnacks removed their assignment Nov 18, 2024
@yash-atreya yash-atreya self-assigned this Nov 18, 2024
@DaniPopes
Copy link
Member

This is because one of the generated modules is named enum which is a keyword in Rust.
The fix is to prefix invalid module names with r#. We can either do it unconditionally or first check if the identifier is invalid

@grandizzy grandizzy added the P-low Priority: low label Nov 19, 2024
@yash-atreya yash-atreya moved this from Todo to Ready For Review in Foundry Jan 27, 2025
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Jan 27, 2025
@grandizzy grandizzy moved this from Done to Completed in Foundry Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-bind Command: forge bind P-low Priority: low T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

6 participants