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

Dynamic linking not supported in create command #1338

Closed
2 tasks done
evmcheb opened this issue Apr 17, 2022 · 27 comments
Closed
2 tasks done

Dynamic linking not supported in create command #1338

evmcheb opened this issue Apr 17, 2022 · 27 comments
Labels
C-forge Command: forge Cmd-forge-create Command: forge create T-bug Type: bug

Comments

@evmcheb
Copy link
Contributor

evmcheb commented Apr 17, 2022

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 (a84a281 2022-04-16T00:15:54.385011+00:00)

What command(s) is the bug in?

forge create

Operating System

macOS (M1)

Describe the bug

Still getting a Dynamic linking not supported in create command error after changing foundry.toml when deploying to a testnet.

First ran forge create Library which works fine.

Got the address from that then add the following line to foundry.toml

libraries= ['./src/lib/LibraryContract.sol:Library:0xaddress']

I've also tried adding the contract that imports the library:

libraries= ['./src/Contract.sol:Library:0xaddress']

@evmcheb evmcheb added the T-bug Type: bug label Apr 17, 2022
@onbjerg
Copy link
Member

onbjerg commented Apr 17, 2022

Do you have multiple contracts that use the library, or do you use multiple libraries? They all need to be specified, otherwise the bytecode is unlinked. Also, can you try running forge build --force with the libraries set before forge create?

@onbjerg onbjerg added C-forge Command: forge Cmd-forge-create Command: forge create labels Apr 17, 2022
@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 17, 2022

forge build --force doesn't help

This is what my foundry.toml looks like. Have included other (internal, so shouldn't matter) libraries as well. The ChainlinkTWAP library is the offensive one

image

@onbjerg
Copy link
Member

onbjerg commented Apr 18, 2022

Interesting, @mattsse any insight? AFAIK this happens in ethers-solc

@onbjerg onbjerg added this to Foundry Apr 18, 2022
@onbjerg onbjerg moved this to Todo in Foundry Apr 18, 2022
@onbjerg
Copy link
Member

onbjerg commented Apr 21, 2022

Is Chainlink TWAP actually a library? I.e. is it defined with library as opposed to contract? I can't seem to find it anywhere.

Also, I'm very interested in figuring out what the root cause of this is, since I cannot reproduce the behavior myself. If you're available through a more real-time channel like Telegram (https://t.me/foundry_support, ping @onbjerg) please let me know.

@onbjerg onbjerg moved this from Todo to May be solved in Foundry Apr 22, 2022
@mattsse
Copy link
Member

mattsse commented Apr 22, 2022

sry guys overlooked this one...
hmm, not sure what the root cause for this is,
does forge config correctly print the libraries @evmcheb?

what contract is causing this error when being deployed?
can you have a look at its bytecode to make sure it includes placeholders?
if so I'd appreciate if you can share that part of the bytecode at least

@evmcheb

This comment was marked as resolved.

@onbjerg
Copy link
Member

onbjerg commented Apr 26, 2022

A lot of the source files mentioned in your original screenshot are not present in the Solidity cache file (e.g. Auction.sol and AuctionOracle.sol). Can you post an updated config with the correct file names? 😄

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 27, 2022

Hey @onbjerg,

thanks for taking a look.

here is the current foundry.toml

[default]
src = 'src'
out = 'out'
libs = ['lib']
optimizer=true
via_ir=true
libraries= [
    './src/SizeAuctionDiscount.sol:Chainlink:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',
    './src/SizeAuction.sol:ChainlinkTWAP:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',
    './src/test/ChainlinkTWAP.t.sol:ChainlinkTWAP:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',

    './src/SizeAuction.sol:Math:0x902f6cf364b8d9470d5793a9b2b2e86bddd21e0c',
    './src/SizeAuctionDiscount.sol:Math:0x902f6cf364b8d9470d5793a9b2b2e86bddd21e0c',
    './src/test/SizeAuction.t.sol:Math:0x902f6cf364b8d9470d5793a9b2b2e86bddd21e0c',

    './src/SizeAuction.sol:SafeTransferLib:0xd98e62914908aec93797657b09974421ee5a3b7e',
    './src/SizeAuctionDiscount.sol:SafeTransferLib:0xd98e62914908aec93797657b09974421ee5a3b7e',
    ]

@onbjerg
Copy link
Member

onbjerg commented Apr 27, 2022

Is this line a typo:

'./src/SizeAuctionDiscount.sol:Chainlink:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',

It says Chainlink, not ChainlinkTWAP. Additionally, it does not appear that SizeAuction.sol imports a file that looks to contain a library named ChainlinkTWAP. Is it defined in SizeAuction.sol?

You also specify libraries for some of the tests - this is not needed, unless you are running fork tests. In that case, there seems to be additional tests which make use of libraries that do not appear in libraries.

What contract are you trying to deploy?

@onbjerg
Copy link
Member

onbjerg commented Apr 28, 2022

Ok, seems I was wrong as well: The path is to the library contract, I will make sure the book reflects this

Another person had this issue on Telegram, and using absolute paths worked for them. This indicates that we probably do have a regression somewhere, since relative paths used to work

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 28, 2022

Thanks for picking up that typo - but it still doesn't work hmm.
I'm trying to deploy SizeAuctionDiscount.sol

Actually, my fork (kovan) testing has been working fine - even the tests with SizeAuctionDiscount. Testing both library deploys + calls, and SizeAuctionDiscount unit tests (which call ChainlinkTWAP library).

I included those extra libraries as a safe measure but probs don't need them because they are all internal funcs? They get embedded as bytecode right?

[default]
src = 'src'
out = 'out'
libs = ['lib']
optimizer=true
via_ir=true
libraries= [
    '/Users/cheb/Documents/GitHub/size-contracts/src/SizeAuctionDiscount.sol:ChainlinkTWAP:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',
    '/Users/cheb/Documents/GitHub/size-contracts/src/SizeAuction.sol:ChainlinkTWAP:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',
    '/Users/cheb/Documents/GitHub/size-contracts/src/test/ChainlinkTWAP.t.sol:ChainlinkTWAP:0xffedba5e171c4f15abaaabc86e8bd01f9b54dae5',
]

@mattsse
Copy link
Member

mattsse commented Apr 28, 2022

libraries is expected to be in the form of path to lib file:lib name:address.
the path to lib file should support remappings.

what does forge remappings print?

if you could provide a simple repro that be helpful.

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

Ahh I've tried path to lib file and path to contract that uses lib file. Wasn't sure

image

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

it's the lib file because we're populating the libraries object in the json compiler input

so solc will we able to link them.

actually, I better have another look at the docs again.

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

Clean repo: https://github.com/evmcheb/chainlink-test

Steps taken:

  1. forge install https://github.com/smartcontractkit/chainlink/

  2. forge test -vvv --fork-url https://kovan.infura.io/v3/xxxx works great without adding anything to foundry.toml. Gets latest ETH price & twap price

  3. forge create ChainlinkTWAP --rpc-url https://kovan.infura.io/v3/xxxx. Deploys successfully to 0x9068c42f083774e78165ec9ac2b9e8b5d26db52e

  4. Added ./src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e to libraries in foundry.toml

  5. forge config outputs

[default]
auto_detect_solc = true
block_base_fee_per_gas = 0
block_coinbase = '0x0000000000000000000000000000000000000000'
block_difficulty = 0
block_number = 0
block_timestamp = 0
bytecode_hash = 'ipfs'
cache = true
cache_path = 'cache'
evm_version = 'london'
extra_output = []
extra_output_files = []
ffi = false
force = false
fuzz_max_global_rejects = 65536
fuzz_max_local_rejects = 1024
fuzz_runs = 256
gas_limit = 9223372036854775807
gas_price = 0
gas_reports = ['*']
ignored_error_codes = [1878]
initial_balance = '0xffffffffffffffffffffffff'
libraries = ['./src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e']
libs = ['lib']
names = false
no_storage_caching = false
offline = false
optimizer = true
optimizer_runs = 200
out = 'out'
remappings = [
    'chainlink/=lib/chainlink/',
    'ds-test/=lib/ds-test/src/',
]
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
sizes = false
sparse_mode = false
src = 'src'
test = 'test'
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
verbosity = 0
via_ir = false

[default.rpc_storage_caching]
chains = 'all'
endpoints = 'all'
  1. forge create Contract --rpc-url https://kovan.infura.io/v3/xxx - fails with Dynamic linking error

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

thank you!
will use this repro to finally get this fixed properly

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

Yo I got it to deploy! Changing the relative path to absolute path.

libraries = ['/Users/cheb/Documents/GitHub/chainlink-test/src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e']

You're right, it should Path To Actual Library File.sol (and the docs are correct). But only works with the absolute path. I will have another fiddle with the main repo but looks like it should be aight for now.

Thanks for being a huge help.

quicc note for people that might have similar issues

  • If you set FOUNDRY_LIBRARIES env variable once, removing it from .rc is not enough, you need to unset it.

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

You're right, it should Path To Actual Library File.sol (and the docs are correct). But only works with the absolute path.

can you clarify because this is ::

libraries = ['/Users/cheb/Documents/GitHub/chainlink-test/src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e']
which contradicts the docs:

The top level key is the the name of the source file where the library is used.

🤔
but I just tried with the path to the contract and it does not link even though the libraries input is:

     "src/Contract.sol": {
        "ChainlinkTWAP": "0xc154fde3374125a29df92b0957ff80be897ff1dc"
      }

only this works

    "libraries": {
      "src/libraries/ChainlinkTWAP.sol": {
        "ChainlinkTWAP": "0xb77fffcdcf99b8a3a380f5e163071f3640831c40"
      }
    }

you should be able to declare the libraries like this

['src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x....']

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

am referencing this part of the docs

https://book.getfoundry.sh/reference/config.html#libraries

An array of libraries to link against in the following format: file:lib:address, for example: src/MyLibrary.sol:MyLibrary:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4.

except src/MyLibrary.sol:MyLibrary:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4. does not work for me, only the absolute path ala

/Users/cheb/Documents/GitHub/chainlink-test/src/MyLibrary.sol:MyLibrary:<addr>

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

hmm can't reproduce this on master because relative paths and "src/.." should be supported now

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

Haven't had any trouble with relative paths anywhere else in foundry so yeah defs weird.

Just confirmed in foundry.toml (after forge clean):

This doesn't work

libraries= [
    'src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e',
]

Nor does this work

libraries= [
    './src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e',
]

But this does work

libraries= [
    '/Users/cheb/Documents/GitHub/chainlink-test/src/libraries/ChainlinkTWAP.sol:ChainlinkTWAP:0x9068c42f083774e78165ec9ac2b9e8b5d26db52e',
]

m1 mac - in vscode zsh terminal with solidity plugin. forge 0.2.0

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

what's your forge --version?

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

forge 0.2.0 (a84a281 2022-04-16T00:15:54.385011+00:00)

will update now

@mattsse
Copy link
Member

mattsse commented Apr 29, 2022

oh that's outdated, can you try after updating, the fix should be in

@evmcheb
Copy link
Contributor Author

evmcheb commented Apr 29, 2022

works with relative paths now - thx mbd!!!!

@onbjerg
Copy link
Member

onbjerg commented Apr 30, 2022

Will close this since it seems your issue was fixed? 😄

@onbjerg onbjerg closed this as completed Apr 30, 2022
Repository owner moved this from May be solved to Done in Foundry Apr 30, 2022
@Divide-By-0
Copy link

I still have this error "Dynamic linking not supported in create command" when trying to pass libraries in to create on command line, i.e. forge create --libraries LIB2:$LIB2_ADDR,LIB1:$LIB1_ADDR. Forge build passes and putting them in my foundry.toml passes, but then all of my tests break once it's in the toml.

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-create Command: forge create T-bug Type: bug
Projects
Archived in project
Development

No branches or pull requests

4 participants