dapptools icon indicating copy to clipboard operation
dapptools copied to clipboard

Dapp has trouble accepting --libraries flag for solc

Open mesozoic-technology opened this issue 5 years ago • 10 comments

If I run

SOLC_FLAGS='--libraries "Controller:0x388be118C18Df3180F4FE0f0A19A4a4180ff45bC SelectiveLiquidity:0x970CC9F79B28662c198167f589af7f854b3BD3F8 ProportionalLiquidity:0x01F6252E54a272145CB2d035bF6a13DBD269426f Shells:0x725C05594edc80E48E8bE2220C9ef02c4d28F617 Swaps:0x9665552d314AC6d8004d3b8f53f6612Af4eF5760"' dapp build --extract

Then it tells me "SelectiveLiquidity:0x970CC9F79B28662c198167f589af7f854b3BD3F8" is not found.

This particular libraries flag works when I perform compiling by running solc instead of dapp.

mesozoic-technology avatar Jul 19 '20 00:07 mesozoic-technology

I believe you need to use the full qualified path of the contract, see https://solidity.readthedocs.io/en/v0.6.11/contracts.html?highlight=library#libraries

MrChico avatar Jul 19 '20 12:07 MrChico

Hmm, the docs from the using the compiler section don't mention a full qualified path, but they do mention something like Controller.sol:Controller:address.

That didn't work for me when compiling with solc, what did wind up working was that same libraries flag mentioned above, run from one directory above where the source files were located including the libraries .

I'll try the full qualified path and see if that works with dapp

mesozoic-technology avatar Jul 21 '20 04:07 mesozoic-technology

I tried it with both a relative path and the absolute path and the same error returned

I did notice it is always the second library in the string, though

mesozoic-technology avatar Jul 22 '20 07:07 mesozoic-technology

I think this is a shell string quoting issue. Try this:

SOLC_FLAGS='--libraries "Controller:0x388be118C18Df3180F4FE0f0A19A4a4180ff45bC SelectiveLiquidity:0x970CC9F79B28662c198167f589af7f854b3BD3F8 ProportionalLiquidity:0x01F6252E54a272145CB2d035bF6a13DBD269426f Shells:0x725C05594edc80E48E8bE2220C9ef02c4d28F617 Swaps:0x9665552d314AC6d8004d3b8f53f6612Af4eF5760"'
dapp build --extract

MrChico avatar Jul 22 '20 09:07 MrChico

with that, there isn't an error, but nor is any linking performed

mesozoic-technology avatar Jul 22 '20 17:07 mesozoic-technology

there is something to what you said -

+ solc --libraries '"Controller:0x13f912AA1ecf7a1AA74f07D59d4A56D21B3139d1' 
Liquidity:0xa3E1838D817a1A63f2Ae1Fd84e531A7E19a183EB 
PartitionedLiquidity:0xb5bB301734d03CDb7861EAC034e7d3590606eE06 
ProportionalLiquidity:0xE678F18C8c47207C9096d5a9Be4e7D468Bd811Df 
SelectiveLiquidity:0x6A5D57BAb80044D73A963B7Fb37e828Dfc327aEd 
Shells:0x718667EB123D0eE9cdAA7c1AC96C05d76B950249 'Swaps:0xC0De35FE50C17db98ce52550cB3B66bD244F43A6"' 

^^ separated onto different lines just for visibility here

Something in the bash script is incorrectly parsing the solc flags. There should only be one double quote at the start and end of the libraries string, but there's a single quote preceding it matched with another single quote after the first library, and a single quote at the start of the last library with the whole thing capped off by another single quote.

mesozoic-technology avatar Jul 22 '20 22:07 mesozoic-technology

here's the culprit

IFS=" " read -r -a opts <<<"$SOLC_FLAGS"

which chops up the libraries string into multiple strings and supplies it to solc here

(set -x; solc "${opts[@]}" "${json_opts[@]}" /=/ "${files[@]}" > "${DAPP_JSON}")

mesozoic-technology avatar Jul 23 '20 01:07 mesozoic-technology

with that, there isn't an error, but nor is any linking performed

I guess you need to export SOLC_FLAGS

MrChico avatar Jul 23 '20 06:07 MrChico

the issue turned out to be that reading SOLC_FLAGS into an array was leaving extra quotes on some elements.

I tried to figure out how to remove those extra quotes and wound up making the entire solc command into a string rather than processing the SOLC_FLAGS from a string

#454

mesozoic-technology avatar Jul 23 '20 16:07 mesozoic-technology

Just FYI, you can dump the library addresses into a file (one per line) and pass the file name to --libraries to avoid quoting altogether.

Hmm, the docs from the using the compiler section don't mention a full qualified path, but they do mention something like Controller.sol:Controller:address.

Yeah, it needs to be fully qualified. There can be more than one library with a given name in the project. Actually, the compiler will accept an unqualified name on the command line but might choose the wrong library if there's a conflict (we still have an open bug about that: https://github.com/ethereum/solidity/issues/10298).

As for the docs, they were indeed inconsistent but have been finally unified: Library Linking. BTW, there's some new stuff there, e.g. support for = as a separator to make the syntax clearer.

cameel avatar Sep 19 '21 17:09 cameel