alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
790 stars 155 forks source link

[Bug] Solidity type alias yields `unresolved custom type:` #744

Open gpsanant opened 2 months ago

gpsanant commented 2 months ago

Component

sol! macro

What version of Alloy are you on?

v0.8.3

Operating System

macOS (Apple Silicon)

Describe the bug

The following abi

DelegationManager.json

along with the following code

mod core {
    alloy::sol!(
        #[allow(missing_docs)]
        #[sol(rpc)]
        DelegationManager,
        "../abis/DelegationManager.json"
    );
}
error: unresolved custom type: DelegatedShares
  --> scenario-generator/src/bin/populate_src.rs:63:5
   |
63 | /     alloy::sol!(
64 | |         #[allow(missing_docs)]
65 | |         #[sol(rpc)]
66 | |         DelegationManager,
67 | |         "../abis/DelegationManager.json"
68 | |     );
   | |_____^
   |
   = note: this error originates in the macro `$crate::sol_types::sol` which comes from the expansion of the macro `alloy::sol` (in Nightly builds, run with -Z macro-backtrace for more info)

If you prefer to build the contracts yourself:

git clone git@github.com:Layr-Labs/eigenlayer-contracts.git
git checkout slashing-magnitues
forge b -C src/contracts

See out/DelegationManager.sol/DelegationManager.json.

I'm using a type alias DelegatedShares for uint256.

mattsse commented 2 months ago

yeah this looks like an issue with type aliases

         {
            "name": "delegatedShares",
            "type": "uint256[]",
            "internalType": "DelegatedShares[]"
          }
DaniPopes commented 2 months ago

There's 2 issues here:

  1. We're ignoring UDVT arrays, fixed in https://github.com/alloy-rs/core/pull/745
  2. After this fix, it still fails because the type doesn't have an assigned contract because it is declared globally, this requires a bit more work to fix
gpsanant commented 2 months ago

Thanks for the prompt response.

For now, I'm actually not using the functions with the custom types so I'll just redefine interfaces.

If I included the types inside of the library contract in which they're defined, would that address (2)?

DaniPopes commented 2 months ago

Yes I think so, if you were to move the type DelegatedShares is uint256; inside of one of the interfaces or libraries referenced by the ABI

gpsanant commented 2 months ago

Cool, confirming that

  1. getting rid of the alias array
  2. stuffing the alias definition inside of the library

Made the contract get imported correctly.

Unfortunately, that makes the solidity syntax quite gross, so I'm temporarily going with

sed -i '' 's/DelegatedShares/uint256/g' out/DelegationManager.sol/DelegationManager.json

which seems to work? :)

dobbobalina2 commented 2 months ago

@DaniPopes Any solutions for using the entrypoint.sol contract from the account abstraction lib found here?

Importing PackedUserOperation is an issue

kayabaNerve commented 3 weeks ago

I believe I have a similar issue here when using the sol macro. I defined an interface which inherits and used types from its parent. When not using the sol macro, yet my own expander which outputs to a file (I need a preprocessor per #602), I get a distinct error of:

proc-macro-error2 API cannot be used outside of entry_point invocation, perhaps you forgot to annotate your #[proc_macro] function with #[proc_macro_error]

I'm unsure exactly how that became my error yet wanted to log it here.