Skip to content

Alloy binding failed: unable to parse token from invalid AST #10055

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
2 tasks done
alxiong opened this issue Mar 11, 2025 · 9 comments
Open
2 tasks done

Alloy binding failed: unable to parse token from invalid AST #10055

alxiong opened this issue Mar 11, 2025 · 9 comments
Assignees
Labels
Cmd-forge-bind Command: forge bind T-bug Type: bug

Comments

@alxiong
Copy link

alxiong commented Mar 11, 2025

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

1.0.0-nightly

What version of Foundryup are you on?

No response

What command(s) is the bug in?

just gen-bindings

Operating System

MacOS

Describe the bug

On 6e86d3c of EspressoSystems/espresso-network#2706, just run gen-bindings which internally run

forge bind --skip test --skip script --libraries contracts/src/libraries/PlonkVerifier.sol:PlonkVerifier:0x5fbdb2315678afecb367f032d93f642f64180aa3 --alloy --contracts ./contracts/src/ --crate-name contract-bindings-alloy --bindings-path contract-bindings-alloy --select "^LightClient(V\d+)?$|^LightClientArbitrum(V\d+)?$|^FeeContract$|^PlonkVerifier(V\d+)?$|^ERC1967Proxy$|^LightClient(V\d+)?Mock$|^PermissionedStakeTable$" --overwrite --force

and got:

[⠊] Compiling 44 files with Solc 0.8.23
[⠒] Solc 0.8.23 finished in 8.32s
Compiler run successful!
Generating bindings for 11 contracts
Error: failed to parse generated tokens as an AST for contract-bindings-alloy/src/lightclientarbitrumv2.rs:lightclientarbitrumv2;
this is likely a bug

Context:
- expected identifier, found keyword `self`

Before this PR, our main has no problem generating bindings (for both ethers and alloys) using the same just command.

p.s. the problem with contract-bindings-alloy/src/lightclientarbitrumv2.rs:lightclientarbitrumv2; also exists for contract-bindings-alloy/src/lightclientv2.rs:lightclientv2; as I have observed that before as well.

cc @sveitser

@alxiong alxiong added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Mar 11, 2025
@github-project-automation github-project-automation bot moved this to Todo in Foundry Mar 11, 2025
@grandizzy
Copy link
Collaborator

grandizzy commented Mar 11, 2025

@alxiong mind to check if problem persists in latest stable? thank you! (be aware that ethers was removed and we're it defaults to alloy)

@alxiong
Copy link
Author

alxiong commented Mar 11, 2025

just updated to the latest, still got this issue:

┌─  espresso-network on  ax/lc-epoch (MERGING) [=$✘»!+] via 🐳 desktop-linux is 📦 v0.1.0 via  v20.18.0 via 🦀 v1.83.0 
└─○ forge bind --skip test --skip script --libraries contracts/src/libraries/PlonkVerifier.sol:PlonkVerifier:0x5fbdb2315678afecb367f032d93f642f64180aa3 --alloy --contracts ./contracts/src/ --crate-name contract-bindings-alloy --bindings-path contract-bindings-alloy --select "^LightClient(V\\d+)?$|^LightClientArbitrum(V\\d+)?$|^FeeContract$|^PlonkVerifier(V\\d+)?$|^ERC1967Proxy$|^LightClient(V\\d+)?Mock$|^PermissionedStakeTable$" --overwrite --force
Warning: This is a nightly build of Foundry. It is recommended to use the latest stable version. Visit https://book.getfoundry.sh/announcements for more information. 
To mute this warning set `FOUNDRY_DISABLE_NIGHTLY_WARNING` in your environment. 

[⠊] Compiling...
[⠰] Compiling 44 files with Solc 0.8.23
[⠔] Solc 0.8.23 finished in 4.50s
Compiler run successful!
Generating bindings for 11 contracts
Error: failed to parse generated tokens as an AST for contract-bindings-alloy/src/lightclientarbitrumv2.rs:lightclientarbitrumv2;
this is likely a bug

Context:
- expected identifier, found keyword `self`

┌─  espresso-network on  ax/lc-epoch (MERGING) [=$✘»!+] via 🐳 desktop-linux is 📦 v0.1.0 via  v20.18.0 via 🦀 v1.83.0 took 5s 
└─○ forge --version
forge Version: 1.0.0-nightly
Commit SHA: 3c048be05726218c405d5d4deec4d3f1ab515f6f
Build Timestamp: 2025-03-11T06:02:02.800485000Z (1741672922)
Build Profile: maxperf

(and yes, I'm only generating alloy bindings)

@alxiong
Copy link
Author

alxiong commented Mar 12, 2025

are you able to reproduce @grandizzy ? (you don't need to enter nix shell, just clone the repo, and run the forge bind above.)

(this is a blocking bug on a somewhat time-sensitive feature I'm working on, so would appreciate if its gets prioritized, I'm happy to hop on call or explaining more about our contracts, if necessary, to help you debug and locate the bug)

@grandizzy
Copy link
Collaborator

yep, going to check why it happens

@grandizzy
Copy link
Collaborator

grandizzy commented Mar 12, 2025

@alxiong self is a reserved keyword, please rename all EvalDomain memory self within contracts/src/libraries/PolynomialEvalV2.sol like this one into something like EvalDomain memory evalDomain (contract PlonkVerifierV2 is PolynomialEvalV2 so bindings fail with self)

Please reopen if still issues, thank you

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Mar 12, 2025
@alxiong
Copy link
Author

alxiong commented Mar 12, 2025

I see, 😂 didn't realize that.

Using the name "self" in library is not uncommon as it appears in the solidity official example: https://docs.soliditylang.org/en/v0.8.29/contracts.html#libraries

While this ticket can be closed, may I suggest adding a compiler warning or hint during binding generations?

@grandizzy
Copy link
Collaborator

grandizzy commented Mar 12, 2025

the error says

Context:
- expected identifier, found keyword `self`

agree could be misleading

@yash-atreya yash-atreya reopened this Mar 12, 2025
@yash-atreya yash-atreya added Cmd-forge-bind Command: forge bind and removed T-needs-triage Type: this issue needs to be labelled labels Mar 12, 2025
@yash-atreya yash-atreya moved this from Done to In Progress in Foundry Mar 12, 2025
@yash-atreya yash-atreya self-assigned this Mar 12, 2025
@yash-atreya
Copy link
Member

yash-atreya commented Mar 12, 2025

Reopening as we have a fix here: alloy-rs/core#903 which will be applied in the next alloy core bump

@alxiong we still can't generate bindings for self due to rust limitations: https://internals.rust-lang.org/t/raw-identifiers-dont-work-for-all-identifiers/9094/4

Having said that, we've opted for mapping self to this in the codegen.

function something(address self) returns (uint256); 

will translate to:

pub struct somethingCall { this: Address };

@alxiong
Copy link
Author

alxiong commented Mar 13, 2025

yes, that's lovely. self or _this are both good choices IMO. This is helpful, thanks for the quick fix.

@yash-atreya yash-atreya moved this from In Progress to Done in Foundry Mar 24, 2025
@grandizzy grandizzy moved this from Done to Completed in Foundry Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-bind Command: forge bind T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants