matter-labs / era-compiler-solidity

Solidity compiler for ZKsync.
Apache License 2.0
62 stars 26 forks source link

Fails to compile Circle's stablecoin contracts with LLVM error #188

Closed cpb8010 closed 1 week ago

cpb8010 commented 1 week ago

πŸ› Bug Report

As originally reported: https://github.com/zkSync-Community-Hub/zksync-developers/discussions/746

πŸ“ Description

Compiling contracts causes a duplicate symbol error to be thrown in LLVM.

πŸ”„ Reproduction Steps

  1. Clone https://github.com/circlefin/stablecoin-evm/tree/master
  2. Perform setup steps (using nvm, yarn, foundry-zksync)
  3. Run forge build --zksync

πŸ€” Expected Behavior

Compile without errors or at least with errors that look like the contracts need to be changed. Not seeing LLVM errors would at least make it look like incompatible Solidity (no selfdestruct is OK)

😯 Current Behavior

Compiling the contracts fails with the following suspicious error

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/v2/FiatTokenV2.sol:FiatTokenV2'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/v2/FiatTokenV2.sol:FiatTokenV2

πŸ–₯️ Environment

Reproduced on both Fedora and OSX, see above log

πŸ“‹ Additional Context

I'm 80% sure someone got these contracts to compile before by making changes, but I don't know who and what changes they made.

πŸ“Ž Log Output

Full error log

stablecoin-evm$ forge build --zksync --zk-optimizer-mode 0
[β ƒ] Using zksolc-1.5.4
[β ’] Compiling (zksync)
[β ”] Compiling 97 files with zksolc and ZKsync solc 0.6.12
[β ’] zksolc and ZKsync solc 0.6.12 finished in 51.53s
Error: 
Compiler run failed:
Warning (7816)
contracts/v2/celo/FiatTokenCeloV2_2.sol:29:5: Warning: Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly.
    /**
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (7816)
contracts/v2/celo/FiatTokenCeloV2_2.sol:74:5: Warning: Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly.
    /**
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (3628)
contracts/upgradeability/AdminUpgradeabilityProxy.sol:31:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
contract AdminUpgradeabilityProxy is UpgradeabilityProxy {
^ (Relevant source part starts here and spans across multiple lines).
contracts/upgradeability/Proxy.sol:35:5: The payable fallback function is defined here.
    fallback() external payable {
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (3628)
contracts/v1/FiatTokenProxy.sol:29:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
contract FiatTokenProxy is AdminUpgradeabilityProxy {
^ (Relevant source part starts here and spans across multiple lines).
contracts/upgradeability/Proxy.sol:35:5: The payable fallback function is defined here.
    fallback() external payable {
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (3628)
contracts/v2/celo/FiatTokenFeeAdapterProxy.sol:29:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
contract FiatTokenFeeAdapterProxy is AdminUpgradeabilityProxy {
^ (Relevant source part starts here and spans across multiple lines).
contracts/upgradeability/Proxy.sol:35:5: The payable fallback function is defined here.
    fallback() external payable {
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (5667)
contracts/v2/celo/FiatTokenCeloV2_2.sol:126:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
        address gatewayFeeRecipient,
        ^-------------------------^
Warning (5667)
contracts/v2/celo/FiatTokenCeloV2_2.sol:131:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
        uint256 gatewayFee,
        ^----------------^
Warning (5667)
contracts/v2/celo/FiatTokenFeeAdapterV1.sol:103:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
        address gatewayFeeRecipient,
        ^-------------------------^
Warning (5667)
contracts/v2/celo/FiatTokenFeeAdapterV1.sol:108:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
        uint256 gatewayFee,
        ^----------------^
Warning (2018)
contracts/v2/FiatTokenV2_2.sol:71:5: Warning: Function state mutability can be restricted to pure
    function _chainId() internal virtual view returns (uint256) {
    ^ (Relevant source part starts here and spans across multiple lines).
Warning (2018)
test/scripts/deploy/celo/deploy-fee-adapter.t.sol:66:5: Warning: Function state mutability can be restricted to view
    function validateImpl(FiatTokenFeeAdapterV1 impl) internal {
    ^ (Relevant source part starts here and spans across multiple lines).
Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/test/MockFiatTokenWithEditableBalanceAndBlacklistStates.sol:MockFiatTokenWithEditableBalanceAndBlacklistStates'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/test/MockFiatTokenWithEditableBalanceAndBlacklistStates.sol:MockFiatTokenWithEditableBalanceAndBlacklistStates

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/test/MockFiatTokenWithEditableChainId.sol:MockFiatTokenWithEditableChainId'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/test/MockFiatTokenWithEditableChainId.sol:MockFiatTokenWithEditableChainId

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/test/UpgradedFiatTokenV2_2NewFieldsTest.sol:UpgradedFiatTokenV2_2NewFieldsTest'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/test/UpgradedFiatTokenV2_2NewFieldsTest.sol:UpgradedFiatTokenV2_2NewFieldsTest

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/test/celo/MockFiatTokenCeloWithExposedFunctions.sol:MockFiatTokenCeloWithExposedFunctions'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/test/celo/MockFiatTokenCeloWithExposedFunctions.sol:MockFiatTokenCeloWithExposedFunctions

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/v2/FiatTokenV2.sol:FiatTokenV2'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/v2/FiatTokenV2.sol:FiatTokenV2

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/v2/FiatTokenV2_1.sol:FiatTokenV2_1'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/v2/FiatTokenV2_1.sol:FiatTokenV2_1

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/v2/FiatTokenV2_2.sol:FiatTokenV2_2'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/v2/FiatTokenV2_2.sol:FiatTokenV2_2

Error
Error: "~/.zksync/zksolc-linux-amd64-musl-v1.5.4" subprocess failed with exit code None:

LLVM ERROR: Duplicating library sub-symbols
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump: 
0.  Running pass 'Function Pass Manager' on module 'contracts/v2/celo/FiatTokenCeloV2_2.sol:FiatTokenCeloV2_2'.
1.  Running pass 'EraVM Assembly Printer' on function '@main'
--> contracts/v2/celo/FiatTokenCeloV2_2.sol:FiatTokenCeloV2_2

Error
Error: LLVM IR generator definition pass: The `SELFDESTRUCT` instruction is not supported
--> contracts/v2/upgrader/helpers/V2UpgraderHelper.sol:V2UpgraderHelper

Error
Error: LLVM IR generator definition pass: The `SELFDESTRUCT` instruction is not supported
--> contracts/v2/upgrader/helpers/V2_2UpgraderHelper.sol:V2_2UpgraderHelper
cpb8010 commented 1 week ago

Running with just hardhat gives a different, but equally suspicious error

Compiler run failed: Error: Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:61):Stack too deep when compiling inline assembly: Variable dataEnd is 2 slot(s) too deep inside the stack. CompilerError: Stack too deep when compiling inline assembly: Variable dataEnd is 2 slot(s) too deep inside the stack.

hedgar2017 commented 1 week ago

@cpb8010 we're investigating the first error and preparing a fix: it is on zksolc's side.

The 2nd one is on solc's side. Is there a zksolc section in the hardhat config? I can only see solc here.

cpb8010 commented 1 week ago

@cpb8010 we're investigating the first error and preparing a fix: it is on zksolc's side.

The 2nd one is on solc's side. Is there a zksolc section in the hardhat config? I can only see solc here.

Oh ignore the second error then, I was trying to reproduce it another way

hedgar2017 commented 1 week ago

@cpb8010 fixed in zksolc v1.5.7! The release will be finalized today after the verifier gets updated.